Search in sources :

Example 56 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project photon-model by vmware.

the class AWSEnumerationUtils method mapInstanceToComputeState.

/**
 * Maps the instance discovered on AWS to a local compute state that will be persisted.
 */
public static ComputeState mapInstanceToComputeState(ServiceHost host, Instance instance, String parentComputeLink, String placementComputeLink, String resourcePoolLink, String existingEndpointLink, Set<String> endpointLinks, String computeDescriptionLink, Set<URI> parentCDStatsAdapterReferences, Set<String> internalTagLinks, String regionId, String zoneId, List<String> tenantLinks, List<Tag> createdExternalTags, Boolean isNewState, List<String> diskLinks) {
    ComputeState computeState = new ComputeState();
    computeState.id = instance.getInstanceId();
    computeState.name = instance.getInstanceId();
    computeState.parentLink = parentComputeLink;
    computeState.computeHostLink = parentComputeLink;
    computeState.type = ComputeType.VM_GUEST;
    computeState.environmentName = ComputeDescription.ENVIRONMENT_NAME_AWS;
    computeState.regionId = regionId;
    computeState.zoneId = zoneId;
    computeState.instanceType = instance.getInstanceType();
    computeState.instanceAdapterReference = AdapterUriUtil.buildAdapterUri(host, AWSUriPaths.AWS_INSTANCE_ADAPTER);
    computeState.enumerationAdapterReference = AdapterUriUtil.buildAdapterUri(host, AWSUriPaths.AWS_ENUMERATION_CREATION_ADAPTER);
    computeState.statsAdapterReference = AdapterUriUtil.buildAdapterUri(host, AWSUriPaths.AWS_STATS_ADAPTER);
    computeState.statsAdapterReferences = parentCDStatsAdapterReferences;
    computeState.resourcePoolLink = resourcePoolLink;
    if (computeState.endpointLinks == null) {
        computeState.endpointLinks = new HashSet<>();
    }
    computeState.endpointLinks.addAll(endpointLinks);
    // assign existing one, if exists
    if (existingEndpointLink != null) {
        computeState.endpointLink = existingEndpointLink;
    } else {
        computeState.endpointLink = endpointLinks.iterator().next();
    }
    // Compute descriptions are looked up by the instanceType in the local list of CDs.
    computeState.descriptionLink = computeDescriptionLink;
    computeState.hostName = instance.getPublicDnsName();
    // TODO VSYM-375 for adding disk information
    computeState.address = instance.getPublicIpAddress();
    computeState.powerState = AWSUtils.mapToPowerState(instance.getState());
    computeState.customProperties = new HashMap<>();
    computeState.customProperties.put(CUSTOM_OS_TYPE, getNormalizedOSType(instance));
    computeState.customProperties.put(SOURCE_TASK_LINK, ResourceEnumerationTaskService.FACTORY_LINK);
    computeState.customProperties.put(ComputeProperties.PLACEMENT_LINK, placementComputeLink);
    // Network State. Create one network state mapping to each VPC that is discovered during
    // enumeration.
    computeState.customProperties.put(AWS_VPC_ID, instance.getVpcId());
    computeState.tagLinks = new HashSet<>();
    // PATCH to update tagLinks of existing disks.
    if (!instance.getTags().isEmpty() && isNewState) {
        // we have already made sure that the tags exist and we can build their links ourselves
        computeState.tagLinks = instance.getTags().stream().filter(t -> !AWSConstants.AWS_TAG_NAME.equals(t.getKey()) && createdExternalTags.contains(t)).map(t -> newTagState(t.getKey(), t.getValue(), true, tenantLinks)).map(TagFactoryService::generateSelfLink).collect(Collectors.toSet());
        if (computeState.tagLinks != null && computeState.tagLinks.contains(null)) {
            host.log(Level.SEVERE, "Null tag link inserted in new ComputeState for instance ID: %s", instance.getInstanceId());
            host.log(Level.SEVERE, "Removing null tag link from new ComputeState");
            computeState.tagLinks.remove(null);
        }
    }
    // The name of the compute state is the value of the AWS_TAG_NAME tag
    String nameTag = getTagValue(instance.getTags(), AWS_TAG_NAME);
    if (nameTag != null && !nameTag.equals(EMPTY_STRING)) {
        computeState.name = nameTag;
    }
    // append internal tagLinks to any existing ones
    if (internalTagLinks != null) {
        computeState.tagLinks.addAll(internalTagLinks);
    }
    if (instance.getLaunchTime() != null) {
        computeState.creationTimeMicros = TimeUnit.MILLISECONDS.toMicros(instance.getLaunchTime().getTime());
    }
    if (diskLinks != null && !diskLinks.isEmpty()) {
        computeState.diskLinks = new ArrayList<>();
        computeState.diskLinks.addAll(diskLinks);
    }
    computeState.tenantLinks = tenantLinks;
    return computeState;
}
Also used : ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) QueryTask(com.vmware.xenon.services.common.QueryTask) OSType(com.vmware.photon.controller.model.ComputeProperties.OSType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) HashSet(java.util.HashSet) AWSConstants(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants) Query(com.vmware.xenon.services.common.QueryTask.Query) TagFactoryService(com.vmware.photon.controller.model.resources.TagFactoryService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) WINDOWS_PLATFORM(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.WINDOWS_PLATFORM) Map(java.util.Map) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) Instance(com.amazonaws.services.ec2.model.Instance) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) AWSConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.getQueryResultLimit) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) Collection(java.util.Collection) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Set(java.util.Set) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) AWS_VPC_ID(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VPC_ID) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CUSTOM_OS_TYPE(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) Tag(com.amazonaws.services.ec2.model.Tag) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) URI_PATH_CHAR(com.vmware.xenon.common.UriUtils.URI_PATH_CHAR) AWSUriPaths(com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TagFactoryService(com.vmware.photon.controller.model.resources.TagFactoryService)

Example 57 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project photon-model by vmware.

the class TestAWSSetupUtils method getAwsInstancesByIds.

/**
 * Method to get Instance details directly from Amazon
 *
 * @throws Throwable
 */
public static List<Instance> getAwsInstancesByIds(AmazonEC2AsyncClient client, VerificationHost host, List<String> instanceIds) throws Throwable {
    host.log("Getting instances with ids " + instanceIds + " from the AWS endpoint using the EC2 client.");
    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceIds);
    DescribeInstancesResult describeInstancesResult = client.describeInstances(describeInstancesRequest);
    return describeInstancesResult.getReservations().stream().flatMap(r -> r.getInstances().stream()).collect(Collectors.toList());
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult) Arrays(java.util.Arrays) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) VerificationHost(com.vmware.xenon.common.test.VerificationHost) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest) AttachInternetGatewayRequest(com.amazonaws.services.ec2.model.AttachInternetGatewayRequest) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) InetAddress(java.net.InetAddress) AWSEnumerationAndDeletionAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSEnumerationAndDeletionAdapterService) Utils(com.vmware.xenon.common.Utils) BlockDeviceMapping(com.amazonaws.services.ec2.model.BlockDeviceMapping) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) ImageService(com.vmware.photon.controller.model.resources.ImageService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) Path(java.nio.file.Path) AWSComputeStateCreationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSComputeStateCreationAdapterService) EnumSet(java.util.EnumSet) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) AWSComputeDescriptionEnumerationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSComputeDescriptionEnumerationAdapterService) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest) CreateNetworkInterfaceResult(com.amazonaws.services.ec2.model.CreateNetworkInterfaceResult) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) Set(java.util.Set) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) DeleteNetworkInterfaceRequest(com.amazonaws.services.ec2.model.DeleteNetworkInterfaceRequest) ServiceStats(com.vmware.xenon.common.ServiceStats) URI_PARAM_ENDPOINT(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_ENDPOINT) AWSUtils.getRegionId(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getRegionId) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) TagService(com.vmware.photon.controller.model.resources.TagService) AWSUtils.getAWSNonTerminatedInstancesFilter(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter) ProvisioningUtils.getVMCount(com.vmware.photon.controller.model.tasks.ProvisioningUtils.getVMCount) Assert.assertFalse(org.junit.Assert.assertFalse) DetachNetworkInterfaceRequest(com.amazonaws.services.ec2.model.DetachNetworkInterfaceRequest) Tag(com.amazonaws.services.ec2.model.Tag) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList) DeleteSnapshotRequest(com.amazonaws.services.ec2.model.DeleteSnapshotRequest) TaskState(com.vmware.xenon.common.TaskState) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) InstanceNetworkInterface(com.amazonaws.services.ec2.model.InstanceNetworkInterface) NicSpec(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NicSpec) DISK_IOPS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DISK_IOPS) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) SYSTEM(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.SYSTEM) AWSS3StorageEnumerationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSS3StorageEnumerationAdapterService) ArrayList(java.util.ArrayList) AWSEBSStorageEnumerationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSEBSStorageEnumerationAdapterService) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Rule(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState.Rule) URI_PARAM_INSTANCE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_INSTANCE_TYPE) USER_DEFINED(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.USER_DEFINED) Query(com.vmware.xenon.services.common.QueryTask.Query) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult) DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) Filter(com.amazonaws.services.ec2.model.Filter) Volume(com.amazonaws.services.ec2.model.Volume) CreateSnapshotResult(com.amazonaws.services.ec2.model.CreateSnapshotResult) CreateVpcRequest(com.amazonaws.services.ec2.model.CreateVpcRequest) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) SecurityGroupService(com.vmware.photon.controller.model.resources.SecurityGroupService) Assert.assertTrue(org.junit.Assert.assertTrue) DetachInternetGatewayRequest(com.amazonaws.services.ec2.model.DetachInternetGatewayRequest) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest) LocalDateTime(org.joda.time.LocalDateTime) UnknownHostException(java.net.UnknownHostException) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) AttachNetworkInterfaceResult(com.amazonaws.services.ec2.model.AttachNetworkInterfaceResult) Assert.assertNull(org.junit.Assert.assertNull) NetworkInterfaceAttachmentChanges(com.amazonaws.services.ec2.model.NetworkInterfaceAttachmentChanges) Paths(java.nio.file.Paths) DescribeSnapshotsResult(com.amazonaws.services.ec2.model.DescribeSnapshotsResult) AsyncHandler(com.amazonaws.handlers.AsyncHandler) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) CreateSnapshotRequest(com.amazonaws.services.ec2.model.CreateSnapshotRequest) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Assert(org.junit.Assert) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) DISCOVERED(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.DISCOVERED) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) RegisterInstancesWithLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest) QueryTask(com.vmware.xenon.services.common.QueryTask) TimeoutException(java.util.concurrent.TimeoutException) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Random(java.util.Random) StatsAggregationTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService) ByteBuffer(java.nio.ByteBuffer) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) StatsAggregationTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsAggregationTaskService.StatsAggregationTaskState) DescribeInstanceStatusRequest(com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest) CreateVolumeRequest(com.amazonaws.services.ec2.model.CreateVolumeRequest) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) ProvisionDiskTaskService(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService) URI(java.net.URI) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) StatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService) Reservation(com.amazonaws.services.ec2.model.Reservation) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) LoadBalancerService(com.vmware.photon.controller.model.resources.LoadBalancerService) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceDescriptionService(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService) DeleteLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerRequest) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AmazonElasticLoadBalancingAsyncClient(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient) List(java.util.List) Snapshot(com.amazonaws.services.ec2.model.Snapshot) DescribeSnapshotsRequest(com.amazonaws.services.ec2.model.DescribeSnapshotsRequest) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) DiskService(com.vmware.photon.controller.model.resources.DiskService) NetSpec(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NetSpec) EndpointRemovalTaskState(com.vmware.photon.controller.model.tasks.EndpointRemovalTaskService.EndpointRemovalTaskState) ResourceRemovalTaskService(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService) DeleteInternetGatewayRequest(com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest) HashMap(java.util.HashMap) CreateNetworkInterfaceRequest(com.amazonaws.services.ec2.model.CreateNetworkInterfaceRequest) AWSEnumerationAndCreationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSEnumerationAndCreationAdapterService) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) RegisterInstancesWithLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerResult) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) Level(java.util.logging.Level) HashSet(java.util.HashSet) AttachNetworkInterfaceRequest(com.amazonaws.services.ec2.model.AttachNetworkInterfaceRequest) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) Subnet(com.amazonaws.services.ec2.model.Subnet) Listener(com.amazonaws.services.elasticloadbalancing.model.Listener) Instance(com.amazonaws.services.ec2.model.Instance) AWSConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.getQueryResultLimit) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Assert.assertNotNull(org.junit.Assert.assertNotNull) Vpc(com.amazonaws.services.ec2.model.Vpc) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) Operation(com.vmware.xenon.common.Operation) RunInstancesRequest(com.amazonaws.services.ec2.model.RunInstancesRequest) DeleteSecurityGroupRequest(com.amazonaws.services.ec2.model.DeleteSecurityGroupRequest) AWS_VPC_ID_FILTER(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VPC_ID_FILTER) ProvisioningUtils.createServiceURI(com.vmware.photon.controller.model.tasks.ProvisioningUtils.createServiceURI) TimeUnit(java.util.concurrent.TimeUnit) ModifyNetworkInterfaceAttributeRequest(com.amazonaws.services.ec2.model.ModifyNetworkInterfaceAttributeRequest) DeleteVolumeRequest(com.amazonaws.services.ec2.model.DeleteVolumeRequest) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) EndpointRemovalTaskService(com.vmware.photon.controller.model.tasks.EndpointRemovalTaskService) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) AWSEnumerationAdapterService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSEnumerationAdapterService) Collections(java.util.Collections) AWS_INVALID_VOLUME_ID_ERROR_CODE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_INVALID_VOLUME_ID_ERROR_CODE) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Example 58 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project photon-model by vmware.

