Search in sources :

Example 36 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class AwsUpscaleServiceTest method upscaleWithLoadBalancers.

@Test
void upscaleWithLoadBalancers() {
    AmazonAutoScalingClient amazonAutoScalingClient = mock(AmazonAutoScalingClient.class);
    AmazonCloudFormationClient amazonCloudFormationClient = mock(AmazonCloudFormationClient.class);
    when(amazonAutoScalingClient.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(new DescribeAutoScalingGroupsResult().withAutoScalingGroups(newAutoScalingGroup("masterASG", List.of("i-master1", "i-master2")), newAutoScalingGroup("workerASG", List.of("i-worker1", "i-worker2", "i-worker3"))));
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), anyString())).thenReturn(amazonAutoScalingClient);
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), anyString())).thenReturn(amazonCloudFormationClient);
    when(awsClient.createEc2Client(any(), any())).thenReturn(mock(AmazonEc2Client.class));
    when(cfStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("worker"))).thenReturn("workerASG");
    CloudContext cloudContext = CloudContext.Builder.builder().withId(1L).withName("teststack").withCrn("crn").withPlatform("AWS").withVariant("AWS").withLocation(Location.location(Region.region("eu-west-1"), AvailabilityZone.availabilityZone("eu-west-1a"))).withAccountId("1").build();
    AuthenticatedContext authenticatedContext = new AuthenticatedContext(cloudContext, new CloudCredential());
    List<CloudResource> allInstances = List.of(newInstanceResource("worker1", "worker", "i-worker1"), newInstanceResource("worker2", "worker", "i-worker2"), newInstanceResource("worker3", "worker", "i-worker3"), newInstanceResource("worker4", "worker", "i-worker4"), newInstanceResource("worker5", "worker", "i-worker5"));
    when(cfStackUtil.getInstanceCloudResources(eq(authenticatedContext), eq(amazonCloudFormationClient), eq(amazonAutoScalingClient), anyList())).thenReturn(allInstances);
    doNothing().when(cfStackUtil).addLoadBalancerTargets(any(), any(), any());
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    List<Group> groups = new ArrayList<>();
    List<CloudLoadBalancer> loadBalancers = List.of(new CloudLoadBalancer(LoadBalancerType.PRIVATE), new CloudLoadBalancer(LoadBalancerType.PUBLIC));
    Group master = getMasterGroup(instanceAuthentication);
    groups.add(master);
    Group worker = getWorkerGroup(instanceAuthentication);
    groups.add(worker);
    Map<String, String> tags = new HashMap<>();
    tags.put("owner", "cbuser");
    tags.put("created", "yesterday");
    CloudStack cloudStack = new CloudStack(groups, getNetwork(), null, emptyMap(), tags, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), null, loadBalancers);
    List<CloudResource> cloudResourceList = Collections.emptyList();
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L);
    awsUpscaleService.upscale(authenticatedContext, cloudStack, cloudResourceList, adjustmentTypeWithThreshold);
    verify(cfStackUtil, times(2)).addLoadBalancerTargets(any(), any(), any());
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) Test(org.junit.jupiter.api.Test)

Example 37 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class AwsUpscaleServiceTest method upscaleAwsVolumeFail.

