Search in sources :

Example 16 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method getEmrClusterByIdAssertCallDescribeCluster.

@Test
public void getEmrClusterByIdAssertCallDescribeCluster() throws Exception {
    String clusterId = "clusterId";
    Cluster expectedCluster = new Cluster();
    when(mockEmrOperations.describeClusterRequest(any(), any())).thenAnswer(new Answer<DescribeClusterResult>() {

        @Override
        public DescribeClusterResult answer(InvocationOnMock invocation) throws Throwable {
            DescribeClusterRequest describeClusterRequest = invocation.getArgument(1);
            assertEquals(clusterId, describeClusterRequest.getClusterId());
            DescribeClusterResult describeClusterResult = new DescribeClusterResult();
            describeClusterResult.setCluster(expectedCluster);
            return describeClusterResult;
        }
    });
    assertEquals(expectedCluster, emrDao.getEmrClusterById(clusterId, new AwsParamsDto()));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) DescribeClusterRequest(com.amazonaws.services.elasticmapreduce.model.DescribeClusterRequest) DescribeClusterResult(com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) Test(org.junit.Test)

Example 17 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method addEmrStepCallsAddJobFlowSteps.

@Test
public void addEmrStepCallsAddJobFlowSteps() throws Exception {
    String clusterName = "clusterName";
    StepConfig emrStepConfig = new StepConfig();
    String clusterId = "clusterId";
    String stepId = "stepId";
    /*
         * Mock the EmrOperations.listEmrClusters() call to return a known result.
         */
    ListClustersResult listClustersResult = new ListClustersResult();
    ClusterSummary clusterSummary = new ClusterSummary();
    clusterSummary.setId(clusterId);
    clusterSummary.setName(clusterName);
    listClustersResult.setClusters(Arrays.asList(clusterSummary));
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult);
    /*
         * Mock EmrOperations.addJobFlowStepsRequest() and assert parameters passed in.
         */
    when(mockEmrOperations.addJobFlowStepsRequest(any(), any())).thenAnswer(new Answer<List<String>>() {

        @Override
        public List<String> answer(InvocationOnMock invocation) throws Throwable {
            AddJobFlowStepsRequest addJobFlowStepsRequest = invocation.getArgument(1);
            assertEquals(clusterId, addJobFlowStepsRequest.getJobFlowId());
            List<StepConfig> steps = addJobFlowStepsRequest.getSteps();
            assertEquals(1, steps.size());
            assertEquals(emrStepConfig, steps.get(0));
            // return a single step with the given stepId
            return Arrays.asList(stepId);
        }
    });
    assertEquals(stepId, emrDao.addEmrStep(clusterId, emrStepConfig, new AwsParamsDto()));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) StepConfig(com.amazonaws.services.elasticmapreduce.model.StepConfig) List(java.util.List) ArrayList(java.util.ArrayList) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) AddJobFlowStepsRequest(com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsRequest) Test(org.junit.Test)

Example 18 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method getEmrClusterStatusByIdAssertReturnNullWhenClusterIsNull.

