Search in sources :

Example 11 with ResourceOperationRequest

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

the class BaseVSphereAdapterTest method createSnapshotAndWaitFailure.

protected void createSnapshotAndWaitFailure(ComputeState vm) throws Throwable {
    String taskLink = UUID.randomUUID().toString();
    ResourceOperationRequest snapshotRequest = getCreateSnapshotRequest(ResourceOperation.CREATE_SNAPSHOT.operation, vm.documentSelfLink, taskLink);
    Operation createSnapshotOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterSnapshotService.SELF_LINK)).setBody(snapshotRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> Assert.assertNull(e));
    TestContext ctx2 = this.host.testCreate(1);
    createTaskResultListener(this.host, taskLink, (u) -> {
        if (u.getAction() != Service.Action.PATCH) {
            return false;
        }
        ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
        if (TaskState.isFailed(response.taskInfo)) {
            ctx2.completeIteration();
            return true;
        } else {
            ctx2.completeIteration();
            return false;
        }
    });
    this.host.send(createSnapshotOp);
    ctx2.await();
}
Also used : ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) TestContext(com.vmware.xenon.common.test.TestContext) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) Operation(com.vmware.xenon.common.Operation)

Example 12 with ResourceOperationRequest

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

the class BaseVSphereAdapterTest method getResizeComputeRequest.

private ResourceOperationRequest getResizeComputeRequest(String operation, String documentSelfLink, String taskLink) {
    Map<String, String> payload = new HashMap<>();
    // update "__cpuCount" to 4 from 2
    payload.put(COMPUTE_CPU_COUNT, "4");
    payload.put(REBOOT_VM_FLAG, // reboot vm flag to true (not expecting hot-plug to be enabled in the provisioned machine)
    "true");
    ResourceOperationRequest resourceOperationRequest = new ResourceOperationRequest();
    resourceOperationRequest.operation = operation;
    resourceOperationRequest.isMockRequest = isMock();
    resourceOperationRequest.resourceReference = UriUtils.buildUri(this.host, documentSelfLink);
    resourceOperationRequest.taskReference = UriUtils.buildUri(this.host, taskLink);
    resourceOperationRequest.payload = payload;
    return resourceOperationRequest;
}
Also used : HashMap(java.util.HashMap) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)

Example 13 with ResourceOperationRequest

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

the class BaseVSphereAdapterTest method createSnapshotAndWait.

protected void createSnapshotAndWait(ComputeState vm, Boolean isSnapshottedAgain) throws Throwable {
    String taskLink = UUID.randomUUID().toString();
    ResourceOperationRequest snapshotRequest = getCreateSnapshotRequest(ResourceOperation.CREATE_SNAPSHOT.operation, vm.documentSelfLink, taskLink);
    Operation createSnapshotOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterSnapshotService.SELF_LINK)).setBody(snapshotRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> Assert.assertNull(e));
    TestRequestSender sender = new TestRequestSender(this.host);
    sender.sendRequest(createSnapshotOp);
    this.host.log("Waiting for the snapshot to be created");
    this.host.waitFor("Create snapshot request failed", () -> {
        ComputeState cState = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, vm.documentSelfLink));
        SnapshotState snapshotState = querySnapshotState(vm.documentSelfLink, true);
        String hasSnapshot = cState.customProperties.get(ComputeProperties.CUSTOM_PROP_COMPUTE_HAS_SNAPSHOTS);
        if (!isSnapshottedAgain) {
            if (hasSnapshot != null && Boolean.parseBoolean(hasSnapshot) && snapshotState.parentLink == null) {
                return true;
            } else {
                return false;
            }
        } else {
            if (hasSnapshot != null && Boolean.parseBoolean(hasSnapshot) && snapshotState.parentLink != null) {
                return true;
            } else {
                return false;
            }
        }
    });
    this.host.log("Create snapshot operation completed successfully");
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) Operation(com.vmware.xenon.common.Operation)

