Search in sources :

Example 96 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.

the class AwsNativeMetadataCollector method describeInstances.

private List<CloudVmMetaDataStatus> describeInstances(List<CloudInstance> vms, List<String> instanceIdList, Map<String, CloudResource> resourcesByInstanceId, AmazonEc2Client ec2Client) {
    LOGGER.info("Collecting metadata for instance IDs: '{}'", String.join(", ", instanceIdList));
    List<CloudVmMetaDataStatus> result = new ArrayList<>();
    DescribeInstancesRequest instancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceIdList);
    DescribeInstancesResult instancesResult = ec2Client.describeInstances(instancesRequest);
    List<Instance> instances = instancesResult.getReservations().stream().flatMap(reservation -> reservation.getInstances().stream()).collect(Collectors.toList());
    for (Instance instance : instances) {
        String instanceId = instance.getInstanceId();
        CloudResource connectedResource = findCloudResourceByInstanceId(resourcesByInstanceId, instanceId);
        CloudInstance matchedInstance = findCloudInstanceByPrivateId(vms, connectedResource);
        CloudInstance updatedInstance = new CloudInstance(connectedResource.getInstanceId(), matchedInstance.getTemplate(), matchedInstance.getAuthentication(), matchedInstance.getSubnetId(), matchedInstance.getAvailabilityZone());
        CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(instance.getPrivateIpAddress(), instance.getPublicIpAddress(), awsLifeCycleMapper.getLifeCycle(instance));
        CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(updatedInstance, updatedInstance.getTemplate().getStatus());
        CloudVmMetaDataStatus newMetadataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
        result.add(newMetadataStatus);
    }
    return result;
}
Also used : EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) LoggerFactory(org.slf4j.LoggerFactory) AwsLifeCycleMapper(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsLifeCycleMapper) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) INSTANCE_NOT_FOUND_ERROR_CODE(com.sequenceiq.cloudbreak.cloud.aws.common.AwsInstanceConnector.INSTANCE_NOT_FOUND_ERROR_CODE) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) Instance(com.amazonaws.services.ec2.model.Instance) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) LinkedHashSet(java.util.LinkedHashSet) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Set(java.util.Set) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) MetadataCollector(com.sequenceiq.cloudbreak.cloud.MetadataCollector) Collectors(java.util.stream.Collectors) List(java.util.List) AwsPlatformResources(com.sequenceiq.cloudbreak.cloud.aws.common.AwsPlatformResources) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Optional(java.util.Optional) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.amazonaws.services.ec2.model.Instance) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 97 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.

the class AwsMetaDataCollectorTest method getReservation.

private Reservation getReservation(Instance... instance) {
    List<Instance> instances = Arrays.asList(instance);
    Reservation r = new Reservation();
    r.setInstances(instances);
    return r;
}
Also used : Reservation(com.amazonaws.services.ec2.model.Reservation) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.amazonaws.services.ec2.model.Instance)

Example 98 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.

the class AwsInstanceConnector method instanceIdsWhichAreNotInCorrectState.

private Collection<String> instanceIdsWhichAreNotInCorrectState(List<CloudInstance> vms, AmazonEc2Client amazonEC2Client, String state) {
    Set<String> instances = vms.stream().map(CloudInstance::getInstanceId).collect(Collectors.toCollection(HashSet::new));
    DescribeInstancesResult describeInstances = amazonEC2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instances));
    for (Reservation reservation : describeInstances.getReservations()) {
        for (Instance instance : reservation.getInstances()) {
            if (state.equalsIgnoreCase(instance.getState().getName())) {
                instances.remove(instance.getInstanceId());
            }
        }
    }
    return instances;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.amazonaws.services.ec2.model.Instance) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 99 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.

the class AwsInstanceConnector method fillCloudVmInstanceStatuses.

private List<CloudVmInstanceStatus> fillCloudVmInstanceStatuses(AuthenticatedContext ac, List<CloudInstance> cloudIntancesWithInstanceId, String region, DescribeInstancesResult result) {
    List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
    for (Reservation reservation : result.getReservations()) {
        for (Instance instance : reservation.getInstances()) {
            Optional<CloudInstance> cloudInstanceForInstanceId = cloudIntancesWithInstanceId.stream().filter(cloudInstance -> cloudInstance.getInstanceId().equals(instance.getInstanceId())).findFirst();
            if (cloudInstanceForInstanceId.isPresent()) {
                CloudInstance cloudInstance = cloudInstanceForInstanceId.get();
                LOGGER.debug("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
                cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(cloudInstance, AwsInstanceStatusMapper.getInstanceStatusByAwsStateAndReason(instance.getState(), instance.getStateReason())));
            }
        }
    }
    return cloudVmInstanceStatuses;
}
Also used : InstanceConnector(com.sequenceiq.cloudbreak.cloud.InstanceConnector) AwsInstanceStatusMapper(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsInstanceStatusMapper) PollerUtil(com.sequenceiq.cloudbreak.cloud.aws.common.poller.PollerUtil) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Matcher(java.util.regex.Matcher) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest) Service(org.springframework.stereotype.Service) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) BiConsumer(java.util.function.BiConsumer) Retryable(org.springframework.retry.annotation.Retryable) Instance(com.amazonaws.services.ec2.model.Instance) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) EnumSet(java.util.EnumSet) GetConsoleOutputRequest(com.amazonaws.services.ec2.model.GetConsoleOutputRequest) Reservation(com.amazonaws.services.ec2.model.Reservation) Logger(org.slf4j.Logger) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Collection(java.util.Collection) Set(java.util.Set) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) Sets(com.google.common.collect.Sets) List(java.util.List) SdkClientException(com.amazonaws.SdkClientException) GetConsoleOutputResult(com.amazonaws.services.ec2.model.GetConsoleOutputResult) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) Optional(java.util.Optional) CloudOperationNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.CloudOperationNotSupportedException) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) Reservation(com.amazonaws.services.ec2.model.Reservation) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.amazonaws.services.ec2.model.Instance) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 100 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project terra-cli by DataBiosphere.

the class GoogleNotebooks method stop.

public void stop(InstanceName instanceName) {
    try {
        Operation stopOperation = notebooks.instances().stop(instanceName).execute();
        pollForSuccess(stopOperation, "Error stopping notebook instance: ");
    } catch (InterruptedException | IOException e) {
        checkFor409BadState(e);
        throw new SystemException("Error stopping notebook instance", e);
    }
}
Also used : SystemException(bio.terra.cli.exception.SystemException) Operation(com.google.api.services.notebooks.v1.model.Operation) IOException(java.io.IOException)

Aggregations

Instance (com.amazonaws.services.ec2.model.Instance)185 Reservation (com.amazonaws.services.ec2.model.Reservation)84 ArrayList (java.util.ArrayList)82 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)71 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)48 List (java.util.List)48 Tag (com.amazonaws.services.ec2.model.Tag)41 Test (org.junit.jupiter.api.Test)38 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)36 Map (java.util.Map)36 Collectors (java.util.stream.Collectors)32 HashMap (java.util.HashMap)26 Filter (com.amazonaws.services.ec2.model.Filter)25 Set (java.util.Set)23 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)22 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)20 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)18 InstanceState (com.amazonaws.services.ec2.model.InstanceState)18 Volume (com.amazonaws.services.ec2.model.Volume)18 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)18