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);
}
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);
}
}
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);
}
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);
}
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();
}
}
Aggregations