-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add graphman unassign/reassign commands to graphman graphql api #5678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shiyasmohd
merged 10 commits into
master
from
shiyasmohd/add-unassign-reassign-to-graphman-api
Feb 17, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1fd4012
core,server: add graphman unassign/reassign command to graphql api
shiyasmohd 228896d
server: update deployment locator
shiyasmohd c16059f
server: added a common reponse type for graphman graphql api
shiyasmohd 3543972
core,server: changed reponse type for graphman unassign/reassign grap…
shiyasmohd b674be5
server: add CompletedWithWarnings return type
shiyasmohd 999825d
server: graphman graphql api tests added for unassign/reassign
shiyasmohd 9a060df
server: improve warning message for graphman graphql api and clean up…
shiyasmohd e67c6aa
server: correction in EmptyResponse creation in deployment mutation m…
shiyasmohd d0d7d5c
server: update warning message for reassign on invalid node ID in dep…
shiyasmohd 38ceded
core,node,server: use common fn for graphman cli & server for unassig…
shiyasmohd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| pub mod info; | ||
| pub mod pause; | ||
| pub mod reassign; | ||
| pub mod resume; | ||
| pub mod unassign; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use anyhow::anyhow; | ||
| use graph::components::store::DeploymentLocator; | ||
| use graph::components::store::StoreEvent; | ||
| use graph::prelude::EntityChange; | ||
| use graph::prelude::NodeId; | ||
| use graph_store_postgres::command_support::catalog; | ||
| use graph_store_postgres::command_support::catalog::Site; | ||
| use graph_store_postgres::connection_pool::ConnectionPool; | ||
| use graph_store_postgres::NotificationSender; | ||
| use thiserror::Error; | ||
|
|
||
| use crate::deployment::DeploymentSelector; | ||
| use crate::deployment::DeploymentVersionSelector; | ||
| use crate::GraphmanError; | ||
|
|
||
| pub struct Deployment { | ||
| locator: DeploymentLocator, | ||
| site: Site, | ||
| } | ||
|
|
||
| impl Deployment { | ||
| pub fn locator(&self) -> &DeploymentLocator { | ||
| &self.locator | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub enum ReassignDeploymentError { | ||
| #[error("deployment '{0}' is already assigned to '{1}'")] | ||
| AlreadyAssigned(String, String), | ||
|
|
||
| #[error(transparent)] | ||
| Common(#[from] GraphmanError), | ||
| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| pub enum ReassignResult { | ||
| EmptyResponse, | ||
| CompletedWithWarnings(Vec<String>), | ||
| } | ||
|
|
||
| pub fn load_deployment( | ||
| primary_pool: ConnectionPool, | ||
| deployment: &DeploymentSelector, | ||
| ) -> Result<Deployment, ReassignDeploymentError> { | ||
| let mut primary_conn = primary_pool.get().map_err(GraphmanError::from)?; | ||
|
|
||
| let locator = crate::deployment::load_deployment_locator( | ||
| &mut primary_conn, | ||
| deployment, | ||
| &DeploymentVersionSelector::All, | ||
| )?; | ||
|
|
||
| let mut catalog_conn = catalog::Connection::new(primary_conn); | ||
|
|
||
| let site = catalog_conn | ||
| .locate_site(locator.clone()) | ||
| .map_err(GraphmanError::from)? | ||
| .ok_or_else(|| { | ||
| GraphmanError::Store(anyhow!("deployment site not found for '{locator}'")) | ||
| })?; | ||
|
|
||
| Ok(Deployment { locator, site }) | ||
| } | ||
|
|
||
| pub fn reassign_deployment( | ||
| primary_pool: ConnectionPool, | ||
| notification_sender: Arc<NotificationSender>, | ||
| deployment: &Deployment, | ||
| node: &NodeId, | ||
| ) -> Result<ReassignResult, ReassignDeploymentError> { | ||
| let primary_conn = primary_pool.get().map_err(GraphmanError::from)?; | ||
| let mut catalog_conn = catalog::Connection::new(primary_conn); | ||
|
|
||
| let changes: Vec<EntityChange> = match catalog_conn | ||
| .assigned_node(&deployment.site) | ||
| .map_err(GraphmanError::from)? | ||
| { | ||
| Some(curr) => { | ||
| if &curr == node { | ||
| vec![] | ||
| } else { | ||
| catalog_conn | ||
| .reassign_subgraph(&deployment.site, &node) | ||
| .map_err(GraphmanError::from)? | ||
| } | ||
| } | ||
| None => catalog_conn | ||
| .assign_subgraph(&deployment.site, &node) | ||
| .map_err(GraphmanError::from)?, | ||
| }; | ||
isum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if changes.is_empty() { | ||
| return Err(ReassignDeploymentError::AlreadyAssigned( | ||
| deployment.locator.to_string(), | ||
| node.to_string(), | ||
| )); | ||
| } | ||
|
|
||
| catalog_conn | ||
| .send_store_event(¬ification_sender, &StoreEvent::new(changes)) | ||
| .map_err(GraphmanError::from)?; | ||
|
|
||
| let mirror = catalog::Mirror::primary_only(primary_pool); | ||
| let count = mirror | ||
| .assignments(&node) | ||
| .map_err(GraphmanError::from)? | ||
| .len(); | ||
| if count == 1 { | ||
| let warning_msg = format!("This is the only deployment assigned to '{}'. Please make sure that the node ID is spelled correctly.",node.as_str()); | ||
| Ok(ReassignResult::CompletedWithWarnings(vec![warning_msg])) | ||
| } else { | ||
| Ok(ReassignResult::EmptyResponse) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use anyhow::anyhow; | ||
| use graph::components::store::DeploymentLocator; | ||
| use graph::components::store::StoreEvent; | ||
| use graph_store_postgres::command_support::catalog; | ||
| use graph_store_postgres::command_support::catalog::Site; | ||
| use graph_store_postgres::connection_pool::ConnectionPool; | ||
| use graph_store_postgres::NotificationSender; | ||
| use thiserror::Error; | ||
|
|
||
| use crate::deployment::DeploymentSelector; | ||
| use crate::deployment::DeploymentVersionSelector; | ||
| use crate::GraphmanError; | ||
|
|
||
| pub struct AssignedDeployment { | ||
| locator: DeploymentLocator, | ||
| site: Site, | ||
| } | ||
|
|
||
| impl AssignedDeployment { | ||
| pub fn locator(&self) -> &DeploymentLocator { | ||
| &self.locator | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub enum UnassignDeploymentError { | ||
| #[error("deployment '{0}' is already unassigned")] | ||
| AlreadyUnassigned(String), | ||
|
|
||
| #[error(transparent)] | ||
| Common(#[from] GraphmanError), | ||
| } | ||
|
|
||
| pub fn load_assigned_deployment( | ||
| primary_pool: ConnectionPool, | ||
| deployment: &DeploymentSelector, | ||
| ) -> Result<AssignedDeployment, UnassignDeploymentError> { | ||
| let mut primary_conn = primary_pool.get().map_err(GraphmanError::from)?; | ||
|
|
||
| let locator = crate::deployment::load_deployment_locator( | ||
| &mut primary_conn, | ||
| deployment, | ||
| &DeploymentVersionSelector::All, | ||
| )?; | ||
|
|
||
| let mut catalog_conn = catalog::Connection::new(primary_conn); | ||
|
|
||
| let site = catalog_conn | ||
| .locate_site(locator.clone()) | ||
| .map_err(GraphmanError::from)? | ||
| .ok_or_else(|| { | ||
| GraphmanError::Store(anyhow!("deployment site not found for '{locator}'")) | ||
| })?; | ||
|
|
||
| match catalog_conn | ||
| .assigned_node(&site) | ||
| .map_err(GraphmanError::from)? | ||
| { | ||
| Some(_) => Ok(AssignedDeployment { locator, site }), | ||
| None => Err(UnassignDeploymentError::AlreadyUnassigned( | ||
| locator.to_string(), | ||
| )), | ||
| } | ||
| } | ||
|
|
||
| pub fn unassign_deployment( | ||
| primary_pool: ConnectionPool, | ||
| notification_sender: Arc<NotificationSender>, | ||
| deployment: AssignedDeployment, | ||
| ) -> Result<(), GraphmanError> { | ||
| let primary_conn = primary_pool.get()?; | ||
| let mut catalog_conn = catalog::Connection::new(primary_conn); | ||
|
|
||
| let changes = catalog_conn.unassign_subgraph(&deployment.site)?; | ||
| catalog_conn.send_store_event(¬ification_sender, &StoreEvent::new(changes))?; | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| pub mod info; | ||
| pub mod pause; | ||
| pub mod reassign; | ||
| pub mod restart; | ||
| pub mod resume; | ||
| pub mod unassign; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use anyhow::Result; | ||
| use graph::prelude::NodeId; | ||
| use graph_store_postgres::connection_pool::ConnectionPool; | ||
| use graph_store_postgres::NotificationSender; | ||
| use graphman::commands::deployment::reassign::{ | ||
| load_deployment, reassign_deployment, ReassignResult, | ||
| }; | ||
| use graphman::deployment::DeploymentSelector; | ||
|
|
||
| pub fn run( | ||
| primary_pool: ConnectionPool, | ||
| notification_sender: Arc<NotificationSender>, | ||
| deployment: DeploymentSelector, | ||
| node: &NodeId, | ||
| ) -> Result<()> { | ||
| let deployment = load_deployment(primary_pool.clone(), &deployment)?; | ||
|
|
||
| println!("Reassigning deployment {}", deployment.locator()); | ||
|
|
||
| let reassign_result = | ||
| reassign_deployment(primary_pool, notification_sender, &deployment, node)?; | ||
|
|
||
| match reassign_result { | ||
| ReassignResult::EmptyResponse => { | ||
| println!( | ||
| "Deployment {} assigned to node {}", | ||
| deployment.locator(), | ||
| node | ||
| ); | ||
| } | ||
| ReassignResult::CompletedWithWarnings(warnings) => { | ||
| for msg in warnings { | ||
| println!("{}", msg); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use anyhow::Result; | ||
| use graph_store_postgres::connection_pool::ConnectionPool; | ||
| use graph_store_postgres::NotificationSender; | ||
| use graphman::commands::deployment::unassign::load_assigned_deployment; | ||
| use graphman::commands::deployment::unassign::unassign_deployment; | ||
| use graphman::deployment::DeploymentSelector; | ||
|
|
||
| pub fn run( | ||
| primary_pool: ConnectionPool, | ||
| notification_sender: Arc<NotificationSender>, | ||
| deployment: DeploymentSelector, | ||
| ) -> Result<()> { | ||
| let assigned_deployment = load_assigned_deployment(primary_pool.clone(), &deployment)?; | ||
|
|
||
| println!("Unassigning deployment {}", assigned_deployment.locator()); | ||
|
|
||
| unassign_deployment(primary_pool, notification_sender, assigned_deployment)?; | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| use async_graphql::SimpleObject; | ||
|
|
||
| #[derive(Clone, Debug, SimpleObject)] | ||
| pub struct CompletedWithWarnings { | ||
| pub warnings: Vec<String>, | ||
| } | ||
|
|
||
| impl CompletedWithWarnings { | ||
| pub fn new(warnings: Vec<String>) -> Self { | ||
| Self { warnings } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note. It is not very common for a Rust function to return
T::EmptyResponseon success (it makes sense for GraphQL types because of GraphQL style and conventions). Maybe a better name for this variant isReassignResult::Ok, but that's not really important right nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I've created a new issue for that.