Example 14 with ResourceOperationRequest

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

the class BaseVSphereAdapterTest method resetVSphereVM.

protected void resetVSphereVM(ComputeState computeState) {
    String taskLink = UUID.randomUUID().toString();
    ResourceOperationRequest resetVMRequest = getResourceOperationRequest("Reset", computeState.documentSelfLink, taskLink);
    TestContext ctx = this.host.testCreate(1);
    createTaskResultListener(this.host, taskLink, (u) -> {
        if (u.getAction() != Service.Action.PATCH) {
            return false;
        }
        ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
        if (TaskState.isFailed(response.taskInfo)) {
            ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
        } else {
            ctx.completeIteration();
        }
        return true;
    });
    TestContext ctx2 = this.host.testCreate(1);
    Operation resetOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterD2PowerOpsService.SELF_LINK)).setBody(resetVMRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
        if (e != null) {
            ctx2.failIteration(e);
            return;
        }
        ctx2.completeIteration();
    });
    this.host.send(resetOp);
    ctx2.await();
    ComputeState[] cState = new ComputeState[1];
    this.host.waitFor("Reset VM request failed", () -> {
        cState[0] = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
        if (ComputeService.PowerState.ON.equals(cState[0].powerState)) {
            return true;
        } else {
            return false;
        }
    });
    assertEquals(ComputeService.PowerState.ON, cState[0].powerState);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) TestContext(com.vmware.xenon.common.test.TestContext) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) Operation(com.vmware.xenon.common.Operation)

Example 15 with ResourceOperationRequest

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

the class BaseVSphereAdapterTest method shutdownGuestOS.

protected void shutdownGuestOS(ComputeState computeState) {
    String taskLink = UUID.randomUUID().toString();
    ResourceOperationRequest shutdownGuestRequest = getResourceOperationRequest("Shutdown", computeState.documentSelfLink, taskLink);
    TestContext ctx = this.host.testCreate(1);
    createTaskResultListener(this.host, taskLink, (u) -> {
        if (u.getAction() != Service.Action.PATCH) {
            return false;
        }
        ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
        if (TaskState.isFailed(response.taskInfo)) {
            ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
        } else {
            ctx.completeIteration();
        }
        return true;
    });
    TestContext ctx2 = this.host.testCreate(1);
    Operation shutdownOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterD2PowerOpsService.SELF_LINK)).setBody(shutdownGuestRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
        if (e != null) {
            ctx2.failIteration(e);
            return;
        }
        ctx2.completeIteration();
    });
    this.host.send(shutdownOp);
    ctx2.await();
    ComputeState[] cState = new ComputeState[1];
    this.host.waitFor("Guest shutdown request failed", () -> {
        cState[0] = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
        if (cState[0].powerState.equals(ComputeService.PowerState.OFF)) {
            assertTrue(cState[0].address.isEmpty());
            return true;
        } else {
            return false;
        }
    });
    assertEquals(ComputeService.PowerState.OFF, cState[0].powerState);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) TestContext(com.vmware.xenon.common.test.TestContext) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) Operation(com.vmware.xenon.common.Operation)

Aggregations

ResourceOperationRequest (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)36 Operation (com.vmware.xenon.common.Operation)20 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)19 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)16 ResourceOperationResponse (com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse)8 TestContext (com.vmware.xenon.common.test.TestContext)8 TestRequestSender (com.vmware.xenon.common.test.TestRequestSender)7 DefaultAdapterContext (com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext)5 StatelessService (com.vmware.xenon.common.StatelessService)5 ResourceOperationUtils.handleAdapterResourceOperationRegistration (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration)4 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)4 DiskService (com.vmware.photon.controller.model.resources.DiskService)4 SnapshotState (com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 FactoryService (com.vmware.xenon.common.FactoryService)4 Service (com.vmware.xenon.common.Service)4 ServiceDocument (com.vmware.xenon.common.ServiceDocument)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)3