use of com.vmware.xenon.common.OperationSequence in project photon-model by vmware.
the class VSphereDiskService method finishDiskDeleteOperation.
/**
* Finish the disk delete operation by cleaning up the disk reference in the system.
*/
private void finishDiskDeleteOperation(DiskContext ctx) {
// Clean up disk description link if it is present.
String diskDescLink = CustomProperties.of(ctx.diskState).getString(PhotonModelConstants.TEMPLATE_DISK_LINK);
OperationSequence seq = null;
if (diskDescLink != null && !diskDescLink.isEmpty()) {
seq = OperationSequence.create(deleteDisk(diskDescLink));
}
List<Operation> nextOps = new ArrayList<>(2);
if (seq == null) {
seq = OperationSequence.create(deleteDisk(ctx.diskState.documentSelfLink));
} else {
nextOps.add(deleteDisk(ctx.diskState.documentSelfLink));
}
nextOps.add(ctx.mgr.createTaskPatch(TaskState.TaskStage.FINISHED));
seq.next(nextOps.toArray(new Operation[nextOps.size()])).setCompletion(ctx.failTaskOnError()).sendWith(this);
}
use of com.vmware.xenon.common.OperationSequence in project photon-model by vmware.
the class SingleResourceStatsAggregationTaskService method batchPublishMetrics.
public void batchPublishMetrics(SingleResourceStatsAggregationTaskState currentState, List<Operation> operations, int batchIndex) {
OperationSequence opSequence = null;
Integer nextBatchIndex = null;
for (int i = batchIndex; i < operations.size(); i++) {
final Operation operation = operations.get(i);
if (opSequence == null) {
opSequence = OperationSequence.create(operation);
continue;
}
opSequence = opSequence.next(operation);
// Batch size of 100
int batchSize = 100;
int opSequenceSize = i + 1;
if ((opSequenceSize % batchSize) == 0) {
nextBatchIndex = opSequenceSize;
break;
}
}
Integer finalNextBatchIndex = nextBatchIndex;
opSequence.setCompletion((ops, exc) -> {
if (exc != null) {
sendSelfFailurePatch(currentState, exc.values().iterator().next().getMessage());
return;
}
if (finalNextBatchIndex == null || finalNextBatchIndex == operations.size()) {
sendSelfPatch(currentState, TaskStage.FINISHED, null);
return;
}
batchPublishMetrics(currentState, operations, finalNextBatchIndex);
});
opSequence.sendWith(this);
}
use of com.vmware.xenon.common.OperationSequence 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);
}
}
Aggregations