@Test
void upscaleAwsVolumeFail() throws AmazonAutoscalingFailed {
    AmazonAutoScalingClient amazonAutoScalingClient = mock(AmazonAutoScalingClient.class);
    AmazonCloudFormationClient amazonCloudFormationClient = mock(AmazonCloudFormationClient.class);
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
    request.setAutoScalingGroupNames(new ArrayList<>(Collections.singletonList("workerASG")));
    DescribeAutoScalingGroupsResult describeScaledAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(newAutoScalingGroup("workerASG", List.of("i-worker1", "i-worker2", "i-worker3")));
    when(amazonAutoScalingClient.describeAutoScalingGroups(eq(request))).thenReturn(describeScaledAutoScalingGroupsResult);
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), anyString())).thenReturn(amazonAutoScalingClient);
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), anyString())).thenReturn(amazonCloudFormationClient);
    when(cfStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("worker"))).thenReturn("workerASG");
    CloudContext cloudContext = CloudContext.Builder.builder().withId(1L).withName("teststack").withCrn("crn").withPlatform("AWS").withVariant("AWS").withLocation(Location.location(Region.region("eu-west-1"), AvailabilityZone.availabilityZone("eu-west-1a"))).withAccountId("1").build();
    AuthenticatedContext authenticatedContext = new AuthenticatedContext(cloudContext, new CloudCredential());
    List<CloudResource> allInstances = new ArrayList<>();
    allInstances.add(newInstanceResource("worker1", "worker", "i-worker1"));
    allInstances.add(newInstanceResource("worker2", "worker", "i-worker2"));
    allInstances.add(newInstanceResource("worker3", "worker", "i-worker3"));
    CloudResource workerInstance4 = newInstanceResource("worker4", "worker", "i-worker4");
    allInstances.add(workerInstance4);
    CloudResource workerInstance5 = newInstanceResource("worker5", "worker", "i-worker5");
    allInstances.add(workerInstance5);
    when(cfStackUtil.getInstanceCloudResources(eq(authenticatedContext), eq(amazonCloudFormationClient), eq(amazonAutoScalingClient), anyList())).thenReturn(allInstances);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    List<Group> groups = new ArrayList<>();
    groups.add(getMasterGroup(instanceAuthentication));
    Group worker = getWorkerGroup(instanceAuthentication);
    groups.add(worker);
    CloudStack cloudStack = new CloudStack(groups, getNetwork(), null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), null);
    List<CloudResource> cloudResourceList = Collections.emptyList();
    AutoScalingGroup newWorkerASGroup = newAutoScalingGroup("workerASG", List.of("i-worker1", "i-worker2", "i-worker3", "i-worker4", "i-worker5"));
    when(awsAutoScalingService.getAutoscalingGroups(eq(amazonAutoScalingClient), any())).thenReturn(List.of(newWorkerASGroup));
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L);
    when(awsComputeResourceService.buildComputeResourcesForUpscale(any(), any(), anyList(), anyList(), anyList(), anyList(), eq(adjustmentTypeWithThreshold))).thenThrow(new CloudConnectorException("volume create error"));
    CloudConnectorException exception = assertThrows(CloudConnectorException.class, () -> awsUpscaleService.upscale(authenticatedContext, cloudStack, cloudResourceList, adjustmentTypeWithThreshold));
    Assertions.assertEquals("Failed to create some resource on AWS for upscaled nodes, please check your quotas on AWS. " + "Original autoscaling group state has been recovered. Exception: volume create error", exception.getMessage());
    verify(awsAutoScalingService, times(1)).updateAutoscalingGroup(any(AmazonAutoScalingClient.class), eq("workerASG"), eq(5));
    verify(awsAutoScalingService, times(1)).scheduleStatusChecks(eq(List.of(worker)), eq(authenticatedContext), eq(amazonCloudFormationClient), any(), any());
    verify(awsComputeResourceService, times(1)).buildComputeResourcesForUpscale(eq(authenticatedContext), eq(cloudStack), anyList(), anyList(), any(), any(), eq(adjustmentTypeWithThreshold));
    verify(awsAutoScalingService, times(2)).suspendAutoScaling(eq(authenticatedContext), eq(cloudStack));
    verify(awsAutoScalingService, times(1)).terminateInstance(eq(amazonAutoScalingClient), eq("i-worker4"));
    verify(awsAutoScalingService, times(1)).terminateInstance(eq(amazonAutoScalingClient), eq("i-worker5"));
    verify(cfStackUtil, times(0)).addLoadBalancerTargets(any(), any(), any());
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) Test(org.junit.jupiter.api.Test)

