use of com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest in project photon-model by vmware.
the class VSphereAdapterInstanceService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
op.setStatusCode(Operation.STATUS_CODE_CREATED);
op.complete();
ComputeInstanceRequest request = op.getBody(ComputeInstanceRequest.class);
TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());
if (request.isMockRequest) {
handleMockRequest(mgr);
return;
}
ProvisionContext.populateContextThen(this, createInitialContext(request, op), ctx -> {
switch(request.requestType) {
case CREATE:
handleCreateInstance(ctx);
break;
case DELETE:
handleDeleteInstance(ctx);
break;
default:
Throwable error = new IllegalStateException("Unsupported requestType " + request.requestType);
ctx.fail(error);
}
});
}
use of com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest in project photon-model by vmware.
the class ResourceRemovalTaskService method sendInstanceDelete.
private void sendInstanceDelete(String resourceLink, String subTaskLink, Operation o, ResourceRemovalTaskState currentState) {
ComputeStateWithDescription chd = o.getBody(ComputeStateWithDescription.class);
if (chd.description.instanceAdapterReference != null) {
ComputeInstanceRequest deleteReq = new ComputeInstanceRequest();
deleteReq.resourceReference = createInventoryUri(this.getHost(), resourceLink);
deleteReq.taskReference = UriUtils.buildUri(getHost(), subTaskLink);
deleteReq.requestType = ComputeInstanceRequest.InstanceRequestType.DELETE;
deleteReq.isMockRequest = currentState.isMockRequest;
sendRequest(Operation.createPatch(chd.description.instanceAdapterReference).setBody(deleteReq).setCompletion((deleteOp, e) -> {
if (e != null) {
logWarning(() -> String.format("PATCH to instance service %s, failed: %s", deleteOp.getUri(), e.toString()));
ResourceOperationResponse fail = ResourceOperationResponse.fail(resourceLink, e);
sendPatch(subTaskLink, fail);
return;
}
}));
} else {
logWarning(() -> String.format("Compute instance %s doesn't not have configured" + " instanceAdapter. Only local resource will be deleted.", resourceLink));
ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.finish(resourceLink);
sendPatch(subTaskLink, subTaskPatchBody);
}
}
use of com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest 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