Search in sources :

Example 26 with ResourceOperationRequest

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

the class TestVSphereComputeDiskDay2Service method createResourceOperationRequest.

private ResourceOperationRequest createResourceOperationRequest(DiskService.DiskState diskState, String taskLink, ResourceOperation resourceOperation) {
    ResourceOperationRequest request = new ResourceOperationRequest();
    request.isMockRequest = isMock();
    request.operation = resourceOperation.operation;
    request.payload = new HashMap<>();
    request.payload.put("diskLink", diskState.documentSelfLink);
    request.resourceReference = UriUtils.buildUri(this.host, this.vm.documentSelfLink);
    request.taskReference = UriUtils.buildUri(this.host, taskLink);
    return request;
}
Also used : ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)

Example 27 with ResourceOperationRequest

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

the class TestVSphereComputeDiskDay2Service method testCDRomInsertOnCompute.

@Test
public void testCDRomInsertOnCompute() throws Throwable {
    try {
        // Step 1: Create VM
        prepareEnvironment();
        if (isMock()) {
            createNetwork(networkId);
        }
        snapshotFactoryState("clone-refresh", NetworkService.class);
        ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
        this.vm = createVmState(vmDescription, true, null, false);
        // kick off a provision task to do the actual VM creation
        ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(this.vm);
        awaitTaskEnd(provisionTask);
        this.vm = getComputeState(this.vm);
        // put fake moref in the vm
        if (isMock()) {
            ManagedObjectReference moref = new ManagedObjectReference();
            moref.setValue("vm-0");
            moref.setType(VimNames.TYPE_VM);
            CustomProperties.of(this.vm).put(MOREF, moref);
            this.vm = doPost(this.host, this.vm, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
            return;
        }
        this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
        assertNotNull(CustomProperties.of(this.vm).getString(COMPUTE_HOST_LINK_PROP_NAME, null));
        assertEquals(3, this.vm.diskLinks.size());
        this.vm.diskLinks.stream().forEach(link -> {
            DiskService.DiskState diskState = this.host.getServiceState(null, DiskService.DiskState.class, UriUtils.buildUri(this.host, link));
            if (diskState.type == DiskService.DiskType.CDROM) {
                this.CDDiskState = diskState;
            }
        });
        // Step 1: Attach a CD-ROM disk
        // prepare a disk with CD-ROM type
        DiskService.DiskState cdDiskState = createCDromWithIso("cdrom-1", DiskService.DiskType.CDROM, 0, null, 1024, null, true, false);
        ResourceOperationRequest request = createResourceOperationRequest(cdDiskState, createComputeDiskTaskService(), ResourceOperation.ATTACH_DISK);
        sendRequest(request, DiskService.DiskType.CDROM, insertCDRomHandler());
        this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
        assertNotNull(this.vm.diskLinks);
        assertEquals(3, this.vm.diskLinks.size());
    } finally {
        if (!isMock()) {
            cleanUpVm(this.vm, null);
        }
    }
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) DiskService(com.vmware.photon.controller.model.resources.DiskService) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Test(org.junit.Test)

Example 28 with ResourceOperationRequest

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

the class VSphereVMContextTest method beforeTest.

@Before
public void beforeTest() {
    final URI mockUri = UriUtils.buildUri(this.host, UUID.randomUUID().toString());
    ResourceOperationRequest resourceOperationRequest = new ResourceOperationRequest();
    resourceOperationRequest.resourceReference = mockUri;
    // reboot operation
    resourceOperationRequest.operation = "Reboot";
    resourceOperationRequest.taskReference = mockUri;
    StatelessService mockService = new StatelessService();
    mockService.setHost(this.host);
    // create context calling the constructor, it should have errorHandler populated by default (i.e. errorHandler != null)
    this.context = new VSphereVMContext(mockService, resourceOperationRequest);
}
Also used : StatelessService(com.vmware.xenon.common.StatelessService) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) URI(java.net.URI) Before(org.junit.Before)

Example 29 with ResourceOperationRequest

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

the class AzureComputeDiskDay2ServiceTest method performDiskOperationOnVM.

private void performDiskOperationOnVM(DiskOpKind opType) throws Throwable {
    AttachDiskTaskTestService.DiskTaskTestState attachTask = new AttachDiskTaskTestService.DiskTaskTestState();
    attachTask.taskSubStage = AttachDiskTaskTestService.DiskTaskTestState.SubStage.STARTED;
    attachTask = TestUtils.doPost(this.host, attachTask, AttachDiskTaskTestService.DiskTaskTestState.class, UriUtils.buildUri(this.host, AttachDiskTaskTestService.FACTORY_LINK));
    ResourceOperationRequest request = new ResourceOperationRequest();
    request.isMockRequest = this.isMock;
    if (opType.equals(DiskOpKind.ATTACH)) {
        request.operation = ResourceOperation.ATTACH_DISK.operation;
    } else {
        request.operation = ResourceOperation.DETACH_DISK.operation;
    }
    request.payload = new HashMap<>();
    request.payload.put(PhotonModelConstants.DISK_LINK, this.diskState.documentSelfLink);
    request.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
    request.taskReference = UriUtils.buildUri(this.host, attachTask.documentSelfLink);
    Operation attachDiskOp = Operation.createPatch(UriUtils.buildUri(this.host, AzureComputeDiskDay2Service.SELF_LINK)).setBody(request).setReferer(this.host.getReferer());
    TestRequestSender sender = new TestRequestSender(this.host);
    sender.sendRequest(attachDiskOp);
    this.host.log("Waiting for disk attach to complete");
    final String attachTaskServiceLink = attachTask.documentSelfLink;
    this.host.waitFor("Attach disk failed.", () -> {
        AttachDiskTaskTestService.DiskTaskTestState diskTaskTestState = this.host.getServiceState(null, AttachDiskTaskTestService.DiskTaskTestState.class, UriUtils.buildUri(this.host, attachTaskServiceLink));
        // Check for the disk is attached to a vm or not.
        return diskTaskTestState.taskSubStage == AttachDiskTaskTestService.DiskTaskTestState.SubStage.FINISHED || diskTaskTestState.taskSubStage == AttachDiskTaskTestService.DiskTaskTestState.SubStage.FAILED;
    });
}
Also used : 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 30 with ResourceOperationRequest

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

the class AzureLifecycleOperationServiceTest method triggerRestart.

private void triggerRestart() {
    String taskLink = UUID.randomUUID().toString();
    ResourceOperationRequest request = new ResourceOperationRequest();
    request.isMockRequest = this.isMock;
    request.operation = ResourceOperation.RESTART.operation;
    request.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
    request.taskReference = UriUtils.buildUri(this.host, taskLink);
    TestContext ctx = this.host.testCreate(2);
    createTaskResultListener(this.host, taskLink, (u) -> {
        if (u.getAction() != Action.PATCH) {
            return false;
        }
        ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
        if (TaskState.isFailed(response.taskInfo)) {
            ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
        } else if (TaskState.isFinished(response.taskInfo)) {
            ctx.completeIteration();
        }
        return true;
    });
    Operation restartOp = Operation.createPatch(UriUtils.buildUri(this.host, AzureLifecycleOperationService.SELF_LINK)).setBody(request).setReferer("/tests").setCompletion((o, e) -> {
        if (e != null) {
            ctx.failIteration(e);
            return;
        }
        ctx.completeIteration();
    });
    this.host.send(restartOp);
    ctx.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) Operation(com.vmware.xenon.common.Operation) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)

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