Search in sources :

Example 36 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class ResourceAllocationTaskService method validateState.

public static void validateState(ResourceAllocationTaskState state) {
    if (state.resourcePoolLink == null) {
        throw new IllegalArgumentException("resourcePoolLink is required");
    }
    if (state.taskInfo == null || state.taskInfo.stage == null) {
        state.taskInfo = new TaskState();
        state.taskInfo.stage = TaskStage.CREATED;
    }
    if (state.computeDescriptionLink == null) {
        throw new IllegalArgumentException("computeDescriptionLink is required");
    }
    if (state.resourceCount <= 0) {
        throw new IllegalArgumentException("resourceCount is required");
    }
    if (state.errorThreshold > 1.0 || state.errorThreshold < 0) {
        throw new IllegalArgumentException("errorThreshold can only be between 0 and 1.0");
    }
    if (state.taskSubStage == null) {
        state.taskSubStage = SubStage.QUERYING_AVAILABLE_COMPUTE_RESOURCES;
    }
    if (state.documentExpirationTimeMicros == 0) {
        state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + DEFAULT_TIMEOUT_MICROS;
    }
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 37 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class SshCommandTaskService method sendSelfPatch.

private void sendSelfPatch(SshCommandTaskState state, TaskStage stage, Map<String, String> commandResponse, Throwable t) {
    SshCommandTaskState patch = new SshCommandTaskState();
    patch.taskInfo = new TaskState();
    patch.taskInfo.stage = stage;
    patch.commandResponse = commandResponse;
    if (t != null) {
        patch.taskInfo.failure = Utils.toServiceErrorResponse(t);
    }
    Operation patchOperation = Operation.createPatch(UriUtils.buildUri(getHost(), state.documentSelfLink)).setBody(patch);
    sendRequest(patchOperation);
}
Also used : Operation(com.vmware.xenon.common.Operation) TaskState(com.vmware.xenon.common.TaskState)

Example 38 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class TaskUtils method createTaskState.

/**
 * Create a TaskState object with the specified stage
 *
 * @param stage
 *         Stage for the TaskState object
 * @return
 */
public static TaskState createTaskState(TaskStage stage) {
    TaskState tState = new TaskState();
    tState.stage = stage;
    return tState;
}
Also used : TaskState(com.vmware.xenon.common.TaskState)

Example 39 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class SingleResourceStatsCollectionTaskService method getDescriptions.

private void getDescriptions(SingleResourceStatsCollectionTaskState currentState) {
    URI computeDescUri = ComputeStateWithDescription.buildUri(UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.computeLink));
    sendRequest(Operation.createGet(computeDescUri).setCompletion((getOp, getEx) -> {
        if (getEx != null) {
            TaskUtils.sendFailurePatch(this, currentState, getEx);
            return;
        }
        ComputeStateWithDescription computeStateWithDesc = getOp.getBody(ComputeStateWithDescription.class);
        ComputeStatsRequest statsRequest = new ComputeStatsRequest();
        statsRequest.isMockRequest = currentState.options != null ? currentState.options.contains(TaskOption.IS_MOCK) : false;
        URI patchUri = null;
        Object patchBody = null;
        ComputeDescription description = computeStateWithDesc.description;
        URI statsAdapterReference = null;
        List<String> tenantLinks = new ArrayList<>();
        if (description != null) {
            tenantLinks = description.tenantLinks;
            // provided
            if (currentState.statsAdapterReference == null) {
                statsAdapterReference = description.statsAdapterReference;
            } else if (description.statsAdapterReferences != null) {
                for (URI uri : description.statsAdapterReferences) {
                    if (uri.getPath().equals(currentState.statsAdapterReference.getPath())) {
                        statsAdapterReference = currentState.statsAdapterReference;
                        break;
                    }
                }
            }
        }
        if (statsAdapterReference != null) {
            statsRequest.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
            statsRequest.resourceReference = UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), computeStateWithDesc.documentSelfLink);
            statsRequest.taskReference = getUri();
            patchUri = statsAdapterReference;
            populateLastCollectionTimeForMetricsInStatsRequest(currentState, statsRequest, patchUri, tenantLinks);
        } else {
            // no adapter associated with this resource, just patch completion
            SingleResourceStatsCollectionTaskState nextStageState = new SingleResourceStatsCollectionTaskState();
            nextStageState.taskInfo = new TaskState();
            nextStageState.taskInfo.stage = TaskStage.FINISHED;
            patchUri = getUri();
            patchBody = nextStageState;
            sendStatsRequestToAdapter(currentState, patchUri, patchBody);
        }
    }));
}
Also used : Service(com.vmware.xenon.common.Service) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) AggregationType(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Utils(com.vmware.xenon.common.Utils) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) Map(java.util.Map) URI(java.net.URI) EnumSet(java.util.EnumSet) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) ServiceStats(com.vmware.xenon.common.ServiceStats) List(java.util.List) TimeSeriesStats(com.vmware.xenon.common.ServiceStats.TimeSeriesStats) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskState(com.vmware.xenon.common.TaskState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) FactoryService(com.vmware.xenon.common.FactoryService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) TaskService(com.vmware.xenon.services.common.TaskService) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) TaskUtils(com.vmware.photon.controller.model.tasks.TaskUtils) InMemoryResourceMetric(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService.InMemoryResourceMetric) HashMap(java.util.HashMap) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) ArrayList(java.util.ArrayList) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) OperationSequence(com.vmware.xenon.common.OperationSequence) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TypeName(com.vmware.xenon.common.ServiceDocumentDescription.TypeName) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) InMemoryResourceMetricService(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) Comparator(java.util.Comparator) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) List(java.util.List) ArrayList(java.util.ArrayList) URI(java.net.URI) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) TaskState(com.vmware.xenon.common.TaskState)