@Test
public void getEmrClusterStatusByIdAssertReturnNullWhenClusterIsNull() throws Exception {
    String clusterId = "clusterId";
    when(mockEmrOperations.describeClusterRequest(any(), any())).then(new Answer<DescribeClusterResult>() {

        @Override
        public DescribeClusterResult answer(InvocationOnMock invocation) throws Throwable {
            DescribeClusterRequest describeClusterRequest = invocation.getArgument(1);
            assertEquals(clusterId, describeClusterRequest.getClusterId());
            return new DescribeClusterResult();
        }
    });
    assertNull(emrDao.getEmrClusterStatusById(clusterId, new AwsParamsDto()));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) DescribeClusterRequest(com.amazonaws.services.elasticmapreduce.model.DescribeClusterRequest) DescribeClusterResult(com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 19 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method createEmrClusterAssertCallRunEmrJobFlowWithInstanceFleetAndMultipleSubnets.

@Test
public void createEmrClusterAssertCallRunEmrJobFlowWithInstanceFleetAndMultipleSubnets() throws Exception {
    // Create objects required for testing.
    final String clusterName = "clusterName";
    final String clusterId = "clusterId";
    final String name = STRING_VALUE;
    final String instanceFleetType = STRING_VALUE_2;
    final Integer targetOnDemandCapacity = INTEGER_VALUE;
    final Integer targetSpotCapacity = INTEGER_VALUE_2;
    final List<EmrClusterDefinitionInstanceTypeConfig> emrClusterDefinitionInstanceTypeConfigs = null;
    final EmrClusterDefinitionLaunchSpecifications emrClusterDefinitionLaunchSpecifications = null;
    final EmrClusterDefinitionInstanceFleet emrClusterDefinitionInstanceFleet = new EmrClusterDefinitionInstanceFleet(name, instanceFleetType, targetOnDemandCapacity, targetSpotCapacity, emrClusterDefinitionInstanceTypeConfigs, emrClusterDefinitionLaunchSpecifications);
    // Create an EMR cluster definition with instance fleet configuration and multiple EC2 subnet IDs.
    EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
    emrClusterDefinition.setInstanceFleets(Arrays.asList(emrClusterDefinitionInstanceFleet));
    emrClusterDefinition.setSubnetId(String.format("%s , %s  ", EC2_SUBNET, EC2_SUBNET_2));
    emrClusterDefinition.setNodeTags(Arrays.asList(new NodeTag("tagName", "tagValue")));
    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();
            assertEquals(0, CollectionUtils.size(jobFlowInstancesConfig.getInstanceGroups()));
            final List<InstanceTypeConfig> expectedInstanceTypeConfigs = null;
            assertEquals(Arrays.asList(new InstanceFleetConfig().withName(name).withInstanceFleetType(instanceFleetType).withTargetOnDemandCapacity(targetOnDemandCapacity).withTargetSpotCapacity(targetSpotCapacity).withInstanceTypeConfigs(expectedInstanceTypeConfigs).withLaunchSpecifications(null)), jobFlowInstancesConfig.getInstanceFleets());
            assertNull(jobFlowInstancesConfig.getEc2SubnetId());
            assertEquals(2, CollectionUtils.size(jobFlowInstancesConfig.getEc2SubnetIds()));
            assertTrue(jobFlowInstancesConfig.getEc2SubnetIds().contains(EC2_SUBNET));
            assertTrue(jobFlowInstancesConfig.getEc2SubnetIds().contains(EC2_SUBNET_2));
            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()));
}
Also used : EmrClusterDefinitionInstanceTypeConfig(org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceTypeConfig) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) RunJobFlowRequest(com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest) JobFlowInstancesConfig(com.amazonaws.services.elasticmapreduce.model.JobFlowInstancesConfig) InstanceFleetConfig(com.amazonaws.services.elasticmapreduce.model.InstanceFleetConfig) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NodeTag(org.finra.herd.model.api.xml.NodeTag) List(java.util.List) ArrayList(java.util.ArrayList) Tag(com.amazonaws.services.elasticmapreduce.model.Tag) NodeTag(org.finra.herd.model.api.xml.NodeTag) EmrClusterDefinitionInstanceFleet(org.finra.herd.model.api.xml.EmrClusterDefinitionInstanceFleet) EmrClusterDefinitionLaunchSpecifications(org.finra.herd.model.api.xml.EmrClusterDefinitionLaunchSpecifications) Test(org.junit.Test)

Example 20 with AwsParamsDto

use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.

the class EmrDaoTest method createEmrClusterAssertInstallOozieDisabled.

@Test
public void createEmrClusterAssertInstallOozieDisabled() 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.setInstallOozie(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);
            // The oozie step should be skipped.
            assertEquals(0, runJobFlowRequest.getSteps().size());
            return clusterId;
        }
    });
    assertEquals(clusterId, emrDao.createEmrCluster(clusterName, emrClusterDefinition, new AwsParamsDto()));
}
Also used : MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) RunJobFlowRequest(com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NodeTag(org.finra.herd.model.api.xml.NodeTag) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) InstanceDefinitions(org.finra.herd.model.api.xml.InstanceDefinitions) Test(org.junit.Test)

Aggregations

AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)67 Test (org.junit.Test)52 InvocationOnMock (org.mockito.invocation.InvocationOnMock)13 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)11 ClientConfiguration (com.amazonaws.ClientConfiguration)9 ArrayList (java.util.ArrayList)9 ListClustersResult (com.amazonaws.services.elasticmapreduce.model.ListClustersResult)8 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)8 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)7 AmazonElasticMapReduceClient (com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 RunJobFlowRequest (com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest)5 NodeTag (org.finra.herd.model.api.xml.NodeTag)5 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)5 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)5 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)4 DescribeClusterResult (com.amazonaws.services.elasticmapreduce.model.DescribeClusterResult)4 ListInstancesResult (com.amazonaws.services.elasticmapreduce.model.ListInstancesResult)4 List (java.util.List)4 InstanceDefinitions (org.finra.herd.model.api.xml.InstanceDefinitions)4