刪除 Connect 叢集

刪除 Connect 叢集會清除所有相關聯的資料,包括儲存在主要 Kafka 叢集中的連接器設定。這個動作無法復原。

如要刪除 Connect 叢集,可以使用 Google Cloud 控制台、gcloud CLI、用戶端程式庫或 Managed Kafka API。您無法使用開放原始碼 Apache Kafka API 刪除 Connect 叢集。

刪除 Connect 叢集所需的角色和權限

如要取得刪除 Connect 叢集所需的權限,請要求管理員授予您專案的代管 Kafka Connect 叢集編輯者 (roles/managedkafka.connectClusterEditor) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

這個預先定義的角色具備刪除 Connect 叢集所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

如要刪除 Connect 叢集,必須具備下列權限:

  • 在 Connect 叢集上授予刪除 Connect 叢集的權限: managedkafka.connectClusters.delete
  • 在指定位置授予「列出連結的叢集」權限。只有在使用 Google Cloud 控制台刪除 Connect 叢集時,才需要這項權限: managedkafka.connectClusters.list

您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

如要進一步瞭解 Managed Kafka Connect 叢集編輯器角色,請參閱「Managed Service for Apache Kafka 預先定義角色」。

刪除 Connect 叢集

  • 瞭解資料遺失的影響:刪除 Connect 叢集會清除叢集本身儲存的所有資料。這包括:

    • 連接器及其設定

    • Connect 叢集直接管理的任何其他資料

    刪除 Connect 叢集不會一併刪除來源或目標 Kafka 叢集中的資料。如果您使用來源連接器將資料移至 Kafka 主題,刪除 Connect 叢集不會刪除已發布至該 Kafka 主題的資料。同樣地,刪除 Connect 叢集時,不會一併刪除與該叢集相關聯的 Kafka 叢集。

  • 規劃服務中斷:任何依賴 Connect 叢集讀取或寫入資料的應用程式或服務,都可能發生中斷情形。請先規劃好這項服務中斷事宜,再刪除叢集。

  • 查看帳單影響:刪除叢集後,系統會停止收取叢集費用。系統可能還是會根據您刪除前使用的資源向您收費。

  • 預期為非同步作業:叢集刪除作業預設為非同步。指令會立即傳回,您可以另外追蹤刪除進度。

