Application Recovery Controller examples using SDK for Java 2.x - AWS SDK for Java 2.x

Application Recovery Controller examples using SDK for Java 2.x

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Java 2.x with Application Recovery Controller.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use GetRoutingControlState.

SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

public static GetRoutingControlStateResponse getRoutingControlState(List<ClusterEndpoint> clusterEndpoints, String routingControlArn) { // As a best practice, we recommend choosing a random cluster endpoint to get or // set routing control states. // For more information, see // https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional Collections.shuffle(clusterEndpoints); for (ClusterEndpoint clusterEndpoint : clusterEndpoints) { try { System.out.println(clusterEndpoint); Route53RecoveryClusterClient client = Route53RecoveryClusterClient.builder() .endpointOverride(URI.create(clusterEndpoint.endpoint())) .region(Region.of(clusterEndpoint.region())).build(); return client.getRoutingControlState( GetRoutingControlStateRequest.builder() .routingControlArn(routingControlArn).build()); } catch (Exception exception) { System.out.println(exception); } } return null; }

The following code example shows how to use UpdateRoutingControlState.

SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

public static UpdateRoutingControlStateResponse updateRoutingControlState(List<ClusterEndpoint> clusterEndpoints, String routingControlArn, String routingControlState) { // As a best practice, we recommend choosing a random cluster endpoint to get or // set routing control states. // For more information, see // https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional Collections.shuffle(clusterEndpoints); for (ClusterEndpoint clusterEndpoint : clusterEndpoints) { try { System.out.println(clusterEndpoint); Route53RecoveryClusterClient client = Route53RecoveryClusterClient.builder() .endpointOverride(URI.create(clusterEndpoint.endpoint())) .region(Region.of(clusterEndpoint.region())) .build(); return client.updateRoutingControlState( UpdateRoutingControlStateRequest.builder() .routingControlArn(routingControlArn).routingControlState(routingControlState).build()); } catch (Exception exception) { System.out.println(exception); } } return null; }