use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class EmrServiceTest method testEmrServiceMethodsNewTx.
/**
* This method is to get the coverage for the emr service method that starts the new transaction.
*/
@Test
public void testEmrServiceMethodsNewTx() throws Exception {
EmrClusterCreateRequest request = getNewEmrClusterCreateRequest();
try {
emrServiceImpl.createCluster(request);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
try {
EmrShellStepAddRequest stepRequest = getNewEmrShellStepAddRequest(request.getEmrClusterName());
emrServiceImpl.addStepToCluster(stepRequest);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
try {
EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest(request.getEmrClusterName());
emrServiceImpl.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
try {
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("test_cluster").build();
emrServiceImpl.getCluster(emrClusterAlternateKeyDto, null, null, false, null, false);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
try {
EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = EmrClusterAlternateKeyDto.builder().withNamespace(NAMESPACE).withEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME).withEmrClusterName("test_cluster").build();
emrServiceImpl.terminateCluster(emrClusterAlternateKeyDto, false, null, null);
fail("Should throw a ObjectNotFoundException.");
} catch (ObjectNotFoundException e) {
assertEquals("Namespace \"" + NAMESPACE + "\" doesn't exist.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class EmrServiceWithAccountIdTest method getNewEmrAddSecurityGroupMasterRequestWithAccountId.
/**
* This method fills-up the parameters required for the EMR add steps request. This is called from all the other test methods.
*/
private EmrMasterSecurityGroupAddRequest getNewEmrAddSecurityGroupMasterRequestWithAccountId(String clusterName) throws Exception {
// Create the EmrMasterSecurityGroupAddRequest object
EmrMasterSecurityGroupAddRequest request = new EmrMasterSecurityGroupAddRequest();
// Fill in the parameters.
request.setNamespace(NAMESPACE);
request.setEmrClusterDefinitionName(EMR_CLUSTER_DEFINITION_NAME);
request.setEmrClusterName(clusterName);
List<String> groupIds = new ArrayList<>();
groupIds.add("A_TEST_SECURITY_GROUP");
request.setSecurityGroupIds(groupIds);
// add account id
request.setAccountId(AWS_ACCOUNT_ID);
return request;
}
use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class EmrServiceWithAccountIdTest method testAddSecurityGroup.
/**
* This method tests the happy path scenario for adding security groups.
*/
@Test
public void testAddSecurityGroup() throws Exception {
// Create the namespace entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create a trusting AWS account.
trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
EmrClusterCreateRequest request = getNewEmrClusterCreateRequestWithAccountId();
emrService.createCluster(request);
// Create the Add security group.
EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequestWithAccountId(request.getEmrClusterName());
EmrMasterSecurityGroup emrMasterSecurityGroup = emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
// Validate the returned object against the input.
assertNotNull(emrMasterSecurityGroup);
assertTrue(emrMasterSecurityGroup.getNamespace().equals(request.getNamespace()));
assertTrue(emrMasterSecurityGroup.getEmrClusterDefinitionName().equals(request.getEmrClusterDefinitionName()));
assertTrue(emrMasterSecurityGroup.getEmrClusterName().equals(request.getEmrClusterName()));
}
use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class EmrRestControllerTest method testAddGroupsToEmrClusterMaster.
@Test
public void testAddGroupsToEmrClusterMaster() throws Exception {
// Create an add EMR master security group request.
EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = new EmrMasterSecurityGroupAddRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, Arrays.asList(AWS_SECURITY_GROUP_ID), EMR_CLUSTER_ID, AWS_ACCOUNT_ID);
// Create an EMR master security group.
EmrMasterSecurityGroup emrMasterSecurityGroup = new EmrMasterSecurityGroup(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, Arrays.asList(AWS_SECURITY_GROUP_ID), EMR_CLUSTER_ID);
// Mock the external calls.
when(emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest)).thenReturn(emrMasterSecurityGroup);
// Call the method under test.
EmrMasterSecurityGroup result = emrRestController.addGroupsToEmrClusterMaster(emrMasterSecurityGroupAddRequest);
// Verify the external calls.
verify(emrService).addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(emrMasterSecurityGroup, result);
}
use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class EmrServiceTest method testAddSecurityGroupNoneSpecified.
/**
* This method tests the scenario when at least one security group must be specified
*/
@Test(expected = IllegalArgumentException.class)
public void testAddSecurityGroupNoneSpecified() 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();
emrService.createCluster(request);
// Create the Add security group.
EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest(request.getEmrClusterName());
emrMasterSecurityGroupAddRequest.setSecurityGroupIds(null);
emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
}
Aggregations