Search in sources :

Example 46 with DescribeInstancesRequest

use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.

the class AWSTaskStatusChecker method buildRequest.

private AmazonWebServiceRequest buildRequest(T type) {
    if (type instanceof Instance) {
        DescribeInstancesRequest descRequest = new DescribeInstancesRequest();
        List<String> instanceIdList = new ArrayList<>();
        instanceIdList.add(this.instanceId);
        descRequest.setInstanceIds(instanceIdList);
        return descRequest;
    } else if (type instanceof NatGateway) {
        DescribeNatGatewaysRequest descRequest = new DescribeNatGatewaysRequest();
        List<String> instanceIdList = new ArrayList<>();
        instanceIdList.add(this.instanceId);
        descRequest.setNatGatewayIds(instanceIdList);
        return descRequest;
    } else if (type instanceof Volume) {
        DescribeVolumesRequest descRequest = new DescribeVolumesRequest();
        List<String> volumeIdList = new ArrayList<>();
        volumeIdList.add(this.instanceId);
        descRequest.setVolumeIds(volumeIdList);
        return descRequest;
    } else {
        AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(new IllegalArgumentException("Invalid type " + type));
        return null;
    }
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) Volume(com.amazonaws.services.ec2.model.Volume) DescribeNatGatewaysRequest(com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest) ArrayList(java.util.ArrayList) NatGateway(com.amazonaws.services.ec2.model.NatGateway) ArrayList(java.util.ArrayList) List(java.util.List) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest)

Example 47 with DescribeInstancesRequest

use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.

the class AWSUtils method waitForTransitionCompletion.

