מחיקת אשכול Connect

מחיקה של אשכול Connect מוחקת את כל הנתונים שמשויכים אליו, כולל הגדרות של מחברים שמאוחסנות באשכול Kafka הראשי שלו. אי אפשר לבטל את הפעולה הזו.

כדי למחוק אשכול Connect, אפשר להשתמש במסוף Google Cloud , ב-CLI של gcloud, בספריית הלקוח או ב-Managed Kafka API. אי אפשר להשתמש ב-API של Apache Kafka בקוד פתוח כדי למחוק אשכול Connect.

תפקידים והרשאות שנדרשים כדי למחוק אשכול Connect

כדי לקבל את ההרשאות שנדרשות למחיקת אשכול Connect, צריך לבקש מהאדמין להקצות לכם את תפקיד ה-IAM‏ Managed Kafka Connect Cluster Editor (roles/managedkafka.connectClusterEditor) בפרויקט. כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

זהו תפקיד שמוגדר מראש וכולל את ההרשאות שנדרשות למחיקת אשכול Connect. כדי לראות בדיוק אילו הרשאות נדרשות, אפשר להרחיב את הקטע ההרשאות הנדרשות:

ההרשאות הנדרשות

כדי למחוק אשכול Connect, צריך את ההרשאות הבאות:

  • נותנים הרשאה למחיקת מקבץ Connect במקבץ Connect: managedkafka.connectClusters.delete
  • מעניקים לרשימה את ההרשאה Connect clusters במיקום שצוין. ההרשאה הזו נדרשת רק למחיקת אשכול Connect באמצעות המסוף Google Cloud : managedkafka.connectClusters.list

יכול להיות שתקבלו את ההרשאות האלה באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש אחרים.

מחיקת מקבץ Connect

  • הבנת ההשלכות של אובדן נתונים: מחיקה של אשכול Connect מוחקת את כל הנתונים שמאוחסנים באשכול Connect עצמו. הדוגמאות הבאות:

    • מחברים וההגדרות שלהם

    • כל נתון אחר שמנוהל ישירות על ידי אשכול Connect

    מחיקה של אשכול Connect לא מוחקת נתונים באשכולות Kafka של המקור או היעד. אם אתם משתמשים במחבר מקור כדי להעביר נתונים לנושא Kafka, מחיקת אשכול Connect לא מוחקת את הנתונים שכבר פורסמו בנושא Kafka הזה. באופן דומה, מחיקה של אשכול Connect לא מוחקת את אשכולות Kafka שאשכול Connect משויך אליהם.

  • תכנון להפרעה בשירות: יכול להיות שיהיו הפרעות באפליקציות או בשירותים שתלויים בנתונים שנקראים או נכתבים על ידי אשכול Connect. כדאי לתכנן את השיבוש בשירות לפני שמוחקים את האשכול.

  • בדיקת ההשלכות על החיוב: אחרי שמוחקים את האשכול, לא מחויבים עליו יותר. יכול להיות שעדיין תחויבו על משאבים שהשתמשתם בהם עד למחיקה.

  • הפעולה אסינכרונית: מחיקת אשכול היא אסינכרונית כברירת מחדל. הפקודה מוחזרת באופן מיידי, ואפשר לעקוב אחרי התקדמות המחיקה בנפרד.

המסוף

  1. נכנסים לדף Connect Clusters במסוף Google Cloud .

    מעבר אל Connect Clusters

  2. בוחרים את אשכול Connect שרוצים למחוק. אפשר לבחור יותר מאפשרות אחת.

  3. לוחצים על Delete.

gcloud

  1. במסוף Google Cloud , מפעילים את Cloud Shell.

    הפעלת Cloud Shell

    בחלק התחתון של Google Cloud המסוף יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.

  2. משתמשים בפקודה gcloud managed-kafka connect-clusters delete כדי למחוק אשכולי Connect:

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

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫CONNECT_CLUSTER: המזהה של אשכול Connect שרוצים למחוק.
    • ‫LOCATION: המיקום של אשכול Connect.

    הדגל הבא הוא אופציונלי:

    • ‫--async: חזרה מיידית, בלי להמתין שהפעולה תסתיים.

המשך

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Go בקטע התקנת ספריות הלקוח. מידע נוסף מופיע ב מאמרי העזרה של ה-API של Go עבור שירות מנוהל ל-Apache Kafka.

כדי לבצע אימות לשירות המנוהל ל-Apache Kafka, צריך להגדיר את Application Default Credentials‏(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.

כדי לבצע אימות לשירות המנוהל ל-Apache Kafka, מגדירים את ה-Application Default Credentials. מידע נוסף זמין במאמר הגדרת 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 במאמר התקנת ספריות הלקוח. מידע נוסף מופיע ב מאמרי העזרה של ה-API בשפת Python של שירות מנוהל ל-Apache Kafka.

כדי לבצע אימות לשירות המנוהל ל-Apache Kafka, מגדירים את ה-Application Default Credentials. מידע נוסף זמין במאמר הגדרת 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 או של השותפים העצמאיים שלה בארצות הברית או במדינות אחרות.