控制台

  1. 前往 Google Cloud 控制台的「Connect Clusters」(連結叢集) 頁面。

    前往「Connect Clusters」(連結叢集)

  2. 選取要刪除的 Connect 叢集。你可以選取多個選項。

  3. 點選「刪除」。

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 使用 gcloud managed-kafka connect-clusters delete 指令刪除 Connect 叢集:

    gcloud managed-kafka connect-clusters delete CONNECT_CLUSTER \
        --location=LOCATION [--async]
    

    更改下列內容:

    • CONNECT_CLUSTER:要刪除的 Connect 叢集 ID。
    • LOCATION:Connect 叢集的位置。

    以下旗標為選用:

    • --async:立即返回,不要等待執行中的作業完成。
  3. Go

    在試用這個範例之前,請先按照「 安裝用戶端程式庫」中的 Go 設定說明操作。詳情請參閱 Managed Service for Apache Kafka Go API 參考說明文件

    如要向 Managed Service for Apache Kafka 進行驗證,請設定應用程式預設憑證(ADC)。 詳情請參閱「為本機開發環境設定 ADC」。

    import (
    	"context"
    	"fmt"
    	"io"
    
    	"cloud.google.com/go/managedkafka/apiv1/managedkafkapb"
    	"google.golang.org/api/option"
    
    	managedkafka "cloud.google.com/go/managedkafka/apiv1"
    )
    
    func deleteConnectCluster(w io.Writer, projectID, region, clusterID string, opts ...option.ClientOption) error {
    	// projectID := "my-project-id"
    	// region := "us-central1"
    	// clusterID := "my-connect-cluster"
    	ctx := context.Background()
    	client, err := managedkafka.NewManagedKafkaConnectClient(ctx, opts...)
    	if err != nil {
    		return fmt.Errorf("managedkafka.NewManagedKafkaConnectClient got err: %w", err)
    	}
    	defer client.Close()
    
    	clusterPath := fmt.Sprintf("projects/%s/locations/%s/connectClusters/%s", projectID, region, clusterID)
    	req := &managedkafkapb.DeleteConnectClusterRequest{
    		Name: clusterPath,
    	}
    	op, err := client.DeleteConnectCluster(ctx, req)
    	if err != nil {
    		return fmt.Errorf("client.DeleteConnectCluster got err: %w", err)
    	}
    	err = op.Wait(ctx)
    	if err != nil {
    		return fmt.Errorf("op.Wait got err: %w", err)
    	}
    	fmt.Fprint(w, "Deleted connect cluster\n")
    	return nil
    }
    

    Java

    在試用這個範例之前,請先按照「 安裝用戶端程式庫」中的 Java 設定操作說明進行操作。詳情請參閱 Managed Service for Apache Kafka Java API 參考說明文件

    如要向 Managed Service for Apache Kafka 進行驗證,請設定應用程式預設憑證。詳情請參閱「 為本機開發環境設定 ADC」。

    
    import com.google.api.gax.longrunning.OperationFuture;
    import com.google.api.gax.longrunning.OperationSnapshot;
    import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
    import com.google.api.gax.retrying.RetrySettings;
    import com.google.api.gax.retrying.TimedRetryAlgorithm;
    import com.google.api.gax.rpc.ApiException;
    import com.google.cloud.managedkafka.v1.ConnectClusterName;
    import com.google.cloud.managedkafka.v1.DeleteConnectClusterRequest;
    import com.google.cloud.managedkafka.v1.ManagedKafkaConnectClient;
    import com.google.cloud.managedkafka.v1.ManagedKafkaConnectSettings;
    import com.google.cloud.managedkafka.v1.OperationMetadata;
    import com.google.protobuf.Empty;
    import java.io.IOException;
    import java.time.Duration;
    
    public class DeleteConnectCluster {
    
      public static void main(String[] args) throws Exception {
        // TODO(developer): Replace these variables before running the example.
        String projectId = "my-project-id";
        String region = "my-region"; // e.g. us-east1
        String clusterId = "my-connect-cluster";
        deleteConnectCluster(projectId, region, clusterId);
      }
    
      public static void deleteConnectCluster(String projectId, String region, String clusterId)
          throws Exception {
    
        // Create the settings to configure the timeout for polling operations
        ManagedKafkaConnectSettings.Builder settingsBuilder = ManagedKafkaConnectSettings.newBuilder();
        TimedRetryAlgorithm timedRetryAlgorithm = OperationTimedPollAlgorithm.create(
            RetrySettings.newBuilder()
                .setTotalTimeoutDuration(Duration.ofHours(1L))
                .build());
        settingsBuilder.deleteConnectClusterOperationSettings()
            .setPollingAlgorithm(timedRetryAlgorithm);
    
        try (ManagedKafkaConnectClient managedKafkaConnectClient = ManagedKafkaConnectClient.create(
            settingsBuilder.build())) {
          DeleteConnectClusterRequest request = DeleteConnectClusterRequest.newBuilder()
              .setName(ConnectClusterName.of(projectId, region, clusterId).toString())
              .build();
          OperationFuture<Empty, OperationMetadata> future = managedKafkaConnectClient
              .deleteConnectClusterOperationCallable().futureCall(request);
    
          // Get the initial LRO and print details. CreateConnectCluster contains sample
          // code for polling logs.
          OperationSnapshot operation = future.getInitialFuture().get();
          System.out.printf(
              "Connect cluster deletion started. Operation name: %s\nDone: %s\nMetadata: %s\n",
              operation.getName(),
              operation.isDone(),
              future.getMetadata().get().toString());
    
          future.get();
          System.out.println("Deleted connect cluster");
        } catch (IOException | ApiException e) {
          System.err.printf("managedKafkaConnectClient.deleteConnectCluster got err: %s\n", 
              e.getMessage());
        }
      }
    }
    

    Python

    在試用這個範例之前,請先按照「 安裝用戶端程式庫」中的 Python 設定說明操作。詳情請參閱 Managed Service for Apache Kafka Python API 參考說明文件

    如要向 Managed Service for Apache Kafka 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。

    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"
    
    connect_client = ManagedKafkaConnectClient()
    
    request = managedkafka_v1.DeleteConnectClusterRequest(
        name=connect_client.connect_cluster_path(project_id, region, connect_cluster_id),
    )
    
    try:
        operation = connect_client.delete_connect_cluster(request=request)
        print(f"Waiting for operation {operation.operation.name} to complete...")
        operation.result()
        print("Deleted Connect cluster")
    except GoogleAPICallError as e:
        print(f"The operation failed with error: {e}")
    

後續步驟

Apache Kafka® 是 The Apache Software Foundation 或其關聯企業在美國與/或其他國家/地區的註冊商標。