List your Connect clusters

Listing your Connect clusters lets you view the details of all your Connect clusters in one pane, including details such as health of the clusters, locations, uptime of the clusters, compute size, associated Google Cloud Managed Service for Apache Kafka cluster, and labels.

To list your Connect clusters, you can use the Google Cloud console, the gcloud CLI, the client library, or the Managed Kafka API. You can't use the open source Apache Kafka API to list Connect clusters.

Required roles and permissions to list your Connect clusters

To get the permissions that you need to list your Connect clusters, ask your administrator to grant you the Managed Kafka Viewer ( roles/managedkafka.viewer ) IAM role on your project. For more information about granting roles, see Manage access to projects, folders, and organizations .

This predefined role contains the permissions required to list your Connect clusters. To see the exact permissions that are required, expand the Required permissionssection:

Required permissions

The following permissions are required to list your Connect clusters:

  • Grant the list clusters permission on the specified location: managedkafka.connectClusters.list
  • Grant the get cluster details permission on the specified location: managedkafka.connectClusters.get

You might also be able to get these permissions with custom roles or other predefined roles .

For more information about the Managed Kafka Viewer role, see Managed Service for Apache Kafka predefined roles .

View your Connect clusters

Console

  1. In the Google Cloud console, go to the Connect Clusterspage.

    Go to Connect Clusters

  2. The clusters you created in a project are listed. The page lets you view the following cluster properties:

    • Name: The unique identifier for your Connect cluster. You can use it to reference the Connect cluster in various operations.
    • State: Indicates the current operational status of the Connect cluster, such as Active.
    • Location: The geographical location where your Connect cluster is hosted.
    • Update time: The time the Connect cluster was last updated.
    • vCPUs: The number of vCPUs assigned to the Connect cluster.
    • Memory: The total amount of memory allocated to the Connect cluster.
    • Primary Kafka cluster: The Managed Service for Apache Kafka cluster associated with the Connect cluster.
    • Labels: Key-value pairs that you can attach to the Connect cluster for organization, filtering, and automation purposes.

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. Use the gcloud managed-kafka connect-clusters list command to list Connect clusters:

     gcloud  
    managed-kafka  
    connect-clusters  
    list  
     \ 
      
    --location = 
     LOCATION 
     
    
  3. To further refine the list of Connect clusters, you can use additional flags:

     gcloud  
    managed-kafka  
    connect-clusters  
    list  
     \ 
      
    --location = 
     LOCATION 
      
     \ 
      
     [ 
    --filter = 
     EXPRESSION 
     ] 
      
     \ 
      
     [ 
    --limit = 
     LIMIT 
     ] 
      
     \ 
      
     [ 
    --page-size = 
     PAGE_SIZE 
     ] 
      
     \ 
      
     [ 
    --sort-by = 
     SORT_BY 
     ] 
     
    

    Replace the following:

    • LOCATION : Required. The location of the Connect clusters you want to list.

    • EXPRESSION : (Optional) A boolean filter expression to apply to the list. If the expression evaluates to True , the item is included in the list. For more details and examples, run gcloud topic filters .

    • LIMIT : (Optional) The maximum number of Connect clusters to display. If not specified, all Connect clusters are listed.

    • PAGE_SIZE : (Optional) The number of results to display per page. If not specified, the service determines a suitable page size.

    • SORT_BY : (Optional) A comma-separated list of fields to sort by. The default sort order is ascending. To sort in descending order, prefix the field with ~ .

Example output:

 NAME                   VCPU  MEMORY_BYTES  STATE   NETWORK
connect-cluster-alpha  3     3221225472    ACTIVE
connect-cluster-beta   3     3221225472    ACTIVE 

Go

Before trying this sample, follow the Go setup instructions in Install the client libraries . For more information, see the Managed Service for Apache Kafka Go API reference documentation .

