use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class AzureComputeDiskDay2Service method updateDiskState.
/**
* Update status and LUN of DiskState
*/
private DeferredResult<Operation> updateDiskState(AzureComputeDiskDay2Context context) {
DiskState diskState = context.diskState;
if (context.request.operation.equals(ResourceOperation.ATTACH_DISK.operation)) {
diskState.status = DiskService.DiskStatus.ATTACHED;
} else if (context.request.operation.equals(ResourceOperation.DETACH_DISK.operation)) {
diskState.status = DiskService.DiskStatus.AVAILABLE;
diskState.customProperties.remove(DISK_CONTROLLER_NUMBER);
}
if (!context.request.isMockRequest) {
DataDisk dataDisk = context.provisionedVm.inner().storageProfile().dataDisks().stream().filter(dd -> diskState.name.equalsIgnoreCase(dd.name())).findFirst().orElse(null);
if (dataDisk != null) {
if (diskState.customProperties == null) {
diskState.customProperties = new HashMap<>();
}
diskState.customProperties.put(DISK_CONTROLLER_NUMBER, String.valueOf(dataDisk.lun()));
}
}
Operation diskPatchOp = null;
if (context.request.operation.equals(ResourceOperation.ATTACH_DISK.operation)) {
diskPatchOp = Operation.createPatch(createInventoryUri(this.getHost(), diskState.documentSelfLink)).setBody(diskState).setReferer(this.getUri());
} else if (context.request.operation.equals(ResourceOperation.DETACH_DISK.operation)) {
diskPatchOp = Operation.createPut(createInventoryUri(this.getHost(), diskState.documentSelfLink)).setBody(diskState).setReferer(this.getUri());
}
return this.sendWithDeferredResult(diskPatchOp);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class AzureSubscriptionEndpointCreationService method handleSubscriptionEndpointCreationRequest.
private void handleSubscriptionEndpointCreationRequest(AzureSubscriptionEndpointCreationRequest request, Operation parentOp) {
// If request.subscriptionId is null, just complete the parentOp
if (request.subscriptionId == null) {
parentOp.complete();
return;
}
// Fail the request if resourceReference to Azure EA endpoint is not provided
if (request.resourceReference == null) {
parentOp.fail(new IllegalArgumentException("reference to parent endpointLink is required"));
}
Operation endpointStateOp = Operation.createGet(request.resourceReference).setCompletion((o, e) -> {
if (e != null) {
parentOp.fail(e);
return;
}
EndpointState endpointState = o.getBody(EndpointState.class);
createSubscriptionEndpoint(endpointState, request, parentOp);
});
this.sendRequest(endpointStateOp);
}
use of com.vmware.xenon.common.Operation 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.xenon.common.Operation 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);
});
});
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class AzureComputeHostStatsGatherer method handleComputeQueryCompletion.
/**
* Get all the children computes and create a query task for each to query the metrics.
*/
private void handleComputeQueryCompletion(QueryTask queryTask, Throwable failure, AzureStatsDataHolder statsData) {
if (failure != null) {
logSevere(failure.getMessage());
statsData.error = failure;
statsData.stage = ComputeHostMetricsStages.ERROR;
handleMetricDiscovery(statsData);
return;
}
if (queryTask == null || queryTask.results == null) {
sendFailurePatch(statsData, new RuntimeException(String.format("Unexpected query result for '%s'", queryTask.documentSelfLink)));
return;
}
if (queryTask.results.documentLinks != null) {
statsData.childComputeLinks.addAll(queryTask.results.documentLinks);
}
if (queryTask.results.nextPageLink != null) {
Operation op = Operation.createGet(createInventoryUri(this.getHost(), queryTask.results.nextPageLink));
sendWithDeferredResult(op).whenComplete((o, e) -> handleComputeQueryCompletion(o.getBody(QueryTask.class), e, statsData));
return;
}
int computeCount = Math.toIntExact(statsData.childComputeLinks.size());
// No children found, proceed to finish
if (computeCount <= 0) {
statsData.stage = ComputeHostMetricsStages.FINISHED;
handleMetricDiscovery(statsData);
return;
}
// Create multiple operations, one each for a VM compute.
List<Operation> statOperations = new ArrayList<>(computeCount);
for (String computeLink : statsData.childComputeLinks) {
Operation statsOp = getStatsQueryTaskOperation(statsData, computeLink);
statOperations.add(statsOp);
}
OperationJoin.create(statOperations).setCompletion((ops, failures) -> handleQueryTaskResponseAndConsolidateStats(ops, failures, statsData)).sendWith(this, 50);
}
Aggregations