use of com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest in project photon-model by vmware.
the class ImageEnumerationTaskService method callImageEnumerationAdapter.
/**
* Call 'image-enumeration' adapter if registered by the end-point OR fail if not registered.
*/
private DeferredResult<SendImageEnumerationAdapterContext> callImageEnumerationAdapter(SendImageEnumerationAdapterContext ctx) {
if (ctx.adapterRef == null) {
// No 'image-enumeration' URI registered for passed end-point
return DeferredResult.failed(new IllegalStateException(String.format("No '%s' URI registered by '%s' end-point.", AdapterTypePath.IMAGE_ENUMERATION_ADAPTER.key, ctx.taskState.endpointType)));
}
// Create 'image-enumeration' adapter request
final ImageEnumerateRequest adapterReq = new ImageEnumerateRequest();
// Set ImageEnumerateRequest specific params
adapterReq.enumerationAction = ctx.taskState.enumerationAction;
if (ctx.taskState.enumeratePrivateImages()) {
adapterReq.requestType = ImageEnumerateRequestType.PRIVATE;
} else if (ctx.taskState.enumeratePublicImages()) {
adapterReq.requestType = ImageEnumerateRequestType.PUBLIC;
}
// Set generic ResourceRequest params
// The end-point is ALWAYS set regardless of Private/Public enum type
// In case of Public, end-point credentials are used to run the enumeration
adapterReq.resourceReference = createInventoryUri(this.getHost(), ctx.endpointState.documentSelfLink);
adapterReq.regionId = ctx.taskState.regionId;
adapterReq.taskReference = buildUri(getHost(), ctx.taskState.documentSelfLink);
adapterReq.isMockRequest = ctx.taskState.options.contains(TaskOption.IS_MOCK);
Operation callAdapterOp = Operation.createPatch(ctx.adapterRef).setBody(adapterReq);
return sendWithDeferredResult(callAdapterOp).thenApply(op -> {
logInfo(() -> String.format("[callImageEnumerationAdapter] adpterRef = %s: SUCCESS", op.getUri()));
return ctx;
});
}
use of com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest in project photon-model by vmware.
the class VSphereAdapterImageEnumerationService method thenWithEndpointState.
private void thenWithEndpointState(ImageEnumerateRequest request, EndpointState endpoint, TaskManager mgr) {
URI parentUri = ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), endpoint.computeLink));
Operation.createGet(PhotonModelUriUtils.createInventoryUri(getHost(), parentUri)).setCompletion(o -> thenWithParentState(request, o.getBody(ComputeStateWithDescription.class), mgr), mgr).sendWith(this);
}
use of com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest in project photon-model by vmware.
the class VSphereAdapterImageEnumerationService 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();
ImageEnumerateRequest request = op.getBody(ImageEnumerateRequest.class);
validate(request);
TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());
if (request.isMockRequest) {
// just finish the mock request
mgr.patchTask(TaskStage.FINISHED);
return;
}
Operation.createGet(PhotonModelUriUtils.createInventoryUri(getHost(), request.resourceReference)).setCompletion(o -> thenWithEndpointState(request, o.getBody(EndpointState.class), mgr), mgr).sendWith(this);
}
Aggregations