use of com.vmware.xenon.common.Operation.CompletionHandler in project photon-model by vmware.
the class EndpointAllocationTaskService method rollbackEndpoint.
private void rollbackEndpoint(EndpointAllocationTaskState currentState) {
Runnable completionHandler = () -> {
sendSelfPatch(createUpdateSubStageTask(TaskStage.FAILED, SubStage.FAILED));
};
if (currentState.createdDocumentLinks == null || currentState.createdDocumentLinks.isEmpty()) {
completionHandler.run();
} else {
List<Operation> deleteOps = currentState.createdDocumentLinks.stream().map(link -> Operation.createDelete(this, link)).collect(Collectors.toList());
// execute the delete ops in a reverse order because of possible dependencies
OperationSequence opSequence = OperationSequence.create(deleteOps.get(deleteOps.size() - 1));
for (int i = deleteOps.size() - 2; i >= 0; i--) {
opSequence = opSequence.next(deleteOps.get(i));
}
opSequence.setCompletion((ops, exs) -> {
if (exs != null) {
logWarning(() -> "Error during rollback of created endpoint documents: " + Utils.toString(exs));
}
completionHandler.run();
}).sendWith(this);
}
}
use of com.vmware.xenon.common.Operation.CompletionHandler in project photon-model by vmware.
the class ProvisionComputeTaskService method doSubStageBootHost.
private void doSubStageBootHost(ProvisionComputeTaskState updatedState, BootDevice[] bootDevices, ProvisionComputeTaskState.SubStage nextStage) {
CompletionHandler c = (o, e) -> {
if (e != null) {
failTask(e);
return;
}
ComputeBootRequest br = new ComputeBootRequest();
br.resourceReference = UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), updatedState.computeLink);
for (BootDevice bootDevice : bootDevices) {
br.bootDeviceOrder.add(bootDevice);
}
ServiceDocument subTask = o.getBody(ServiceDocument.class);
br.taskReference = UriUtils.buildUri(this.getHost(), subTask.documentSelfLink);
br.isMockRequest = updatedState.isMockRequest;
sendHostServiceRequest(br, updatedState.bootAdapterReference);
};
// After setting boot order and rebooting, we want the sub-task
// to patch the main task to the "next" state.
createSubTask(c, nextStage, updatedState);
}
use of com.vmware.xenon.common.Operation.CompletionHandler in project photon-model by vmware.
the class ProvisionComputeTaskService method doSubStageCreateHost.
private void doSubStageCreateHost(ProvisionComputeTaskState updatedState, ProvisionComputeTaskState.SubStage nextStage) {
CompletionHandler c = (o, e) -> {
if (e != null) {
failTask(e);
return;
}
ComputeInstanceRequest cr = new ComputeInstanceRequest();
cr.resourceReference = createInventoryUri(this.getHost(), updatedState.computeLink);
cr.endpointLinkReference = createInventoryUri(this.getHost(), updatedState.endpointLink);
cr.requestType = InstanceRequestType.CREATE;
// the first reboot needs to be from the network, and the bare metal
// services
// will provide the image reference (retrieved from the computeReference)
ServiceDocument subTask = o.getBody(ServiceDocument.class);
cr.taskReference = UriUtils.buildUri(this.getHost(), subTask.documentSelfLink);
cr.isMockRequest = updatedState.isMockRequest;
sendHostServiceRequest(cr, updatedState.instanceAdapterReference);
};
// after setting boot order and rebooting, we want the sub
// task to patch us, the main task, to the "next" state
createSubTask(c, nextStage, updatedState);
}
Aggregations