com.amazonaws.services.ec2.waiters.AmazonEC2Waiters Java Examples

The following examples show how to use com.amazonaws.services.ec2.waiters.AmazonEC2Waiters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsRepairTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
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(amazonCloudFormationRetryClient.describeStackResource(any()))
            .thenReturn(new DescribeStackResourceResult()
                    .withStackResourceDetail(new StackResourceDetail().withPhysicalResourceId(AUTOSCALING_GROUP_NAME)));

    when(amazonAutoScalingRetryClient.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")))
    );


    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);

    verify(amazonAutoScalingRetryClient).resumeProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName())
            && argument.getScalingProcesses().contains("Launch")));
    verify(amazonAutoScalingRetryClient).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(amazonAutoScalingRetryClient, 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(4)).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);
}
 
Example #2
Source File: EmptyAmazonEC2.java    From ec2-spot-jenkins-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public AmazonEC2Waiters waiters() {
    return null;
}
 
Example #3
Source File: EucaEc2Client.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
@Override
public AmazonEC2Waiters waiters() {
    return null;
}
 
Example #4
Source File: AwsRepairTest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private void downscaleStack() throws IOException {
    when(amazonEC2Client.describeVolumes(any()))
            .thenReturn(new DescribeVolumesResult().
                    withVolumes(new com.amazonaws.services.ec2.model.Volume()
                                    .withVolumeId(VOLUME_ID_1)
                                    .withState(VolumeState.InUse),
                            new com.amazonaws.services.ec2.model.Volume()
                                    .withVolumeId(VOLUME_ID_2)
                                    .withState(VolumeState.InUse)
                    ));

    when(amazonCloudFormationRetryClient.describeStackResource(any()))
            .thenReturn(new DescribeStackResourceResult()
                    .withStackResourceDetail(new StackResourceDetail().withPhysicalResourceId(AUTOSCALING_GROUP_NAME)));

    when(amazonEC2Client.describeInstances(any()))
            .thenReturn(new DescribeInstancesResult().withReservations(new Reservation().withInstances(List.of())));

    AmazonEC2Waiters mockWaiter = mock(AmazonEC2Waiters.class);
    when(amazonEC2Client.waiters())
            .thenReturn(mockWaiter);
    when(mockWaiter.instanceTerminated())
            .thenReturn(mock(Waiter.class));

    List<Volume> volumes = List.of();
    InstanceTemplate instanceTemplate = new InstanceTemplate("", WORKER_GROUP, 0L, volumes, InstanceStatus.STARTED, Map.of(), 0L, IMAGE_ID);
    InstanceAuthentication authentication = new InstanceAuthentication("publicKey", "publicKeyId", "cloudbreak");
    CloudInstance firstCloudInstance = new CloudInstance(INSTANCE_ID_1, instanceTemplate, authentication);
    CloudInstance secondCloudInstance = new CloudInstance(INSTANCE_ID_2, instanceTemplate, authentication);
    List<CloudInstance> cloudInstancesToRemove = List.of(firstCloudInstance, secondCloudInstance);

    CloudResource instance1VolumeResource = createVolumeResource(VOLUME_ID_1, INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1, CommonStatus.CREATED);
    CloudResource instance2VolumeResource = createVolumeResource(VOLUME_ID_2, INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2, CommonStatus.CREATED);
    List<CloudResource> resources = List.of(instance1VolumeResource, instance2VolumeResource);

    AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext();
    CloudStack cloudStack = componentTestUtil.getStack(InstanceStatus.DELETE_REQUESTED, InstanceStatus.CREATE_REQUESTED);
    underTest.downscale(authenticatedContext, cloudStack, resources, cloudInstancesToRemove, null);

    verify(persistenceNotifier).notifyUpdate(argThat(cloudResource -> ResourceType.AWS_VOLUMESET.equals(cloudResource.getType())
                    && VOLUME_ID_1.equals(cloudResource.getName())
                    && INSTANCE_ID_1.equals(cloudResource.getInstanceId())
                    && CommonStatus.DETACHED.equals(cloudResource.getStatus())
                    && cloudResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class).getDeleteOnTermination()),
            eq(authenticatedContext.getCloudContext()));

    verify(persistenceNotifier).notifyUpdate(argThat(cloudResource -> ResourceType.AWS_VOLUMESET.equals(cloudResource.getType())
                    && VOLUME_ID_2.equals(cloudResource.getName())
                    && INSTANCE_ID_2.equals(cloudResource.getInstanceId())
                    && CommonStatus.DETACHED.equals(cloudResource.getStatus())
                    && cloudResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class).getDeleteOnTermination()),
            eq(authenticatedContext.getCloudContext()));

    verify(amazonAutoScalingRetryClient).detachInstances(argThat(argument -> argument.getAutoScalingGroupName().equals(AUTOSCALING_GROUP_NAME)
            && argument.getShouldDecrementDesiredCapacity()
            && argument.getInstanceIds().size() == 2
            && argument.getInstanceIds().contains(INSTANCE_ID_1)
            && argument.getInstanceIds().contains(INSTANCE_ID_2)
    ));

    verify(amazonEC2Client).terminateInstances(argThat(argument -> argument.getInstanceIds().size() == 2
            && argument.getInstanceIds().contains(INSTANCE_ID_1)
            && argument.getInstanceIds().contains(INSTANCE_ID_2)));

    verify(amazonAutoScalingRetryClient).updateAutoScalingGroup(argThat(argument -> argument.getAutoScalingGroupName().equals(AUTOSCALING_GROUP_NAME)
            && argument.getMaxSize().equals(1)));
}