use of com.vmware.photon.controller.model.tasks.SubTaskService.SubTaskState 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.photon.controller.model.tasks.SubTaskService.SubTaskState in project photon-model by vmware.
the class StatsCollectionTaskService method createSingleResourceComputeTask.
private void createSingleResourceComputeTask(String computeLink, String subtaskLink, StatsCollectionTaskState currentState) {
SingleResourceStatsCollectionTaskState initState = new SingleResourceStatsCollectionTaskState();
initState.parentTaskReference = UriUtils.buildPublicUri(getHost(), subtaskLink);
initState.computeLink = computeLink;
initState.statsAdapterReference = currentState.statsAdapterReference;
SubTaskState<StatsCollectionStage> patchState = new SubTaskState<>();
patchState.taskInfo = TaskUtils.createTaskState(TaskStage.FINISHED);
initState.parentPatchBody = patchState;
if (currentState.options != null && currentState.options.contains(TaskOption.IS_MOCK)) {
initState.options = EnumSet.of(TaskOption.IS_MOCK);
}
sendRequest(Operation.createPost(this, SingleResourceStatsCollectionTaskService.FACTORY_LINK).setBody(initState).setCompletion((factoryPostOp, factoryPostEx) -> {
if (factoryPostEx != null) {
TaskUtils.sendFailurePatch(this, new StatsCollectionTaskState(), factoryPostEx);
}
}));
}
Aggregations