Example 40 with TaskState

use of com.vmware.xenon.common.TaskState in project photon-model by vmware.

the class ProvisionSubnetTaskService method handleStart.

@Override
public void handleStart(Operation start) {
    if (!start.hasBody()) {
        start.fail(new IllegalArgumentException("body is required"));
        return;
    }
    ProvisionSubnetTaskState state = start.getBody(ProvisionSubnetTaskState.class);
    try {
        state.validate();
    } catch (Exception e) {
        start.fail(e);
    }
    state.taskInfo = new TaskState();
    state.taskInfo.stage = TaskState.TaskStage.CREATED;
    state.taskSubStage = SubStage.CREATED;
    start.complete();
    // start the task
    sendSelfPatch(TaskState.TaskStage.CREATED, null);
}
Also used : ProvisionSubnetTaskState(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState) ProvisionSubnetTaskState(com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState) TaskState(com.vmware.xenon.common.TaskState)

Aggregations

TaskState (com.vmware.xenon.common.TaskState)45 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)6 NicSecurityGroupsTaskState (com.vmware.photon.controller.model.tasks.NicSecurityGroupsTaskService.NicSecurityGroupsTaskState)5 ProvisionSubnetTaskState (com.vmware.photon.controller.model.tasks.ProvisionSubnetTaskService.ProvisionSubnetTaskState)5 Operation (com.vmware.xenon.common.Operation)5 ImageEnumerationTaskState (com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState)4 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)3 IPAddressAllocationTaskState (com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState)3 ProvisionSecurityGroupTaskState (com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState)3 SubTaskState (com.vmware.photon.controller.model.tasks.SubTaskService.SubTaskState)3 HashMap (java.util.HashMap)3 UriPaths (com.vmware.photon.controller.model.UriPaths)2 EndpointType (com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType)2 ProvisionDiskTaskState (com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState)2 ResourceIPDeallocationTaskState (com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState)2 PropertyUsageOption (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption)2 UriUtils (com.vmware.xenon.common.UriUtils)2 Utils (com.vmware.xenon.common.Utils)2 TaskService (com.vmware.xenon.services.common.TaskService)2 List (java.util.List)2