-
Notifications
You must be signed in to change notification settings - Fork 97
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
API Peer Validation for SQL Server #483
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 |
---|---|---|
|
@@ -7,7 +7,7 @@ use catalog::{Catalog, CatalogConfig, WorkflowDetails}; | |
use clap::Parser; | ||
use cursor::PeerCursors; | ||
use dashmap::DashMap; | ||
use flow_rs::grpc::FlowGrpcClient; | ||
use flow_rs::grpc::{FlowGrpcClient, PeerValidationResult}; | ||
use peer_bigquery::BigQueryQueryExecutor; | ||
use peer_connections::{PeerConnectionTracker, PeerConnections}; | ||
use peer_cursor::{ | ||
|
@@ -153,7 +153,6 @@ impl NexusBackend { | |
let unsupported_peer_types = vec![ | ||
4, // EVENTHUB | ||
5, // S3 | ||
6, // SQLSERVER | ||
7, // EVENTHUBGROUP | ||
]; | ||
!unsupported_peer_types.contains(&peer_type) | ||
|
@@ -205,6 +204,53 @@ impl NexusBackend { | |
} | ||
} | ||
|
||
async fn validate_peer<'a>(&self, peer_type: i32, peer: &Peer) -> anyhow::Result<()> { | ||
if peer_type != 6 { | ||
let peer_executor = self.get_peer_executor(&peer).await.map_err(|err| { | ||
PgWireError::ApiError(Box::new(PgError::Internal { | ||
err_msg: format!("unable to get peer executor: {:?}", err), | ||
})) | ||
})?; | ||
peer_executor.is_connection_valid().await.map_err(|e| { | ||
self.executors.remove(&peer.name); // Otherwise it will keep returning the earlier configured executor | ||
PgWireError::UserError(Box::new(ErrorInfo::new( | ||
"ERROR".to_owned(), | ||
"internal_error".to_owned(), | ||
format!("[peer]: invalid configuration: {}", e), | ||
))) | ||
})?; | ||
self.executors.remove(&peer.name); | ||
Ok(()) | ||
} else { | ||
let mut flow_handler = self.flow_handler.as_ref().unwrap().lock().await; | ||
let validate_request = pt::peerdb_route::ValidatePeerRequest { | ||
peer: Some(Peer { | ||
name: peer.name.clone(), | ||
r#type: peer.r#type, | ||
config: peer.config.clone(), | ||
}), | ||
}; | ||
let validity = flow_handler | ||
.validate_peer(&validate_request) | ||
.await | ||
.map_err(|err| { | ||
PgWireError::ApiError(Box::new(PgError::Internal { | ||
err_msg: format!("unable to check peer validity: {:?}", err), | ||
})) | ||
})?; | ||
if let PeerValidationResult::Invalid(validation_err) = validity { | ||
return Err(PgWireError::UserError(Box::new(ErrorInfo::new( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"ERROR".to_owned(), | ||
"internal_error".to_owned(), | ||
format!("[peer]: invalid configuration: {}", validation_err), | ||
))) | ||
.into()); | ||
} else { | ||
return Ok(()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
} | ||
|
||
async fn handle_query<'a>( | ||
&self, | ||
nexus_stmt: NexusStatement, | ||
|
@@ -218,20 +264,13 @@ impl NexusBackend { | |
} => { | ||
let peer_type = peer.r#type; | ||
if Self::is_peer_validity_supported(peer_type) { | ||
let peer_executor = self.get_peer_executor(&peer).await.map_err(|err| { | ||
PgWireError::ApiError(Box::new(PgError::Internal { | ||
err_msg: format!("unable to get peer executor: {:?}", err), | ||
})) | ||
})?; | ||
peer_executor.is_connection_valid().await.map_err(|e| { | ||
self.executors.remove(&peer.name); // Otherwise it will keep returning the earlier configured executor | ||
self.validate_peer(peer_type, &peer).await.map_err(|e| { | ||
PgWireError::UserError(Box::new(ErrorInfo::new( | ||
"ERROR".to_owned(), | ||
"internal_error".to_owned(), | ||
format!("[peer]: invalid configuration: {}", e), | ||
e.to_string(), | ||
))) | ||
})?; | ||
self.executors.remove(&peer.name); | ||
} | ||
|
||
let catalog = self.catalog.lock().await; | ||
|
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.