@Override public void handleStart(Operation start) { ServiceUtils.logInfo(this, "Starting service %s", getSelfLink()); State startState = start.getBody(State.class); InitializationUtils.initialize(startState); if (null == startState.queryCreateVmTaskInterval) { startState.queryCreateVmTaskInterval = HostUtils.getDeployerContext(this).getTaskPollDelay(); } validateState(startState); if (TaskState.TaskStage.CREATED == startState.taskState.stage) { startState.taskState.stage = TaskState.TaskStage.STARTED; } start.setBody(startState).complete(); try { if (ControlFlags.isOperationProcessingDisabled(startState.controlFlags)) { ServiceUtils.logInfo(this, "Skipping patch handling (disabled)"); } else if (TaskState.TaskStage.STARTED == startState.taskState.stage) { TaskUtils.sendSelfPatch(this, buildPatch(startState.taskState.stage, (Throwable) null)); } } catch (Throwable t) { failTask(t); } }
/** * This method is called when a patch operation is performed on the current service. * * @param patch Supplies the patch operation object. */ @Override public void handlePatch(Operation patch) { ServiceUtils.logInfo(this, "Handling patch for service %s", getSelfLink()); State startState = getState(patch); State patchState = patch.getBody(State.class); validatePatchState(startState, patchState); PatchUtils.patchState(startState, patchState); validateState(startState); patch.complete(); try { if (ControlFlags.isOperationProcessingDisabled(startState.controlFlags)) { ServiceUtils.logInfo(this, "Skipping patch handling (disabled)"); } else if (TaskState.TaskStage.STARTED == startState.taskState.stage) { processStartedStage(startState); } } catch (Throwable t) { failTask(t); } }