package software.amazon.sagemaker.pipeline; import software.amazon.awssdk.awscore.exception.AwsServiceException; import software.amazon.awssdk.services.sagemaker.SageMakerClient; import software.amazon.awssdk.services.sagemaker.model.DescribePipelineRequest; import software.amazon.awssdk.services.sagemaker.model.DescribePipelineResponse; import software.amazon.awssdk.services.sagemaker.model.ResourceNotFoundException; import software.amazon.cloudformation.Action; import software.amazon.cloudformation.exceptions.CfnNotFoundException; import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy; import software.amazon.cloudformation.proxy.Logger; import software.amazon.cloudformation.proxy.ProgressEvent; import software.amazon.cloudformation.proxy.ProxyClient; import software.amazon.cloudformation.proxy.ResourceHandlerRequest; public class ReadHandler extends BaseHandlerStd { private static final String OPERATION = "AWS-SageMaker-Pipeline::Read"; private Logger logger; protected ProgressEvent handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest request, final CallbackContext callbackContext, final ProxyClient proxyClient, final Logger logger ) { this.logger = logger; final ResourceModel model = request.getDesiredResourceState(); return proxy.initiate(OPERATION, proxyClient, model, callbackContext) .translateToServiceRequest(TranslatorForRequest::translateToReadRequest) .makeServiceCall(this::readResource) .done(this::constructResourceModelFromResponse); } /** * Client invocation of the read request through the proxyClient, which is already initialised with * caller credentials, correct region and retry settings * @param awsRequest the aws service request to describe a resource * @param proxyClient the aws service client to make the call * @return describe resource response */ private DescribePipelineResponse readResource( final DescribePipelineRequest awsRequest, final ProxyClient proxyClient ) { DescribePipelineResponse response = null; try { response = proxyClient.injectCredentialsAndInvokeV2(awsRequest, proxyClient.client()::describePipeline); } catch (final ResourceNotFoundException e) { throw new CfnNotFoundException(ResourceModel.TYPE_NAME, awsRequest.pipelineName(), e); } catch (final AwsServiceException e) { Translator.throwCfnException(Action.READ.toString(), ResourceModel.TYPE_NAME, awsRequest.pipelineName(), e); } return response; } /** * Implement client invocation of the read request through the proxyClient, which is already * initialised with caller credentials, correct region and retry settings * * @param awsResponse the aws service describe resource response * @return progressEvent indicating success, in progress with delay callback or failed state */ private ProgressEvent constructResourceModelFromResponse( final DescribePipelineResponse awsResponse) { return ProgressEvent.defaultSuccessHandler(TranslatorForResponse.translateFromReadResponse(awsResponse)); } }