public static void waitForTransitionCompletion(ServiceHost host, List<InstanceStateChange> stateChangeList, final String desiredState, AmazonEC2AsyncClient client, BiConsumer<InstanceState, Exception> callback) {
    InstanceStateChange stateChange = stateChangeList.get(0);
    try {
        DescribeInstancesRequest request = new DescribeInstancesRequest();
        request.withInstanceIds(stateChange.getInstanceId());
        DescribeInstancesResult result = client.describeInstances(request);
        Instance instance = result.getReservations().stream().flatMap(r -> r.getInstances().stream()).filter(i -> i.getInstanceId().equalsIgnoreCase(stateChange.getInstanceId())).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("%s instance not found", stateChange.getInstanceId())));
        String state = instance.getState().getName();
        if (state.equals(desiredState)) {
            callback.accept(instance.getState(), null);
        } else {
            host.schedule(() -> waitForTransitionCompletion(host, stateChangeList, desiredState, client, callback), 5, TimeUnit.SECONDS);
        }
    } catch (AmazonServiceException | IllegalArgumentException ase) {
        callback.accept(null, ase);
    }
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) AmazonCloudWatchAsyncClientBuilder(com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClientBuilder) PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) Arrays(java.util.Arrays) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) PROVISIONED_SSD_MIN_SIZE_IN_MB(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.PROVISIONED_SSD_MIN_SIZE_IN_MB) AWSCsvBillParser(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser) DEVICE_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_NAME) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) INSTANCE_STATE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.INSTANCE_STATE) AmazonElasticLoadBalancingAsyncClientBuilder(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClientBuilder) AssumeRoleRequest(com.amazonaws.services.securitytoken.model.AssumeRoleRequest) Utils(com.vmware.xenon.common.Utils) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) AWSSecurityTokenServiceException(com.amazonaws.services.securitytoken.model.AWSSecurityTokenServiceException) Map(java.util.Map) Credentials(com.amazonaws.services.securitytoken.model.Credentials) EXTERNAL_ID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.EXTERNAL_ID_KEY) TransferManagerBuilder(com.amazonaws.services.s3.transfer.TransferManagerBuilder) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) AmazonServiceException(com.amazonaws.AmazonServiceException) AWSAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSAsyncHandler) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AWSSecurityTokenServiceAsyncClientBuilder(com.amazonaws.services.securitytoken.AWSSecurityTokenServiceAsyncClientBuilder) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) AssumeRoleResult(com.amazonaws.services.securitytoken.model.AssumeRoleResult) BackoffStrategy(com.amazonaws.retry.RetryPolicy.BackoffStrategy) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) STATUS_CODE_UNAUTHORIZED(com.vmware.xenon.common.Operation.STATUS_CODE_UNAUTHORIZED) DescribeTagsRequest(com.amazonaws.services.ec2.model.DescribeTagsRequest) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VOLUME_TYPE_PROVISIONED_SSD(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.VOLUME_TYPE_PROVISIONED_SSD) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) AmazonClientException(com.amazonaws.AmazonClientException) SESSION_TOKEN_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.SESSION_TOKEN_KEY) OperationContext(com.vmware.xenon.common.OperationContext) InstanceAttributeName(com.amazonaws.services.ec2.model.InstanceAttributeName) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) InstanceBlockDeviceMappingSpecification(com.amazonaws.services.ec2.model.InstanceBlockDeviceMappingSpecification) INSTANCE_STATE_STOPPING(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.INSTANCE_STATE_STOPPING) ArrayList(java.util.ArrayList) Regions(com.amazonaws.regions.Regions) InstanceStateChange(com.amazonaws.services.ec2.model.InstanceStateChange) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) UriPaths(com.vmware.photon.controller.model.UriPaths) BiConsumer(java.util.function.BiConsumer) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Filter(com.amazonaws.services.ec2.model.Filter) InstanceState(com.amazonaws.services.ec2.model.InstanceState) AmazonS3(com.amazonaws.services.s3.AmazonS3) DEVICE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_TYPE) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) STATUS_CODE_FORBIDDEN(com.vmware.xenon.common.Operation.STATUS_CODE_FORBIDDEN) INSTANCE_STATE_RUNNING(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.INSTANCE_STATE_RUNNING) DeleteTagsRequest(com.amazonaws.services.ec2.model.DeleteTagsRequest) Bucket(com.amazonaws.services.s3.model.Bucket) ModifyInstanceAttributeResult(com.amazonaws.services.ec2.model.ModifyInstanceAttributeResult) VOLUME_TYPE_GENERAL_PURPOSED_SSD(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.VOLUME_TYPE_GENERAL_PURPOSED_SSD) ClientConfiguration(com.amazonaws.ClientConfiguration) AsyncHandler(com.amazonaws.handlers.AsyncHandler) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) PROVISIONED_SSD_MAX_SIZE_IN_MB(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.PROVISIONED_SSD_MAX_SIZE_IN_MB) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) AWSNicContext(com.vmware.photon.controller.model.adapters.awsadapter.AWSInstanceContext.AWSNicContext) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) RetryPolicy(com.amazonaws.retry.RetryPolicy) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) Service(com.vmware.xenon.common.Service) AWSSecurityTokenServiceAsync(com.amazonaws.services.securitytoken.AWSSecurityTokenServiceAsync) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Pair(com.vmware.photon.controller.model.adapters.util.Pair) DEFAULT_BACKOFF_STRATEGY(com.amazonaws.retry.PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY) INSTANCE_STATE_SHUTTING_DOWN(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.INSTANCE_STATE_SHUTTING_DOWN) Date(java.util.Date) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AmazonEC2AsyncClientBuilder(com.amazonaws.services.ec2.AmazonEC2AsyncClientBuilder) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) EbsInstanceBlockDeviceSpecification(com.amazonaws.services.ec2.model.EbsInstanceBlockDeviceSpecification) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) DEFAULT_SECURITY_GROUP_NAME(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient.DEFAULT_SECURITY_GROUP_NAME) Collection(java.util.Collection) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) UUID(java.util.UUID) INSTANCE_STATE_PENDING(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.INSTANCE_STATE_PENDING) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) VOLUME_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.VOLUME_TYPE) DEFAULT_RETRY_CONDITION(com.amazonaws.retry.PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION) Objects(java.util.Objects) AmazonElasticLoadBalancingAsyncClient(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient) List(java.util.List) Optional(java.util.Optional) AWS_MOCK_HOST_SYSTEM_PROPERTY(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_MOCK_HOST_SYSTEM_PROPERTY) DiskService(com.vmware.photon.controller.model.resources.DiskService) TransferManager(com.amazonaws.services.s3.transfer.TransferManager) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) AmazonCloudWatchAsyncClient(com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient) HashMap(java.util.HashMap) SESSION_EXPIRATION_TIME_MICROS_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.SESSION_EXPIRATION_TIME_MICROS_KEY) DeleteSecurityGroupResult(com.amazonaws.services.ec2.model.DeleteSecurityGroupResult) Level(java.util.logging.Level) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) INSTANCE_STATE_STOPPED(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.INSTANCE_STATE_STOPPED) CollectionUtils(org.apache.commons.collections.CollectionUtils) AWS_S3PROXY_SYSTEM_PROPERTY(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_S3PROXY_SYSTEM_PROPERTY) Instance(com.amazonaws.services.ec2.model.Instance) TagDescription(com.amazonaws.services.ec2.model.TagDescription) ExecutorService(java.util.concurrent.ExecutorService) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) Vpc(com.amazonaws.services.ec2.model.Vpc) EncryptionUtils(com.vmware.photon.controller.model.security.util.EncryptionUtils) Operation(com.vmware.xenon.common.Operation) DeleteSecurityGroupRequest(com.amazonaws.services.ec2.model.DeleteSecurityGroupRequest) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) DescribeTagsResult(com.amazonaws.services.ec2.model.DescribeTagsResult) ModifyInstanceAttributeRequest(com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest) ARN_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ARN_KEY) Collections(java.util.Collections) Instance(com.amazonaws.services.ec2.model.Instance) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) InstanceStateChange(com.amazonaws.services.ec2.model.InstanceStateChange)

