use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class SshCommandTaskService method handleStart.
@Override
public void handleStart(Operation start) {
if (!start.hasBody()) {
start.fail(new IllegalArgumentException("body is required"));
return;
}
SshCommandTaskState state = start.getBody(SshCommandTaskState.class);
if (state.host == null) {
start.fail(new IllegalArgumentException("host is required"));
return;
}
if (state.authCredentialLink == null) {
start.fail(new IllegalArgumentException("authCredentialLink is required"));
return;
}
if (state.commands == null || state.commands.isEmpty()) {
start.fail(new IllegalArgumentException("commands must be specified"));
return;
}
if (this.executor == null) {
start.fail(new IllegalArgumentException("executor must not be null"));
return;
}
if (state.taskInfo == null) {
state.taskInfo = new TaskState();
}
if (TaskState.isFinished(state.taskInfo)) {
// task is in the finished state, just return.
start.complete();
return;
}
if (state.taskInfo.stage != null && state.taskInfo.stage != TaskStage.CREATED) {
start.fail(new IllegalStateException("SshCommand cannot be restarted."));
return;
}
state.taskInfo.stage = TaskStage.STARTED;
if (state.documentExpirationTimeMicros == 0) {
// always set expiration so we do not accumulate tasks.
state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + TimeUnit.SECONDS.toMicros(DEFAULT_EXPIRATION_SECONDS);
}
start.setBody(state).complete();
getAuth(state);
}
use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class TaskUtils method sendFailureSelfPatch.
/**
* Send a failure patch to the specified service
*
* @param service
* service to send the patch to
* @param e
* Exception
*/
private static void sendFailureSelfPatch(StatefulService service, Throwable e) {
// It looks like Xenon can't handle correctly serializing abstract classes, so we have to
// use a simple class which extend the abstract.
StatefulTaskDocument body = new StatefulTaskDocument();
body.taskInfo = new TaskState();
body.taskInfo.stage = TaskStage.FAILED;
body.taskInfo.failure = Utils.toServiceErrorResponse(e);
service.logWarning(() -> String.format("Operation failed: %s", Utils.toString(e)));
sendPatch(service, body);
}
use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class TaskUtils method sendFailurePatch.
/**
* Patch a service to failure
*
* @param service
* Service to patch
* @param t
* Throwable object
*/
public static void sendFailurePatch(StatefulService service, TaskServiceState taskState, Throwable t) {
TaskState state = new TaskState();
state.stage = TaskStage.FAILED;
state.failure = Utils.toServiceErrorResponse(t);
service.logWarning(() -> String.format("Operation failed: %s", Utils.toString(t)));
taskState.taskInfo = state;
sendPatch(service, taskState);
}
use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class EndpointRemovalTaskService method createPatchSubStageTask.
private EndpointRemovalTaskState createPatchSubStageTask(TaskState.TaskStage stage, SubStage subStage, Throwable e) {
EndpointRemovalTaskState body = new EndpointRemovalTaskState();
body.taskInfo = new TaskState();
body.taskInfo.stage = stage;
body.taskSubStage = subStage;
if (e != null) {
body.taskInfo.failure = Utils.toServiceErrorResponse(e);
logWarning(() -> String.format("Patching to failed: %s", Utils.toString(e)));
}
return body;
}
use of com.vmware.xenon.common.TaskState in project photon-model by vmware.
the class NicSecurityGroupsTaskService method sendSelfPatch.
private void sendSelfPatch(TaskState.TaskStage stage, Throwable e) {
NicSecurityGroupsTaskState body = new NicSecurityGroupsTaskState();
body.taskInfo = new TaskState();
if (e == null) {
body.taskInfo.stage = stage;
} else {
body.taskInfo.stage = TaskState.TaskStage.FAILED;
body.taskInfo.failure = Utils.toServiceErrorResponse(e);
logWarning(() -> String.format("Patching to failed: %s", Utils.toString(e)));
}
sendSelfPatch(body);
}
Aggregations