Search in sources :

Example 16 with ResourceOperationSpec

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

the class ResourceOperationSpecServiceTest method getByEndpointXXX.

private void getByEndpointXXX(String operation) {
    ResourceOperationSpec[] states = registerResourceOperation(this.endpointType, ResourceType.COMPUTE, operation);
    ResourceOperationSpec requestedState = states[0];
    ResourceOperationSpec persistedState = states[1];
    DeferredResult<ResourceOperationSpec> dr = ResourceOperationUtils.lookUpByEndpointType(super.host, super.host.getReferer(), requestedState.endpointType, requestedState.resourceType, requestedState.operation, null, null);
    ResourceOperationSpec found = join(dr);
    Assert.assertNotNull(found);
    this.logger.info("Lookup: " + found);
    Assert.assertEquals(requestedState.endpointType, found.endpointType);
    Assert.assertEquals(requestedState.resourceType, found.resourceType);
    Assert.assertEquals(requestedState.operation, found.operation);
    Assert.assertEquals(persistedState.documentSelfLink, found.documentSelfLink);
}
Also used : ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec)

Example 17 with ResourceOperationSpec

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

the class ResourceOperationSpecServiceTest method testRegisterAndPatchExtensions.

@Test
public void testRegisterAndPatchExtensions() {
    ResourceOperationSpec[] states = registerResourceOperation(this.endpointType, ResourceType.COMPUTE, "testRegisterAndPatchExtensions");
    ResourceOperationSpec requestedState = states[0];
    ResourceOperationSpec persistedState = states[1];
    Assert.assertTrue(persistedState.documentSelfLink.endsWith(ResourceOperationSpecFactoryService.generateSelfLink(requestedState)));
    this.logger.info("Persisted: " + persistedState);
    String E_2 = "e2";
    ResourceOperationSpec specWithExtension = new ResourceOperationSpec();
    specWithExtension.documentSelfLink = ResourceOperationSpecFactoryService.generateSelfLink(requestedState.endpointType, requestedState.resourceType, requestedState.operation);
    specWithExtension.extensions = new HashMap<>();
    specWithExtension.extensions.put(E_2, "v2");
    Operation patchOne = Operation.createPatch(super.host, specWithExtension.documentSelfLink).setBodyNoCloning(specWithExtension);
    TestRequestSender sender = super.host.getTestRequestSender();
    sender.sendAndWait(patchOne);
    ResourceOperationSpec patchedSpec = sender.sendGetAndWait(UriUtils.buildUri(super.host, specWithExtension.documentSelfLink), ResourceOperationSpec.class);
    Assert.assertNotNull(patchedSpec);
    Assert.assertNotNull(patchedSpec.extensions);
    Assert.assertNotNull(patchedSpec.extensions.get(E_2));
    specWithExtension.name = "tryNewName";
    Operation patchTwo = Operation.createPatch(super.host, specWithExtension.documentSelfLink).setBodyNoCloning(specWithExtension);
    try {
        sender.sendAndWait(patchTwo);
    } catch (RuntimeException rte) {
        Throwable[] allSuppressed = rte.getSuppressed();
        Assert.assertNotNull(allSuppressed);
        Assert.assertEquals(1, allSuppressed.length);
        Throwable suppressed = allSuppressed[0];
        this.logger.info("Suppressed error: " + suppressed.getMessage());
        Assert.assertTrue(suppressed instanceof IllegalArgumentException);
    }
}
Also used : TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test)

Example 18 with ResourceOperationSpec

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

the class ResourceOperationUtilsTest method testIsAvailable_simple_neg.

@Test
public void testIsAvailable_simple_neg() {
    ResourceOperationSpec spec = createResourceOperationSpec();
    spec.targetCriteria = SCRIPT_CONTEXT_RESOURCE + ".hostName.startsWith('noWay')";
    ComputeState computeState = createComputeState("testIsAvailable_simple_neg");
    boolean ret = ResourceOperationUtils.isAvailable(computeState, spec);
    Assert.assertFalse(ret);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) BaseResourceOperationTest.createComputeState(com.vmware.photon.controller.model.adapters.registry.operations.BaseResourceOperationTest.createComputeState) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) BaseResourceOperationTest.createResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.BaseResourceOperationTest.createResourceOperationSpec) Test(org.junit.Test)

