use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class TestAWSMissingEnumerationResourcesService method getLinkedAccountComputeDescs.
private void getLinkedAccountComputeDescs(Request request, int expectedCount) {
this.host.waitFor("Timeout waiting for getLinkedAccountComputeDescriptions()", () -> {
ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(getQuerySpecForComputeDesc(request), expectedCount, expectedCount);
Collection<Object> values = result.documents.values();
if (values.size() != expectedCount) {
return false;
}
for (Object computeDesc : result.documents.values()) {
ComputeDescription cDesc = Utils.fromJson(computeDesc, ComputeDescription.class);
linkedAccountDescriptions.put(cDesc.name, cDesc);
if (!cDesc.endpointLink.equals(request.primaryAccountCompute.endpointLink)) {
return false;
}
}
return true;
});
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AWSEndpointAdapterService method computeDesc.
private BiConsumer<ComputeDescription, Retriever> computeDesc() {
return (cd, r) -> {
cd.regionId = r.get(REGION_KEY).orElse(null);
cd.zoneId = r.get(ZONE_KEY).orElse(null);
cd.environmentName = ComputeDescription.ENVIRONMENT_NAME_AWS;
List<String> children = new ArrayList<>();
children.add(ComputeType.ZONE.toString());
cd.supportedChildren = children;
cd.instanceAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_INSTANCE_ADAPTER);
cd.enumerationAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_ENUMERATION_ADAPTER);
cd.powerAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_POWER_ADAPTER);
cd.diskAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_DISK_ADAPTER);
{
URI statsAdapterUri = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_STATS_ADAPTER);
URI costStatsAdapterUri = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_COST_STATS_ADAPTER);
cd.statsAdapterReferences = new LinkedHashSet<>();
cd.statsAdapterReferences.add(costStatsAdapterUri);
cd.statsAdapterReferences.add(statsAdapterUri);
cd.statsAdapterReference = statsAdapterUri;
}
};
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createComputeDescriptionForRegion.
private ComputeDescription createComputeDescriptionForRegion(EnumerationContext context, RegionInfo r) {
ComputeDescriptionService.ComputeDescription cd = Utils.clone(context.parentCompute.description);
cd.supportedChildren = new ArrayList<>();
cd.supportedChildren.add(ComputeType.VM_GUEST.toString());
cd.id = r.regionId;
cd.documentSelfLink = generateRegionComputeDescriptionLinkId(r.regionId, context.request.endpointLink);
cd.name = r.name;
cd.regionId = r.regionId;
cd.endpointLink = context.request.endpointLink;
AdapterUtils.addToEndpointLinks(cd, context.request.endpointLink);
// Book keeping information about the creation of the compute description in the system.
if (cd.customProperties == null) {
cd.customProperties = new HashMap<>();
}
cd.customProperties.put(SOURCE_TASK_LINK, ResourceEnumerationTaskService.FACTORY_LINK);
return cd;
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AzureSubscriptionEndpointCreationService method createSubscriptionEndpoint.
private void createSubscriptionEndpoint(EndpointState azureEaEndpoint, AzureSubscriptionEndpointCreationRequest request, Operation parentOp) {
Operation authOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), AuthCredentialsService.FACTORY_LINK));
Operation cdOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeDescriptionService.FACTORY_LINK));
Operation csOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeService.FACTORY_LINK));
Operation endPointOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), EndpointService.FACTORY_LINK));
AuthCredentialsServiceState authCredentialsState = createAuthCredentialsState(azureEaEndpoint, request);
EndpointState endpointState = createEndpointState(azureEaEndpoint, request);
ComputeDescription computeDescState = AzureUtils.constructAzureSubscriptionComputeDescription(endpointState.documentSelfLink, azureEaEndpoint.tenantLinks, request.subscriptionId, null, null, endpointState.computeLink);
authOp.setBody(authCredentialsState);
OperationSequence sequence = OperationSequence.create(authOp).setCompletion((ops, exs) -> {
if (exs != null) {
handleFailure(exs, parentOp);
return;
}
Operation o = ops.get(authOp.getId());
AuthCredentialsServiceState authState = o.getBody(AuthCredentialsServiceState.class);
computeDescState.authCredentialsLink = authState.documentSelfLink;
endpointState.authCredentialsLink = authState.documentSelfLink;
cdOp.setBody(computeDescState);
}).next(cdOp).setCompletion((ops, exs) -> {
if (exs != null) {
handleFailure(exs, parentOp);
return;
}
Operation o = ops.get(cdOp.getId());
ComputeDescription cd = o.getBody(ComputeDescription.class);
ComputeState cs = AzureUtils.constructAzureSubscriptionComputeState(endpointState.documentSelfLink, cd.documentSelfLink, azureEaEndpoint.tenantLinks, request.subscriptionId, azureEaEndpoint.resourcePoolLink, getCustomPropertiesMap(endpointState, request), null, endpointState.computeLink);
csOp.setBody(cs);
endpointState.computeDescriptionLink = cd.documentSelfLink;
}).next(csOp).setCompletion((ops, exs) -> {
if (exs != null) {
handleFailure(exs, parentOp);
return;
}
Operation o = ops.get(csOp.getId());
ComputeState cs = o.getBody(ComputeState.class);
endpointState.computeLink = cs.documentSelfLink;
endPointOp.setBody(endpointState);
}).next(endPointOp).setCompletion((ops, exs) -> {
if (exs != null) {
handleFailure(exs, parentOp);
return;
}
Operation o = ops.get(endPointOp.getId());
EndpointState es = o.getBody(EndpointState.class);
parentOp.setBody(es);
parentOp.complete();
});
sequence.sendWith(this);
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AzureSubscriptionsEnumerationService method createResources.
private void createResources(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage) {
// Go through new subscriptions and create corresponding ComputeState
// and ComputeDescription for them
Collection<ComputeState> computesToCreate = new ArrayList<>();
// Create ComputeDescription
Collection<Operation> createComputeDescOps = enumerationContext.idToSubscription.values().stream().map(subscription -> Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeDescriptionService.FACTORY_LINK)).setBody(AzureUtils.constructAzureSubscriptionComputeDescription(enumerationContext.parent.endpointLink, enumerationContext.parent.tenantLinks, subscription.entityId, null, null, enumerationContext.parent.documentSelfLink)).setCompletion((o, e) -> {
if (e != null) {
logSevere(() -> String.format("Compute description creation " + " failed for azure subscription %s", subscription.entityId));
return;
}
ComputeDescription cd = o.getBody(ComputeDescription.class);
String csName = AzureUtils.constructSubscriptionName(subscription);
computesToCreate.add(AzureUtils.constructAzureSubscriptionComputeState(enumerationContext.parent.endpointLink, cd.documentSelfLink, enumerationContext.parent.tenantLinks, csName, enumerationContext.parent.resourcePoolLink, getPropertiesMap(enumerationContext, subscription, true), null, enumerationContext.parent.documentSelfLink));
})).collect(Collectors.toList());
joinOperationAndSendRequest(createComputeDescOps, enumerationContext, (subsEnumCtx) -> {
// Now create the ComputeState
Collection<Operation> createComputeOps = computesToCreate.stream().map(computeState -> Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeService.FACTORY_LINK)).setBody(computeState).setCompletion((o, e) -> {
if (e != null) {
logSevere(() -> String.format("Compute state creation failed for azure" + " subscription %s", computeState.name));
}
})).collect(Collectors.toList());
joinOperationAndSendRequest(createComputeOps, subsEnumCtx, (enumCtx) -> {
enumCtx.stage = nextStage;
handleAzureSubscriptionsEnumerationRequest(enumCtx);
});
});
}
Aggregations