Search in sources :

Example 11 with TestRequestSender

use of com.vmware.xenon.common.test.TestRequestSender in project photon-model by vmware.

the class BaseVSphereAdapterTest method revertToSnapshotAndWait.

protected void revertToSnapshotAndWait(ComputeState computeState) throws Throwable {
    // Get the snapshot to revert to
    SnapshotState snapshotStateToRevertTo = querySnapshotState(computeState.documentSelfLink, false);
    String taskLink = UUID.randomUUID().toString();
    ResourceOperationRequest snapshotRequest = getDeleteOrRevertSnapshotRequest(ResourceOperation.REVERT_SNAPSHOT.operation, "REVERT", computeState.documentSelfLink, snapshotStateToRevertTo.documentSelfLink, taskLink);
    Operation revertSnapshotOp = 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(revertSnapshotOp);
    this.host.log("Waiting for the snapshot to be reverted");
    this.host.waitFor("Revert snapshot request failed", () -> {
        SnapshotState finalSnapshotState = querySnapshotState(computeState.documentSelfLink, true);
        ComputeState finalComputeState = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
        String hasSnapshot = finalComputeState.customProperties.get(ComputeProperties.CUSTOM_PROP_COMPUTE_HAS_SNAPSHOTS);
        // Check for the snapshot state and _hasSnapshots flag in compute
        if (hasSnapshot != null && Boolean.parseBoolean(hasSnapshot) && finalSnapshotState.documentSelfLink.equals(snapshotStateToRevertTo.documentSelfLink)) {
            return true;
        } else {
            return false;
        }
    });
    this.host.log("Revert to 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 12 with TestRequestSender

use of com.vmware.xenon.common.test.TestRequestSender in project photon-model by vmware.

the class BaseVSphereAdapterTest method resizeVM.

protected void resizeVM(ComputeState vm) {
    String taskLink = UUID.randomUUID().toString();
    ResourceOperationRequest resizeRequest = getResizeComputeRequest(ResourceOperation.RESIZE.operation, vm.documentSelfLink, taskLink);
    Operation resizeComputeOperation = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterResizeComputeService.SELF_LINK)).setBody(resizeRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> Assert.assertNull(e));
    TestRequestSender sender = new TestRequestSender(this.host);
    sender.sendRequest(resizeComputeOperation);
    this.host.log("Waiting for the resource resize to complete");
    ComputeState cState = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, vm.documentSelfLink));
    this.host.waitFor("Resize compute request failed", () -> {
        Operation op = this.host.waitForResponse(Operation.createGet(this.host, cState.documentSelfLink + "?expand"));
        ComputeService.ComputeStateWithDescription cDesc = op.getBody(ComputeService.ComputeStateWithDescription.class);
        if (cDesc != null && cDesc.description.cpuCount == 4L) {
            return true;
        } else {
            return false;
        }
    });
    this.host.log("Resize compute operation completed successfully");
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) 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) ComputeService(com.vmware.photon.controller.model.resources.ComputeService)

Example 13 with TestRequestSender

use of com.vmware.xenon.common.test.TestRequestSender in project photon-model by vmware.

the class BaseVSphereAdapterTest method queryAllSnapshotStates.

private List<SnapshotState> queryAllSnapshotStates(String computeReferenceLink) {
    List<SnapshotState> snapshotStates = new ArrayList<>();
    QueryTask.Query querySnapshot = QueryTask.Query.Builder.create().addKindFieldClause(SnapshotState.class).addFieldClause(SnapshotState.FIELD_NAME_COMPUTE_LINK, computeReferenceLink).build();
    QueryTask qTask = QueryTask.Builder.createDirectTask().setQuery(querySnapshot).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).build();
    Operation postOperation = QueryUtils.createQueryTaskOperation(this.host, qTask, ServiceTypeCluster.INVENTORY_SERVICE);
    TestRequestSender sender = new TestRequestSender(this.host);
    Operation responseOp = sender.sendAndWait(postOperation);
    QueryResultsProcessor rp = QueryResultsProcessor.create(responseOp);
    if (rp.hasResults()) {
        snapshotStates.addAll(rp.streamDocuments(SnapshotState.class).collect(Collectors.toList()));
    }
    return snapshotStates;
}
Also used : QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) ArrayList(java.util.ArrayList) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) Operation(com.vmware.xenon.common.Operation)

