use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.InstanceDescKey in project photon-model by vmware.
the class AWSComputeStateCreationAdapterService method getRelatedComputeDescriptions.
/**
* Looks up the compute descriptions associated with the compute states to be created in the
* system.
*/
private void getRelatedComputeDescriptions(AWSComputeStateCreationContext context, AWSComputeStateCreationStage next) {
// Get the related compute descriptions for all the compute states are to be updated and
// created.
Set<InstanceDescKey> representativeCDSet = getRepresentativeListOfCDsFromInstanceList(context.request.instancesToBeCreated, context.request.zones);
representativeCDSet.addAll(getRepresentativeListOfCDsFromInstanceList(context.request.instancesToBeUpdated.values(), context.request.zones));
if (representativeCDSet.isEmpty()) {
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
return;
}
QueryTask queryTask = getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery(representativeCDSet, context.request.tenantLinks, context.request.regionId, context.request.parentComputeLink, context.request.endpointLink);
queryTask.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + QUERY_TASK_EXPIRY_MICROS;
// create the query to find an existing compute description
QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((qrt, e) -> {
if (e != null) {
logWarning(() -> String.format("Failure retrieving query results: %s", e.toString()));
finishWithFailure(context, e);
return;
}
if (qrt != null && qrt.results.documentCount > 0) {
for (Object s : qrt.results.documents.values()) {
ComputeDescription localComputeDescription = Utils.fromJson(s, ComputeDescription.class);
context.computeDescriptionMap.put(getKeyForComputeDescriptionFromCD(localComputeDescription), localComputeDescription.documentSelfLink);
}
logFine(() -> String.format("%d compute descriptions found", context.computeDescriptionMap.size()));
} else {
logFine(() -> "No compute descriptions found");
}
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
});
}
use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.InstanceDescKey in project photon-model by vmware.
the class AWSComputeStateCreationAdapterService method populateCreateOperations.
/**
* Method to create Compute States associated with the instances received from the AWS host.
*/
private void populateCreateOperations(AWSComputeStateCreationContext context, AWSComputeStateCreationStage next) {
if (context.request.instancesToBeCreated == null || context.request.instancesToBeCreated.size() == 0) {
logFine(() -> "No local compute states to be created");
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
} else {
logFine(() -> String.format("Need to create %d local compute states", context.request.instancesToBeCreated.size()));
for (int i = 0; i < context.request.instancesToBeCreated.size(); i++) {
Instance instance = context.request.instancesToBeCreated.get(i);
String zoneId = instance.getPlacement().getAvailabilityZone();
ZoneData zoneData = context.request.zones.get(zoneId);
String regionId = zoneData.regionId;
InstanceDescKey descKey = InstanceDescKey.build(regionId, zoneId, instance.getInstanceType());
Set<String> endpointLinks = new HashSet<>();
endpointLinks.add(context.request.endpointLink);
ComputeState computeStateToBeCreated = mapInstanceToComputeState(this.getHost(), instance, context.request.parentComputeLink, zoneData.computeLink, context.request.resourcePoolLink, null, endpointLinks, context.computeDescriptionMap.get(descKey), context.request.parentCDStatsAdapterReferences, context.internalTagLinksMap.get(ec2_instance.toString()), regionId, zoneId, context.request.tenantLinks, context.createdExternalTags, true, context.diskLinksByInstances.get(instance));
computeStateToBeCreated.networkInterfaceLinks = new ArrayList<>();
if (!AWSEnumerationUtils.instanceIsInStoppedState(instance)) {
// ComputeState to be created to the NIC State
for (InstanceNetworkInterface awsNic : instance.getNetworkInterfaces()) {
if (context.request.enumeratedNetworks != null && context.request.enumeratedNetworks.subnets != null && context.request.enumeratedNetworks.subnets.containsKey(awsNic.getSubnetId())) {
NetworkInterfaceState nicState = createNICStateAndDescription(context, awsNic, null, endpointLinks);
computeStateToBeCreated.networkInterfaceLinks.add(UriUtils.buildUriPath(NetworkInterfaceService.FACTORY_LINK, nicState.documentSelfLink));
}
}
}
Operation postComputeState = createPostOperation(this, computeStateToBeCreated, ComputeService.FACTORY_LINK);
context.enumerationOperations.add(postComputeState);
}
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
}
}
use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.InstanceDescKey in project photon-model by vmware.
the class TestAWSEnumerationUtils method testGetComputeDescriptionKeyFromAWSInstance.
@Test
public void testGetComputeDescriptionKeyFromAWSInstance() throws Throwable {
Map<String, ZoneData> zones = new HashMap<>();
zones.put(AWS_ZONE_ID, ZoneData.build(AWS_REGION_ID, AWS_ZONE_ID, ""));
Instance awsInstance = new Instance();
awsInstance.setInstanceId(AWS_INSTANCE_ID);
Placement placement = new Placement();
placement.setAvailabilityZone(AWS_ZONE_ID);
awsInstance.setPlacement(placement);
String regionId = getRegionId(awsInstance);
awsInstance.setInstanceType(AWS_INSTANCE_TYPE);
awsInstance.setVpcId(AWS_VPC_ID);
assertEquals(AWS_REGION_ID, regionId);
InstanceDescKey computeDescriptionKey = getKeyForComputeDescriptionFromInstance(awsInstance, zones);
assertEquals(AWS_COMPUTE_DESCRIPTION_KEY, computeDescriptionKey);
}
Aggregations