@Test public void handleRequest_PredictArn_TypeNotFoundException() { final CloudFormationClient client = getServiceClient(); when(client.serviceName()).thenReturn("cloudformation"); final ResourceModel resourceModel = ResourceModel.builder() .typeName("AWS::Demo::Resource") .visibility("PRIVATE") .sourceUrl("https: .build(); final RegisterTypeResponse registerTypeResponse = RegisterTypeResponse.builder() .registrationToken(UUID.randomUUID().toString()) .build(); when(client.registerType(ArgumentMatchers.any(RegisterTypeRequest.class))) .thenReturn(registerTypeResponse); when(client.listTypeVersions(ArgumentMatchers.any(ListTypeVersionsRequest.class))) .thenThrow(make( TypeNotFoundException.builder(), 404, "Type not found", TypeNotFoundException.class)); when(client.describeTypeRegistration(ArgumentMatchers.any(DescribeTypeRegistrationRequest.class))) .thenThrow(make( CfnRegistryException.builder(), 500, "some exception", CfnRegistryException.class)); final ResourceHandlerRequest<ResourceModel> request = ResourceHandlerRequest.<ResourceModel>builder() .desiredResourceState(resourceModel) .awsPartition("aws") .region("us-west-2") .awsAccountId("123456789012") .build(); final ResourceModel resourceModelResult = ResourceModel.builder() .typeName("AWS::Demo::Resource") .visibility("PRIVATE") .sourceUrl("https: .arn("arn:aws:cloudformation:us-west-2:123456789012:type/resource/AWS-Demo-Resource/00000001") .build(); final ProgressEvent<ResourceModel, CallbackContext> response = handler.handleRequest(proxy, request, null, loggerProxy); assertThat(response).isNotNull(); assertThat(response.getStatus()).isEqualTo(OperationStatus.FAILED); assertThat(response.getCallbackContext().getPredictedArn()).isEqualTo("arn:aws:cloudformation:us-west-2:123456789012:type/resource/AWS-Demo-Resource/00000001"); assertThat(response.getCallbackContext().getRegistrationToken()).isEqualTo(registerTypeResponse.registrationToken()); assertThat(response.getCallbackDelaySeconds()).isEqualTo(0); assertThat(response.getResourceModels()).isNull(); assertThat(response.getResourceModel()).isEqualToComparingFieldByField(resourceModelResult); assertThat(response.getMessage()).isEqualTo("some exception (Service: null, Status Code: 0, Request ID: null, Extended Request ID: null)"); assertThat(response.getErrorCode()).isEqualTo(HandlerErrorCode.GeneralServiceException); }
protected ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); return initiator .translateToServiceRequest(Translator::translateToCreateRequest) .makeServiceCall((awsRequest, sdkProxyClient) -> sdkProxyClient.injectCredentialsAndInvokeV2(awsRequest, sdkProxyClient.client()::registerType)) .done((registerTypeRequest, registerTypeResponse, sdkProxyClient, model, cc) -> { cc.setRegistrationToken(registerTypeResponse.registrationToken()); return predictArn(request, initiator); }) .then(progress -> stabilizeOnCreate(initiator, progress.getCallbackContext().getRegistrationToken())) .then(progress -> new ReadHandler().handleRequest(proxy, request, progress.getCallbackContext(), proxyClient, logger)); }
CreateHandler extends BaseHandlerStd { protected ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); return initiator .translateToServiceRequest(Translator::translateToCreateRequest) .makeServiceCall((awsRequest, sdkProxyClient) -> sdkProxyClient.injectCredentialsAndInvokeV2(awsRequest, sdkProxyClient.client()::registerType)) .done((registerTypeRequest, registerTypeResponse, sdkProxyClient, model, cc) -> { cc.setRegistrationToken(registerTypeResponse.registrationToken()); return predictArn(request, initiator); }) .then(progress -> stabilizeOnCreate(initiator, progress.getCallbackContext().getRegistrationToken())) .then(progress -> new ReadHandler().handleRequest(proxy, request, progress.getCallbackContext(), proxyClient, logger)); } }
CreateHandler extends BaseHandlerStd { protected ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); return initiator .translateToServiceRequest(Translator::translateToCreateRequest) .makeServiceCall((awsRequest, sdkProxyClient) -> sdkProxyClient.injectCredentialsAndInvokeV2(awsRequest, sdkProxyClient.client()::registerType)) .done((registerTypeRequest, registerTypeResponse, sdkProxyClient, model, cc) -> { cc.setRegistrationToken(registerTypeResponse.registrationToken()); return predictArn(request, initiator); }) .then(progress -> stabilizeOnCreate(initiator, progress.getCallbackContext().getRegistrationToken())) .then(progress -> new ReadHandler().handleRequest(proxy, request, progress.getCallbackContext(), proxyClient, logger)); }  }
CreateHandler extends BaseHandlerStd { protected ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); return initiator .translateToServiceRequest(Translator::translateToCreateRequest) .makeServiceCall((awsRequest, sdkProxyClient) -> sdkProxyClient.injectCredentialsAndInvokeV2(awsRequest, sdkProxyClient.client()::registerType)) .done((registerTypeRequest, registerTypeResponse, sdkProxyClient, model, cc) -> { cc.setRegistrationToken(registerTypeResponse.registrationToken()); return predictArn(request, initiator); }) .then(progress -> stabilizeOnCreate(initiator, progress.getCallbackContext().getRegistrationToken())) .then(progress -> new ReadHandler().handleRequest(proxy, request, progress.getCallbackContext(), proxyClient, logger)); }   }
CreateHandler extends BaseHandlerStd { protected ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); return initiator .translateToServiceRequest(Translator::translateToCreateRequest) .makeServiceCall((awsRequest, sdkProxyClient) -> sdkProxyClient.injectCredentialsAndInvokeV2(awsRequest, sdkProxyClient.client()::registerType)) .done((registerTypeRequest, registerTypeResponse, sdkProxyClient, model, cc) -> { cc.setRegistrationToken(registerTypeResponse.registrationToken()); return predictArn(request, initiator); }) .then(progress -> stabilizeOnCreate(initiator, progress.getCallbackContext().getRegistrationToken())) .then(progress -> new ReadHandler().handleRequest(proxy, request, progress.getCallbackContext(), proxyClient, logger)); }    }