Example 14 with TestRequestSender

use of com.vmware.xenon.common.test.TestRequestSender 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 15 with TestRequestSender

use of com.vmware.xenon.common.test.TestRequestSender in project photon-model by vmware.

the class AzureSubscriptionEndpointCreationServiceTest method testSubscriptionEndpointCreation.

@Test
public void testSubscriptionEndpointCreation() throws Throwable {
    AzureSubscriptionEndpointCreationRequest request = new AzureSubscriptionEndpointCreationRequest();
    request.resourceReference = UriUtils.buildUri(this.host, this.eaEndPointLink);
    request.subscriptionId = SUBSCRIPTION_ID;
    request.accountId = ACCOUNT_ID;
    Operation endPointCreationOp = Operation.createPatch(this.host, AzureSubscriptionEndpointCreationService.SELF_LINK);
    endPointCreationOp.setBody(request);
    TestRequestSender sender = new TestRequestSender(this.host);
    EndpointState subscriptionEndpoint = sender.sendAndWait(endPointCreationOp, EndpointState.class);
    // Assert the subscriptionEndpoint created
    Assert.assertEquals(this.eaEndPointLink, subscriptionEndpoint.parentLink);
    Assert.assertNotNull(subscriptionEndpoint.endpointProperties.get(EndpointConfigRequest.USER_LINK_KEY));
    Assert.assertEquals(SUBSCRIPTION_ID, subscriptionEndpoint.endpointProperties.get(EndpointConfigRequest.USER_LINK_KEY));
    ComputeState cs = getServiceSynchronously(subscriptionEndpoint.computeLink, ComputeState.class);
    Assert.assertNotNull(cs.customProperties.get(AzureConstants.AZURE_ACCOUNT_OWNER_EMAIL_ID));
    Assert.assertEquals(ACCOUNT_ID, cs.customProperties.get(AzureConstants.AZURE_ACCOUNT_OWNER_EMAIL_ID));
    Assert.assertNotNull(cs.customProperties.get(AzureConstants.AZURE_SUBSCRIPTION_ID_KEY));
    Assert.assertEquals(SUBSCRIPTION_ID, cs.customProperties.get(AzureConstants.AZURE_SUBSCRIPTION_ID_KEY));
}
Also used : AzureSubscriptionEndpointCreationRequest(com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionEndpointCreationService.AzureSubscriptionEndpointCreationRequest) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test)

Aggregations

Operation (com.vmware.xenon.common.Operation)15 TestRequestSender (com.vmware.xenon.common.test.TestRequestSender)15 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)10 ResourceOperationRequest (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)7 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)6 SnapshotState (com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 QueryResultsProcessor (com.vmware.xenon.common.QueryResultsProcessor)2 QueryTask (com.vmware.xenon.services.common.QueryTask)2 Query (com.vmware.xenon.services.common.QueryTask.Query)2 VolumeTypeList (com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSVolumeTypeDiscoveryService.VolumeTypeList)1 AzureSubscriptionEndpointCreationRequest (com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionEndpointCreationService.AzureSubscriptionEndpointCreationRequest)1 AzureSubscriptionEndpointsEnumerationRequest (com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionEndpointsEnumerationService.AzureSubscriptionEndpointsEnumerationRequest)1 AzureSubscriptionsEnumerationRequest (com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionsEnumerationService.AzureSubscriptionsEnumerationRequest)1 ResourceOperationSpec (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec)1 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)1 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)1 ProvisionDiskTaskService (com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService)1