the class TestAWSSetupUtils method detachNICDirectlyWithEC2Client.

/**
 * Removes a specified AWS NIC from the VM it is currently attached to
 */
public static void detachNICDirectlyWithEC2Client(String instanceId, String nicAttachmentId, String nicId, AmazonEC2Client client, VerificationHost host) {
    // detach the new AWS NIC to the AWS VM
    DetachNetworkInterfaceRequest detachNic = new DetachNetworkInterfaceRequest();
    detachNic.withAttachmentId(nicAttachmentId);
    host.log("Detaching NIC with id: %s and attachment id: %s", nicId, nicAttachmentId);
    client.detachNetworkInterface(detachNic);
    host.waitFor("Timeout waiting for AWS to detach a NIC from " + instanceId + " with attachment id: " + nicAttachmentId, () -> {
        DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest().withFilters(new Filter("instance-id", Collections.singletonList(instanceId)));
        DescribeInstancesResult result = client.describeInstances(describeInstancesRequest);
        Instance currentInstance = result.getReservations().get(0).getInstances().get(0);
        for (InstanceNetworkInterface awsNic : currentInstance.getNetworkInterfaces()) {
            if (awsNic.getNetworkInterfaceId().equals(nicId)) {
                // Requested NIC was not detached from the instance
                return false;
            }
        }
        host.log("Detached NIC with attachment id: %s", nicAttachmentId);
        return true;
    });
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) AWSUtils.getAWSNonTerminatedInstancesFilter(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter) Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) DetachNetworkInterfaceRequest(com.amazonaws.services.ec2.model.DetachNetworkInterfaceRequest) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) InstanceNetworkInterface(com.amazonaws.services.ec2.model.InstanceNetworkInterface)

