Search in sources :

Example 1 with ImageEnumerateRequest

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;
    });
}
Also used : ImageEnumerateRequest(com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest) Operation(com.vmware.xenon.common.Operation)

Example 2 with ImageEnumerateRequest

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);
}
Also used : PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RpcException(com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException) HashSet(java.util.HashSet) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) ImageService(com.vmware.photon.controller.model.resources.ImageService) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ObjectContent(com.vmware.vim25.ObjectContent) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) DatacenterLister(com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Set(java.util.Set) IOException(java.io.IOException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Phaser(java.util.concurrent.Phaser) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) ImageEnumerateRequest(com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) URI(java.net.URI)

Example 3 with ImageEnumerateRequest

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);
}
Also used : PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RpcException(com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException) HashSet(java.util.HashSet) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) ImageService(com.vmware.photon.controller.model.resources.ImageService) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ObjectContent(com.vmware.vim25.ObjectContent) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) DatacenterLister(com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Set(java.util.Set) IOException(java.io.IOException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Phaser(java.util.concurrent.Phaser) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) ImageEnumerateRequest(com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) ImageEnumerateRequest(com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest)

Aggregations

ImageEnumerateRequest (com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest)3 Operation (com.vmware.xenon.common.Operation)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)2 TaskManager (com.vmware.photon.controller.model.adapters.util.TaskManager)2 Connection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection)2 DatacenterLister (com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister)2 Element (com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element)2 LibraryClient (com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient)2 RpcException (com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException)2 VapiClient (com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient)2 VapiConnection (com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection)2 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)2 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)2 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)2 ImageService (com.vmware.photon.controller.model.resources.ImageService)2 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)2 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)2 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2