Search in sources :

Example 1 with CloudCredential

use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.

the class AwsCredentialConnector method verify.

@Override
public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext) {
    CloudCredential credential = authenticatedContext.getCloudCredential();
    LOGGER.info("Create credential: {}", credential);
    AwsCredentialView awsCredential = new AwsCredentialView(credential);
    String roleArn = awsCredential.getRoleArn();
    String accessKey = awsCredential.getAccessKey();
    String secretKey = awsCredential.getSecretKey();
    String smartSenseId = smartSenseIdGenerator.getSmartSenseId(awsCredential);
    if (isNoneEmpty(smartSenseId)) {
        credential.putParameter(SMART_SENSE_ID, smartSenseId);
    }
    if (isNoneEmpty(roleArn) && isNoneEmpty(accessKey) && isNoneEmpty(secretKey)) {
        String message = "Please only provide the 'role arn' or the 'access' and 'secret key'";
        return new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message);
    }
    if (isNoneEmpty(roleArn)) {
        return verifyIamRoleIsAssumable(credential);
    }
    if (isEmpty(accessKey) || isEmpty(secretKey)) {
        String message = "Please provide both the 'access' and 'secret key'";
        return new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message);
    } else {
        return verifyAccessKeySecretKeyIsAssumable(credential);
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) AmazonClientException(com.amazonaws.AmazonClientException) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Example 2 with CloudCredential

use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.

the class AwsPlatformResourcesTest method collectAccessConfigsWhenUserIsUnathorizedToGetInfoThenItShouldReturnEmptyList.

@Test
public void collectAccessConfigsWhenUserIsUnathorizedToGetInfoThenItShouldReturnEmptyList() throws Exception {
    AmazonServiceException amazonServiceException = new AmazonServiceException("unauthorized.");
    amazonServiceException.setStatusCode(403);
    when(awsClient.createAmazonIdentityManagement(any(AwsCredentialView.class))).thenReturn(amazonCFClient);
    when(amazonCFClient.listInstanceProfiles()).thenThrow(amazonServiceException);
    thrown.expect(CloudConnectorException.class);
    thrown.expectMessage("Could not get instance profile roles because the user does not have enough permission.");
    CloudAccessConfigs cloudAccessConfigs = underTest.accessConfigs(new CloudCredential(1L, "aws-credential"), region("London"), new HashMap<>());
    Assert.assertEquals(0, cloudAccessConfigs.getCloudAccessConfigs().size());
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) Test(org.junit.Test)

Example 3 with CloudCredential

use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.

the class AwsPlatformResourcesTest method collectAccessConfigsWhenWeGetBackInfoThenItShouldReturnListWithElements.

@Test
public void collectAccessConfigsWhenWeGetBackInfoThenItShouldReturnListWithElements() throws Exception {
    ListInstanceProfilesResult listInstanceProfilesResult = new ListInstanceProfilesResult();
    Set<InstanceProfile> instanceProfileSet = new HashSet<>();
    instanceProfileSet.add(instanceProfile(1));
    instanceProfileSet.add(instanceProfile(2));
    instanceProfileSet.add(instanceProfile(3));
    instanceProfileSet.add(instanceProfile(4));
    listInstanceProfilesResult.setInstanceProfiles(instanceProfileSet);
    when(awsClient.createAmazonIdentityManagement(any(AwsCredentialView.class))).thenReturn(amazonCFClient);
    when(amazonCFClient.listInstanceProfiles()).thenReturn(listInstanceProfilesResult);
    CloudAccessConfigs cloudAccessConfigs = underTest.accessConfigs(new CloudCredential(1L, "aws-credential"), region("London"), new HashMap<>());
    Assert.assertEquals(4, cloudAccessConfigs.getCloudAccessConfigs().size());
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) ListInstanceProfilesResult(com.amazonaws.services.identitymanagement.model.ListInstanceProfilesResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with CloudCredential

use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.

the class ASGroupStatusCheckerTaskTest method successTest.

@Test
public void successTest() throws Exception {
    int requiredInstances = 160;
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudContext cloudContext = mock(CloudContext.class);
    String regionName = "eu-west-1";
    when(cloudContext.getLocation()).thenReturn(Location.location(Region.region(regionName)));
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    CloudCredential cloudCredential = mock(CloudCredential.class);
    when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
    String asGroupName = "as-group";
    AwsClient awsClient = mock(AwsClient.class);
    AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class);
    when(awsClient.createAccess(any(AwsCredentialView.class), eq(regionName))).thenReturn(amazonEC2Client);
    DescribeInstanceStatusResult firstDescribeInstanceStatusResult = new DescribeInstanceStatusResult();
    List<InstanceStatus> firstInstanceStatuses = returnInstanceStatus(0, 100);
    firstDescribeInstanceStatusResult.setInstanceStatuses(firstInstanceStatuses);
    DescribeInstanceStatusResult secondDescribeInstanceStatusResult = new DescribeInstanceStatusResult();
    List<InstanceStatus> secondInstanceStatuses = returnInstanceStatus(100, 160);
    secondDescribeInstanceStatusResult.setInstanceStatuses(secondInstanceStatuses);
    when(amazonEC2Client.describeInstanceStatus(any(DescribeInstanceStatusRequest.class))).thenReturn(firstDescribeInstanceStatusResult).thenReturn(secondDescribeInstanceStatusResult);
    CloudFormationStackUtil cloudFormationStackUtil = mock(CloudFormationStackUtil.class);
    List<String> instancIds = new ArrayList<>();
    for (int i = 0; i < requiredInstances; i++) {
        instancIds.add(Integer.toString(i));
    }
    AmazonAutoScalingClient autoScalingClient = mock(AmazonAutoScalingClient.class);
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), anyString())).thenReturn(autoScalingClient);
    when(autoScalingClient.describeScalingActivities(any(DescribeScalingActivitiesRequest.class))).thenReturn(new DescribeScalingActivitiesResult());
    when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq(asGroupName))).thenReturn(instancIds);
    ASGroupStatusCheckerTask asGroupStatusCheckerTask = new ASGroupStatusCheckerTask(authenticatedContext, asGroupName, requiredInstances, awsClient, cloudFormationStackUtil);
    Boolean taskResult = asGroupStatusCheckerTask.call();
    ArgumentCaptor<DescribeInstanceStatusRequest> instanceStatusRequestArgumentCaptor = ArgumentCaptor.forClass(DescribeInstanceStatusRequest.class);
    verify(amazonEC2Client, times(2)).describeInstanceStatus(instanceStatusRequestArgumentCaptor.capture());
    List<DescribeInstanceStatusRequest> allValues = instanceStatusRequestArgumentCaptor.getAllValues();
    assertEquals(100, allValues.get(0).getInstanceIds().size());
    assertEquals(60, allValues.get(1).getInstanceIds().size());
    assertTrue(taskResult);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DescribeInstanceStatusRequest(com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Matchers.anyString(org.mockito.Matchers.anyString) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) DescribeScalingActivitiesResult(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesResult) InstanceStatus(com.amazonaws.services.ec2.model.InstanceStatus) AwsClient(com.sequenceiq.cloudbreak.cloud.aws.AwsClient) DescribeScalingActivitiesRequest(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest) CloudFormationStackUtil(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil) Test(org.junit.Test)

