Search in sources :

Example 1 with SubTaskState

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);
}
Also used : SubTaskState(com.vmware.photon.controller.model.tasks.SubTaskService.SubTaskState) Operation(com.vmware.xenon.common.Operation) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)

Example 2 with SubTaskState

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);
        }
    }));
}
Also used : Service(com.vmware.xenon.common.Service) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) SubTaskService(com.vmware.photon.controller.model.tasks.SubTaskService) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) URI(java.net.URI) EnumSet(java.util.EnumSet) SubTaskState(com.vmware.photon.controller.model.tasks.SubTaskService.SubTaskState) ServiceTaskCallback(com.vmware.photon.controller.model.tasks.ServiceTaskCallback) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ServiceTaskCallbackResponse(com.vmware.photon.controller.model.tasks.ServiceTaskCallback.ServiceTaskCallbackResponse) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) FactoryService(com.vmware.xenon.common.FactoryService) TaskService(com.vmware.xenon.services.common.TaskService) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) TaskUtils(com.vmware.photon.controller.model.tasks.TaskUtils) SubTaskState(com.vmware.photon.controller.model.tasks.SubTaskService.SubTaskState) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)

Aggregations

SubTaskState (com.vmware.photon.controller.model.tasks.SubTaskService.SubTaskState)2 SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)2 Operation (com.vmware.xenon.common.Operation)2 UriPaths (com.vmware.photon.controller.model.UriPaths)1 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)1 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)1 PhotonModelUtils (com.vmware.photon.controller.model.resources.util.PhotonModelUtils)1 ServiceTaskCallback (com.vmware.photon.controller.model.tasks.ServiceTaskCallback)1 ServiceTaskCallbackResponse (com.vmware.photon.controller.model.tasks.ServiceTaskCallback.ServiceTaskCallbackResponse)1 SubTaskService (com.vmware.photon.controller.model.tasks.SubTaskService)1 TaskOption (com.vmware.photon.controller.model.tasks.TaskOption)1 TaskUtils (com.vmware.photon.controller.model.tasks.TaskUtils)1 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)1 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)1 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)1 FactoryService (com.vmware.xenon.common.FactoryService)1 Service (com.vmware.xenon.common.Service)1 PropertyUsageOption (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption)1 ServiceNotFoundException (com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)1 TaskState (com.vmware.xenon.common.TaskState)1