Search in sources :

Example 11 with AwsParamsDto

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

the class UploadDownloadHelperServiceImpl method assertS3ObjectKeyDoesNotExist.

@Override
public void assertS3ObjectKeyDoesNotExist(String bucketName, String key) {
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    s3FileTransferRequestParamsDto.setS3BucketName(bucketName);
    s3FileTransferRequestParamsDto.setS3KeyPrefix(key);
    AwsParamsDto awsParamsDto = awsHelper.getAwsParamsDto();
    String httpProxyHost = awsParamsDto.getHttpProxyHost();
    s3FileTransferRequestParamsDto.setHttpProxyHost(httpProxyHost);
    Integer httpProxyPort = awsParamsDto.getHttpProxyPort();
    s3FileTransferRequestParamsDto.setHttpProxyPort(httpProxyPort);
    Assert.isTrue(!s3Dao.s3FileExists(s3FileTransferRequestParamsDto), String.format("A S3 object already exists in bucket \"%s\" and key \"%s\".", bucketName, key));
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto)

Example 12 with AwsParamsDto

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

the class EmrServiceImpl method terminateClusterImpl.

/**
 * Terminates the EMR Cluster.
 *
 * @param emrClusterAlternateKeyDto the EMR cluster alternate key
 * @param overrideTerminationProtection parameter for whether to override termination protection
 * @param emrClusterId The EMR cluster ID
 * @param accountId The account Id
 *
 * @return the terminated EMR cluster object
 * @throws Exception if there were any errors while terminating the cluster
 */
protected EmrCluster terminateClusterImpl(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, boolean overrideTerminationProtection, String emrClusterId, String accountId) 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());
    String clusterId = null;
    String clusterName = emrHelper.buildEmrClusterName(namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName());
    try {
        clusterId = emrHelper.getActiveEmrClusterId(emrClusterId, clusterName, accountId);
        emrDao.terminateEmrCluster(clusterId, overrideTerminationProtection, awsParamsDto);
    } catch (AmazonServiceException ex) {
        handleAmazonException(ex, "An Amazon exception occurred while terminating EMR cluster with name \"" + clusterName + "\".");
    }
    return createEmrClusterFromRequest(clusterId, namespaceEntity.getCode(), emrClusterDefinitionEntity.getName(), emrClusterAlternateKeyDto.getEmrClusterName(), accountId, emrDao.getEmrClusterStatusById(clusterId, awsParamsDto), null, null, null);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AmazonServiceException(com.amazonaws.AmazonServiceException) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity)

Example 13 with AwsParamsDto

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

the class EmrDaoTest method getEmrMasterInstanceThrowsWhenNoInstance.

@Test
public void getEmrMasterInstanceThrowsWhenNoInstance() throws Exception {
    String clusterId = "clusterId";
    when(mockEmrOperations.listClusterInstancesRequest(any(), any())).thenReturn(new ListInstancesResult());
    try {
        emrDao.getEmrMasterInstance(clusterId, new AwsParamsDto());
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("No master instances found for the cluster \"" + clusterId + "\".", e.getMessage());
    }
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListInstancesResult(com.amazonaws.services.elasticmapreduce.model.ListInstancesResult) Test(org.junit.Test)

Example 14 with AwsParamsDto

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

the class EmrDaoTest method addEmrMasterSecurityGroupsThrowWhenNoInstancesFound.

@Test
public void addEmrMasterSecurityGroupsThrowWhenNoInstancesFound() throws Exception {
    String clusterName = "clusterName";
    List<String> securityGroups = Arrays.asList("securityGroup");
    AwsParamsDto awsParams = new AwsParamsDto();
    ListClustersResult listClustersResult = new ListClustersResult();
    listClustersResult.setClusters(new ArrayList<>());
    ClusterSummary clusterSummary = new ClusterSummary();
    clusterSummary.setId("clusterId");
    clusterSummary.setName(clusterName);
    listClustersResult.getClusters().add(clusterSummary);
    when(mockEmrOperations.listEmrClusters(any(), any())).thenReturn(listClustersResult);
    when(mockEmrOperations.listClusterInstancesRequest(any(), any())).thenReturn(new ListInstancesResult());
    try {
        emrDao.addEmrMasterSecurityGroups(clusterName, securityGroups, awsParams);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("No master instances found for the cluster \"" + clusterName + "\".", e.getMessage());
    }
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) ListInstancesResult(com.amazonaws.services.elasticmapreduce.model.ListInstancesResult) ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) Test(org.junit.Test)

Example 15 with AwsParamsDto

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

the class EmrDaoTest method getClusterActiveStepAssertReturnNullWhenStepListIsEmpty.

@Test
public void getClusterActiveStepAssertReturnNullWhenStepListIsEmpty() throws Exception {
    String clusterId = "clusterId";
    when(mockEmrOperations.listStepsRequest(any(), any())).thenReturn(new ListStepsResult());
    assertNull(emrDao.getClusterActiveStep(clusterId, new AwsParamsDto()));
}
Also used : ListStepsResult(com.amazonaws.services.elasticmapreduce.model.ListStepsResult) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) 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