To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials(ADC). For more information, see Set up ADC for a local development environment .

  import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "io" 
  
 "cloud.google.com/go/managedkafka/apiv1/managedkafkapb" 
  
 "google.golang.org/api/iterator" 
  
 "google.golang.org/api/option" 
  
 managedkafka 
  
 "cloud.google.com/go/managedkafka/apiv1" 
 ) 
 func 
  
 listConnectClusters 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 projectID 
 , 
  
 region 
  
 string 
 , 
  
 opts 
  
 ... 
 option 
 . 
 ClientOption 
 ) 
  
 error 
  
 { 
  
 // projectID := "my-project-id" 
  
 // region := "us-central1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 managedkafka 
 . 
 NewManagedKafkaConnectClient 
 ( 
 ctx 
 , 
  
 opts 
 ... 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "managedkafka.NewManagedKafkaConnectClient got err: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 locationPath 
  
 := 
  
 fmt 
 . 
 Sprintf 
 ( 
 "projects/%s/locations/%s" 
 , 
  
 projectID 
 , 
  
 region 
 ) 
  
 req 
  
 := 
  
& managedkafkapb 
 . 
 ListConnectClustersRequest 
 { 
  
 Parent 
 : 
  
 locationPath 
 , 
  
 } 
  
 clusterIter 
  
 := 
  
 client 
 . 
 ListConnectClusters 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 for 
  
 { 
  
 res 
 , 
  
 err 
  
 := 
  
 clusterIter 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "clusterIter.Next() got err: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "Got connect cluster: %v" 
 , 
  
 res 
 ) 
  
 } 
  
 return 
  
 nil 
 } 
 

Java

Before trying this sample, follow the Java setup instructions in Install the client libraries . For more information, see the Managed Service for Apache Kafka Java API reference documentation .

To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials. For more information, see Set up ADC for a local development environment .

  import 
  
 com.google.api.gax.rpc. ApiException 
 
 ; 
 import 
  
 com.google.cloud.managedkafka.v1. ConnectCluster 
 
 ; 
 import 
  
 com.google.cloud.managedkafka.v1. LocationName 
 
 ; 
 import 
  
 com.google.cloud.managedkafka.v1. ManagedKafkaConnectClient 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 public 
  
 class 
 ListConnectClusters 
  
 { 
  
 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 
  
 listConnectClusters 
 ( 
 projectId 
 , 
  
 region 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 listConnectClusters 
 ( 
 String 
  
 projectId 
 , 
  
 String 
  
 region 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 try 
  
 ( 
  ManagedKafkaConnectClient 
 
  
 managedKafkaConnectClient 
  
 = 
  
  
  ManagedKafkaConnectClient 
 
 . 
 create 
 ()) 
  
 { 
  
  LocationName 
 
  
 locationName 
  
 = 
  
  LocationName 
 
 . 
 of 
 ( 
 projectId 
 , 
  
 region 
 ); 
  
 // This operation is being handled synchronously. 
  
 for 
  
 ( 
  ConnectCluster 
 
  
 connectCluster 
  
 : 
  
 managedKafkaConnectClient 
  
 . 
 listConnectClusters 
 ( 
 locationName 
 ). 
 iterateAll 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 connectCluster 
 . 
 getAllFields 
 ()); 
  
 } 
  
 } 
  
 catch 
  
 ( 
 IOException 
  
 | 
  
  ApiException 
 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 err 
 . 
 printf 
 ( 
 "managedKafkaConnectClient.listConnectClusters got err: %s\n" 
 , 
  
  
 e 
 . 
  getMessage 
 
 ()); 
  
 } 
  
 } 
 } 
 

Python

Before trying this sample, follow the Python setup instructions in Install the client libraries . For more information, see the Managed Service for Apache Kafka Python API reference documentation .

To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials. For more information, see Set up ADC for a local development environment .

  from 
  
 google.cloud 
  
 import 
  managedkafka_v1 
 
 from 
  
 google.cloud.managedkafka_v1.services.managed_kafka_connect 
  
 import 
 ( 
  ManagedKafkaConnectClient 
 
 , 
 ) 
 from 
  
 google.api_core.exceptions 
  
 import 
 GoogleAPICallError 
 # TODO(developer) 
 # project_id = "my-project-id" 
 # region = "us-central1" 
 connect_client 
 = 
 ManagedKafkaConnectClient 
 () 
 request 
 = 
  managedkafka_v1 
 
 . 
  ListConnectClustersRequest 
 
 ( 
 parent 
 = 
 connect_client 
 . 
  common_location_path 
 
 ( 
 project_id 
 , 
 region 
 ), 
 ) 
 response 
 = 
 connect_client 
 . 
  list_connect_clusters 
 
 ( 
 request 
 = 
 request 
 ) 
 for 
 cluster 
 in 
 response 
 : 
 try 
 : 
 print 
 ( 
 "Got Connect cluster:" 
 , 
 cluster 
 ) 
 except 
 GoogleAPICallError 
 as 
 e 
 : 
 print 
 ( 
 f 
 "Failed to list Connect clusters with error: 
 { 
 e 
 } 
 " 
 ) 
 

What's next?

Apache Kafka® is a registered trademark of The Apache Software Foundation or its affiliates in the United States and/or other countries.
Create a Mobile Website
View Site in Mobile | Classic
Share by: