/** * Terminates an existing EMR cluster. <p>Requires EXECUTE permission on namespace</p> * * @param namespace the namespace * @param emrClusterDefinitionName the EMR cluster definition name * @param emrClusterName the EMR cluster name * @param overrideTerminationProtection parameter for whether to override termination protection * @param emrClusterId EMR cluster ID * @param accountId account Id * * @return the EMR cluster that was terminated * @throws Exception if there was an error terminating the EMR cluster. */ @RequestMapping(value = "/emrClusters/namespaces/{namespace}/emrClusterDefinitionNames/{emrClusterDefinitionName}/emrClusterNames/{emrClusterName}", method = RequestMethod.DELETE) @Secured(SecurityFunctions.FN_EMR_CLUSTERS_DELETE) public EmrCluster terminateEmrCluster(@PathVariable("namespace") String namespace, @PathVariable("emrClusterDefinitionName") String emrClusterDefinitionName, @PathVariable("emrClusterName") String emrClusterName, @RequestParam(value = "overrideTerminationProtection", required = false, defaultValue = "false") Boolean overrideTerminationProtection, @RequestParam(value = "emrClusterId", required = false) String emrClusterId, @RequestParam(value = "accountId", required = false) String accountId) throws Exception { EmrClusterAlternateKeyDto alternateKey = EmrClusterAlternateKeyDto.builder().withNamespace(namespace).withEmrClusterDefinitionName(emrClusterDefinitionName) .withEmrClusterName(emrClusterName).build(); return emrService.terminateCluster(alternateKey, overrideTerminationProtection, emrClusterId, accountId); } }
/** * Terminates an existing EMR cluster. <p>Requires EXECUTE permission on namespace</p> * * @param namespace the namespace * @param emrClusterDefinitionName the EMR cluster definition name * @param emrClusterName the EMR cluster name * @param overrideTerminationProtection parameter for whether to override termination protection * @param emrClusterId EMR cluster ID * @param accountId account Id * * @return the EMR cluster that was terminated * @throws Exception if there was an error terminating the EMR cluster. */ @RequestMapping(value = "/emrClusters/namespaces/{namespace}/emrClusterDefinitionNames/{emrClusterDefinitionName}/emrClusterNames/{emrClusterName}", method = RequestMethod.DELETE) @Secured(SecurityFunctions.FN_EMR_CLUSTERS_DELETE) public EmrCluster terminateEmrCluster(@PathVariable("namespace") String namespace, @PathVariable("emrClusterDefinitionName") String emrClusterDefinitionName, @PathVariable("emrClusterName") String emrClusterName, @RequestParam(value = "overrideTerminationProtection", required = false, defaultValue = "false") Boolean overrideTerminationProtection, @RequestParam(value = "emrClusterId", required = false) String emrClusterId, @RequestParam(value = "accountId", required = false) String accountId) throws Exception { EmrClusterAlternateKeyDto alternateKey = EmrClusterAlternateKeyDto.builder().withNamespace(namespace).withEmrClusterDefinitionName(emrClusterDefinitionName) .withEmrClusterName(emrClusterName).build(); return emrService.terminateCluster(alternateKey, overrideTerminationProtection, emrClusterId, accountId); } }
@Override public void executeImpl(DelegateExecution execution) throws Exception { EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = getClusterAlternateKey(execution); boolean overrideTerminationProtectionBoolean = activitiHelper.getExpressionVariableAsBoolean(overrideTerminationProtection, execution, "overrideTerminationProtection", false, false); String emrClusterIdString = activitiHelper.getExpressionVariableAsString(emrClusterId, execution); String accountIdString = activitiHelper.getExpressionVariableAsString(accountId, execution); // Terminate the EMR cluster. EmrCluster emrCluster = emrService.terminateCluster(emrClusterAlternateKeyDto, overrideTerminationProtectionBoolean, emrClusterIdString, accountIdString); // Set workflow variables based on the result EMR cluster that was terminated. setIdStatusWorkflowVariables(execution, emrCluster); LOGGER.info("{} EMR cluster terminated. emrClusterId=\"{}\"", activitiHelper.getProcessIdentifyingInformation(execution), emrCluster.getId()); } }
@Override public void executeImpl(DelegateExecution execution) throws Exception { EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = getClusterAlternateKey(execution); boolean overrideTerminationProtectionBoolean = activitiHelper.getExpressionVariableAsBoolean(overrideTerminationProtection, execution, "overrideTerminationProtection", false, false); String emrClusterIdString = activitiHelper.getExpressionVariableAsString(emrClusterId, execution); String accountIdString = activitiHelper.getExpressionVariableAsString(accountId, execution); // Terminate the EMR cluster. EmrCluster emrCluster = emrService.terminateCluster(emrClusterAlternateKeyDto, overrideTerminationProtectionBoolean, emrClusterIdString, accountIdString); // Set workflow variables based on the result EMR cluster that was terminated. setIdStatusWorkflowVariables(execution, emrCluster); LOGGER.info("{} EMR cluster terminated. emrClusterId=\"{}\"", activitiHelper.getProcessIdentifyingInformation(execution), emrCluster.getId()); } }
@Test public void testTerminateEmrCluster() throws Exception { // Create an EMR cluster key. EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME); // Create an EMR cluster. EmrCluster emrCluster = new EmrCluster(); emrCluster.setId(EMR_CLUSTER_ID); // Mock the external calls. when(emrService.terminateCluster(emrClusterAlternateKeyDto, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID)).thenReturn(emrCluster); // Call the method under test. EmrCluster result = emrRestController .terminateEmrCluster(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID); // Verify the external calls. verify(emrService).terminateCluster(emrClusterAlternateKeyDto, OVERRIDE_TERMINATION_PROTECTION, EMR_CLUSTER_ID, AWS_ACCOUNT_ID); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(emrCluster, result); }
/** * This method tests the scenario when no active cluster exists. */ @Test(expected = IllegalArgumentException.class) public void testTerminateEmrClusterNoCluster() throws Exception { // Create the namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME) .withEmrClusterName("cluster_not_found").build(); emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null); }
emrService.terminateCluster(emrClusterAlternateKeyDto, overrideTerminationProtection, emrClusterId, null);
/** * This method tests the scenario where AmazonServiceException is thrown */ @Test(expected = AmazonServiceException.class) public void testTerminateEmrClusterAmazonException() throws Exception { // Create the namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); EmrClusterCreateRequest request = getNewEmrClusterCreateRequest(); request.setEmrClusterName(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION); emrService.createCluster(request); EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME) .withEmrClusterName(request.getEmrClusterName()).build(); emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null); }
/** * This method tests the happy path scenario by providing all the parameters */ @Test public void testTerminateEmrCluster() throws Exception { // Create the namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); // Create a new EMR cluster create request EmrClusterCreateRequest request = getNewEmrClusterCreateRequest(); EmrCluster emrCluster = emrService.createCluster(request); EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME) .withEmrClusterName(request.getEmrClusterName()).build(); EmrCluster emrClusterTerminated = emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null); // Validate the returned object against the input. assertNotNull(emrCluster); assertNotNull(emrClusterTerminated); assertTrue(emrCluster.getNamespace().equals(emrClusterTerminated.getNamespace())); assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterTerminated.getEmrClusterDefinitionName())); assertTrue(emrCluster.getEmrClusterName().equals(emrClusterTerminated.getEmrClusterName())); }
/** * This method tests the happy path scenario by providing all the parameters. */ @Test public void testTerminateEmrCluster() throws Exception { // Create the namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream())); // Create a trusting AWS account. trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN); // Create a new EMR cluster create request EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId(); EmrCluster emrCluster = emrService.createCluster(request); EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME) .withEmrClusterName(request.getEmrClusterName()).build(); EmrCluster emrClusterTerminated = emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null); // Validate the returned object against the input. assertNotNull(emrCluster); assertNotNull(emrClusterTerminated); assertTrue(emrCluster.getNamespace().equals(emrClusterTerminated.getNamespace())); assertTrue(emrCluster.getEmrClusterDefinitionName().equals(emrClusterTerminated.getEmrClusterDefinitionName())); assertTrue(emrCluster.getEmrClusterName().equals(emrClusterTerminated.getEmrClusterName())); assertEquals(AWS_ACCOUNT_ID, emrCluster.getAccountId()); }
emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, null);
emrService.terminateCluster(emrClusterAlternateKeyDto, true, null, AWS_ACCOUNT_ID);
EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME) .withEmrClusterName("test_cluster").build(); emrServiceImpl.terminateCluster(emrClusterAlternateKeyDto, false, null, null); fail("Should throw a ObjectNotFoundException.");