Example 38 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class AwsUpscaleServiceTest method upscaleAwsASGroupFail.

@Test
void upscaleAwsASGroupFail() throws AmazonAutoscalingFailed {
    AmazonAutoScalingClient amazonAutoScalingClient = mock(AmazonAutoScalingClient.class);
    AmazonCloudFormationClient amazonCloudFormationClient = mock(AmazonCloudFormationClient.class);
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
    request.setAutoScalingGroupNames(List.of("workerASG"));
    DescribeAutoScalingGroupsResult describeScaledAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult().withAutoScalingGroups(newAutoScalingGroup("workerASG", List.of("i-worker1", "i-worker2", "i-worker3")));
    when(amazonAutoScalingClient.describeAutoScalingGroups(eq(request))).thenReturn(describeScaledAutoScalingGroupsResult);
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), anyString())).thenReturn(amazonAutoScalingClient);
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), anyString())).thenReturn(amazonCloudFormationClient);
    when(cfStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("worker"))).thenReturn("workerASG");
    CloudContext cloudContext = CloudContext.Builder.builder().withId(1L).withName("teststack").withCrn("crn").withPlatform("AWS").withVariant("AWS").withLocation(Location.location(Region.region("eu-west-1"), AvailabilityZone.availabilityZone("eu-west-1a"))).withAccountId("1").build();
    AuthenticatedContext authenticatedContext = new AuthenticatedContext(cloudContext, new CloudCredential());
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    List<Group> groups = new ArrayList<>();
    groups.add(getMasterGroup(instanceAuthentication));
    Group worker = getWorkerGroup(instanceAuthentication);
    groups.add(worker);
    CloudStack cloudStack = new CloudStack(groups, getNetwork(), null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), null);
    List<CloudResource> cloudResourceList = Collections.emptyList();
    AutoScalingGroup newWorkerASGroup = newAutoScalingGroup("workerASG", List.of("i-worker1", "i-worker2", "i-worker3", "i-worker4", "i-worker5"));
    when(awsAutoScalingService.getAutoscalingGroups(eq(amazonAutoScalingClient), any())).thenReturn(Collections.singletonList(newWorkerASGroup));
    doThrow(new AmazonAutoscalingFailed("autoscaling failed")).when(awsAutoScalingService).scheduleStatusChecks(eq(List.of(worker)), eq(authenticatedContext), eq(amazonCloudFormationClient), any(Date.class), any());
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L);
    CloudConnectorException exception = assertThrows(CloudConnectorException.class, () -> awsUpscaleService.upscale(authenticatedContext, cloudStack, cloudResourceList, adjustmentTypeWithThreshold));
    Assertions.assertEquals("Autoscaling group update failed: Amazon Autoscaling Group was not able to reach the desired state (3 instances instead of 5). " + "Original autoscaling group state has been recovered. Failure reason: autoscaling failed", exception.getMessage());
    verify(awsAutoScalingService, times(1)).updateAutoscalingGroup(any(AmazonAutoScalingClient.class), eq("workerASG"), eq(5));
    verify(awsAutoScalingService, times(1)).scheduleStatusChecks(eq(List.of(worker)), eq(authenticatedContext), eq(amazonCloudFormationClient), any(), any());
    verify(awsComputeResourceService, times(0)).buildComputeResourcesForUpscale(eq(authenticatedContext), eq(cloudStack), anyList(), anyList(), any(), any(), eq(adjustmentTypeWithThreshold));
    verify(awsAutoScalingService, times(1)).suspendAutoScaling(eq(authenticatedContext), eq(cloudStack));
    verify(awsAutoScalingService, times(1)).terminateInstance(eq(amazonAutoScalingClient), eq("i-worker4"));
    verify(awsAutoScalingService, times(1)).terminateInstance(eq(amazonAutoScalingClient), eq("i-worker5"));
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Date(java.util.Date) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) Test(org.junit.jupiter.api.Test)

Example 39 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class AwsLaunchTest method launchStackWithEfs.

