Application Recovery Controller examples using SDK for SAP ABAP - Amazon SDK for SAP ABAP
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Application Recovery Controller examples using SDK for SAP ABAP

The following code examples show you how to perform actions and implement common scenarios by using the Amazon SDK for SAP ABAP 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.

Each example includes a link to the complete source code, 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 SAP ABAP
Note

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

CONSTANTS cv_pfl TYPE /aws1/rt_profile_id VALUE 'ZCODE_DEMO'. DATA lo_exception TYPE REF TO /aws1/cx_rt_generic. DATA lo_session TYPE REF TO /aws1/cl_rt_session_base. DATA lo_client TYPE REF TO /aws1/if_r5v. DATA lt_endpoints TYPE TABLE OF string. DATA lv_endpoint TYPE string. DATA lv_region TYPE /aws1/rt_region_id. " Parse the comma-separated cluster endpoints " Expected format: "https://endpoint1.com|us-west-2,https://endpoint2.com|us-east-1" SPLIT iv_cluster_endpoints AT ',' INTO TABLE lt_endpoints. " As a best practice, shuffle cluster endpoints to distribute load " For more information, see https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional " For simplicity, we'll try them in order (shuffling can be added if needed) " Try each endpoint in order LOOP AT lt_endpoints INTO lv_endpoint. TRY. " Parse endpoint and region from the format "url|region" DATA(lv_pos) = find( val = lv_endpoint sub = '|' ). IF lv_pos > 0. DATA(lv_url) = substring( val = lv_endpoint len = lv_pos ). lv_region = substring( val = lv_endpoint off = lv_pos + 1 ). ELSE. " If no region specified, use default lv_url = lv_endpoint. lv_region = 'us-east-1'. ENDIF. " Create session for this region lo_session = /aws1/cl_rt_session_aws=>create( cv_pfl ). " Create client with the specific endpoint lo_client = create_recovery_client( iv_endpoint = lv_url iv_region = lv_region io_session = lo_session ). " Try to get the routing control state oo_result = lo_client->getroutingcontrolstate( iv_routingcontrolarn = iv_routing_control_arn ). " If successful, return the result RETURN. CATCH /aws1/cx_r5vendpttmpyunavailex INTO DATA(lo_endpoint_ex). " This endpoint is temporarily unavailable, try the next one lo_exception = lo_endpoint_ex. CONTINUE. CATCH /aws1/cx_r5vaccessdeniedex /aws1/cx_r5vinternalserverex /aws1/cx_r5vresourcenotfoundex /aws1/cx_r5vthrottlingex /aws1/cx_r5vvalidationex /aws1/cx_rt_generic INTO lo_exception. " For other errors, re-raise immediately RAISE EXCEPTION lo_exception. ENDTRY. ENDLOOP. " If we get here, all endpoints failed - re-raise the last exception IF lo_exception IS BOUND. RAISE EXCEPTION lo_exception. ENDIF.

The following code example shows how to use UpdateRoutingControlState.

SDK for SAP ABAP
Note

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

CONSTANTS cv_pfl TYPE /aws1/rt_profile_id VALUE 'ZCODE_DEMO'. DATA lo_exception TYPE REF TO /aws1/cx_rt_generic. DATA lo_session TYPE REF TO /aws1/cl_rt_session_base. DATA lo_client TYPE REF TO /aws1/if_r5v. DATA lt_endpoints TYPE TABLE OF string. DATA lv_endpoint TYPE string. DATA lv_region TYPE /aws1/rt_region_id. " Parse the comma-separated cluster endpoints " Expected format: "https://endpoint1.com|us-west-2,https://endpoint2.com|us-east-1" SPLIT iv_cluster_endpoints AT ',' INTO TABLE lt_endpoints. " As a best practice, shuffle cluster endpoints to distribute load " For more information, see https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional " For simplicity, we'll try them in order (shuffling can be added if needed) " Try each endpoint in order LOOP AT lt_endpoints INTO lv_endpoint. TRY. " Parse endpoint and region from the format "url|region" DATA(lv_pos) = find( val = lv_endpoint sub = '|' ). IF lv_pos > 0. DATA(lv_url) = substring( val = lv_endpoint len = lv_pos ). lv_region = substring( val = lv_endpoint off = lv_pos + 1 ). ELSE. " If no region specified, use default lv_url = lv_endpoint. lv_region = 'us-east-1'. ENDIF. " Create session for this region lo_session = /aws1/cl_rt_session_aws=>create( cv_pfl ). " Create client with the specific endpoint lo_client = create_recovery_client( iv_endpoint = lv_url iv_region = lv_region io_session = lo_session ). " Try to update the routing control state oo_result = lo_client->updateroutingcontrolstate( iv_routingcontrolarn = iv_routing_control_arn iv_routingcontrolstate = iv_routing_control_state it_safetyrulestooverride = it_safety_rules_override ). " If successful, return the result RETURN. CATCH /aws1/cx_r5vendpttmpyunavailex INTO DATA(lo_endpoint_ex). " This endpoint is temporarily unavailable, try the next one lo_exception = lo_endpoint_ex. CONTINUE. CATCH /aws1/cx_r5vaccessdeniedex /aws1/cx_r5vconflictexception /aws1/cx_r5vinternalserverex /aws1/cx_r5vresourcenotfoundex /aws1/cx_r5vthrottlingex /aws1/cx_r5vvalidationex /aws1/cx_rt_generic INTO lo_exception. " For other errors, re-raise immediately RAISE EXCEPTION lo_exception. ENDTRY. ENDLOOP. " If we get here, all endpoints failed - re-raise the last exception IF lo_exception IS BOUND. RAISE EXCEPTION lo_exception. ENDIF.