-
Notifications
You must be signed in to change notification settings - Fork 6.6k
MKC Examples - Connector Operations #13527
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
glasnt
merged 28 commits into
GoogleCloudPlatform:main
from
salmany:python-connector-examples
Sep 12, 2025
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c928344
Add Managed Kafka Connect code samples for
salmany 8f2224a
Update google-cloud-managedkafka version to 0.1.12
salmany 1feb354
Update managedkafka/snippets/connect/clusters/create_connect_cluster.py
salmany 5840336
Update managedkafka/snippets/connect/clusters/create_connect_cluster.py
salmany d0df10f
Update managedkafka/snippets/connect/clusters/delete_connect_cluster.py
salmany 505759a
Update managedkafka/snippets/connect/clusters/get_connect_cluster.py
salmany d3fba2c
Update managedkafka/snippets/connect/clusters/list_connect_clusters.py
salmany 0a85a8b
Update managedkafka/snippets/connect/clusters/update_connect_cluster.py
salmany dfa07d2
Add timeouts and improve error handling.
salmany ab697bf
Addressed PR comments.
salmany 3339325
Adds requirements.txt file for samples.
salmany f1bb355
Adds code examples for Managed Kafka Connect
salmany 8084f5b
Minor fixes.
salmany 328ab0c
Remove redundant file.
salmany cf01686
Merge remote-tracking branch 'origin/main' into pr/salmany/13527
salmany 9769a25
Merge branch 'main' into pr/salmany/13527
salmany 0fc9597
Fix merge issues.
salmany bf5d2c3
Add example for `bootstrap.servers`
salmany 831952c
Remove obsolete MM2 connector example.
salmany c4b610f
Clarify use for restart_connector.
salmany b49fa0f
Fix comment on bootstrap.servers for MM2 example.
salmany 2635674
Remove obsolete file.
salmany 692c41f
Fix variable naming and tasks.max value.
salmany fd5aa27
Fix connectors_test.py linting errors.
salmany 561adc5
Fix linting errors for connector samples.
salmany 15b0e76
linting (black)
glasnt 5a9febe
Remove requirements.txt to fix linting conflicts.
salmany 700f6b3
sort order
glasnt 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
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
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
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
61 changes: 61 additions & 0 deletions
61
managedkafka/snippets/connect/connectors/delete_connector.py
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,61 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| def delete_connector( | ||
| project_id: str, | ||
| region: str, | ||
| connect_cluster_id: str, | ||
| connector_id: str, | ||
| ) -> None: | ||
| """ | ||
| Delete a connector. | ||
|
|
||
| Args: | ||
| project_id: Google Cloud project ID. | ||
| region: Cloud region. | ||
| connect_cluster_id: ID of the Kafka Connect cluster. | ||
| connector_id: ID of the connector. | ||
|
|
||
| Raises: | ||
| This method will raise the GoogleAPICallError exception if the operation errors. | ||
| """ | ||
| # [START managedkafka_delete_connector] | ||
| from google.api_core.exceptions import GoogleAPICallError | ||
| from google.cloud.managedkafka_v1.services.managed_kafka_connect import ( | ||
| ManagedKafkaConnectClient, | ||
| ) | ||
| from google.cloud import managedkafka_v1 | ||
|
|
||
| # TODO(developer) | ||
| # project_id = "my-project-id" | ||
| # region = "us-central1" | ||
| # connect_cluster_id = "my-connect-cluster" | ||
| # connector_id = "my-connector" | ||
|
|
||
| connect_client = ManagedKafkaConnectClient() | ||
|
|
||
| request = managedkafka_v1.DeleteConnectorRequest( | ||
| name=connect_client.connector_path(project_id, region, connect_cluster_id, connector_id), | ||
| ) | ||
|
|
||
| try: | ||
| operation = connect_client.delete_connector(request=request) | ||
| print(f"Waiting for operation {operation.operation.name} to complete...") | ||
| operation.result() | ||
|
Contributor
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. 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. Could you apply this suggestion? Thanks! |
||
| print("Deleted connector") | ||
| except GoogleAPICallError as e: | ||
| print(f"The operation failed with error: {e}") | ||
|
|
||
| # [END managedkafka_delete_connector] | ||
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.
@rQ-Qrr responding to your comments on #13522 here:
You are correct that this is the default on the UI, but I was following the sample config provided here for consistency: https://screenshot.googleplex.com/5gESHNHH6yh25ex