From a623076f124e69956f7d43d479faf41432770c17 Mon Sep 17 00:00:00 2001 From: Nick Linker Date: Fri, 11 Sep 2020 00:56:57 +0600 Subject: [PATCH 1/7] Method created Signed-off-by: Nick Linker --- iml-api/src/graphql.rs | 47 ++++++++++++++++++++++++++++++++++++++++++ iml-api/src/main.rs | 32 ++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/iml-api/src/graphql.rs b/iml-api/src/graphql.rs index 1c41e2e16f..74001ac49d 100644 --- a/iml-api/src/graphql.rs +++ b/iml-api/src/graphql.rs @@ -284,6 +284,7 @@ impl QueryRoot { Ok(xs) } + #[graphql(arguments( limit(description = "paging limit, defaults to 20"), offset(description = "Offset into items, defaults to 0"), @@ -322,6 +323,52 @@ impl QueryRoot { Ok(snapshots) } + + /// Fetch the list of commands + #[graphql(arguments( + limit(description = "paging limit, defaults to 20"), + offset(description = "Offset into items, defaults to 0"), + dir(description = "Sort direction, defaults to desc"), + is_active(description = "Command status, active means not completed, default is true"), + msg(description = "Substring of the command's message"), + ))] + async fn commands( + context: &Context, + limit: Option, + offset: Option, + dir: Option, + is_active: Option, + msg: Option, + ) -> juniper::FieldResult> { + let dir = dir.unwrap_or_default(); + let is_completed = !is_active.unwrap_or(true); + let commands = sqlx::query_as!( + Command, + r#" + SELECT + id + complete, + errored, + cancelled, + message, + created_at + FROM chroma_core_command c + WHERE complete = $4 AND ($5::text IS NULL OR c.message LIKE '%' || $5 || '%') + ORDER BY + CASE WHEN $3 = 'asc' THEN c.created_at END ASC, + CASE WHEN $3 = 'desc' THEN c.created_at END DESC + OFFSET $1 LIMIT $2"#, + offset.unwrap_or(0) as i64, + limit.unwrap_or(20) as i64, + dir.deref(), + is_completed, + msg, + ) + .fetch_all(&context.pg_pool) + .await?; + + Ok(commands) + } } #[juniper::graphql_object(Context = Context)] diff --git a/iml-api/src/main.rs b/iml-api/src/main.rs index 96e376f922..705c07e302 100644 --- a/iml-api/src/main.rs +++ b/iml-api/src/main.rs @@ -12,18 +12,50 @@ use iml_manager_env::get_pool_limit; use iml_postgres::get_db_pool; use iml_rabbit::{self, create_connection_filter}; use iml_wire_types::Conf; +use iml_postgres::sqlx; use std::sync::Arc; use warp::Filter; // Default pool limit if not overridden by POOL_LIMIT const DEFAULT_POOL_LIMIT: u32 = 5; +async fn dbg_main() -> Result<(), Box> { + let conf = Conf { + allow_anonymous_read: true, + build: "Not Loaded".to_string(), + version: "0".to_string(), + exa_version: None, + is_release: false, + branding: Default::default(), + use_stratagem: false, + monitor_sfa: false, + }; + let pg_pool = sqlx::postgres::PgPoolOptions::new() + .max_connections(1) + .connect("postgres://chroma@tiv1:8432/chroma") + .await?; + + let mut num_rows = sqlx::query!("SELECT COUNT(*) FROM chroma_core_command") + .fetch_one(&pg_pool) + .await? + .count + .expect("Something impossible, count should not return None"); + + println!("{:?}", num_rows); + Ok(()) + + // let pg_pool = get_db_pool(get_pool_limit().unwrap_or(DEFAULT_POOL_LIMIT)).await?; + +} + #[tokio::main] async fn main() -> Result<(), Box> { iml_tracing::init(); let addr = iml_manager_env::get_iml_api_addr(); + return dbg_main().await; + let conf = Conf { allow_anonymous_read: iml_manager_env::get_allow_anonymous_read(), build: iml_manager_env::get_build(), From 1897786039ae10f9f6940eaab83286dbd54ac648 Mon Sep 17 00:00:00 2001 From: Nick Linker Date: Fri, 11 Sep 2020 18:23:01 +0600 Subject: [PATCH 2/7] Debugging routine Signed-off-by: Nick Linker --- iml-api/src/graphql.rs | 32 ++++++++++++++++++++++++++++---- iml-api/src/main.rs | 6 +++--- vagrant/Vagrantfile | 1 + 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/iml-api/src/graphql.rs b/iml-api/src/graphql.rs index 74001ac49d..df67597a85 100644 --- a/iml-api/src/graphql.rs +++ b/iml-api/src/graphql.rs @@ -19,6 +19,7 @@ use std::{ sync::Arc, }; use warp::Filter; +use iml_postgres::sqlx::types::chrono::{DateTime, Utc}; #[derive(juniper::GraphQLObject)] /// A Corosync Node found in `crm_mon` @@ -340,13 +341,24 @@ impl QueryRoot { is_active: Option, msg: Option, ) -> juniper::FieldResult> { + + #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] + #[cfg_attr(feature = "graphql", derive(juniper::GraphQLObject))] + struct TransientCommand { + pub cancelled: bool, + pub complete: bool, + pub created_at: DateTime, + pub errored: bool, + pub id: i32, + pub message: String, + } let dir = dir.unwrap_or_default(); let is_completed = !is_active.unwrap_or(true); - let commands = sqlx::query_as!( - Command, + let commands: Vec = sqlx::query_as!( + TransientCommand, r#" SELECT - id + id, complete, errored, cancelled, @@ -366,7 +378,19 @@ impl QueryRoot { ) .fetch_all(&context.pg_pool) .await?; - + let commands = commands.into_iter().map(|t| + Command { + cancelled: t.cancelled, + complete: t.complete, + created_at: t.created_at.to_string(), + errored: t.errored, + id: t.id, + jobs: vec![], + logs: "".to_string(), + message: t.message.clone(), + resource_uri: format!("/api/command/{}/", t.id), + }) + .collect::>(); Ok(commands) } } diff --git a/iml-api/src/main.rs b/iml-api/src/main.rs index 705c07e302..1075091f47 100644 --- a/iml-api/src/main.rs +++ b/iml-api/src/main.rs @@ -35,7 +35,7 @@ async fn dbg_main() -> Result<(), Box> { .connect("postgres://chroma@tiv1:8432/chroma") .await?; - let mut num_rows = sqlx::query!("SELECT COUNT(*) FROM chroma_core_command") + let num_rows = sqlx::query!("SELECT COUNT(*) FROM chroma_core_command") .fetch_one(&pg_pool) .await? .count @@ -52,10 +52,10 @@ async fn dbg_main() -> Result<(), Box> { async fn main() -> Result<(), Box> { iml_tracing::init(); - let addr = iml_manager_env::get_iml_api_addr(); - return dbg_main().await; + let addr = iml_manager_env::get_iml_api_addr(); + let conf = Conf { allow_anonymous_read: iml_manager_env::get_allow_anonymous_read(), build: iml_manager_env::get_build(), diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile index f5f58bda19..fc92f2f9d6 100644 --- a/vagrant/Vagrantfile +++ b/vagrant/Vagrantfile @@ -133,6 +133,7 @@ Vagrant.configure('2') do |config| adm.vm.network 'forwarded_port', guest: 5432, host: 8432 adm.vm.network 'forwarded_port', guest: 443, host: 8443 adm.vm.network 'forwarded_port', guest: 7443, host: 7443 + adm.vm.network 'forwarded_port', guest: 5672, host: 8672 # Admin / management network provision_mgmt_net adm, '10' From fc024c0bc1341331cc6afea4b90dcf1f879317cf Mon Sep 17 00:00:00 2001 From: Nick Linker Date: Mon, 14 Sep 2020 02:21:36 +0600 Subject: [PATCH 3/7] Debugging wip Signed-off-by: Nick Linker --- iml-api/src/graphql.rs | 4 +- iml-api/src/main.rs | 48 +++++-------- iml-manager-env/src/lib.rs | 7 ++ iml-postgres/src/lib.rs | 6 ++ sqlx-data.json | 140 ++++++++++++++----------------------- 5 files changed, 86 insertions(+), 119 deletions(-) diff --git a/iml-api/src/graphql.rs b/iml-api/src/graphql.rs index df67597a85..52b96904e8 100644 --- a/iml-api/src/graphql.rs +++ b/iml-api/src/graphql.rs @@ -289,7 +289,7 @@ impl QueryRoot { #[graphql(arguments( limit(description = "paging limit, defaults to 20"), offset(description = "Offset into items, defaults to 0"), - dir(description = "Sort direction, defaults to asc"), + dir(description = "Sort direction, defaults to ASC"), fsname(description = "Filesystem the snapshot was taken from"), name(description = "Name of the snapshot"), ))] @@ -329,7 +329,7 @@ impl QueryRoot { #[graphql(arguments( limit(description = "paging limit, defaults to 20"), offset(description = "Offset into items, defaults to 0"), - dir(description = "Sort direction, defaults to desc"), + dir(description = "Sort direction, defaults to ASC"), is_active(description = "Command status, active means not completed, default is true"), msg(description = "Substring of the command's message"), ))] diff --git a/iml-api/src/main.rs b/iml-api/src/main.rs index 1075091f47..4bb1afcb8b 100644 --- a/iml-api/src/main.rs +++ b/iml-api/src/main.rs @@ -12,47 +12,33 @@ use iml_manager_env::get_pool_limit; use iml_postgres::get_db_pool; use iml_rabbit::{self, create_connection_filter}; use iml_wire_types::Conf; -use iml_postgres::sqlx; use std::sync::Arc; use warp::Filter; +use std::env; // Default pool limit if not overridden by POOL_LIMIT const DEFAULT_POOL_LIMIT: u32 = 5; -async fn dbg_main() -> Result<(), Box> { - let conf = Conf { - allow_anonymous_read: true, - build: "Not Loaded".to_string(), - version: "0".to_string(), - exa_version: None, - is_release: false, - branding: Default::default(), - use_stratagem: false, - monitor_sfa: false, - }; - let pg_pool = sqlx::postgres::PgPoolOptions::new() - .max_connections(1) - .connect("postgres://chroma@tiv1:8432/chroma") - .await?; - - let num_rows = sqlx::query!("SELECT COUNT(*) FROM chroma_core_command") - .fetch_one(&pg_pool) - .await? - .count - .expect("Something impossible, count should not return None"); - - println!("{:?}", num_rows); - Ok(()) - - // let pg_pool = get_db_pool(get_pool_limit().unwrap_or(DEFAULT_POOL_LIMIT)).await?; - -} - #[tokio::main] async fn main() -> Result<(), Box> { iml_tracing::init(); - return dbg_main().await; + env::set_var("PROXY_HOST", "localhost"); + env::set_var("IML_API_PORT", "8080"); + env::set_var("AMQP_BROKER_URL", "false"); + env::set_var("DB_HOST", "tiv1"); + env::set_var("DB_PORT", "8432"); + env::set_var("DB_USER", "chroma"); + env::set_var("DB_PASSWORD", ""); + env::set_var("DB_NAME", "chroma"); + + env::set_var("ALLOW_ANONYMOUS_READ", "true"); + env::set_var("BUILD", ""); + env::set_var("VERSION", "6.1.0-1"); + env::set_var("IS_RELEASE", "false"); + // env::set_var("EXA_VERSION"); + env::set_var("BRANDING", "Whamcloud"); + env::set_var("USE_STRATAGEM", "false"); let addr = iml_manager_env::get_iml_api_addr(); diff --git a/iml-manager-env/src/lib.rs b/iml-manager-env/src/lib.rs index 635d3a96cf..c3059f40d7 100644 --- a/iml-manager-env/src/lib.rs +++ b/iml-manager-env/src/lib.rs @@ -238,6 +238,13 @@ pub fn get_db_host() -> Option { empty_str_to_none(get_var("DB_HOST")) } +pub fn get_db_port() -> Option { + env::var("DB_PORT") + .ok() + .map(|l| l.parse().ok()) + .flatten() +} + pub fn get_db_name() -> Option { empty_str_to_none(get_var("DB_NAME")) } diff --git a/iml-postgres/src/lib.rs b/iml-postgres/src/lib.rs index dc8babfd61..aeb411f718 100644 --- a/iml-postgres/src/lib.rs +++ b/iml-postgres/src/lib.rs @@ -30,6 +30,12 @@ pub async fn get_db_pool(pool_size: u32) -> Result { opts }; + opts = if let Some(x) = iml_manager_env::get_db_port() { + opts.port(x) + } else { + opts + }; + opts = if let Some(x) = iml_manager_env::get_db_name() { opts.database(&x) } else { diff --git a/sqlx-data.json b/sqlx-data.json index 72d4808f0a..6a7dbe10f4 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -13,16 +13,6 @@ "nullable": [] } }, - "07317ab9fddc66855470ba840c4b68a340b188eabcfce0bc8fed4f410df1b7db": { - "query": "INSERT INTO chroma_core_managedhost\n (\n state_modified_at,\n state,\n immutable_state,\n not_deleted,\n address,\n fqdn,\n nodename,\n boot_time,\n needs_update,\n corosync_ring0,\n install_method,\n content_type_id,\n server_profile_id)\n VALUES\n ('2020-07-02 15:50:34.356076-04', 'unconfigured', 'f', 't', 'foo', 'foo.bar', '', Null, 'f', '', '', Null, 'foo')\n ON CONFLICT DO NOTHING", - "describe": { - "columns": [], - "parameters": { - "Left": [] - }, - "nullable": [] - } - }, "07d03b70c5d9813b0432b582ad8239edd1a3ce7ef7ce9be7c22dbb8189db8861": { "query": "select id from chroma_core_managedfilesystem where name = $1 and not_deleted = 't'", "describe": { @@ -595,72 +585,6 @@ ] } }, - "2eedae727c7336f9edd217051685ebfd1e7a8e28597a0803aad92147c49f6805": { - "query": "SELECT * FROM chroma_core_lustreclientmount", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "state_modified_at", - "type_info": "Timestamptz" - }, - { - "ordinal": 2, - "name": "state", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "immutable_state", - "type_info": "Bool" - }, - { - "ordinal": 4, - "name": "not_deleted", - "type_info": "Bool" - }, - { - "ordinal": 5, - "name": "content_type_id", - "type_info": "Int4" - }, - { - "ordinal": 6, - "name": "filesystem", - "type_info": "Varchar" - }, - { - "ordinal": 7, - "name": "host_id", - "type_info": "Int4" - }, - { - "ordinal": 8, - "name": "mountpoints", - "type_info": "TextArray" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - false, - false, - false, - false, - true, - true, - false, - false, - false - ] - } - }, "36188079437a0e3df0d4584e22b15673bfadcf66128168b59e13717eedcd8470": { "query": "\n DELETE FROM corosync_node\n USING corosync_node_managed_host\n WHERE id = corosync_node_id\n AND host_id = $1\n AND corosync_node_id != ALL($2::corosync_node_key[])\n ", "describe": { @@ -1428,6 +1352,60 @@ "nullable": [] } }, + "7828c607ff8a0dadd487f58c1417ec2e38910a38cdb59aac17abebcb645f683f": { + "query": "\n SELECT\n id,\n complete,\n errored,\n cancelled,\n message,\n created_at\n FROM chroma_core_command c\n WHERE complete = $4 AND ($5::text IS NULL OR c.message LIKE '%' || $5 || '%')\n ORDER BY\n CASE WHEN $3 = 'asc' THEN c.created_at END ASC,\n CASE WHEN $3 = 'desc' THEN c.created_at END DESC\n OFFSET $1 LIMIT $2", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "complete", + "type_info": "Bool" + }, + { + "ordinal": 2, + "name": "errored", + "type_info": "Bool" + }, + { + "ordinal": 3, + "name": "cancelled", + "type_info": "Bool" + }, + { + "ordinal": 4, + "name": "message", + "type_info": "Varchar" + }, + { + "ordinal": 5, + "name": "created_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [ + "Int8", + "Int8", + "Text", + "Bool", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false + ] + } + }, "7bee1c38d05ac3f8bcf4d48b375c740341121c04d2f5b04ceb1d58ef0a006c08": { "query": "\n SELECT * FROM chroma_core_lustreclientmount\n WHERE\n state = 'mounted'\n AND not_deleted = 't'\n AND id != ALL($1)\n LIMIT $2\n ", "describe": { @@ -2687,16 +2665,6 @@ ] } }, - "b8e774ab32b79eb3f2d87b7f373b609831f72f63f716dcbb7917871531466b1a": { - "query": "\n INSERT INTO chroma_core_serverprofile\n (name, ui_name, ui_description, managed, worker, user_selectable, initial_state, ntp, corosync, corosync2, pacemaker, \"default\")\n VALUES\n ('foo', 'foo', 'foo', 'f', 'f', 't', 'bar', 'f', 'f', 'f', 'f', 't')\n ON CONFLICT DO NOTHING\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [] - }, - "nullable": [] - } - }, "bb7fb337cfeac9a17eefb21a498e76be70c2f395473ba42331f51cc5e6d48679": { "query": "\n INSERT INTO chroma_core_device\n (fqdn, devices)\n VALUES ($1, $2)\n ON CONFLICT (fqdn) DO UPDATE\n SET devices = EXCLUDED.devices\n ", "describe": { From 356f647c053e1bdd525f62be0a42c63e68e4028c Mon Sep 17 00:00:00 2001 From: Nick Linker Date: Mon, 14 Sep 2020 19:07:26 +0600 Subject: [PATCH 4/7] Finished Signed-off-by: Nick Linker --- iml-api/src/graphql.rs | 93 +++++++++---------- iml-api/src/main.rs | 18 ---- sqlx-data.json | 200 ++++++++++++++++++++++++++++++----------- 3 files changed, 193 insertions(+), 118 deletions(-) diff --git a/iml-api/src/graphql.rs b/iml-api/src/graphql.rs index 52b96904e8..2799a86f8a 100644 --- a/iml-api/src/graphql.rs +++ b/iml-api/src/graphql.rs @@ -6,7 +6,7 @@ use crate::{command::get_command, error::ImlApiError}; use futures::{TryFutureExt, TryStreamExt}; use iml_postgres::{sqlx, PgPool}; use iml_rabbit::Pool; -use iml_wire_types::{snapshot::Snapshot, Command}; +use iml_wire_types::{snapshot::Snapshot, Command, EndpointName, Job}; use itertools::Itertools; use juniper::{ http::{graphiql::graphiql_source, GraphQLRequest}, @@ -19,7 +19,6 @@ use std::{ sync::Arc, }; use warp::Filter; -use iml_postgres::sqlx::types::chrono::{DateTime, Utc}; #[derive(juniper::GraphQLObject)] /// A Corosync Node found in `crm_mon` @@ -331,7 +330,7 @@ impl QueryRoot { offset(description = "Offset into items, defaults to 0"), dir(description = "Sort direction, defaults to ASC"), is_active(description = "Command status, active means not completed, default is true"), - msg(description = "Substring of the command's message"), + msg(description = "Substring of the command's message, null or empty matches all"), ))] async fn commands( context: &Context, @@ -341,56 +340,58 @@ impl QueryRoot { is_active: Option, msg: Option, ) -> juniper::FieldResult> { - - #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] - #[cfg_attr(feature = "graphql", derive(juniper::GraphQLObject))] - struct TransientCommand { - pub cancelled: bool, - pub complete: bool, - pub created_at: DateTime, - pub errored: bool, - pub id: i32, - pub message: String, - } let dir = dir.unwrap_or_default(); let is_completed = !is_active.unwrap_or(true); - let commands: Vec = sqlx::query_as!( - TransientCommand, - r#" + let commands: Vec = sqlx::query!( + r#" SELECT - id, + c.id AS id, + cancelled, complete, errored, - cancelled, - message, - created_at + created_at, + array_agg(cj.job_id)::integer[] AS job_ids, + message FROM chroma_core_command c - WHERE complete = $4 AND ($5::text IS NULL OR c.message LIKE '%' || $5 || '%') + JOIN chroma_core_command_jobs cj ON c.id = cj.command_id + WHERE complete = $4 AND ($5::TEXT IS NULL OR c.message LIKE '%' || $5 || '%') + GROUP BY c.id ORDER BY - CASE WHEN $3 = 'asc' THEN c.created_at END ASC, - CASE WHEN $3 = 'desc' THEN c.created_at END DESC - OFFSET $1 LIMIT $2"#, - offset.unwrap_or(0) as i64, - limit.unwrap_or(20) as i64, - dir.deref(), - is_completed, - msg, - ) - .fetch_all(&context.pg_pool) - .await?; - let commands = commands.into_iter().map(|t| - Command { - cancelled: t.cancelled, - complete: t.complete, - created_at: t.created_at.to_string(), - errored: t.errored, - id: t.id, - jobs: vec![], - logs: "".to_string(), - message: t.message.clone(), - resource_uri: format!("/api/command/{}/", t.id), - }) - .collect::>(); + CASE WHEN $3 = 'asc' THEN c.id END ASC, + CASE WHEN $3 = 'desc' THEN c.id END DESC + OFFSET $1 LIMIT $2 + "#, + offset.unwrap_or(0) as i64, + limit.unwrap_or(20) as i64, + dir.deref(), + is_completed, + msg, + ) + .fetch_all(&context.pg_pool) + .map_ok(|xs: Vec<_>| { + xs.into_iter() + .map(|x| Command { + id: x.id, + cancelled: x.cancelled, + complete: x.complete, + errored: x.errored, + created_at: x.created_at.format("%Y-%m-%dT%T%.6f").to_string(), + jobs: { + x.job_ids + .unwrap_or_default() + .into_iter() + .map(|job_id: i32| { + format!("/api/{}/{}/", Job::<()>::endpoint_name(), job_id) + }) + .collect::>() + }, + logs: "".to_string(), + message: x.message.clone(), + resource_uri: format!("/api/{}/{}/", Command::endpoint_name(), x.id), + }) + .collect::>() + }) + .await?; Ok(commands) } } diff --git a/iml-api/src/main.rs b/iml-api/src/main.rs index 4bb1afcb8b..96e376f922 100644 --- a/iml-api/src/main.rs +++ b/iml-api/src/main.rs @@ -14,7 +14,6 @@ use iml_rabbit::{self, create_connection_filter}; use iml_wire_types::Conf; use std::sync::Arc; use warp::Filter; -use std::env; // Default pool limit if not overridden by POOL_LIMIT const DEFAULT_POOL_LIMIT: u32 = 5; @@ -23,23 +22,6 @@ const DEFAULT_POOL_LIMIT: u32 = 5; async fn main() -> Result<(), Box> { iml_tracing::init(); - env::set_var("PROXY_HOST", "localhost"); - env::set_var("IML_API_PORT", "8080"); - env::set_var("AMQP_BROKER_URL", "false"); - env::set_var("DB_HOST", "tiv1"); - env::set_var("DB_PORT", "8432"); - env::set_var("DB_USER", "chroma"); - env::set_var("DB_PASSWORD", ""); - env::set_var("DB_NAME", "chroma"); - - env::set_var("ALLOW_ANONYMOUS_READ", "true"); - env::set_var("BUILD", ""); - env::set_var("VERSION", "6.1.0-1"); - env::set_var("IS_RELEASE", "false"); - // env::set_var("EXA_VERSION"); - env::set_var("BRANDING", "Whamcloud"); - env::set_var("USE_STRATAGEM", "false"); - let addr = iml_manager_env::get_iml_api_addr(); let conf = Conf { diff --git a/sqlx-data.json b/sqlx-data.json index 6a7dbe10f4..d5d2b04775 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -13,6 +13,16 @@ "nullable": [] } }, + "07317ab9fddc66855470ba840c4b68a340b188eabcfce0bc8fed4f410df1b7db": { + "query": "INSERT INTO chroma_core_managedhost\n (\n state_modified_at,\n state,\n immutable_state,\n not_deleted,\n address,\n fqdn,\n nodename,\n boot_time,\n needs_update,\n corosync_ring0,\n install_method,\n content_type_id,\n server_profile_id)\n VALUES\n ('2020-07-02 15:50:34.356076-04', 'unconfigured', 'f', 't', 'foo', 'foo.bar', '', Null, 'f', '', '', Null, 'foo')\n ON CONFLICT DO NOTHING", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + } + }, "07d03b70c5d9813b0432b582ad8239edd1a3ce7ef7ce9be7c22dbb8189db8861": { "query": "select id from chroma_core_managedfilesystem where name = $1 and not_deleted = 't'", "describe": { @@ -585,6 +595,72 @@ ] } }, + "2eedae727c7336f9edd217051685ebfd1e7a8e28597a0803aad92147c49f6805": { + "query": "SELECT * FROM chroma_core_lustreclientmount", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "state_modified_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 2, + "name": "state", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "immutable_state", + "type_info": "Bool" + }, + { + "ordinal": 4, + "name": "not_deleted", + "type_info": "Bool" + }, + { + "ordinal": 5, + "name": "content_type_id", + "type_info": "Int4" + }, + { + "ordinal": 6, + "name": "filesystem", + "type_info": "Varchar" + }, + { + "ordinal": 7, + "name": "host_id", + "type_info": "Int4" + }, + { + "ordinal": 8, + "name": "mountpoints", + "type_info": "TextArray" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + false, + false, + true, + true, + false, + false, + false + ] + } + }, "36188079437a0e3df0d4584e22b15673bfadcf66128168b59e13717eedcd8470": { "query": "\n DELETE FROM corosync_node\n USING corosync_node_managed_host\n WHERE id = corosync_node_id\n AND host_id = $1\n AND corosync_node_id != ALL($2::corosync_node_key[])\n ", "describe": { @@ -1352,60 +1428,6 @@ "nullable": [] } }, - "7828c607ff8a0dadd487f58c1417ec2e38910a38cdb59aac17abebcb645f683f": { - "query": "\n SELECT\n id,\n complete,\n errored,\n cancelled,\n message,\n created_at\n FROM chroma_core_command c\n WHERE complete = $4 AND ($5::text IS NULL OR c.message LIKE '%' || $5 || '%')\n ORDER BY\n CASE WHEN $3 = 'asc' THEN c.created_at END ASC,\n CASE WHEN $3 = 'desc' THEN c.created_at END DESC\n OFFSET $1 LIMIT $2", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "complete", - "type_info": "Bool" - }, - { - "ordinal": 2, - "name": "errored", - "type_info": "Bool" - }, - { - "ordinal": 3, - "name": "cancelled", - "type_info": "Bool" - }, - { - "ordinal": 4, - "name": "message", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "created_at", - "type_info": "Timestamptz" - } - ], - "parameters": { - "Left": [ - "Int8", - "Int8", - "Text", - "Bool", - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - false - ] - } - }, "7bee1c38d05ac3f8bcf4d48b375c740341121c04d2f5b04ceb1d58ef0a006c08": { "query": "\n SELECT * FROM chroma_core_lustreclientmount\n WHERE\n state = 'mounted'\n AND not_deleted = 't'\n AND id != ALL($1)\n LIMIT $2\n ", "describe": { @@ -2330,6 +2352,66 @@ ] } }, + "a9ccd8503e661db11e58568d58eef3fbc5f2598e208e5bf06c58705ab8be7b3e": { + "query": "\n SELECT\n c.id AS id,\n cancelled,\n complete,\n errored,\n created_at,\n array_agg(cj.job_id)::integer[] AS job_ids,\n message\n FROM chroma_core_command c\n JOIN chroma_core_command_jobs cj ON c.id = cj.command_id\n WHERE complete = $4 AND ($5::TEXT IS NULL OR c.message LIKE '%' || $5 || '%')\n GROUP BY c.id\n ORDER BY\n CASE WHEN $3 = 'asc' THEN c.id END ASC,\n CASE WHEN $3 = 'desc' THEN c.id END DESC\n OFFSET $1 LIMIT $2\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "cancelled", + "type_info": "Bool" + }, + { + "ordinal": 2, + "name": "complete", + "type_info": "Bool" + }, + { + "ordinal": 3, + "name": "errored", + "type_info": "Bool" + }, + { + "ordinal": 4, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 5, + "name": "job_ids", + "type_info": "Int4Array" + }, + { + "ordinal": 6, + "name": "message", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [ + "Int8", + "Int8", + "Text", + "Bool", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false + ] + } + }, "ac70df86a340aefc11b2e55dbfc1ce6720f52d9055bc892c98779daf83ea849f": { "query": "\n INSERT INTO corosync_target_resource (\n id,\n cluster_id,\n resource_agent,\n role,\n active,\n orphaned,\n managed,\n failed,\n failure_ignored,\n nodes_running_on,\n active_node,\n mount_point\n )\n SELECT\n id,\n $12,\n resource_agent,\n role,\n active,\n orphaned,\n managed,\n failed,\n failure_ignored,\n nodes_running_on,\n active_node::corosync_node_key,\n mount_point\n FROM UNNEST(\n $1::text[],\n $2::text[],\n $3::text[],\n $4::bool[],\n $5::bool[],\n $6::bool[],\n $7::bool[],\n $8::bool[],\n $9::int[],\n $10::text[],\n $11::text[]\n )\n AS t(\n id,\n resource_agent,\n role,\n active,\n orphaned,\n managed,\n failed,\n failure_ignored,\n nodes_running_on,\n active_node,\n mount_point\n )\n ON CONFLICT (id, cluster_id) DO UPDATE\n SET\n resource_agent = excluded.resource_agent,\n role = excluded.role,\n active = excluded.active,\n orphaned = excluded.orphaned,\n managed = excluded.managed,\n failed = excluded.failed,\n failure_ignored = excluded.failure_ignored,\n nodes_running_on = excluded.nodes_running_on,\n active_node = excluded.active_node,\n mount_point = excluded.mount_point\n ", "describe": { @@ -2665,6 +2747,16 @@ ] } }, + "b8e774ab32b79eb3f2d87b7f373b609831f72f63f716dcbb7917871531466b1a": { + "query": "\n INSERT INTO chroma_core_serverprofile\n (name, ui_name, ui_description, managed, worker, user_selectable, initial_state, ntp, corosync, corosync2, pacemaker, \"default\")\n VALUES\n ('foo', 'foo', 'foo', 'f', 'f', 't', 'bar', 'f', 'f', 'f', 'f', 't')\n ON CONFLICT DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + } + }, "bb7fb337cfeac9a17eefb21a498e76be70c2f395473ba42331f51cc5e6d48679": { "query": "\n INSERT INTO chroma_core_device\n (fqdn, devices)\n VALUES ($1, $2)\n ON CONFLICT (fqdn) DO UPDATE\n SET devices = EXCLUDED.devices\n ", "describe": { From 53084addf98bf2d111648d05b5fdb7c059d13c9d Mon Sep 17 00:00:00 2001 From: Nick Linker Date: Mon, 14 Sep 2020 19:29:26 +0600 Subject: [PATCH 5/7] Fix more formatting Signed-off-by: Nick Linker --- iml-manager-env/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/iml-manager-env/src/lib.rs b/iml-manager-env/src/lib.rs index c3059f40d7..1222d3bc05 100644 --- a/iml-manager-env/src/lib.rs +++ b/iml-manager-env/src/lib.rs @@ -239,10 +239,7 @@ pub fn get_db_host() -> Option { } pub fn get_db_port() -> Option { - env::var("DB_PORT") - .ok() - .map(|l| l.parse().ok()) - .flatten() + env::var("DB_PORT").ok().map(|l| l.parse().ok()).flatten() } pub fn get_db_name() -> Option { From 66459fba8fc7c198a706c63fac00b02330dcd1b3 Mon Sep 17 00:00:00 2001 From: Nick Linker Date: Tue, 15 Sep 2020 15:57:57 +0600 Subject: [PATCH 6/7] Using case insensitive search for a message Signed-off-by: Nick Linker --- iml-api/src/graphql.rs | 38 ++++---- sqlx-data.json | 206 ++++++++++++----------------------------- 2 files changed, 79 insertions(+), 165 deletions(-) diff --git a/iml-api/src/graphql.rs b/iml-api/src/graphql.rs index 2799a86f8a..d002610f0e 100644 --- a/iml-api/src/graphql.rs +++ b/iml-api/src/graphql.rs @@ -329,7 +329,7 @@ impl QueryRoot { limit(description = "paging limit, defaults to 20"), offset(description = "Offset into items, defaults to 0"), dir(description = "Sort direction, defaults to ASC"), - is_active(description = "Command status, active means not completed, default is true"), + is_active(description = "Command status, active means not completed, default is false"), msg(description = "Substring of the command's message, null or empty matches all"), ))] async fn commands( @@ -341,26 +341,26 @@ impl QueryRoot { msg: Option, ) -> juniper::FieldResult> { let dir = dir.unwrap_or_default(); - let is_completed = !is_active.unwrap_or(true); + let is_completed = !is_active.unwrap_or(false); let commands: Vec = sqlx::query!( r#" - SELECT - c.id AS id, - cancelled, - complete, - errored, - created_at, - array_agg(cj.job_id)::integer[] AS job_ids, - message - FROM chroma_core_command c - JOIN chroma_core_command_jobs cj ON c.id = cj.command_id - WHERE complete = $4 AND ($5::TEXT IS NULL OR c.message LIKE '%' || $5 || '%') - GROUP BY c.id - ORDER BY - CASE WHEN $3 = 'asc' THEN c.id END ASC, - CASE WHEN $3 = 'desc' THEN c.id END DESC - OFFSET $1 LIMIT $2 - "#, + SELECT + c.id AS id, + cancelled, + complete, + errored, + created_at, + array_agg(cj.job_id)::INT[] AS job_ids, + message + FROM chroma_core_command c + JOIN chroma_core_command_jobs cj ON c.id = cj.command_id + WHERE complete = $4 + AND ($5::TEXT IS NULL OR c.message ILIKE '%' || $5 || '%') + GROUP BY c.id + ORDER BY + CASE WHEN $3 = 'asc' THEN c.id END ASC, + CASE WHEN $3 = 'desc' THEN c.id END DESC + OFFSET $1 LIMIT $2 "#, offset.unwrap_or(0) as i64, limit.unwrap_or(20) as i64, dir.deref(), diff --git a/sqlx-data.json b/sqlx-data.json index d5d2b04775..f608897cfa 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -13,16 +13,6 @@ "nullable": [] } }, - "07317ab9fddc66855470ba840c4b68a340b188eabcfce0bc8fed4f410df1b7db": { - "query": "INSERT INTO chroma_core_managedhost\n (\n state_modified_at,\n state,\n immutable_state,\n not_deleted,\n address,\n fqdn,\n nodename,\n boot_time,\n needs_update,\n corosync_ring0,\n install_method,\n content_type_id,\n server_profile_id)\n VALUES\n ('2020-07-02 15:50:34.356076-04', 'unconfigured', 'f', 't', 'foo', 'foo.bar', '', Null, 'f', '', '', Null, 'foo')\n ON CONFLICT DO NOTHING", - "describe": { - "columns": [], - "parameters": { - "Left": [] - }, - "nullable": [] - } - }, "07d03b70c5d9813b0432b582ad8239edd1a3ce7ef7ce9be7c22dbb8189db8861": { "query": "select id from chroma_core_managedfilesystem where name = $1 and not_deleted = 't'", "describe": { @@ -595,72 +585,6 @@ ] } }, - "2eedae727c7336f9edd217051685ebfd1e7a8e28597a0803aad92147c49f6805": { - "query": "SELECT * FROM chroma_core_lustreclientmount", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "state_modified_at", - "type_info": "Timestamptz" - }, - { - "ordinal": 2, - "name": "state", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "immutable_state", - "type_info": "Bool" - }, - { - "ordinal": 4, - "name": "not_deleted", - "type_info": "Bool" - }, - { - "ordinal": 5, - "name": "content_type_id", - "type_info": "Int4" - }, - { - "ordinal": 6, - "name": "filesystem", - "type_info": "Varchar" - }, - { - "ordinal": 7, - "name": "host_id", - "type_info": "Int4" - }, - { - "ordinal": 8, - "name": "mountpoints", - "type_info": "TextArray" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - false, - false, - false, - false, - true, - true, - false, - false, - false - ] - } - }, "36188079437a0e3df0d4584e22b15673bfadcf66128168b59e13717eedcd8470": { "query": "\n DELETE FROM corosync_node\n USING corosync_node_managed_host\n WHERE id = corosync_node_id\n AND host_id = $1\n AND corosync_node_id != ALL($2::corosync_node_key[])\n ", "describe": { @@ -2034,6 +1958,66 @@ ] } }, + "96578c531d3344f51586bd7f502d258fe105acafebd361a5458d14fa4c26af8d": { + "query": "\n SELECT\n c.id AS id,\n cancelled,\n complete,\n errored,\n created_at,\n array_agg(cj.job_id)::INT[] AS job_ids,\n message\n FROM chroma_core_command c\n JOIN chroma_core_command_jobs cj ON c.id = cj.command_id\n WHERE complete = $4\n AND ($5::TEXT IS NULL OR c.message ILIKE '%' || $5 || '%')\n GROUP BY c.id\n ORDER BY\n CASE WHEN $3 = 'asc' THEN c.id END ASC,\n CASE WHEN $3 = 'desc' THEN c.id END DESC\n OFFSET $1 LIMIT $2 ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "cancelled", + "type_info": "Bool" + }, + { + "ordinal": 2, + "name": "complete", + "type_info": "Bool" + }, + { + "ordinal": 3, + "name": "errored", + "type_info": "Bool" + }, + { + "ordinal": 4, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 5, + "name": "job_ids", + "type_info": "Int4Array" + }, + { + "ordinal": 6, + "name": "message", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [ + "Int8", + "Int8", + "Text", + "Bool", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false + ] + } + }, "9a4c05da9d9233e6b3fa63ca2f50cf90feb0c305b1cc05e0eb2edcf2572db4ba": { "query": "select * from chroma_core_volume where not_deleted = 't'", "describe": { @@ -2352,66 +2336,6 @@ ] } }, - "a9ccd8503e661db11e58568d58eef3fbc5f2598e208e5bf06c58705ab8be7b3e": { - "query": "\n SELECT\n c.id AS id,\n cancelled,\n complete,\n errored,\n created_at,\n array_agg(cj.job_id)::integer[] AS job_ids,\n message\n FROM chroma_core_command c\n JOIN chroma_core_command_jobs cj ON c.id = cj.command_id\n WHERE complete = $4 AND ($5::TEXT IS NULL OR c.message LIKE '%' || $5 || '%')\n GROUP BY c.id\n ORDER BY\n CASE WHEN $3 = 'asc' THEN c.id END ASC,\n CASE WHEN $3 = 'desc' THEN c.id END DESC\n OFFSET $1 LIMIT $2\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "cancelled", - "type_info": "Bool" - }, - { - "ordinal": 2, - "name": "complete", - "type_info": "Bool" - }, - { - "ordinal": 3, - "name": "errored", - "type_info": "Bool" - }, - { - "ordinal": 4, - "name": "created_at", - "type_info": "Timestamptz" - }, - { - "ordinal": 5, - "name": "job_ids", - "type_info": "Int4Array" - }, - { - "ordinal": 6, - "name": "message", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [ - "Int8", - "Int8", - "Text", - "Bool", - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - null, - false - ] - } - }, "ac70df86a340aefc11b2e55dbfc1ce6720f52d9055bc892c98779daf83ea849f": { "query": "\n INSERT INTO corosync_target_resource (\n id,\n cluster_id,\n resource_agent,\n role,\n active,\n orphaned,\n managed,\n failed,\n failure_ignored,\n nodes_running_on,\n active_node,\n mount_point\n )\n SELECT\n id,\n $12,\n resource_agent,\n role,\n active,\n orphaned,\n managed,\n failed,\n failure_ignored,\n nodes_running_on,\n active_node::corosync_node_key,\n mount_point\n FROM UNNEST(\n $1::text[],\n $2::text[],\n $3::text[],\n $4::bool[],\n $5::bool[],\n $6::bool[],\n $7::bool[],\n $8::bool[],\n $9::int[],\n $10::text[],\n $11::text[]\n )\n AS t(\n id,\n resource_agent,\n role,\n active,\n orphaned,\n managed,\n failed,\n failure_ignored,\n nodes_running_on,\n active_node,\n mount_point\n )\n ON CONFLICT (id, cluster_id) DO UPDATE\n SET\n resource_agent = excluded.resource_agent,\n role = excluded.role,\n active = excluded.active,\n orphaned = excluded.orphaned,\n managed = excluded.managed,\n failed = excluded.failed,\n failure_ignored = excluded.failure_ignored,\n nodes_running_on = excluded.nodes_running_on,\n active_node = excluded.active_node,\n mount_point = excluded.mount_point\n ", "describe": { @@ -2747,16 +2671,6 @@ ] } }, - "b8e774ab32b79eb3f2d87b7f373b609831f72f63f716dcbb7917871531466b1a": { - "query": "\n INSERT INTO chroma_core_serverprofile\n (name, ui_name, ui_description, managed, worker, user_selectable, initial_state, ntp, corosync, corosync2, pacemaker, \"default\")\n VALUES\n ('foo', 'foo', 'foo', 'f', 'f', 't', 'bar', 'f', 'f', 'f', 'f', 't')\n ON CONFLICT DO NOTHING\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [] - }, - "nullable": [] - } - }, "bb7fb337cfeac9a17eefb21a498e76be70c2f395473ba42331f51cc5e6d48679": { "query": "\n INSERT INTO chroma_core_device\n (fqdn, devices)\n VALUES ($1, $2)\n ON CONFLICT (fqdn) DO UPDATE\n SET devices = EXCLUDED.devices\n ", "describe": { From e2f3888513f661a82dcc986005235ca0f75c5a95 Mon Sep 17 00:00:00 2001 From: Nick Linker Date: Tue, 15 Sep 2020 20:02:22 +0600 Subject: [PATCH 7/7] Regenerate sqlx to fix the CI error Signed-off-by: Nick Linker --- sqlx-data.json | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/sqlx-data.json b/sqlx-data.json index f608897cfa..3b534925c8 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -13,6 +13,16 @@ "nullable": [] } }, + "07317ab9fddc66855470ba840c4b68a340b188eabcfce0bc8fed4f410df1b7db": { + "query": "INSERT INTO chroma_core_managedhost\n (\n state_modified_at,\n state,\n immutable_state,\n not_deleted,\n address,\n fqdn,\n nodename,\n boot_time,\n needs_update,\n corosync_ring0,\n install_method,\n content_type_id,\n server_profile_id)\n VALUES\n ('2020-07-02 15:50:34.356076-04', 'unconfigured', 'f', 't', 'foo', 'foo.bar', '', Null, 'f', '', '', Null, 'foo')\n ON CONFLICT DO NOTHING", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + } + }, "07d03b70c5d9813b0432b582ad8239edd1a3ce7ef7ce9be7c22dbb8189db8861": { "query": "select id from chroma_core_managedfilesystem where name = $1 and not_deleted = 't'", "describe": { @@ -585,6 +595,72 @@ ] } }, + "2eedae727c7336f9edd217051685ebfd1e7a8e28597a0803aad92147c49f6805": { + "query": "SELECT * FROM chroma_core_lustreclientmount", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "state_modified_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 2, + "name": "state", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "immutable_state", + "type_info": "Bool" + }, + { + "ordinal": 4, + "name": "not_deleted", + "type_info": "Bool" + }, + { + "ordinal": 5, + "name": "content_type_id", + "type_info": "Int4" + }, + { + "ordinal": 6, + "name": "filesystem", + "type_info": "Varchar" + }, + { + "ordinal": 7, + "name": "host_id", + "type_info": "Int4" + }, + { + "ordinal": 8, + "name": "mountpoints", + "type_info": "TextArray" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + false, + false, + true, + true, + false, + false, + false + ] + } + }, "36188079437a0e3df0d4584e22b15673bfadcf66128168b59e13717eedcd8470": { "query": "\n DELETE FROM corosync_node\n USING corosync_node_managed_host\n WHERE id = corosync_node_id\n AND host_id = $1\n AND corosync_node_id != ALL($2::corosync_node_key[])\n ", "describe": { @@ -2671,6 +2747,16 @@ ] } }, + "b8e774ab32b79eb3f2d87b7f373b609831f72f63f716dcbb7917871531466b1a": { + "query": "\n INSERT INTO chroma_core_serverprofile\n (name, ui_name, ui_description, managed, worker, user_selectable, initial_state, ntp, corosync, corosync2, pacemaker, \"default\")\n VALUES\n ('foo', 'foo', 'foo', 'f', 'f', 't', 'bar', 'f', 'f', 'f', 'f', 't')\n ON CONFLICT DO NOTHING\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + } + }, "bb7fb337cfeac9a17eefb21a498e76be70c2f395473ba42331f51cc5e6d48679": { "query": "\n INSERT INTO chroma_core_device\n (fqdn, devices)\n VALUES ($1, $2)\n ON CONFLICT (fqdn) DO UPDATE\n SET devices = EXCLUDED.devices\n ", "describe": {