Example 5 with CloudCredential

use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.

the class ASGroupStatusCheckerTaskTest method failTest.

@Test
public void failTest() throws Exception {
    int requiredInstances = 160;
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudContext cloudContext = mock(CloudContext.class);
    String regionName = "eu-west-1";
    when(cloudContext.getLocation()).thenReturn(Location.location(Region.region(regionName)));
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    CloudCredential cloudCredential = mock(CloudCredential.class);
    when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
    String asGroupName = "as-group";
    AwsClient awsClient = mock(AwsClient.class);
    AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class);
    when(awsClient.createAccess(any(AwsCredentialView.class), eq(regionName))).thenReturn(amazonEC2Client);
    DescribeInstanceStatusResult firstDescribeInstanceStatusResult = new DescribeInstanceStatusResult();
    List<InstanceStatus> firstInstanceStatuses = returnInstanceStatus(0, 99);
    firstDescribeInstanceStatusResult.setInstanceStatuses(firstInstanceStatuses);
    DescribeInstanceStatusResult secondDescribeInstanceStatusResult = new DescribeInstanceStatusResult();
    List<InstanceStatus> secondInstanceStatuses = returnInstanceStatus(100, 160);
    secondDescribeInstanceStatusResult.setInstanceStatuses(secondInstanceStatuses);
    when(amazonEC2Client.describeInstanceStatus(any(DescribeInstanceStatusRequest.class))).thenReturn(firstDescribeInstanceStatusResult).thenReturn(secondDescribeInstanceStatusResult);
    CloudFormationStackUtil cloudFormationStackUtil = mock(CloudFormationStackUtil.class);
    List<String> instancIds = new ArrayList<>();
    for (int i = 0; i < requiredInstances; i++) {
        instancIds.add(Integer.toString(i));
    }
    AmazonAutoScalingClient autoScalingClient = mock(AmazonAutoScalingClient.class);
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), anyString())).thenReturn(autoScalingClient);
    when(autoScalingClient.describeScalingActivities(any(DescribeScalingActivitiesRequest.class))).thenReturn(new DescribeScalingActivitiesResult());
    when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq(asGroupName))).thenReturn(instancIds);
    ASGroupStatusCheckerTask asGroupStatusCheckerTask = new ASGroupStatusCheckerTask(authenticatedContext, asGroupName, requiredInstances, awsClient, cloudFormationStackUtil);
    Boolean taskResult = asGroupStatusCheckerTask.call();
    ArgumentCaptor<DescribeInstanceStatusRequest> instanceStatusRequestArgumentCaptor = ArgumentCaptor.forClass(DescribeInstanceStatusRequest.class);
    verify(amazonEC2Client, times(2)).describeInstanceStatus(instanceStatusRequestArgumentCaptor.capture());
    List<DescribeInstanceStatusRequest> allValues = instanceStatusRequestArgumentCaptor.getAllValues();
    assertEquals(100, allValues.get(0).getInstanceIds().size());
    assertEquals(60, allValues.get(1).getInstanceIds().size());
    assertFalse(taskResult);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DescribeInstanceStatusRequest(com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Matchers.anyString(org.mockito.Matchers.anyString) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) DescribeScalingActivitiesResult(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesResult) InstanceStatus(com.amazonaws.services.ec2.model.InstanceStatus) AwsClient(com.sequenceiq.cloudbreak.cloud.aws.AwsClient) DescribeScalingActivitiesRequest(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest) CloudFormationStackUtil(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil) Test(org.junit.Test)

Aggregations

CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)47 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)27 Location (com.sequenceiq.cloudbreak.cloud.model.Location)18 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)9 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 Stack (com.sequenceiq.cloudbreak.domain.Stack)8 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)7 HashSet (java.util.HashSet)7 Compute (com.google.api.services.compute.Compute)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)6 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)5 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)5 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)4 Strings (com.google.common.base.Strings)3