use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class EndpointRemovalTaskService method doInstanceDelete.
/**
* Delete endpoint
*/
private void doInstanceDelete(EndpointRemovalTaskState currentState, SubStage next) {
EndpointState endpoint = currentState.endpoint;
Operation crdOp = Operation.createDelete(createInventoryUri(this.getHost(), endpoint.authCredentialsLink));
Operation epOp = Operation.createDelete(createInventoryUri(this.getHost(), endpoint.documentSelfLink));
// custom header identifier for endpoint service to validate before deleting endpoint
epOp.addRequestHeader(ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME, ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE);
OperationJoin.create(crdOp, epOp).setCompletion((ops, exc) -> {
if (exc != null) {
// failing to delete the endpoint itself is considered a critical error
Throwable endpointRemovalException = exc.get(epOp.getId());
if (endpointRemovalException != null) {
sendFailureSelfPatch(endpointRemovalException);
return;
}
// other removal exceptions are just warnings
logFine(() -> String.format("Failed delete some of the associated resources," + " reason %s", Utils.toString(exc)));
}
// Endpoint and AuthCredentials are deleted; mark the operation as complete
sendSelfPatch(TaskStage.STARTED, next);
}).sendWith(this);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class IPAddressReleaseTaskService method markIPAddressesAsAvailable.
/**
* Releases IP Addresses and marks them as available.
* @param ipAddressStates IP Address states
*/
private DeferredResult<List<Operation>> markIPAddressesAsAvailable(List<IPAddressService.IPAddressState> ipAddressStates) {
IPAddressService.IPAddressState addressState = new IPAddressService.IPAddressState();
addressState.ipAddressStatus = IPAddressService.IPAddressState.IPAddressStatus.AVAILABLE;
List<DeferredResult<Operation>> ipAddressOperations = new ArrayList<>();
for (IPAddressService.IPAddressState ipAddressState : ipAddressStates) {
Operation patchOp = Operation.createPatch(this, ipAddressState.documentSelfLink).setBody(addressState).setCompletion((o, e) -> {
if (e != null) {
logWarning("Failed to mark IP address resource %s as available due to failure %s", ipAddressState.ipAddress, e.getMessage());
} else {
logInfo("The IP address %s is made available", ipAddressState.ipAddress);
}
});
ipAddressOperations.add(this.sendWithDeferredResult(patchOp));
}
return DeferredResult.allOf(ipAddressOperations);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class ProvisionComputeTaskService method sendSelfPatch.
private void sendSelfPatch(TaskStage newStage, ProvisionComputeTaskState.SubStage newSubStage, Throwable ex) {
ProvisionComputeTaskState patchBody = new ProvisionComputeTaskState();
patchBody.taskInfo = new TaskState();
patchBody.taskInfo.stage = newStage;
patchBody.taskSubStage = newSubStage;
if (ex != null) {
patchBody.taskInfo.failure = Utils.toServiceErrorResponse(ex);
}
Operation patch = Operation.createPatch(getUri()).setBody(patchBody).setCompletion((o, e) -> {
if (e != null) {
logWarning(() -> String.format("Self patch failed: %s", com.vmware.xenon.common.Utils.toString(e)));
}
});
sendRequest(patch);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class ProvisionComputeTaskService method handleStart.
@Override
public void handleStart(Operation startPost) {
try {
ProvisionComputeTaskState state = startPost.getBody(ProvisionComputeTaskState.class);
validateState(state);
// we need to retrieve and cache the power and boot services we need
// to actuate
URI computeHost = buildComputeHostUri(state);
sendRequest(Operation.createGet(computeHost).addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY).setCompletion((o, e) -> validateComputeHostAndStart(startPost, o, e, state)));
} catch (Throwable e) {
logSevere(e);
startPost.fail(e);
}
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class SingleResourceStatsCollectionTaskService method batchPersistStats.
private void batchPersistStats(List<Operation> operations, int batchIndex, boolean isFinalBatch) {
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) {
logWarning(() -> String.format("Failed stats collection: %s", exc.values().iterator().next().getMessage()));
TaskUtils.sendFailurePatch(this, new SingleResourceStatsCollectionTaskState(), exc.values());
return;
}
if (finalNextBatchIndex == null || finalNextBatchIndex == operations.size()) {
if (isFinalBatch) {
SingleResourceStatsCollectionTaskState nextStatePatch = new SingleResourceStatsCollectionTaskState();
nextStatePatch.taskInfo = TaskUtils.createTaskState(TaskStage.FINISHED);
TaskUtils.sendPatch(this, nextStatePatch);
}
return;
}
batchPersistStats(operations, finalNextBatchIndex, isFinalBatch);
});
opSequence.sendWith(this);
}
Aggregations