@Test
public void launchStackWithEfs() throws Exception {
    setup();
    setupRetryService();
    setupFreemarkerTemplateProcessing();
    setupDescribeStacksResponses();
    setupDescribeImagesResponse();
    setupDescribeStackResourceResponse();
    setupAutoscalingResponses();
    setupDescribeInstancesResponse();
    setupCreateVolumeResponse();
    setupDescribeVolumeResponse();
    setupDescribeSubnetResponse();
    setupDescribePrefixListsResponse();
    setupCreateFileSystem();
    setupDescribeFileSystems();
    setupDescribeMountTargets();
    setupDeleteMountTarget();
    setupDeleteFileSystem();
    InMemoryStateStore.putStack(1L, PollGroup.POLLABLE);
    AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext();
    authenticatedContext.putParameter(AmazonEc2Client.class, amazonEc2Client);
    authenticatedContext.putParameter(AmazonElasticFileSystemClient.class, amazonElasticFileSystemClient);
    authenticatedContext.putParameter(AmazonEfsClient.class, amazonEfsClient);
    awsResourceConnector.launch(authenticatedContext, componentTestUtil.getStackForLaunch(InstanceStatus.CREATE_REQUESTED, InstanceStatus.CREATE_REQUESTED), persistenceNotifier, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, Long.MAX_VALUE));
    // assert
    verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_VPC.equals(cloudResource.getType())), any());
    verify(persistenceNotifier, times(2)).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_VOLUMESET.equals(cloudResource.getType())), any());
    verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_SUBNET.equals(cloudResource.getType())), any());
    verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.CLOUDFORMATION_STACK.equals(cloudResource.getType())), any());
    InOrder inOrder = inOrder(amazonElasticFileSystemClient, amazonEfsClient, amazonCloudFormationClient, amazonEc2Client);
    inOrder.verify(amazonEc2Client).describeImages(any());
    inOrder.verify(amazonCloudFormationClient).createStack(any());
    inOrder.verify(amazonEc2Client, times(2)).createVolume(any());
    inOrder.verify(amazonEc2Client, times(2)).attachVolume(any());
    inOrder.verify(amazonEc2Client, never()).describePrefixLists();
}
Also used : DescribeMountTargetsResult(com.amazonaws.services.elasticfilesystem.model.DescribeMountTargetsResult) Arrays(java.util.Arrays) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ActiveProfiles(org.springframework.test.context.ActiveProfiles) AmazonCloudWatchClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonCloudWatchClient) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) AmazonEC2Waiters(com.amazonaws.services.ec2.waiters.AmazonEC2Waiters) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) DescribeScalingActivitiesRequest(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest) SpringRunner(org.springframework.test.context.junit4.SpringRunner) AmazonAutoScalingWaiters(com.amazonaws.services.autoscaling.waiters.AmazonAutoScalingWaiters) Waiter(com.amazonaws.waiters.Waiter) MockBean(org.springframework.boot.test.mock.mockito.MockBean) Reservation(com.amazonaws.services.ec2.model.Reservation) LifeCycleState(com.amazonaws.services.elasticfilesystem.model.LifeCycleState) DescribeFileSystemsResult(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Output(com.amazonaws.services.cloudformation.model.Output) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) TestPropertySource(org.springframework.test.context.TestPropertySource) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Retry(com.sequenceiq.cloudbreak.service.Retry) FreeMarkerTemplateUtils(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils) AwsResourceConnector(com.sequenceiq.cloudbreak.cloud.aws.connector.resource.AwsResourceConnector) CreateFileSystemResult(com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) VolumeState(com.amazonaws.services.ec2.model.VolumeState) Mockito.inOrder(org.mockito.Mockito.inOrder) DeleteFileSystemResult(com.amazonaws.services.elasticfilesystem.model.DeleteFileSystemResult) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) LocationHelper(com.sequenceiq.cloudbreak.cloud.storage.LocationHelper) Mock(org.mockito.Mock) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) AVAILABILITY_ZONE(com.sequenceiq.cloudbreak.cloud.aws.component.ComponentTestUtil.AVAILABILITY_ZONE) RunWith(org.junit.runner.RunWith) AmazonEfsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient) ResourceRetriever(com.sequenceiq.cloudbreak.cloud.service.ResourceRetriever) Supplier(java.util.function.Supplier) StackResourceDetail(com.amazonaws.services.cloudformation.model.StackResourceDetail) Inject(javax.inject.Inject) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) Answer(org.mockito.stubbing.Answer) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) DeleteMountTargetResult(com.amazonaws.services.elasticfilesystem.model.DeleteMountTargetResult) DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) ResourceType(com.sequenceiq.common.api.type.ResourceType) InOrder(org.mockito.InOrder) AmazonElasticFileSystemClient(com.amazonaws.services.elasticfilesystem.AmazonElasticFileSystemClient) FileSystemDescription(com.amazonaws.services.elasticfilesystem.model.FileSystemDescription) DescribeScalingActivitiesResult(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesResult) AwsCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) DescribePrefixListsResult(com.amazonaws.services.ec2.model.DescribePrefixListsResult) InMemoryStateStore(com.sequenceiq.cloudbreak.cloud.store.InMemoryStateStore) Import(org.springframework.context.annotation.Import) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Stack(com.amazonaws.services.cloudformation.model.Stack) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) LifecycleState(com.amazonaws.services.autoscaling.model.LifecycleState) Mockito.verify(org.mockito.Mockito.verify) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) Mockito.never(org.mockito.Mockito.never) MountTargetDescription(com.amazonaws.services.elasticfilesystem.model.MountTargetDescription) CustomAmazonWaiterProvider(com.sequenceiq.cloudbreak.cloud.aws.scheduler.CustomAmazonWaiterProvider) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Instance(com.amazonaws.services.autoscaling.model.Instance) DescribeStackResourceResult(com.amazonaws.services.cloudformation.model.DescribeStackResourceResult) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InOrder(org.mockito.InOrder) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Test(org.junit.Test)

