use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class ResourceOperationUtils method lookUp.
/**
* Lookup for {@link ResourceOperationSpec}s by given {@code endpointType},
* {@code resourceType} and optionally {@code operation}
* <p>
* If operation not specified then return all resource operation specs for the given
* {@code endpointType} and {@code resourceType}
* @param host
* host to use to create operation
* @param refererURI
* the referer to use when send the operation
* @param endpointType
* the resource's endpoint type
* @param resourceType
* the resource type
* @param operation
* optional operation id argument
* @param queryTaskTenantLinks
* tenant links used for the QueryTask
* @param authorizationContext
* authorization context that will be used for operations (if set to null the context
* will not be changed)
* @return
*/
private static DeferredResult<List<ResourceOperationSpec>> lookUp(ServiceHost host, URI refererURI, String endpointType, ResourceType resourceType, String operation, List<String> queryTaskTenantLinks, AuthorizationContext authorizationContext) {
Query.Builder builder = Query.Builder.create().addKindFieldClause(ResourceOperationSpec.class).addFieldClause(ResourceOperationSpec.FIELD_NAME_ENDPOINT_TYPE, endpointType).addFieldClause(ResourceOperationSpec.FIELD_NAME_RESOURCE_TYPE, resourceType);
if (operation != null) {
builder.addFieldClause(ResourceOperationSpec.FIELD_NAME_OPERATION, operation);
}
Query query = builder.build();
QueryTop<ResourceOperationSpec> top = new QueryTop<>(host, query, ResourceOperationSpec.class, null).setQueryTaskTenantLinks(queryTaskTenantLinks).setAuthorizationContext(authorizationContext);
if (operation != null) {
// resource operation spec id and selfLink are built from the endpoint type, resource
// type and operation id, so the query result is guaranteed to return at most 1 element
top.setMaxResultsLimit(1);
}
top.setReferer(refererURI);
return top.collectDocuments(Collectors.toList());
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class BaseResourceOperationTest method createResourceOperationSpec.
public static ResourceOperationSpec createResourceOperationSpec() {
ResourceOperationSpec spec = new ResourceOperationSpec();
spec.resourceType = ResourceType.COMPUTE;
spec.operation = "operation";
spec.name = "name";
spec.endpointType = "endpointType";
spec.description = "description";
spec.adapterReference = URI.create("uri");
return spec;
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class ResourceOperationServiceTest method testGetResourceOperations.
@Test
public void testGetResourceOperations() throws Throwable {
EndpointState endpoint = registerEndpoint(this.endpointType);
ResourceOperationSpec spec1 = createResourceOperationSpec(endpoint.endpointType, ResourceType.COMPUTE, "testGetResourceOperations_1");
ResourceOperationSpec spec2 = createResourceOperationSpec(endpoint.endpointType, ResourceType.COMPUTE, "testGetResourceOperations_2");
spec2.targetCriteria = "false";
ResourceOperationSpec spec3 = createResourceOperationSpec(endpoint.endpointType, ResourceType.COMPUTE, "testGetResourceOperations_3");
spec3.targetCriteria = "true";
ResourceOperationSpec spec4 = createResourceOperationSpec(endpoint.endpointType, ResourceType.NETWORK, "testGetResourceOperations_4");
registerResourceOperation(spec1);
registerResourceOperation(spec2);
registerResourceOperation(spec3);
registerResourceOperation(spec4);
ComputeState computeState = new ComputeState();
computeState.descriptionLink = "dummy-descriptionLink";
computeState.endpointLink = endpoint.documentSelfLink;
ComputeState createdComputeState = registerComputeState(computeState);
String query = UriUtils.buildUriQuery(ResourceOperationService.QUERY_PARAM_RESOURCE, createdComputeState.documentSelfLink);
URI uri = UriUtils.buildUri(super.host, ResourceOperationService.SELF_LINK, query);
Operation operation = sendOperationSynchronously(Operation.createGet(uri).setReferer(super.host.getReferer()));
Assert.assertNotNull(operation);
String json = Utils.toJson(operation.getBodyRaw());
List<ResourceOperationSpec> list = Utils.fromJson(json, new TypeToken<List<ResourceOperationSpec>>() {
}.getType());
this.logger.info("list: " + list);
Assert.assertEquals(2, list.size());
Assert.assertNotNull(list.get(0));
Assert.assertNotNull(list.get(1));
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class VSphereAdapterD2PowerOpsService method getResourceOperationSpecs.
public static ResourceOperationSpec[] getResourceOperationSpecs() {
ResourceOperationSpec operationSpec1 = getResourceOperationSpec(ResourceOperation.REBOOT, ResourceOperationUtils.TargetCriteria.RESOURCE_POWER_STATE_ON.getCriteria());
ResourceOperationSpec operationSpec2 = getResourceOperationSpec(ResourceOperation.SUSPEND, ResourceOperationUtils.TargetCriteria.RESOURCE_POWER_STATE_ON.getCriteria());
ResourceOperationSpec operationSpec3 = getResourceOperationSpec(ResourceOperation.SHUTDOWN, ResourceOperationUtils.TargetCriteria.RESOURCE_POWER_STATE_ON.getCriteria());
ResourceOperationSpec operationSpec4 = getResourceOperationSpec(ResourceOperation.RESET, ResourceOperationUtils.TargetCriteria.RESOURCE_POWER_STATE_ON.getCriteria());
return new ResourceOperationSpec[] { operationSpec1, operationSpec2, operationSpec3, operationSpec4 };
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class AzureLifecycleOperationService method getResourceOperationSpecs.
public static ResourceOperationSpec[] getResourceOperationSpecs() {
ResourceOperationSpec operationSpec1 = getResourceOperationSpec(ResourceOperation.RESTART, TargetCriteria.RESOURCE_POWER_STATE_ON.getCriteria());
ResourceOperationSpec operationSpec2 = getResourceOperationSpec(ResourceOperation.SUSPEND, TargetCriteria.RESOURCE_POWER_STATE_ON.getCriteria());
return new ResourceOperationSpec[] { operationSpec1, operationSpec2 };
}
Aggregations