Search in sources :

Example 51 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class AWSResetService method updateComputeState.

private void updateComputeState(DefaultAdapterContext c) {
    ComputeState state = new ComputeState();
    state.powerState = ComputeService.PowerState.ON;
    Operation.createPatch(c.resourceReference).setBody(state).setCompletion((o, e) -> {
        if (e != null) {
            c.taskManager.patchTaskToFailure(e);
            return;
        }
        c.taskManager.finishTask();
    }).sendWith(this);
}
Also used : Service(com.vmware.xenon.common.Service) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) ResourceOperationUtils.handleAdapterResourceOperationRegistration(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) AWSAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSAsyncHandler) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) ServiceDocument(com.vmware.xenon.common.ServiceDocument) BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest) DefaultAdapterContext(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) FactoryService(com.vmware.xenon.common.FactoryService) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) ResourceType(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceType) ResourceOperationUtils(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState)

Example 52 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState 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 53 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState 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)

Example 54 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class ResourceOperationUtilsTest method testIsAvailable_changeContextFromScript.

@Test
public void testIsAvailable_changeContextFromScript() {
    ResourceOperationSpec spec = createResourceOperationSpec();
    spec.targetCriteria = SCRIPT_CONTEXT_RESOURCE + ".hostName='changed'";
    ComputeState computeState = createComputeState("testIsAvailable_changeContextFromScript");
    String originalValue = computeState.hostName;
    ResourceOperationUtils.isAvailable(computeState, spec);
    Assert.assertEquals(originalValue, computeState.hostName);
}
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 55 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class ResourceOperationUtilsTest method testIsAvailable_custProps_neg.

@Test
public void testIsAvailable_custProps_neg() {
    ResourceOperationSpec spec = createResourceOperationSpec();
    spec.targetCriteria = SCRIPT_CONTEXT_RESOURCE + ".customProperties.p1=='v2'";
    ComputeState computeState = createComputeState("testIsAvailable_custProps_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)

Aggregations

ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)214 Operation (com.vmware.xenon.common.Operation)93 ArrayList (java.util.ArrayList)63 QueryTask (com.vmware.xenon.services.common.QueryTask)58 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)57 HashMap (java.util.HashMap)54 List (java.util.List)51 Map (java.util.Map)50 Utils (com.vmware.xenon.common.Utils)45 Test (org.junit.Test)45 UriUtils (com.vmware.xenon.common.UriUtils)44 URI (java.net.URI)42 Collectors (java.util.stream.Collectors)42 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)40 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)40 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)40 StatelessService (com.vmware.xenon.common.StatelessService)40 Query (com.vmware.xenon.services.common.QueryTask.Query)40 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)38 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)36