Search in sources :

Example 1 with ResourceType

use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceType in project photon-model by vmware.

the class ResourceOperationUtils method lookupByResourceState.

/**
 * Lookup for {@link ResourceOperationSpec} by given {@code resourceState} and {@code operation}
 * @param host
 *         host to use to create operation
 * @param refererURI
 *         the referer to use when send the operation
 * @param resourceState
 *         the resource state specialization for which to lookup the spec
 * @param operation
 *         the operation
 * @param authorizationContext
 *         authorization context that will be used for operations (if set to null the context
 *         will not be changed)
 * @return
 */
public static <T extends ResourceState> DeferredResult<List<ResourceOperationSpec>> lookupByResourceState(ServiceHost host, URI refererURI, T resourceState, String operation, AuthorizationContext authorizationContext) {
    AssertUtil.assertNotNull(resourceState, "'resourceState' must be set.");
    String endpointLink = null;
    // All endpoint links have to be of the same type, so it's enough to get the first one
    if (resourceState.endpointLinks != null && !resourceState.endpointLinks.isEmpty()) {
        endpointLink = resourceState.endpointLinks.iterator().next();
    }
    ResourceType resourceType;
    if (resourceState instanceof ComputeState) {
        ComputeState compute = (ComputeState) resourceState;
        endpointLink = endpointLink == null ? compute.endpointLink : endpointLink;
        resourceType = ResourceType.COMPUTE;
    } else if (resourceState instanceof NetworkState) {
        NetworkState network = (NetworkState) resourceState;
        endpointLink = endpointLink == null ? network.endpointLink : endpointLink;
        resourceType = ResourceType.NETWORK;
    } else {
        throw new IllegalArgumentException("Unsupported resource state: " + resourceState.getClass().getName());
    }
    AssertUtil.assertNotNull(endpointLink, " must be set.");
    return host.sendWithDeferredResult(Operation.createGet(host, endpointLink).setReferer(refererURI), EndpointState.class).thenCompose(ep -> lookUp(host, refererURI, (ep).endpointType, resourceType, operation, resourceState.tenantLinks, authorizationContext));
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceType(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceType) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState)

Aggregations

ResourceType (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceType)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)1 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)1