Search in sources :

Example 1 with ResourceOperationSpec

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;
}
Also used : ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec)

Example 2 with ResourceOperationSpec

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);
    }
}
Also used : Schema(com.vmware.photon.controller.model.data.Schema) SchemaBuilder(com.vmware.photon.controller.model.data.SchemaBuilder) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) Test(org.junit.Test)

Example 3 with ResourceOperationSpec

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);
}
Also used : ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) Test(org.junit.Test)

Example 4 with ResourceOperationSpec

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);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) List(java.util.List) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) Test(org.junit.Test)

Example 5 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_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);
}
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)

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