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;
}
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());
}
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;
});
}
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;
}
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;
}
Aggregations