Example 48 with DescribeInstancesRequest

use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.

the class TestAWSSetupUtils method checkInstancesStarted.

/**
 * Checks if all the instances represented by the list of passed in instanceIds have been turned
 * ON.
 *
 * @return
 */
public static void checkInstancesStarted(VerificationHost host, AmazonEC2AsyncClient client, List<String> instanceIds, List<Boolean> provisioningFlags) throws Throwable {
    AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host, AWSEnumerationAsyncHandler.MODE.CHECK_START, provisioningFlags, null, null, null, null);
    DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceIds);
    client.describeInstancesAsync(request, enumerationHandler);
    host.waitFor("Waiting to get response from AWS ", () -> {
        return enumerationHandler.responseReceived;
    });
}
Also used : DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 49 with DescribeInstancesRequest

use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.

the class TestAWSSetupUtils method checkInstancesDeleted.

/**
 * Checks if a newly deleted instance has its status set to terminated.
 *
 * @return
 */
public static void checkInstancesDeleted(AmazonEC2AsyncClient client, VerificationHost host, List<String> instanceIdsToDelete, ArrayList<Boolean> deletionFlags) throws Throwable {
    AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host, AWSEnumerationAsyncHandler.MODE.CHECK_TERMINATION, null, deletionFlags, null, null, null);
    DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceIdsToDelete);
    client.describeInstancesAsync(request, enumerationHandler);
    // Waiting to get a response from AWS before the state computation is done for the list of
    // VMs.
    host.waitFor("Waiting to get response from AWS ", () -> {
        return enumerationHandler.responseReceived;
    });
}
Also used : DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 50 with DescribeInstancesRequest

use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.

the class TestAWSSetupUtils method getBaseLineInstanceCount.

/**
 * Gets the instance count of non-terminated instances on the AWS endpoint. This is used to run
 * the asserts and validate the results for the data that is collected during enumeration.This
 * also calculates the compute descriptions that will be used to represent the instances that
 * were discovered on the AWS endpoint. Further factoring in the
 *
 * @throws Throwable
 */
public static BaseLineState getBaseLineInstanceCount(VerificationHost host, AmazonEC2AsyncClient client, List<String> testComputeDescriptions) throws Throwable {
    BaseLineState baseLineState = new BaseLineState();
    AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host, AWSEnumerationAsyncHandler.MODE.GET_COUNT, null, null, null, testComputeDescriptions, baseLineState);
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    Filter runningInstanceFilter = getAWSNonTerminatedInstancesFilter();
    request.getFilters().add(runningInstanceFilter);
    client.describeInstancesAsync(request, enumerationHandler);
    host.waitFor("Error waiting to get base line instance count from AWS in test ", () -> {
        return baseLineState.isCountPopulated;
    });
    return baseLineState;
}
Also used : AWSUtils.getAWSNonTerminatedInstancesFilter(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter) Filter(com.amazonaws.services.ec2.model.Filter) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Aggregations

DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)74 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)49 Reservation (com.amazonaws.services.ec2.model.Reservation)47 Instance (com.amazonaws.services.ec2.model.Instance)42 ArrayList (java.util.ArrayList)40 Filter (com.amazonaws.services.ec2.model.Filter)29 List (java.util.List)28 Map (java.util.Map)18 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)17 Collectors (java.util.stream.Collectors)17 Tag (com.amazonaws.services.ec2.model.Tag)13 Inject (javax.inject.Inject)13 Set (java.util.Set)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 TerminateInstancesRequest (com.amazonaws.services.ec2.model.TerminateInstancesRequest)11 TerminateInstancesResult (com.amazonaws.services.ec2.model.TerminateInstancesResult)11 Collection (java.util.Collection)11 DescribeVolumesResult (com.amazonaws.services.ec2.model.DescribeVolumesResult)10 StopInstancesRequest (com.amazonaws.services.ec2.model.StopInstancesRequest)10