Example 59 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project Gatekeeper by FINRAOS.

the class Ec2LookupServiceTests method fakeInstance.

private Reservation fakeInstance(String instanceID, String instanceIP, String instanceName, String instanceApplication, String platform) {
    Reservation container = new Reservation();
    List<Instance> instances = new ArrayList<>();
    Instance i = new Instance();
    List<Tag> tags = new ArrayList<>();
    i.setInstanceId(instanceID);
    i.setPrivateIpAddress(instanceIP);
    Tag nameTag = new Tag();
    nameTag.setKey("Name");
    nameTag.setValue(instanceName);
    Tag applicationTag = new Tag();
    applicationTag.setKey("Application");
    applicationTag.setValue(instanceApplication);
    tags.add(applicationTag);
    tags.add(nameTag);
    i.setTags(tags);
    i.setPlatform(platform);
    instances.add(i);
    container.setInstances(instances);
    return container;
}
Also used : Reservation(com.amazonaws.services.ec2.model.Reservation) GatekeeperAWSInstance(org.finra.gatekeeper.services.aws.model.GatekeeperAWSInstance) Instance(com.amazonaws.services.ec2.model.Instance) Tag(com.amazonaws.services.ec2.model.Tag)

Example 60 with Instance

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

the class AwsInstanceConnector method check.

@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
    for (CloudInstance vm : vms) {
        try {
            String region = ac.getCloudContext().getLocation().getRegion().value();
            DescribeInstancesResult result = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value()).describeInstances(new DescribeInstancesRequest().withInstanceIds(vm.getInstanceId()));
            for (Reservation reservation : result.getReservations()) {
                for (Instance instance : reservation.getInstances()) {
                    if ("Stopped".equalsIgnoreCase(instance.getState().getName())) {
                        LOGGER.info("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
                        cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.STOPPED));
                    } else if ("Running".equalsIgnoreCase(instance.getState().getName())) {
                        LOGGER.info("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
                        cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.STARTED));
                    } else if ("Terminated".equalsIgnoreCase(instance.getState().getName())) {
                        LOGGER.info("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
                        cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
                    } else {
                        LOGGER.info("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
                        cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.IN_PROGRESS));
                    }
                }
            }
        } catch (AmazonEC2Exception e) {
            LOGGER.warn("Instance does not exist with this id: {}, original message: {}", vm.getInstanceId(), e.getMessage());
        }
    }
    return cloudVmInstanceStatuses;
}
Also used : DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) 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) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception)

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