@Test public void handleRequest_ServiceManagedSS_SimpleSuccess() { request = ResourceHandlerRequest.<ResourceModel>builder() .desiredResourceState(SERVICE_MANAGED_MODEL) .logicalResourceIdentifier(LOGICAL_ID) .clientRequestToken(REQUEST_TOKEN) .build(); when(proxyClient.client().getTemplateSummary(any(GetTemplateSummaryRequest.class))) .thenReturn(VALID_TEMPLATE_SUMMARY_RESPONSE); when(proxyClient.client().createStackSet(any(CreateStackSetRequest.class))) .thenReturn(CREATE_STACK_SET_RESPONSE); when(proxyClient.client().createStackInstances(any(CreateStackInstancesRequest.class))) .thenReturn(CREATE_STACK_INSTANCES_RESPONSE); when(proxyClient.client().describeStackSetOperation(any(DescribeStackSetOperationRequest.class))) .thenReturn(OPERATION_SUCCEED_RESPONSE); when(proxyClient.client().describeStackSet(any(DescribeStackSetRequest.class))) .thenReturn(DESCRIBE_SERVICE_MANAGED_STACK_SET_RESPONSE); when(proxyClient.client().listStackInstances(any(ListStackInstancesRequest.class))) .thenReturn(LIST_SERVICE_MANAGED_STACK_SET_RESPONSE); when(proxyClient.client().describeStackInstance(any(DescribeStackInstanceRequest.class))) .thenReturn(DESCRIBE_STACK_INSTANCE_RESPONSE_1, DESCRIBE_STACK_INSTANCE_RESPONSE_2, DESCRIBE_STACK_INSTANCE_RESPONSE_3, DESCRIBE_STACK_INSTANCE_RESPONSE_4); final ProgressEvent<ResourceModel, CallbackContext> response = handler.handleRequest(proxy, request, new CallbackContext(), proxyClient, logger); assertThat(response).isNotNull(); assertThat(response.getStatus()).isEqualTo(OperationStatus.SUCCESS); assertThat(response.getCallbackContext()).isNull(); assertThat(response.getCallbackDelaySeconds()).isEqualTo(0); assertThat(response.getResourceModel()).isEqualTo(SERVICE_MANAGED_MODEL_FOR_READ); assertThat(response.getMessage()).isNull(); assertThat(response.getErrorCode()).isNull(); verify(proxyClient.client()).getTemplateSummary(any(GetTemplateSummaryRequest.class)); verify(proxyClient.client()).createStackSet(any(CreateStackSetRequest.class)); verify(proxyClient.client()).createStackInstances(any(CreateStackInstancesRequest.class)); verify(proxyClient.client()).describeStackSetOperation(any(DescribeStackSetOperationRequest.class)); verify(proxyClient.client()).describeStackSet(any(DescribeStackSetRequest.class)); verify(proxyClient.client()).listStackInstances(any(ListStackInstancesRequest.class)); verify(proxyClient.client(), times(4)).describeStackInstance(any(DescribeStackInstanceRequest.class)); }
protected ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { this.logger = logger; final ResourceModel model = request.getDesiredResourceState(); final StackInstancesPlaceHolder placeHolder = new StackInstancesPlaceHolder(); analyzeTemplate(proxyClient, request, placeHolder, Action.CREATE); return proxy.initiate("AWS-CloudFormation-StackSet::Create", proxyClient, model, callbackContext) .translateToServiceRequest(resourceModel -> createStackSetRequest(resourceModel, request.getClientRequestToken())) .makeServiceCall((modelRequest, proxyInvocation) -> { final CreateStackSetResponse response = proxyClient.injectCredentialsAndInvokeV2(modelRequest, proxyClient.client()::createStackSet); model.setStackSetId(response.stackSetId()); logger.log(String.format("%s [%s] StackSet creation succeeded", ResourceModel.TYPE_NAME, model.getStackSetId())); return response; }) .progress() .then(progress -> createStackInstances(proxy, proxyClient, progress, placeHolder.getCreateStackInstances(), logger)) .then(progress -> new ReadHandler().handleRequest(proxy, request, callbackContext, 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) { this.logger = logger; final ResourceModel model = request.getDesiredResourceState(); final StackInstancesPlaceHolder placeHolder = new StackInstancesPlaceHolder(); analyzeTemplate(proxyClient, request, placeHolder, Action.CREATE); return proxy.initiate("AWS-CloudFormation-StackSet::Create", proxyClient, model, callbackContext) .translateToServiceRequest(resourceModel -> createStackSetRequest(resourceModel, request.getClientRequestToken())) .makeServiceCall((modelRequest, proxyInvocation) -> { final CreateStackSetResponse response = proxyClient.injectCredentialsAndInvokeV2(modelRequest, proxyClient.client()::createStackSet); model.setStackSetId(response.stackSetId()); logger.log(String.format("%s [%s] StackSet creation succeeded", ResourceModel.TYPE_NAME, model.getStackSetId())); return response; }) .progress() .then(progress -> createStackInstances(proxy, proxyClient, progress, placeHolder.getCreateStackInstances(), logger)) .then(progress -> new ReadHandler().handleRequest(proxy, request, callbackContext, 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) { this.logger = logger; final ResourceModel model = request.getDesiredResourceState(); final StackInstancesPlaceHolder placeHolder = new StackInstancesPlaceHolder(); analyzeTemplate(proxyClient, request, placeHolder, Action.CREATE); return proxy.initiate("AWS-CloudFormation-StackSet::Create", proxyClient, model, callbackContext) .translateToServiceRequest(resourceModel -> createStackSetRequest(resourceModel, request.getClientRequestToken())) .makeServiceCall((modelRequest, proxyInvocation) -> { final CreateStackSetResponse response = proxyClient.injectCredentialsAndInvokeV2(modelRequest, proxyClient.client()::createStackSet); model.setStackSetId(response.stackSetId()); logger.log(String.format("%s [%s] StackSet creation succeeded", ResourceModel.TYPE_NAME, model.getStackSetId())); return response; }) .progress() .then(progress -> createStackInstances(proxy, proxyClient, progress, placeHolder.getCreateStackInstances(), logger)) .then(progress -> new ReadHandler().handleRequest(proxy, request, callbackContext, 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) { this.logger = logger; final ResourceModel model = request.getDesiredResourceState(); final StackInstancesPlaceHolder placeHolder = new StackInstancesPlaceHolder(); analyzeTemplate(proxyClient, request, placeHolder, Action.CREATE); return proxy.initiate("AWS-CloudFormation-StackSet::Create", proxyClient, model, callbackContext) .translateToServiceRequest(resourceModel -> createStackSetRequest(resourceModel, request.getClientRequestToken())) .makeServiceCall((modelRequest, proxyInvocation) -> { final CreateStackSetResponse response = proxyClient.injectCredentialsAndInvokeV2(modelRequest, proxyClient.client()::createStackSet); model.setStackSetId(response.stackSetId()); logger.log(String.format("%s [%s] StackSet creation succeeded", ResourceModel.TYPE_NAME, model.getStackSetId())); return response; }) .progress() .then(progress -> createStackInstances(proxy, proxyClient, progress, placeHolder.getCreateStackInstances(), logger)) .then(progress -> new ReadHandler().handleRequest(proxy, request, callbackContext, 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) { this.logger = logger; final ResourceModel model = request.getDesiredResourceState(); final StackInstancesPlaceHolder placeHolder = new StackInstancesPlaceHolder(); analyzeTemplate(proxyClient, request, placeHolder, Action.CREATE); return proxy.initiate("AWS-CloudFormation-StackSet::Create", proxyClient, model, callbackContext) .translateToServiceRequest(resourceModel -> createStackSetRequest(resourceModel, request.getClientRequestToken())) .makeServiceCall((modelRequest, proxyInvocation) -> { final CreateStackSetResponse response = proxyClient.injectCredentialsAndInvokeV2(modelRequest, proxyClient.client()::createStackSet); model.setStackSetId(response.stackSetId()); logger.log(String.format("%s [%s] StackSet creation succeeded", ResourceModel.TYPE_NAME, model.getStackSetId())); return response; }) .progress() .then(progress -> createStackInstances(proxy, proxyClient, progress, placeHolder.getCreateStackInstances(), logger)) .then(progress -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger)); }    }