use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class AddEmrMasterSecurityGroup method executeImpl.
@Override
public void executeImpl(DelegateExecution execution) throws Exception {
// Create the request.
EmrMasterSecurityGroupAddRequest request = new EmrMasterSecurityGroupAddRequest();
request.setNamespace(activitiHelper.getExpressionVariableAsString(namespace, execution));
request.setEmrClusterDefinitionName(activitiHelper.getExpressionVariableAsString(emrClusterDefinitionName, execution));
request.setEmrClusterName(activitiHelper.getExpressionVariableAsString(emrClusterName, execution));
request.setAccountId(activitiHelper.getExpressionVariableAsString(accountId, execution));
String groupIdStr = activitiHelper.getExpressionVariableAsString(securityGroupIds, execution);
if (StringUtils.isBlank(groupIdStr)) {
throw new IllegalArgumentException("At least one security group must be specified.");
}
request.setSecurityGroupIds(daoHelper.splitStringWithDefaultDelimiter(groupIdStr.trim()));
// Create the cluster in a new transaction.
EmrMasterSecurityGroup emrMasterSecurityGroup = emrService.addSecurityGroupsToClusterMaster(request);
// Set workflow variables based on the security groups.
setTaskWorkflowVariable(execution, VARIABLE_EMR_MASTER_SECURITY_GROUPS, herdStringHelper.buildStringWithDefaultDelimiter(emrMasterSecurityGroup.getSecurityGroupIds()));
}
use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class EmrServiceTest 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);
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());
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 EmrServiceTest method testAddSecurityGroupClusterDoesNotExist.
/**
* This method tests the scenario where cluster does not exist
*/
@Test(expected = IllegalArgumentException.class)
public void testAddSecurityGroupClusterDoesNotExist() 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 the Add security group.
EmrMasterSecurityGroupAddRequest emrMasterSecurityGroupAddRequest = getNewEmrAddSecurityGroupMasterRequest("DOES_NOT_EXIST");
emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
}
use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class EmrServiceTest method testAddSecurityGroupAmazonException.
/**
* This method tests the scenario where AmazonServiceException is thrown
*/
@Test(expected = AmazonServiceException.class)
public void testAddSecurityGroupAmazonException() 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.getSecurityGroupIds().clear();
emrMasterSecurityGroupAddRequest.getSecurityGroupIds().add(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION);
emrService.addSecurityGroupsToClusterMaster(emrMasterSecurityGroupAddRequest);
}
use of org.finra.herd.model.api.xml.EmrMasterSecurityGroupAddRequest in project herd by FINRAOS.
the class EmrServiceTest method getNewEmrAddSecurityGroupMasterRequest.
/**
* This method fills-up the parameters required for the EMR add steps request. This is called from all the other test methods.
*/
private EmrMasterSecurityGroupAddRequest getNewEmrAddSecurityGroupMasterRequest(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);
return request;
}
Aggregations