use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class ProvisionSecurityGroupTaskService method patchAdapter.
private void patchAdapter(ProvisionSecurityGroupTaskState taskState, String subTaskLink) {
if (subTaskLink == null) {
createSubTask(taskState, link -> patchAdapter(taskState, link));
return;
}
taskState.securityGroupDescriptionLinks.forEach(sgLink -> sendRequest(Operation.createGet(UriUtils.buildUri(this.getHost(), sgLink)).setCompletion((o, e) -> {
if (e != null) {
// don't fail the task; just update the subtask, which will
// handle the failure if necessary
ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(sgLink, e);
updateSubTask(subTaskLink, subTaskPatchBody);
return;
}
SecurityGroupState securityGroupState = o.getBody(SecurityGroupState.class);
SecurityGroupInstanceRequest req = toReq(securityGroupState, taskState, sgLink, subTaskLink);
sendRequest(Operation.createPatch(securityGroupState.instanceAdapterReference).setBody(req).setCompletion((oo, ee) -> {
if (ee != null) {
ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(sgLink, ee);
updateSubTask(subTaskLink, subTaskPatchBody);
}
}));
})));
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse 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);
}
}
Aggregations