use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class StatsCollectionTaskService method createSubTask.
private void createSubTask(List<String> computeResources, String nextPageLink, StatsCollectionTaskState currentState) {
ServiceTaskCallback<StatsCollectionStage> callback = ServiceTaskCallback.create(UriUtils.buildPublicUri(getHost(), getSelfLink()));
if (nextPageLink != null) {
callback.onSuccessTo(StatsCollectionStage.GET_RESOURCES).addProperty(PROP_NEXT_PAGE_LINK, nextPageLink);
} else {
callback.onSuccessFinishTask();
}
SubTaskState<StatsCollectionStage> subTaskInitState = new SubTaskState<>();
subTaskInitState.errorThreshold = 0;
subTaskInitState.completionsRemaining = computeResources.size();
subTaskInitState.serviceTaskCallback = callback;
Operation startPost = Operation.createPost(this, SubTaskService.FACTORY_LINK).setBody(subTaskInitState).setCompletion((postOp, postEx) -> {
if (postEx != null) {
TaskUtils.sendFailurePatch(this, new StatsCollectionTaskState(), postEx);
return;
}
SubTaskState<?> body = postOp.getBody(SubTaskState.class);
// via the compute subtask
for (String computeLink : computeResources) {
createSingleResourceComputeTask(computeLink, body.documentSelfLink, currentState);
}
});
sendRequest(startPost);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class ResourceEnumerationTaskService method sendEnumRequest.
private void sendEnumRequest(Operation start, ResourceEnumerationTaskState state) {
ComputeEnumerateResourceRequest req = new ComputeEnumerateResourceRequest();
req.resourcePoolLink = state.resourcePoolLink;
req.adapterManagementReference = state.adapterManagementReference;
req.resourceReference = createInventoryUri(this.getHost(), state.parentComputeLink);
req.endpointLinkReference = createInventoryUri(this.getHost(), state.endpointLink);
req.enumerationAction = state.enumerationAction;
req.taskReference = UriUtils.buildUri(getHost(), state.documentSelfLink);
req.isMockRequest = state.options.contains(TaskOption.IS_MOCK);
req.preserveMissing = state.options.contains(TaskOption.PRESERVE_MISSING_RESOUCES);
req.endpointLink = state.endpointLink;
req.deletedResourceExpirationMicros = getResourceExpirationMicros(state.expirationPolicy == null ? ResourceExpirationPolicy.EXPIRE_AFTER_ONE_MONTH : state.expirationPolicy);
// Patch the enumerate service URI from the CHD
CompletionHandler descriptionCompletion = (o, ex) -> {
if (ex != null) {
TaskUtils.sendFailurePatch(this, state, ex);
start.fail(ex);
return;
}
ComputeStateWithDescription csd = o.getBody(ComputeStateWithDescription.class);
if (csd.description.enumerationAdapterReference == null) {
// no enumeration adapter associated with this resource, just patch completion
sendSelfFinishedPatch(state);
return;
}
sendRequest(Operation.createPatch(csd.description.enumerationAdapterReference).setBody(req));
};
URI computeUri = UriUtils.extendUriWithQuery(UriUtils.buildUri(this.getHost(), state.parentComputeLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
sendRequest(Operation.createGet(computeUri).setCompletion(descriptionCompletion));
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class ResourceIPDeallocationTaskService method getComputeResource.
private DeferredResult<ResourceIPDeallocationContext> getComputeResource(ResourceIPDeallocationContext ctx) {
Operation op = Operation.createGet(ComputeService.ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), ctx.resourceLink)));
return sendWithDeferredResult(op, ComputeState.class).thenApply(computeState -> {
ctx.computeResource = computeState;
logFine("Retrieved resource [%s]", ctx.resourceLink);
return ctx;
});
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TagGroomerTaskServiceTest method executeTagsGroomerTask.
/**
* Run groomer task and wait for completion
*/
private void executeTagsGroomerTask() {
TagDeletionRequest state = new TagDeletionRequest();
state.documentSelfLink = UriUtils.buildUriPath(TagGroomerTaskService.FACTORY_LINK, UUID.randomUUID().toString());
Operation postOp = Operation.createPost(UriUtils.buildUri(this.host, TagGroomerTaskService.FACTORY_LINK)).setBody(state);
this.host.waitForResponse(postOp);
this.host.waitForFinishedTask(TagDeletionRequest.class, state.documentSelfLink);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TagGroomerTaskServiceTest method createComputesWithTags.
/**
* Create n computes associated with specific tags
*/
private void createComputesWithTags(int count, List<String> tagLinks) {
ComputeState computeState = new ComputeState();
computeState.descriptionLink = "description-link";
computeState.id = UUID.randomUUID().toString();
computeState.name = computeState.id;
computeState.tagLinks = new HashSet<>();
for (int i = 0; i < count; i++) {
computeState.tagLinks.add(tagLinks.get(i));
Operation op = Operation.createPost(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)).setBody(computeState);
this.host.waitForResponse(op);
// clear tagLinks and assign new one on the next round
computeState.tagLinks.clear();
}
}
Aggregations