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;
}
}
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);
}
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;
}
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);
}
}));
}
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);
}
Aggregations