use of org.finra.herd.model.api.xml.InstanceDefinitions in project herd by FINRAOS.
the class EmrClusterDefinitionHelperTest method createValidEmrClusterDefinition.
/**
* Creates a EMR cluster definition which does not cause validateEmrClusterDefinitionConfiguration() to throw an exception.
* <p/>
* - One subnet is specified - Master, core, and task instances are specified - Instance count, and instance type are specified for each instance
* definition. - One node tag is specified
*
* @return A new instance of {@link EmrClusterDefinition}
*/
private EmrClusterDefinition createValidEmrClusterDefinition() {
EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
emrClusterDefinition.setSubnetId(MockEc2OperationsImpl.SUBNET_1);
InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
masterInstanceDefinition.setInstanceCount(1);
masterInstanceDefinition.setInstanceType(MockEc2OperationsImpl.INSTANCE_TYPE_1);
instanceDefinitions.setMasterInstances(masterInstanceDefinition);
InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
coreInstanceDefinition.setInstanceCount(1);
coreInstanceDefinition.setInstanceType(MockEc2OperationsImpl.INSTANCE_TYPE_1);
instanceDefinitions.setCoreInstances(coreInstanceDefinition);
InstanceDefinition taskInstanceDefinition = new InstanceDefinition();
taskInstanceDefinition.setInstanceCount(1);
taskInstanceDefinition.setInstanceType(MockEc2OperationsImpl.INSTANCE_TYPE_1);
instanceDefinitions.setTaskInstances(taskInstanceDefinition);
emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
List<NodeTag> nodeTags = new ArrayList<>();
{
nodeTags.add(new NodeTag("test_nodeTagName", "test_nodeTagValue"));
}
emrClusterDefinition.setNodeTags(nodeTags);
return emrClusterDefinition;
}
use of org.finra.herd.model.api.xml.InstanceDefinitions in project herd by FINRAOS.
the class EmrDaoImplTest method testGetInstanceGroupConfigs.
@Test
public void testGetInstanceGroupConfigs() {
// Create objects required for testing.
final Integer instanceCount = 0;
final InstanceDefinitions instanceDefinitions = new InstanceDefinitions(new MasterInstanceDefinition(), new InstanceDefinition(), new InstanceDefinition());
// Mock the external calls.
when(emrHelper.isInstanceDefinitionsEmpty(instanceDefinitions)).thenReturn(false);
// Call the method under test.
List<InstanceGroupConfig> result = emrDaoImpl.getInstanceGroupConfigs(instanceDefinitions);
// Verify the external calls.
verify(emrHelper).isInstanceDefinitionsEmpty(instanceDefinitions);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(3, CollectionUtils.size(result));
assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.MASTER, null, instanceCount)));
assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.CORE, null, instanceCount)));
assertTrue(result.contains(new InstanceGroupConfig(InstanceRoleType.TASK, null, instanceCount)));
}
use of org.finra.herd.model.api.xml.InstanceDefinitions in project herd by FINRAOS.
the class EmrPricingHelperTest method updateEmrClusterDefinitionWithBestPrice.
/**
* Creates a new EMR cluster definition using the specified parameters, updates it with best price algorithm, and returns the definition.
*
* @param subnetId Subnet ID. Optional.
* @param masterInstanceDefinition The master instance definition
* @param coreInstanceDefinition The core instance definition
* @param taskInstanceDefinition The task instance definition. Optional.
*
* @return Updated EMR cluster definition.
*/
private EmrClusterDefinition updateEmrClusterDefinitionWithBestPrice(String subnetId, MasterInstanceDefinition masterInstanceDefinition, InstanceDefinition coreInstanceDefinition, InstanceDefinition taskInstanceDefinition) {
EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
emrClusterDefinition.setSubnetId(subnetId);
InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
instanceDefinitions.setMasterInstances(masterInstanceDefinition);
instanceDefinitions.setCoreInstances(coreInstanceDefinition);
instanceDefinitions.setTaskInstances(taskInstanceDefinition);
emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
emrPricingHelper.updateEmrClusterDefinitionWithBestPrice(new EmrClusterAlternateKeyDto(), emrClusterDefinition, new AwsParamsDto());
return emrClusterDefinition;
}
use of org.finra.herd.model.api.xml.InstanceDefinitions in project herd by FINRAOS.
the class EmrDaoTest method createEmrClusterAssertEncryptionDisabled.
@Test
public void createEmrClusterAssertEncryptionDisabled() throws Exception {
/*
* Use only minimum required options
*/
String clusterName = "clusterName";
EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
instanceDefinitions.setMasterInstances(new MasterInstanceDefinition(10, "masterInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
instanceDefinitions.setCoreInstances(new InstanceDefinition(20, "coreInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
emrClusterDefinition.setNodeTags(Arrays.asList(new NodeTag("tagName", "tagValue")));
emrClusterDefinition.setEncryptionEnabled(false);
String clusterId = "clusterId";
when(mockEmrOperations.runEmrJobFlow(any(), any())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
RunJobFlowRequest runJobFlowRequest = invocation.getArgument(1);
// No bootstrap action should be added
assertEquals(0, runJobFlowRequest.getBootstrapActions().size());
return clusterId;
}
});
assertEquals(clusterId, emrDao.createEmrCluster(clusterName, emrClusterDefinition, new AwsParamsDto()));
}
use of org.finra.herd.model.api.xml.InstanceDefinitions in project herd by FINRAOS.
the class EmrDaoTest method createEmrClusterAssertCallRunEmrJobFlowRequiredParamsOnly.
@Test
public void createEmrClusterAssertCallRunEmrJobFlowRequiredParamsOnly() throws Exception {
String clusterName = "clusterName";
EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
instanceDefinitions.setMasterInstances(new MasterInstanceDefinition(10, "masterInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
instanceDefinitions.setCoreInstances(new InstanceDefinition(20, "coreInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
emrClusterDefinition.setNodeTags(Arrays.asList(new NodeTag("tagName", "tagValue")));
String clusterId = "clusterId";
when(mockEmrOperations.runEmrJobFlow(any(), any())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
/*
* Assert that the given EMR cluster definition produced the correct RunJobFlowRequest
*/
RunJobFlowRequest runJobFlowRequest = invocation.getArgument(1);
JobFlowInstancesConfig jobFlowInstancesConfig = runJobFlowRequest.getInstances();
List<InstanceGroupConfig> instanceGroupConfigs = jobFlowInstancesConfig.getInstanceGroups();
assertEquals(2, instanceGroupConfigs.size());
{
InstanceGroupConfig instanceGroupConfig = instanceGroupConfigs.get(0);
assertEquals(10, instanceGroupConfig.getInstanceCount().intValue());
assertEquals("masterInstanceType", instanceGroupConfig.getInstanceType());
}
{
InstanceGroupConfig instanceGroupConfig = instanceGroupConfigs.get(1);
assertEquals(20, instanceGroupConfig.getInstanceCount().intValue());
assertEquals("coreInstanceType", instanceGroupConfig.getInstanceType());
}
assertEquals(herdStringHelper.getRequiredConfigurationValue(ConfigurationValue.EMR_DEFAULT_EC2_NODE_IAM_PROFILE_NAME), runJobFlowRequest.getJobFlowRole());
assertEquals(herdStringHelper.getRequiredConfigurationValue(ConfigurationValue.EMR_DEFAULT_SERVICE_IAM_ROLE_NAME), runJobFlowRequest.getServiceRole());
List<StepConfig> stepConfigs = runJobFlowRequest.getSteps();
assertEquals(0, stepConfigs.size());
List<Tag> tags = runJobFlowRequest.getTags();
assertEquals(1, tags.size());
{
Tag tag = tags.get(0);
assertEquals("tagName", tag.getKey());
assertEquals("tagValue", tag.getValue());
}
return clusterId;
}
});
assertEquals(clusterId, emrDao.createEmrCluster(clusterName, emrClusterDefinition, new AwsParamsDto()));
}
Aggregations