forked from chaostoolkit-incubator/chaostoolkit-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobes.py
43 lines (36 loc) · 1.38 KB
/
probes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from typing import List
from chaoslib.types import Configuration, Secrets
from chaoslib.exceptions import FailedActivity
from chaosaws import aws_client, get_logger
from chaosaws.types import AWSResponse
__all__ = ["describe_msk_cluster", "get_bootstrap_servers"]
logger = get_logger()
def describe_msk_cluster(
cluster_arn: str,
configuration: Configuration = None,
secrets: Secrets = None,
) -> AWSResponse:
"""
Describe an MSK cluster.
"""
client = aws_client("kafka", configuration, secrets)
logger.debug(f"Describing MSK cluster: {cluster_arn}")
try:
return client.describe_cluster(ClusterArn=cluster_arn)
except client.exceptions.NotFoundException as e:
raise FailedActivity("The specified cluster was not found") from e
def get_bootstrap_servers(
cluster_arn: str,
configuration: Configuration = None,
secrets: Secrets = None,
) -> List[str]:
"""
Get the bootstrap servers for an MSK cluster.
"""
client = aws_client("kafka", configuration, secrets)
logger.debug(f"Getting bootstrap servers for MSK cluster: {cluster_arn}")
try:
response = client.get_bootstrap_brokers(ClusterArn=cluster_arn)
return response["BootstrapBrokerString"].split(",") if response else []
except client.exceptions.NotFoundException as e:
raise FailedActivity("The specified cluster was not found") from e