/** * Once the task has been validated, we need to initialize the state to valid values. * * @see TaskService#initializeState(TaskServiceState, Operation) */ @Override protected void initializeState(NodeGroupMigrationState task, Operation taskOperation) { super.initializeState(task, taskOperation); task.subStage = SubStage.INITIALIZING; }
/** * This method initializes a {@link DemoTaskState} from the body of a valid POST operation. * @param taskState Supplies the task state to be initialized. * @param startOp Supplies the POST {@link Operation} which has caused this task to be created. */ @Override protected void initializeState(DemoTaskState taskState, Operation startOp) { super.initializeState(taskState, startOp); taskState.taskInfo.stage = TaskState.TaskStage.CREATED; }
@Override protected void initializeState(StatsAggregationTaskState state, Operation postOp) { logFine(() -> "Started stats aggregation"); super.initializeState(state, postOp); state.taskSubStage = StatsAggregationStage.INIT; }
@Override protected void initializeState(EndpointAllocationTaskState state, Operation taskOperation) { if (state.taskSubStage == null) { state.taskSubStage = SubStage.POPULATE_ADAPTER_REFERENCE; } if (state.options == null) { state.options = EnumSet.noneOf(TaskOption.class); } if (state.documentExpirationTimeMicros == 0) { state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + DEFAULT_TIMEOUT_MICROS; } super.initializeState(state, taskOperation); }
@Override protected void initializeState(StatsAggregationTaskState state, Operation postOp) { logFine(() -> "Started stats aggregation"); super.initializeState(state, postOp); state.taskSubStage = StatsAggregationStage.INIT; }
@Override protected void initializeState(EndpointRemovalTaskState state, Operation taskOperation) { if (state.taskSubStage == null) { state.taskSubStage = SubStage.LOAD_ENDPOINT; } if (state.options == null) { state.options = EnumSet.noneOf(TaskOption.class); } if (state.documentExpirationTimeMicros == 0) { state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + DEFAULT_TIMEOUT_MICROS; } super.initializeState(state, taskOperation); }
@Override protected void initializeState(EndpointRemovalTaskState state, Operation taskOperation) { if (state.taskSubStage == null) { state.taskSubStage = SubStage.LOAD_ENDPOINT; } if (state.options == null) { state.options = EnumSet.noneOf(TaskOption.class); } if (state.documentExpirationTimeMicros == 0) { state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + DEFAULT_TIMEOUT_MICROS; } super.initializeState(state, taskOperation); }
@Override protected void initializeState(SingleResourceStatsCollectionTaskState state, Operation postOp) { super.initializeState(state, postOp); // Override the default expiration of 4 hours to 10 minutes. setExpiration(state, DEFAULT_EXPIRATION_MINUTES, TimeUnit.MINUTES); state.taskStage = SingleResourceTaskCollectionStage.GET_DESCRIPTIONS; state.taskInfo = TaskUtils.createTaskState(TaskStage.STARTED); }
@Override protected void initializeState(SingleResourceStatsCollectionTaskState state, Operation postOp) { super.initializeState(state, postOp); // Override the default expiration of 4 hours to 10 minutes. setExpiration(state, DEFAULT_EXPIRATION_MINUTES, TimeUnit.MINUTES); state.taskStage = SingleResourceTaskCollectionStage.GET_DESCRIPTIONS; state.taskInfo = TaskUtils.createTaskState(TaskStage.STARTED); }
@Override protected void initializeState(EndpointAllocationTaskState state, Operation taskOperation) { if (state.taskSubStage == null) { state.taskSubStage = SubStage.VALIDATE_CREDENTIALS; } if (state.options == null) { state.options = EnumSet.noneOf(TaskOption.class); } if (state.adapterReference == null) { state.adapterReference = getAdapterUri(this, AdapterTypePath.ENDPOINT_CONFIG_ADAPTER, state.endpointState.endpointType); } if (state.documentExpirationTimeMicros == 0) { state.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + DEFAULT_TIMEOUT_MICROS; } super.initializeState(state, taskOperation); }
/** * Initialize the task * * We set it to be STARTED: we skip CREATED because we don't need the CREATED state * If your task does significant initialization, you may prefer to do it in the * CREATED state. */ @Override protected void initializeState(ExampleTaskServiceState task, Operation taskOperation) { task.subStage = SubStage.QUERY_EXAMPLES; if (task.taskLifetime != null) { task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc( TimeUnit.SECONDS.toMicros(task.taskLifetime)); } else if (task.documentExpirationTimeMicros != 0) { task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc( TimeUnit.SECONDS.toMicros(DEFAULT_TASK_LIFETIME)); } // Do our task-specific logic... This will allow our ExampleTaskService's "default" // expiration to take precedence over the default expiration set by TaskService super.initializeState(task, taskOperation); }
super.initializeState(task, taskOperation);
@Override protected void initializeState(SingleResourceStatsAggregationTaskState state, Operation postOp) { super.initializeState(state, postOp); // Override the default expiration of 4 hours to 10 minutes. setExpiration(state, DEFAULT_EXPIRATION_MINUTES, TimeUnit.MINUTES); state.taskStage = StatsAggregationStage.GET_LAST_ROLLUP_TIME; state.taskInfo = TaskUtils.createTaskState(TaskStage.STARTED); if (state.query == null) { state.query = Query.Builder.create().addFieldClause( ServiceDocument.FIELD_NAME_SELF_LINK, state.resourceLink).build(); } if (state.aggregations == null) { state.aggregations = Collections.emptyMap(); } if (state.latestValueOnly == null) { state.latestValueOnly = Collections.emptySet(); } }
@Override protected void initializeState(SingleResourceStatsAggregationTaskState state, Operation postOp) { super.initializeState(state, postOp); // Override the default expiration of 4 hours to 10 minutes. setExpiration(state, DEFAULT_EXPIRATION_MINUTES, TimeUnit.MINUTES); state.taskStage = StatsAggregationStage.GET_LAST_ROLLUP_TIME; state.taskInfo = TaskUtils.createTaskState(TaskStage.STARTED); if (state.query == null) { state.query = Query.Builder.create().addFieldClause( ServiceDocument.FIELD_NAME_SELF_LINK, state.resourceLink).build(); } if (state.aggregations == null) { state.aggregations = Collections.emptyMap(); } if (state.latestValueOnly == null) { state.latestValueOnly = Collections.emptySet(); } }
/** * This handles the initial {@code POST} that creates the task service. Most subclasses won't * need to override this method, although they likely want to override the {@link * #validateStartPost(Operation)} and {@link #initializeState(TaskServiceState, Operation)} * methods. */ @Override public void handleStart(Operation taskOperation) { T task = validateStartPost(taskOperation); if (task == null) { return; } taskOperation.complete(); if (!ServiceHost.isServiceCreate(taskOperation) || (task.taskInfo != null && !TaskState.isCreated(task.taskInfo))) { // Skip self patch to STARTED if this is a restart operation, or, task stage is // other than CREATED. // Tasks that handle restart should override handleStart and decide if they should // continue processing on restart, or fail return; } initializeState(task, taskOperation); sendSelfPatch(task); }