private boolean isImageReady(Operation patch) { ServiceTaskCallback.ServiceTaskCallbackResponse callbackResponse = patch .getBody(ServiceTaskCallback.ServiceTaskCallbackResponse.class); TaskState taskInfo = callbackResponse.taskInfo; return TaskState.isFinished(taskInfo); }
@Override protected EndpointRemovalTaskState validateStartPost(Operation taskOperation) { EndpointRemovalTaskState task = super.validateStartPost(taskOperation); if (task == null) { return null; } if (TaskState.isCancelled(task.taskInfo) || TaskState.isFailed(task.taskInfo) || TaskState.isFinished(task.taskInfo)) { return null; } if (!ServiceHost.isServiceCreate(taskOperation)) { return task; } if (task.endpointLink == null) { taskOperation.fail(new IllegalArgumentException("endpointLink is required")); return null; } return task; }
@Override protected EndpointRemovalTaskState validateStartPost(Operation taskOperation) { EndpointRemovalTaskState task = super.validateStartPost(taskOperation); if (task == null) { return null; } if (TaskState.isCancelled(task.taskInfo) || TaskState.isFailed(task.taskInfo) || TaskState.isFinished(task.taskInfo)) { return null; } if (!ServiceHost.isServiceCreate(taskOperation)) { return task; } if (task.endpointLink == null) { taskOperation.fail(new IllegalArgumentException("endpointLink is required")); return null; } return task; }
@Override protected EndpointAllocationTaskState validateStartPost(Operation taskOperation) { EndpointAllocationTaskState task = super.validateStartPost(taskOperation); if (task == null) { return null; } if (TaskState.isCancelled(task.taskInfo) || TaskState.isFailed(task.taskInfo) || TaskState.isFinished(task.taskInfo)) { return null; } if (!ServiceHost.isServiceCreate(taskOperation)) { return task; } if (task.endpointState == null) { taskOperation.fail(new IllegalArgumentException("endpointState is required")); return null; } if (task.endpointState.endpointType == null) { taskOperation.fail(new IllegalArgumentException("endpointType is required")); return null; } return task; }
@Override protected EndpointAllocationTaskState validateStartPost(Operation taskOperation) { EndpointAllocationTaskState task = super.validateStartPost(taskOperation); if (task == null) { return null; } if (TaskState.isCancelled(task.taskInfo) || TaskState.isFailed(task.taskInfo) || TaskState.isFinished(task.taskInfo)) { return null; } if (!ServiceHost.isServiceCreate(taskOperation)) { return task; } if (task.endpointState == null) { taskOperation.fail(new IllegalArgumentException("endpointState is required")); return null; } if (task.endpointState.endpointType == null) { taskOperation.fail(new IllegalArgumentException("endpointType is required")); return null; } return task; }
} else if (r.hasResult()) { DockerImage dockerImage = r.getResult(); if (TaskState.isFinished(dockerImage.taskInfo)) { compStateLinks.add(dockerImage.computeStateLink);
if (q.taskInfo.isDirect || TaskState.isFinished(q.taskInfo)) { processQueryResult(q, handler); return; if (!TaskState.isFinished(rsp.taskInfo)) { host.log(Level.FINE, "Resource query not complete yet, retrying...");
if (TaskState.isFinished(body.taskInfo)) { currentState.taskInfo.stage = body.taskInfo.stage; currentState.taskSubStage = SubStage.FINISHED;
private void handleBaseDockerBuildImageRequest(ContainerDescription containerDesc, AdmiralAdapterTaskState state, DockerImage imageRequest, int retriesCount) { if (TaskState.isFinished(imageRequest.taskInfo)) {
private void handleDockerBuildImageRequest(ContainerDescription containerDesc, AdmiralAdapterTaskState state, DockerImage imageRequest, int retriesCount) { if (TaskState.isFinished(imageRequest.taskInfo)) {
@Override public void handlePatch(Operation patch) { SshCommandTaskState currentState = getState(patch); SshCommandTaskState patchState = patch .getBody(SshCommandTaskState.class); if (TaskState.isFinished(currentState.taskInfo) || TaskState.isFailed(currentState.taskInfo) || TaskState.isCancelled(currentState.taskInfo)) { logFine(() -> "Task is complete, patch ignored"); patch.complete(); return; } if (patchState.commandResponse != null) { currentState.commandResponse = patchState.commandResponse; } if (patchState.taskInfo != null) { currentState.taskInfo = patchState.taskInfo; } patch.complete(); return; }
@Override public void handlePatch(Operation patch) { SshCommandTaskState currentState = getState(patch); SshCommandTaskState patchState = patch .getBody(SshCommandTaskState.class); if (TaskState.isFinished(currentState.taskInfo) || TaskState.isFailed(currentState.taskInfo) || TaskState.isCancelled(currentState.taskInfo)) { logFine(() -> "Task is complete, patch ignored"); patch.complete(); return; } if (patchState.commandResponse != null) { currentState.commandResponse = patchState.commandResponse; } if (patchState.taskInfo != null) { currentState.taskInfo = patchState.taskInfo; } patch.complete(); return; }
private void processQuery(QueryTask q, ResultHandler<T> handler) { if (TaskState.isFailed(q.taskInfo)) { handler.handle(noResult(), new IllegalStateException(q.taskInfo.failure.message)); return; } if (q.taskInfo.isDirect || TaskState.isFinished(q.taskInfo)) { processQueryResult(q, handler); return; } this.serviceRequestSender.sendRequest(Operation .createGet(UriUtils.extendUri(this.baseUri, q.documentSelfLink)) .setReferer(this.host.getUri()) .setCompletion((o, e) -> { if (e != null) { handler.handle(noResult(), e); return; } QueryTask rsp = o.getBody(QueryTask.class); if (!TaskState.isFinished(rsp.taskInfo)) { this.host.log(Level.FINE, "Resource query not complete yet, retrying..."); this.host.scheduleCore(() -> processQuery(rsp, handler), QUERY_RETRIEVAL_RETRY_INTERVAL_MICROS, TimeUnit.MICROSECONDS); return; } processQueryResult(rsp, handler); })); }
if (initState.taskInfo == null) { initState.taskInfo = new TaskState(); } else if (TaskState.isFinished(initState.taskInfo)) { startPost.complete(); return;
@Override public void handlePatch(Operation patchOperation) { State patchState = getBody(patchOperation); State currentState = getState(patchOperation); applyPatch(patchState, currentState); if (!verifyState(currentState, patchOperation) && !verifyPatchedState(currentState, patchOperation)) { return; } patchOperation.complete(); logInfo("After PATCH, the latest state is: %s", currentState); if (TaskState.isFinished(currentState.taskInfo) || TaskState.isFailed(currentState.taskInfo) || TaskState.isCancelled(currentState.taskInfo)) { return; } if ((patchState.maintenanceIntervalMicros != null || patchState.continuousMigration != null) && currentState.continuousMigration) { setMaintenanceIntervalMicros(currentState.maintenanceIntervalMicros); } resolveNodeGroupReferences(currentState); }
private void subscribeToResourceRemovalTask(ComputeRemovalTaskState state) { String taskLink = UriUtils .buildUriPath(ResourceRemovalTaskService.FACTORY_LINK, getSelfId()); Consumer<Operation> notificationTarget = (op) -> { // We only care about listening to PATCH updates... if (!op.hasBody() || !PATCH.equals(op.getAction())) { op.complete(); return; } ResourceRemovalTaskState deletionState = op.getBody(ResourceRemovalTaskState.class); op.complete(); if (TaskState.isFinished(deletionState.taskInfo)) { logInfo("ResourceRemoval Task completed successfully: %s", deletionState.documentSelfLink); SubscriptionUtils.unsubscribeNotifications(getHost(), taskLink, op.getUri()); removeAutoGeneratedPlacementZones(state); } else if (TaskState.isCancelled(deletionState.taskInfo) || TaskState.isFailed(deletionState.taskInfo)) { SubscriptionUtils.unsubscribeNotifications(getHost(), taskLink, op.getUri()); failTask("Error deleting resources", new IllegalStateException( "Error deleting resources: " + getFailureMessage(deletionState))); } }; logInfo("Subscribing to ResourceRemovalTask, waiting for removal of %d compute hosts", state.resourceLinks.size()); SubscriptionUtils.subscribeToNotifications(getHost(), notificationTarget, e -> failTask("Error subscribing for resource removal", e), taskLink); }
@Override public void handleStart(Operation startPost) { State initState = getBody(startPost); logInfo("Starting migration with initState: %s", initState); initState = initialize(initState); if (TaskState.isFinished(initState.taskInfo)) { startPost.complete(); return; } if (!verifyState(initState, startPost)) { return; } startPost.complete(); State patchState = new State(); if (initState.taskInfo == null) { patchState.taskInfo = TaskState.create(); } if (initState.continuousMigration) { setMaintenanceIntervalMicros(initState.maintenanceIntervalMicros); } if (initState.taskInfo.stage == TaskStage.CANCELLED) { logInfo("In stage %s, will restart on next maintenance interval", initState.taskInfo.stage); return; } Operation.createPatch(getUri()) .setBody(patchState) .sendWith(this); }
@Test public void testRequestStatusShouldNotBeModifiedAfterCompletion() throws Throwable { ContainerDescription desc1 = TestRequestStateFactory.createContainerDescription("name1"); desc1.portBindings = null; ContainerDescription desc2 = TestRequestStateFactory.createContainerDescription("name2"); desc2.portBindings = null; desc2.affinity = new String[] { desc1.name }; CompositeDescription compositeDesc = createCompositeDesc(desc1, desc2); RequestStatus requestStatus = verifyRequestStatus(compositeDesc.documentSelfLink, ResourceType.COMPOSITE_COMPONENT_TYPE); assertEquals(compositeDesc.name, requestStatus.name); String compositionTaskLink = UriUtils.buildUriPath(CompositionTaskFactoryService.SELF_LINK, extractId(requestStatus.documentSelfLink)); CompositionTaskState compositionTaskState = getDocument(CompositionTaskState.class, compositionTaskLink); assertNotNull(compositionTaskState); assertEquals(1, requestStatus.resourceLinks.size()); assertEquals(compositionTaskState.compositeComponentLink, requestStatus.resourceLinks.iterator().next()); // The request is already finished the patch should not change the state requestStatus.taskInfo = TaskState.createAsStarted(); doOperation(requestStatus, UriUtils.buildUri(host, requestStatus.documentSelfLink), false, Action.PATCH); RequestStatus finalStatus = getRequestStatus(requestId); assertTrue(TaskState.isFinished(finalStatus.taskInfo)); }
return TaskState.isFinished(status.taskInfo) && (status.progress.intValue() == 100); }); return TaskState.isFinished(status.taskInfo) && (status.progress.intValue() == 100); });
|| TaskState.isCancelled(imageRequest.taskInfo)) { logWarning("Failed to seed docker base image: %s", imageRequest); } else if (TaskState.isFinished(imageRequest.taskInfo)) { seedWithDockerImage(containerDesc, computeStateLink, state); touchDockerImage(dockerBuildImageLink, imageRequest);