Example 19 with ResourceOperationSpec

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

the class ResourceOperationUtilsTest method testIsAvailable_null_neg.

@Test
public void testIsAvailable_null_neg() {
    ResourceOperationSpec spec = createResourceOperationSpec();
    ComputeState computeState = createComputeState("testIsAvailable_null_neg");
    boolean ret = ResourceOperationUtils.isAvailable(computeState, spec);
    Assert.assertTrue(ret);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) BaseResourceOperationTest.createComputeState(com.vmware.photon.controller.model.adapters.registry.operations.BaseResourceOperationTest.createComputeState) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) BaseResourceOperationTest.createResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.BaseResourceOperationTest.createResourceOperationSpec) Test(org.junit.Test)

Example 20 with ResourceOperationSpec

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

the class ResourceOperationUtils method handleAdapterResourceOperationRegistration.

/**
 * Handles Resource Operation Registration during an adapter's start
 *
 * @param service the Adapter Service
 * @param startPost the startPost operation
 * @param registerResourceOperation should the Resource Operation Specs be registered
 * @param resourceOperationSpecs Resource Operation Specs to register
 */
public static void handleAdapterResourceOperationRegistration(Service service, Operation startPost, boolean registerResourceOperation, ResourceOperationSpec... resourceOperationSpecs) {
    if (registerResourceOperation) {
        Operation.CompletionHandler handler = (op, exc) -> {
            if (exc != null) {
                startPost.fail(exc);
            } else {
                startPost.complete();
            }
        };
        ResourceOperationUtils.registerResourceOperation(service, handler, resourceOperationSpecs);
    } else {
        startPost.complete();
    }
}
Also used : Service(com.vmware.xenon.common.Service) Arrays(java.util.Arrays) ServiceEndpointLocator(com.vmware.photon.controller.model.util.ServiceEndpointLocator) Level(java.util.logging.Level) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) URI(java.net.URI) AssertUtil(com.vmware.photon.controller.model.util.AssertUtil) ScriptException(javax.script.ScriptException) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) ScriptEngineManager(javax.script.ScriptEngineManager) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) ScriptContext(javax.script.ScriptContext) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) List(java.util.List) SELF_SERVICE(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster.SELF_SERVICE) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ScriptEngine(javax.script.ScriptEngine) ResourceType(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceType) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) AuthorizationContext(com.vmware.xenon.common.Operation.AuthorizationContext) Operation(com.vmware.xenon.common.Operation) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler)

Aggregations

ResourceOperationSpec (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec)26 Test (org.junit.Test)14 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)10 BaseResourceOperationTest.createResourceOperationSpec (com.vmware.photon.controller.model.adapters.registry.operations.BaseResourceOperationTest.createResourceOperationSpec)7 BaseResourceOperationTest.createComputeState (com.vmware.photon.controller.model.adapters.registry.operations.BaseResourceOperationTest.createComputeState)6 Operation (com.vmware.xenon.common.Operation)4 List (java.util.List)3 QueryTop (com.vmware.photon.controller.model.query.QueryUtils.QueryTop)2 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)2 Query (com.vmware.xenon.services.common.QueryTask.Query)2 URI (java.net.URI)2 TypeToken (com.google.gson.reflect.TypeToken)1 ResourceType (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceType)1 Schema (com.vmware.photon.controller.model.data.Schema)1 SchemaBuilder (com.vmware.photon.controller.model.data.SchemaBuilder)1 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)1 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)1 AssertUtil (com.vmware.photon.controller.model.util.AssertUtil)1 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)1 SELF_SERVICE (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster.SELF_SERVICE)1