use of com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult in project herd by FINRAOS.
the class EmrDaoImplTest method testGetListInstanceFleetsResult.
@Test
public void testGetListInstanceFleetsResult() {
// Create an AWS parameters DTO.
AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Create a mock AmazonElasticMapReduceClient.
AmazonElasticMapReduceClient amazonElasticMapReduceClient = mock(AmazonElasticMapReduceClient.class);
// Create a list instance fleets request.
ListInstanceFleetsRequest listInstanceFleetsRequest = new ListInstanceFleetsRequest().withClusterId(EMR_CLUSTER_ID);
// Create a list instance fleets result.
ListInstanceFleetsResult listInstanceFleetsResult = new ListInstanceFleetsResult().withMarker(MARKER);
// Mock the external calls.
when(awsClientFactory.getEmrClient(awsParamsDto)).thenReturn(amazonElasticMapReduceClient);
when(emrOperations.listInstanceFleets(amazonElasticMapReduceClient, listInstanceFleetsRequest)).thenReturn(listInstanceFleetsResult);
// Call the method under test.
ListInstanceFleetsResult result = emrDaoImpl.getListInstanceFleetsResult(EMR_CLUSTER_ID, awsParamsDto);
// Verify the external calls.
verify(awsClientFactory).getEmrClient(awsParamsDto);
verify(emrOperations).listInstanceFleets(amazonElasticMapReduceClient, listInstanceFleetsRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(listInstanceFleetsResult, result);
}
use of com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult in project herd by FINRAOS.
the class EmrHelperTest method testBuildEmrClusterInstanceFleetFromAwsResult.
@Test
public void testBuildEmrClusterInstanceFleetFromAwsResult() {
ListInstanceFleetsResult listInstanceFleetsResult = null;
assertNull(emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
listInstanceFleetsResult = new ListInstanceFleetsResult();
assertNull(emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
String instanceId = "instance id";
String instanceName = "instance name";
String instanceFleetType = "instance fleet type";
int targetOnDemandCapacity = 1;
int targetSpotCapacity = 2;
int provisionedOnDemandCapacity = 3;
int provisionedSpotCapacity = 4;
EmrClusterInstanceFleet expectedEmrInstanceFleet = new EmrClusterInstanceFleet();
expectedEmrInstanceFleet.setId(instanceId);
expectedEmrInstanceFleet.setName(instanceName);
expectedEmrInstanceFleet.setInstanceFleetType(instanceFleetType);
expectedEmrInstanceFleet.setTargetOnDemandCapacity(targetOnDemandCapacity);
expectedEmrInstanceFleet.setTargetSpotCapacity(targetSpotCapacity);
expectedEmrInstanceFleet.setProvisionedOnDemandCapacity(provisionedOnDemandCapacity);
expectedEmrInstanceFleet.setProvisionedSpotCapacity(provisionedSpotCapacity);
InstanceFleet instanceFleet = new InstanceFleet();
instanceFleet.setId(instanceId);
instanceFleet.setName(instanceName);
instanceFleet.setInstanceFleetType(instanceFleetType);
instanceFleet.setTargetOnDemandCapacity(targetOnDemandCapacity);
instanceFleet.setTargetSpotCapacity(targetSpotCapacity);
instanceFleet.setProvisionedSpotCapacity(provisionedSpotCapacity);
instanceFleet.setProvisionedOnDemandCapacity(provisionedOnDemandCapacity);
List<InstanceFleet> instanceFleets = new ArrayList<>();
instanceFleets.add(null);
instanceFleets.add(instanceFleet);
listInstanceFleetsResult.setInstanceFleets(instanceFleets);
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
EmrClusterInstanceFleetStatus emrClusterInstanceFleetStatus = new EmrClusterInstanceFleetStatus();
String emrClusterInstanceFleetStatus_State = "state 1";
emrClusterInstanceFleetStatus.setState(emrClusterInstanceFleetStatus_State);
expectedEmrInstanceFleet.setInstanceFleetStatus(emrClusterInstanceFleetStatus);
InstanceFleetStatus instanceFleetStatus = new InstanceFleetStatus();
instanceFleetStatus.setState(emrClusterInstanceFleetStatus_State);
instanceFleet.setStatus(instanceFleetStatus);
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
String emrClusterInstanceFleetStatus_StateChangeCode = "change code 1";
String emrClusterInstanceFleetStatus_StateChangeMsg = "change msg 1";
InstanceFleetStateChangeReason instanceFleetStateChangeReason = new InstanceFleetStateChangeReason();
instanceFleetStateChangeReason.setCode(emrClusterInstanceFleetStatus_StateChangeCode);
instanceFleetStateChangeReason.setMessage(emrClusterInstanceFleetStatus_StateChangeMsg);
instanceFleetStatus.setStateChangeReason(instanceFleetStateChangeReason);
InstanceFleetTimeline instanceFleetTimeline = new InstanceFleetTimeline();
java.util.Date now = Calendar.getInstance().getTime();
instanceFleetTimeline.setCreationDateTime(now);
instanceFleetTimeline.setReadyDateTime(now);
instanceFleetTimeline.setEndDateTime(now);
instanceFleetStatus.setTimeline(instanceFleetTimeline);
EmrClusterInstanceFleetStateChangeReason emrClusterInstanceFleetStateChangeReason = new EmrClusterInstanceFleetStateChangeReason();
emrClusterInstanceFleetStateChangeReason.setCode(emrClusterInstanceFleetStatus_StateChangeCode);
emrClusterInstanceFleetStateChangeReason.setMessage(emrClusterInstanceFleetStatus_StateChangeMsg);
emrClusterInstanceFleetStatus.setStateChangeReason(emrClusterInstanceFleetStateChangeReason);
EmrClusterInstanceFleetTimeline emrClusterInstanceFleetTimeline = new EmrClusterInstanceFleetTimeline();
emrClusterInstanceFleetTimeline.setCreationDateTime(HerdDateUtils.getXMLGregorianCalendarValue(now));
emrClusterInstanceFleetTimeline.setReadyDateTime(HerdDateUtils.getXMLGregorianCalendarValue(now));
emrClusterInstanceFleetTimeline.setEndDateTime(HerdDateUtils.getXMLGregorianCalendarValue(now));
emrClusterInstanceFleetStatus.setTimeline(emrClusterInstanceFleetTimeline);
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
String instanceType = "instance type 1";
int weightedCapacity = 1;
String bidPrice = "1.0";
double bidPricePercent = 0.8;
boolean ebsOptimized = true;
InstanceTypeSpecification instanceTypeSpecification = new InstanceTypeSpecification();
instanceTypeSpecification.setInstanceType(instanceType);
instanceTypeSpecification.setWeightedCapacity(weightedCapacity);
instanceTypeSpecification.setBidPrice(bidPrice);
instanceTypeSpecification.setBidPriceAsPercentageOfOnDemandPrice(bidPricePercent);
instanceTypeSpecification.setEbsOptimized(ebsOptimized);
List<InstanceTypeSpecification> instanceTypeSpecifications = new ArrayList<>();
instanceTypeSpecifications.add(null);
instanceTypeSpecifications.add(instanceTypeSpecification);
instanceFleet.setInstanceTypeSpecifications(instanceTypeSpecifications);
EmrClusterInstanceTypeSpecification emrClusterInstanceTypeSpecification = new EmrClusterInstanceTypeSpecification();
emrClusterInstanceTypeSpecification.setInstanceType(instanceType);
emrClusterInstanceTypeSpecification.setWeightedCapacity(weightedCapacity);
emrClusterInstanceTypeSpecification.setBidPrice(bidPrice);
emrClusterInstanceTypeSpecification.setBidPriceAsPercentageOfOnDemandPrice(bidPricePercent);
emrClusterInstanceTypeSpecification.setEbsOptimized(ebsOptimized);
expectedEmrInstanceFleet.setInstanceTypeSpecifications(Arrays.asList(emrClusterInstanceTypeSpecification));
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
EbsBlockDevice ebsBlockDevice = new EbsBlockDevice();
String device = "device 1";
ebsBlockDevice.setDevice(device);
List<EbsBlockDevice> ebsBlockDevices = new ArrayList<>();
ebsBlockDevices.add(ebsBlockDevice);
ebsBlockDevices.add(null);
instanceTypeSpecification.setEbsBlockDevices(ebsBlockDevices);
EmrClusterEbsBlockDevice emrClusterEbsBlockDevice = new EmrClusterEbsBlockDevice();
emrClusterEbsBlockDevice.setDevice(device);
emrClusterInstanceTypeSpecification.setEbsBlockDevices(Arrays.asList(emrClusterEbsBlockDevice));
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
int iops = 100;
int sizeInGB = 20;
String volumeType = "volume type 1";
VolumeSpecification volumeSpecification = new VolumeSpecification();
volumeSpecification.setIops(iops);
volumeSpecification.setSizeInGB(sizeInGB);
volumeSpecification.setVolumeType(volumeType);
ebsBlockDevice.setVolumeSpecification(volumeSpecification);
EmrClusterVolumeSpecification emrClusterVolumeSpecification = new EmrClusterVolumeSpecification();
emrClusterVolumeSpecification.setIops(iops);
emrClusterVolumeSpecification.setSizeInGB(sizeInGB);
emrClusterVolumeSpecification.setVolumeType(volumeType);
emrClusterEbsBlockDevice.setVolumeSpecification(emrClusterVolumeSpecification);
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
InstanceFleetProvisioningSpecifications instanceFleetProvisioningSpecifications = new InstanceFleetProvisioningSpecifications();
instanceFleet.setLaunchSpecifications(instanceFleetProvisioningSpecifications);
EmrClusterInstanceFleetProvisioningSpecifications emrClusterInstanceFleetProvisioningSpecifications = new EmrClusterInstanceFleetProvisioningSpecifications();
expectedEmrInstanceFleet.setLaunchSpecifications(emrClusterInstanceFleetProvisioningSpecifications);
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
List<Configuration> configurations = new ArrayList<>();
Configuration configuration = new Configuration();
String classification = "classification 1";
configuration.setClassification(classification);
configurations.add(null);
configurations.add(configuration);
instanceTypeSpecification.setConfigurations(configurations);
EmrClusterInstanceTypeConfiguration emrClusterInstanceTypeConfiguration = new EmrClusterInstanceTypeConfiguration();
emrClusterInstanceTypeConfiguration.setClassification(classification);
emrClusterInstanceTypeSpecification.setConfigurations(Arrays.asList(emrClusterInstanceTypeConfiguration));
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
String paramKey = "param 1";
String paramVal = "param val 1";
java.util.Map<String, String> map = new HashMap<>();
map.put(paramKey, paramVal);
configuration.setProperties(map);
Parameter parameter = new Parameter(paramKey, paramVal);
emrClusterInstanceTypeConfiguration.setProperties(Arrays.asList(parameter));
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
int blockDurationMin = 30;
String timeoutAction = "action 1";
int timeoutDurationMin = 60;
// to do time out action
SpotProvisioningSpecification spotProvisioningSpecification = new SpotProvisioningSpecification();
spotProvisioningSpecification.setBlockDurationMinutes(blockDurationMin);
spotProvisioningSpecification.setTimeoutAction(timeoutAction);
spotProvisioningSpecification.setTimeoutDurationMinutes(timeoutDurationMin);
instanceFleetProvisioningSpecifications.setSpotSpecification(spotProvisioningSpecification);
EmrClusterSpotProvisioningSpecification emrClusterSpotProvisioningSpecification = new EmrClusterSpotProvisioningSpecification();
emrClusterSpotProvisioningSpecification.setBlockDurationMinutes(blockDurationMin);
emrClusterSpotProvisioningSpecification.setTimeoutAction(timeoutAction);
emrClusterSpotProvisioningSpecification.setTimeoutDurationMinutes(timeoutDurationMin);
emrClusterInstanceFleetProvisioningSpecifications.setSpotSpecification(emrClusterSpotProvisioningSpecification);
assertEquals(Arrays.asList(expectedEmrInstanceFleet), emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
}
use of com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult in project herd by FINRAOS.
the class MockEmrOperationsImpl method listInstanceFleets.
@Override
public ListInstanceFleetsResult listInstanceFleets(AmazonElasticMapReduceClient emrClient, ListInstanceFleetsRequest listInstanceFleetsRequest) {
ListInstanceFleetsResult listInstanceFleetsResult = new ListInstanceFleetsResult();
List<InstanceFleet> instanceFleets = new ArrayList<>();
InstanceFleet instanceFleet = new InstanceFleet();
instanceFleet.setId("mock_instance_id_1");
instanceFleet.setName("mock_instance_name");
instanceFleets.add(instanceFleet);
listInstanceFleetsResult.setInstanceFleets(instanceFleets);
return listInstanceFleetsResult;
}
use of com.amazonaws.services.elasticmapreduce.model.ListInstanceFleetsResult in project herd by FINRAOS.
the class EmrServiceImpl method getClusterImpl.
/**
* Gets details of an existing EMR Cluster.
*
* @param emrClusterAlternateKeyDto the EMR cluster alternate key
* @param emrClusterId the cluster id of the cluster to get details
* @param emrStepId the step id of the step to get details
* @param verbose parameter for whether to return detailed information
* @param accountId the optional AWS account that EMR cluster is running in
* @param retrieveInstanceFleets parameter for whether to retrieve instance fleets
*
* @return the EMR Cluster object with details.
* @throws Exception if an error occurred while getting the cluster
*/
protected EmrCluster getClusterImpl(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, String emrClusterId, String emrStepId, boolean verbose, String accountId, Boolean retrieveInstanceFleets) throws Exception {
AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDtoByAcccountId(accountId);
// Perform the request validation.
validateEmrClusterKey(emrClusterAlternateKeyDto);
// Get the namespace and ensure it exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(emrClusterAlternateKeyDto.getNamespace());
// Get the EMR cluster definition and ensure it exists.
EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName());
EmrCluster emrCluster = createEmrClusterFromRequest(null, namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName(), accountId, null, null, null, null);
String clusterName = emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName());
try {
// Get Cluster status if clusterId is specified
if (StringUtils.isNotBlank(emrClusterId)) {
Cluster cluster = emrDao.getEmrClusterById(emrClusterId.trim(), awsParamsDto);
// Validate that, Cluster exists
Assert.notNull(cluster, "An EMR cluster must exists with the cluster ID \"" + emrClusterId + "\".");
// Validate that, Cluster name match as specified
Assert.isTrue(clusterName.equalsIgnoreCase(cluster.getName()), "Cluster name of specified cluster id \"" + emrClusterId + "\" must match the name specified.");
emrCluster.setId(cluster.getId());
setEmrClusterStatus(emrCluster, cluster.getStatus());
} else {
ClusterSummary clusterSummary = emrDao.getActiveEmrClusterByName(clusterName, awsParamsDto);
// Validate that, Cluster exists with the name
Assert.notNull(clusterSummary, "An EMR cluster must exists with the name \"" + clusterName + "\".");
emrCluster.setId(clusterSummary.getId());
setEmrClusterStatus(emrCluster, clusterSummary.getStatus());
}
// Get active step details
if (emrHelper.isActiveEmrState(emrCluster.getStatus())) {
StepSummary stepSummary = emrDao.getClusterActiveStep(emrCluster.getId(), awsParamsDto);
if (stepSummary != null) {
EmrStep activeStep;
// If verbose get active step details
if (verbose) {
activeStep = buildEmrStepFromAwsStep(stepSummary, true);
} else {
activeStep = buildEmrStepFromAwsStepSummary(stepSummary);
}
emrCluster.setActiveStep(activeStep);
}
}
// Get requested step details
if (StringUtils.isNotBlank(emrStepId)) {
Step step = emrDao.getClusterStep(emrCluster.getId(), emrStepId.trim(), awsParamsDto);
emrCluster.setStep(buildEmrStepFromAwsStep(step, verbose));
}
// Get instance fleet if true
if (BooleanUtils.isTrue(retrieveInstanceFleets)) {
ListInstanceFleetsResult listInstanceFleetsResult = emrDao.getListInstanceFleetsResult(emrCluster.getId(), awsParamsDto);
emrCluster.setInstanceFleets(emrHelper.buildEmrClusterInstanceFleetFromAwsResult(listInstanceFleetsResult));
}
} catch (AmazonServiceException ex) {
handleAmazonException(ex, "An Amazon exception occurred while getting EMR cluster details with name \"" + clusterName + "\".");
}
return emrCluster;
}
Aggregations