use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class AWSRebootService method getResourceOperationSpec.
public static ResourceOperationSpec getResourceOperationSpec() {
ResourceOperationSpec spec = new ResourceOperationSpec();
spec.endpointType = EndpointType.aws.name();
spec.resourceType = ResourceType.COMPUTE;
spec.operation = ResourceOperation.REBOOT.operation;
spec.name = ResourceOperation.REBOOT.displayName;
spec.description = ResourceOperation.REBOOT.description;
spec.targetCriteria = TargetCriteria.RESOURCE_POWER_STATE_ON.getCriteria();
return spec;
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class ResourceOperationSpecJsonTest method testRoundtrip.
@Test
public void testRoundtrip() {
ResourceOperationSpec origSpec = new ResourceOperationSpec();
origSpec.operation = "oper";
origSpec.targetCriteria = "true";
origSpec.adapterReference = URI.create("http://localhost");
origSpec.description = "OP desc";
origSpec.name = "OP name";
origSpec.resourceType = ResourceType.COMPUTE;
origSpec.endpointType = "myEP";
// @formatter:off
origSpec.schema = new SchemaBuilder().withName("schema1").addField("f1").withDataType(SchemaField.DATATYPE_STRING).withLabel("F One").withType(Type.VALUE).done().build();
ExtensionOne origExtensionOne = new ExtensionOne();
origExtensionOne.prop1 = "property one";
origExtensionOne.prop2 = URI.create("urn:prop2:value");
ExtensionTwo origExtensionTwo = new ExtensionTwo();
origExtensionTwo.int1 = 42;
origSpec.extensions = new HashMap<>();
origSpec.extensions.put(EX_ONE, Utils.toJson(origExtensionOne));
origSpec.extensions.put(EX_TWO, Utils.toJson(origExtensionTwo));
// @formatter:on
String json = Utils.toJson(origSpec);
this.logger.info("json: " + json);
ResourceOperationSpec trgtSpec = Utils.fromJson(json, ResourceOperationSpec.class);
Assert.assertNotNull(trgtSpec.schema);
Schema origSchema = origSpec.schema;
Schema trgtSchema = trgtSpec.schema;
Assert.assertEquals(origSchema.name, trgtSchema.name);
Assert.assertEquals(origSchema.fields, trgtSchema.fields);
String jsonExtensionOne = trgtSpec.extensions.get(EX_ONE);
{
Assert.assertNotNull(jsonExtensionOne);
this.logger.info("jsonExtensionOne: " + jsonExtensionOne);
BaseExtension be = Utils.fromJson(jsonExtensionOne, BaseExtension.class);
Assert.assertEquals(ExtensionOne.KIND, be.documentKind);
ExtensionOne trgtExtensionOne = Utils.fromJson(jsonExtensionOne, ExtensionOne.class);
this.logger.info("trgtExtensionOne: " + trgtExtensionOne);
Assert.assertEquals(origExtensionOne.prop1, trgtExtensionOne.prop1);
Assert.assertEquals(origExtensionOne.prop2, trgtExtensionOne.prop2);
}
String jsonExtensionTwo = trgtSpec.extensions.get(EX_TWO);
{
Assert.assertNotNull(jsonExtensionTwo);
this.logger.info("jsonExtensionTwo: " + jsonExtensionTwo);
BaseExtension be = Utils.fromJson(jsonExtensionTwo, BaseExtension.class);
Assert.assertEquals(ExtensionTwo.KIND, be.documentKind);
ExtensionTwo trgtExtensionTwo = Utils.fromJson(jsonExtensionTwo, ExtensionTwo.class);
this.logger.info("trgtExtensionTwo: " + trgtExtensionTwo);
Assert.assertEquals(origExtensionTwo.int1, trgtExtensionTwo.int1);
}
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class ResourceOperationSpecServiceTest method testRegister.
@Test
public void testRegister() {
ResourceOperationSpec[] states = registerResourceOperation(this.endpointType, ResourceType.COMPUTE, "testRegister");
ResourceOperationSpec requestedState = states[0];
ResourceOperationSpec persistedState = states[1];
Assert.assertTrue(persistedState.documentSelfLink.endsWith(ResourceOperationSpecFactoryService.generateSelfLink(requestedState)));
this.logger.info("Persisted: " + persistedState);
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class ResourceOperationSpecServiceTest method testGetByResourceStateAndOperation.
@Test
public void testGetByResourceStateAndOperation() throws Throwable {
String operation = UUID.randomUUID().toString();
ComputeState computeState = prepare(this.endpointType, "testGetByResourceStateAndOperation_1", "testGetByResourceStateAndOperation_2", operation);
DeferredResult<List<ResourceOperationSpec>> dr = ResourceOperationUtils.lookupByResourceState(super.host, super.host.getReferer(), computeState, operation, null);
List<ResourceOperationSpec> found = join(dr);
Assert.assertNotNull(found);
Assert.assertEquals(1, found.size());
ResourceOperationSpec resourceOperationSpec = found.get(0);
Assert.assertEquals(operation, resourceOperationSpec.operation);
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec in project photon-model by vmware.
the class ResourceOperationUtilsTest method testIsAvailable_simple_pos.
@Test
public void testIsAvailable_simple_pos() {
ResourceOperationSpec spec = createResourceOperationSpec();
spec.targetCriteria = SCRIPT_CONTEXT_RESOURCE + ".hostName.startsWith('test')" + " && " + SCRIPT_CONTEXT_RESOURCE + ".cpuCount==4";
ComputeState computeState = createComputeState("testIsAvailable_simple_pos");
boolean ret = ResourceOperationUtils.isAvailable(computeState, spec);
Assert.assertTrue(ret);
}
Aggregations