protected ProgressEvent handleRequest()

in aws-ssmincidents-replicationset/src/main/java/software/amazon/ssmincidents/replicationset/ReadHandler.java [24:73]


  protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
      AmazonWebServicesClientProxy proxy,
      ResourceHandlerRequest<ResourceModel> request,
      CallbackContext callbackContext,
      ProxyClient<SsmIncidentsClient> proxyClient,
      Logger logger) {

    this.logger = logger;

    ResourceModel model = request.getDesiredResourceState();

    // should never be null, returning NotFound according to RPDK contract test expectation
    if (model.getArn() == null) {
      return ProgressEvent.defaultFailureHandler(
          ResourceNotFoundException.builder()
              .message("arn was null, cannot read replication set with null arn")
              .build(),
          HandlerErrorCode.NotFound
      );
    }

    GetReplicationSetRequest awsRequest = Translator.translateToReadRequest(model);
    try {
      GetReplicationSetResponse awsResponse = proxyClient.injectCredentialsAndInvokeV2(
          awsRequest,
          proxyClient.client()::getReplicationSet
      );
      Set<ReplicationRegion> replicationRegions = awsResponse.replicationSet().regionMap().entrySet().stream().map(
          regionConfig ->
              new ReplicationRegion(
                  regionConfig.getKey(),
                  Optional.ofNullable(defaultKeyIdToNull(regionConfig.getValue().sseKmsKeyId()))
                      .map(RegionConfiguration::new)
                      .orElse(null)
              )
      )
          .collect(Collectors.toSet());

      model.setArn(awsRequest.arn());
      model.setDeletionProtected(awsResponse.replicationSet().deletionProtected());
      model.setRegions(ImmutableSet.copyOf(replicationRegions));
      return ProgressEvent.defaultSuccessHandler(model);
    } catch (ResourceNotFoundException exception) {
      return ProgressEvent.defaultFailureHandler(exception, HandlerErrorCode.NotFound);
    } catch (ValidationException exception) {
      return ProgressEvent.defaultFailureHandler(exception, HandlerErrorCode.InvalidRequest);
    } catch (Exception exception) {
      return ProgressEvent.defaultFailureHandler(exception, HandlerErrorCode.GeneralServiceException);
    }
  }