Example 40 with AdjustmentTypeWithThreshold

use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.

the class AwsRepairTest method upscaleStack.

private void upscaleStack() throws Exception {
    AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext();
    CloudStack stack = componentTestUtil.getStack(InstanceStatus.CREATE_REQUESTED, InstanceStatus.STARTED);
    List<CloudResource> cloudResources = List.of(CloudResource.builder().name(AWS_SUBNET_ID).type(ResourceType.AWS_SUBNET).build(), createVolumeResource(VOLUME_ID_1, INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1, CommonStatus.DETACHED), createVolumeResource(VOLUME_ID_2, INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2, CommonStatus.DETACHED), createVolumeResource(VOLUME_ID_3, INSTANCE_ID_3, SIZE_DISK_2, FSTAB_2, CommonStatus.CREATED));
    InMemoryStateStore.putStack(1L, PollGroup.POLLABLE);
    when(amazonCloudFormationClient.describeStackResource(any())).thenReturn(new DescribeStackResourceResult().withStackResourceDetail(new StackResourceDetail().withPhysicalResourceId(AUTOSCALING_GROUP_NAME)));
    when(amazonAutoScalingClient.describeAutoScalingGroups(any())).thenReturn(new DescribeAutoScalingGroupsResult().withAutoScalingGroups(new AutoScalingGroup().withAutoScalingGroupName(AUTOSCALING_GROUP_NAME).withInstances(List.of(new Instance().withInstanceId(INSTANCE_ID_1).withLifecycleState(LifecycleState.InService), new Instance().withInstanceId(INSTANCE_ID_2).withLifecycleState(LifecycleState.InService)))));
    when(amazonEC2Client.describeVolumes(any())).thenReturn(new DescribeVolumesResult().withVolumes(new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_1).withState(VolumeState.Available), new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_2).withState(VolumeState.Available), new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_3).withState(VolumeState.InUse)));
    when(amazonEC2Client.describeInstances(any())).thenReturn(new DescribeInstancesResult().withReservations(new Reservation().withInstances(new com.amazonaws.services.ec2.model.Instance().withInstanceId("i-instance"))));
    DescribeScalingActivitiesResult result = new DescribeScalingActivitiesResult();
    result.setActivities(List.of());
    when(amazonAutoScalingClient.describeScalingActivities(any(DescribeScalingActivitiesRequest.class))).thenReturn(result);
    AmazonEC2Waiters waiters = mock(AmazonEC2Waiters.class);
    when(amazonEC2Client.waiters()).thenReturn(waiters);
    Waiter<DescribeInstancesRequest> instanceWaiter = mock(Waiter.class);
    when(waiters.instanceRunning()).thenReturn(instanceWaiter);
    when(amazonAutoScalingClient.waiters()).thenReturn(asWaiters);
    when(asWaiters.groupInService()).thenReturn(describeAutoScalingGroupsRequestWaiter);
    underTest.upscale(authenticatedContext, stack, cloudResources, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L));
    verify(amazonAutoScalingClient).resumeProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && argument.getScalingProcesses().contains("Launch")));
    verify(amazonAutoScalingClient).updateAutoScalingGroup(argThat(argument -> {
        Group workerGroup = stack.getGroups().get(1);
        return AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && workerGroup.getInstancesSize().equals(argument.getMaxSize()) && workerGroup.getInstancesSize().equals(argument.getDesiredCapacity());
    }));
    verify(amazonAutoScalingClient, times(stack.getGroups().size())).suspendProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && SUSPENDED_PROCESSES.equals(argument.getScalingProcesses())));
    ArgumentCaptor<CloudResource> updatedCloudResourceArgumentCaptor = ArgumentCaptor.forClass(CloudResource.class);
    verify(resourceNotifier, times(2)).notifyUpdate(updatedCloudResourceArgumentCaptor.capture(), any());
    assertVolumeResource(updatedCloudResourceArgumentCaptor.getAllValues(), INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1);
    assertVolumeResource(updatedCloudResourceArgumentCaptor.getAllValues(), INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2);
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) AmazonCloudWatchClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonCloudWatchClient) AmazonEC2Waiters(com.amazonaws.services.ec2.waiters.AmazonEC2Waiters) Arrays.asList(java.util.Arrays.asList) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) MockBean(org.springframework.boot.test.mock.mockito.MockBean) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) LifeCycleState(com.amazonaws.services.elasticfilesystem.model.LifeCycleState) CloudVolumeUsageType(com.sequenceiq.cloudbreak.cloud.model.CloudVolumeUsageType) DescribeFileSystemsResult(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) TestPropertySource(org.springframework.test.context.TestPropertySource) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Retry(com.sequenceiq.cloudbreak.service.Retry) AwsResourceConnector(com.sequenceiq.cloudbreak.cloud.aws.connector.resource.AwsResourceConnector) CreateFileSystemResult(com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) VolumeState(com.amazonaws.services.ec2.model.VolumeState) SIZE_DISK_1(com.sequenceiq.cloudbreak.cloud.aws.component.ComponentTestUtil.SIZE_DISK_1) SIZE_DISK_2(com.sequenceiq.cloudbreak.cloud.aws.component.ComponentTestUtil.SIZE_DISK_2) Mockito.mock(org.mockito.Mockito.mock) LocationHelper(com.sequenceiq.cloudbreak.cloud.storage.LocationHelper) Mock(org.mockito.Mock) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) AVAILABILITY_ZONE(com.sequenceiq.cloudbreak.cloud.aws.component.ComponentTestUtil.AVAILABILITY_ZONE) RunWith(org.junit.runner.RunWith) AmazonEfsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient) Supplier(java.util.function.Supplier) StackResourceDetail(com.amazonaws.services.cloudformation.model.StackResourceDetail) ResourceNotifier(com.sequenceiq.cloudbreak.cloud.notification.ResourceNotifier) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DeleteMountTargetResult(com.amazonaws.services.elasticfilesystem.model.DeleteMountTargetResult) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) DescribeScalingActivitiesResult(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesResult) AwsCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient) InMemoryStateStore(com.sequenceiq.cloudbreak.cloud.store.InMemoryStateStore) Assert.assertTrue(org.junit.Assert.assertTrue) Import(org.springframework.context.annotation.Import) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) LifecycleState(com.amazonaws.services.autoscaling.model.LifecycleState) INSTANCE_ID_1(com.sequenceiq.cloudbreak.cloud.aws.component.ComponentTestUtil.INSTANCE_ID_1) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) INSTANCE_ID_2(com.sequenceiq.cloudbreak.cloud.aws.component.ComponentTestUtil.INSTANCE_ID_2) INSTANCE_ID_3(com.sequenceiq.cloudbreak.cloud.aws.component.ComponentTestUtil.INSTANCE_ID_3) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) DescribeStackResourceResult(com.amazonaws.services.cloudformation.model.DescribeStackResourceResult) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DescribeMountTargetsResult(com.amazonaws.services.elasticfilesystem.model.DescribeMountTargetsResult) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ActiveProfiles(org.springframework.test.context.ActiveProfiles) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeScalingActivitiesRequest(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest) Assert.fail(org.junit.Assert.fail) SpringRunner(org.springframework.test.context.junit4.SpringRunner) AmazonAutoScalingWaiters(com.amazonaws.services.autoscaling.waiters.AmazonAutoScalingWaiters) Waiter(com.amazonaws.waiters.Waiter) Reservation(com.amazonaws.services.ec2.model.Reservation) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Collectors(java.util.stream.Collectors) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Group(com.sequenceiq.cloudbreak.cloud.model.Group) DeleteFileSystemResult(com.amazonaws.services.elasticfilesystem.model.DeleteFileSystemResult) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HashMap(java.util.HashMap) AwsMetadataCollector(com.sequenceiq.cloudbreak.cloud.aws.AwsMetadataCollector) ResourceRetriever(com.sequenceiq.cloudbreak.cloud.service.ResourceRetriever) Inject(javax.inject.Inject) ArgumentCaptor(org.mockito.ArgumentCaptor) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) ResourceType(com.sequenceiq.common.api.type.ResourceType) FileSystemDescription(com.amazonaws.services.elasticfilesystem.model.FileSystemDescription) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) Mockito(org.mockito.Mockito) MountTargetDescription(com.amazonaws.services.elasticfilesystem.model.MountTargetDescription) CustomAmazonWaiterProvider(com.sequenceiq.cloudbreak.cloud.aws.scheduler.CustomAmazonWaiterProvider) DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) Instance(com.amazonaws.services.autoscaling.model.Instance) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) Collections(java.util.Collections) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.amazonaws.services.autoscaling.model.Instance) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AmazonEC2Waiters(com.amazonaws.services.ec2.waiters.AmazonEC2Waiters) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) StackResourceDetail(com.amazonaws.services.cloudformation.model.StackResourceDetail) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) DescribeScalingActivitiesResult(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesResult) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) DescribeScalingActivitiesRequest(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeStackResourceResult(com.amazonaws.services.cloudformation.model.DescribeStackResourceResult)

Aggregations

AdjustmentTypeWithThreshold (com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold)41 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)20 Group (com.sequenceiq.cloudbreak.cloud.model.Group)20 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)18 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)15 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)14 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)12 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 List (java.util.List)12 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)11 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)11 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 QuotaExceededException (com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException)9 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)9 AdjustmentType (com.sequenceiq.common.api.type.AdjustmentType)9 Inject (javax.inject.Inject)9