use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AWSComputeDescriptionEnumerationAdapterService method getLocalComputeDescriptions.
/**
* Get all the compute descriptions already in the system and filtered by
* - Supported Children (Docker Container)
* - Environment name(AWS),
* - Name (instance type),
* - ZoneId(placement).
* - Endpoint link
*/
private void getLocalComputeDescriptions(AWSComputeDescriptionCreationServiceContext context, AWSComputeDescCreationStage next) {
QueryTask queryTask = getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery(context.representativeComputeDescriptionSet, context.cdState.tenantLinks, context.cdState.regionId, context.cdState.parentComputeLink, context.cdState.endpointLink);
// 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.localComputeDescriptionMap.put(getKeyForComputeDescriptionFromCD(localComputeDescription), localComputeDescription);
}
logFine(() -> String.format("%d compute descriptions found", context.localComputeDescriptionMap.size()));
} else {
logFine(() -> "No compute descriptions found");
}
context.creationStage = next;
handleComputeDescriptionCreation(context);
});
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AWSComputeDescriptionEnumerationAdapterService method populateUpdateOperations.
private void populateUpdateOperations(AWSComputeDescriptionCreationServiceContext context, AWSComputeDescCreationStage next) {
if (context.computeDescriptionsToBeUpdatedList == null || context.computeDescriptionsToBeUpdatedList.isEmpty()) {
logFine(() -> "No local compute descriptions need to be updated");
context.creationStage = next;
handleComputeDescriptionCreation(context);
return;
}
logFine(() -> String.format("Need to update %d local compute descriptions", context.computeDescriptionsToBeUpdatedList.size()));
context.computeDescriptionsToBeUpdatedList.stream().forEach(entry -> {
ComputeDescription cd = context.localComputeDescriptionMap.get(entry);
if (StringUtils.isEmpty(cd.endpointLink)) {
cd.endpointLink = context.cdState.endpointLink;
sendRequest(Operation.createPatch(this.getHost(), cd.documentSelfLink).setReferer(this.getHost().getUri()).setBody(cd));
}
});
context.computeDescriptionsToBeUpdatedList.stream().map(dk -> updateComputeDescriptionOperation(dk, context)).forEach(o -> context.enumerationOperations.add(o));
context.creationStage = next;
handleComputeDescriptionCreation(context);
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription 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.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AWSMissingResourcesEnumerationService method createLinkedComputeStates.
/**
* creates new linked account endpoint states of a primary account
* @param context
*/
private void createLinkedComputeStates(AwsMissingResourcesEnumContext context) {
AtomicInteger completionCounter = new AtomicInteger(context.request.missingLinkedAccountIds.size());
AtomicBoolean isSuccessful = new AtomicBoolean(true);
context.request.missingLinkedAccountIds.forEach(linkedAccountId -> {
ComputeDescription computeDescription = populateComputeDescription(context, linkedAccountId);
ComputeState computeState = populateComputeState(context, linkedAccountId);
computeState.descriptionLink = computeDescription.documentSelfLink;
Operation csOp = Operation.createPost(this, ComputeService.FACTORY_LINK).setBody(computeState);
Operation cdOp = Operation.createPost(this, ComputeDescriptionService.FACTORY_LINK).setBody(computeDescription);
JoinedCompletionHandler completionHandler = (ops, exs) -> {
if (exs != null && !exs.isEmpty()) {
logWarning(() -> String.format("Error creating missing resources for" + " account with ID %s.", linkedAccountId));
isSuccessful.set(false);
} else {
logInfo(() -> String.format("Created missing resources for account " + "with ID %s.", linkedAccountId));
}
if (completionCounter.decrementAndGet() == 0) {
if (isSuccessful.get()) {
context.requestOp.complete();
} else {
context.requestOp.fail(new Exception("Failed to create missing resources " + "for atleast one linked account."));
}
}
};
Operation.createGet(this, computeDescription.documentSelfLink).setReferer(this.getUri()).setCompletion((o, e) -> {
if (e != null && (e instanceof ServiceNotFoundException || o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND)) {
OperationSequence.create(cdOp).next(csOp).setCompletion(completionHandler).sendWith(this);
} else {
OperationSequence.create(csOp).setCompletion(completionHandler).sendWith(this);
}
}).sendWith(this);
});
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class MockCostStatsAdapterService method getAccountDescription.
@Override
protected void getAccountDescription(AWSCostStatsCreationContext statsData, AWSCostStatsCreationStages next) {
ComputeDescription compDesc = new ComputeDescription();
compDesc.id = "123";
compDesc.documentSelfLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, generateUuidFromStr(compDesc.id));
Set<URI> statsAdapterReferences = new HashSet<>();
statsAdapterReferences.add(UriUtils.buildUri("stats-adapter-references"));
compDesc.statsAdapterReferences = statsAdapterReferences;
statsData.accountId = TestAWSCostAdapterService.account1Id;
ComputeStateWithDescription account1ComputeState = new ComputeStateWithDescription();
account1ComputeState.documentSelfLink = TestAWSCostAdapterService.account1SelfLink;
account1ComputeState.type = ComputeType.ENDPOINT_HOST;
account1ComputeState.endpointLink = "endpoint1";
account1ComputeState.endpointLinks = new HashSet<String>();
account1ComputeState.endpointLinks.add("endpoint1");
account1ComputeState.name = "account1";
account1ComputeState.descriptionLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, generateUuidFromStr("123"));
account1ComputeState.creationTimeMicros = Utils.getNowMicrosUtc();
account1ComputeState.customProperties = new HashMap<>();
account1ComputeState.customProperties.put(AWSConstants.AWS_ACCOUNT_ID_KEY, "account1Id");
account1ComputeState.customProperties.put(EndpointAllocationTaskService.CUSTOM_PROP_ENPOINT_TYPE, EndpointType.aws.name());
account1ComputeState.description = new ComputeDescription();
account1ComputeState.description.statsAdapterReferences = statsAdapterReferences;
account1ComputeState.tenantLinks = Collections.singletonList("tenant-1");
statsData.computeDesc = account1ComputeState;
statsData.awsAccountIdToComputeStates.put(TestAWSCostAdapterService.account1Id, Collections.singletonList(account1ComputeState));
inferEndpointLink(statsData);
getParentAuth(statsData, next);
}
Aggregations