Search in sources :

Example 6 with SnapshotState

use of com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState in project photon-model by vmware.

the class BaseVSphereAdapterTest method deleteSnapshotAndWait.

protected void deleteSnapshotAndWait(ComputeState computeState) throws Throwable {
    // Get the snapshot associated with the compute
    SnapshotState snapshotState = querySnapshotState(computeState.documentSelfLink, true);
    String taskLink = UUID.randomUUID().toString();
    ResourceOperationRequest snapshotRequest = getDeleteOrRevertSnapshotRequest(ResourceOperation.DELETE_SNAPSHOT.operation, "DELETE", computeState.documentSelfLink, snapshotState.documentSelfLink, taskLink);
    Operation deleteSnapshotOp = 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(deleteSnapshotOp);
    this.host.log("Waiting for the snapshot to be deleted");
    this.host.waitFor("Delete 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);
        // snapshot. So hasSnapshot will still be true.
        if (hasSnapshot != null && Boolean.parseBoolean(hasSnapshot) && finalSnapshotState == null) {
            return true;
        } else {
            return false;
        }
    });
    this.host.log("Delete 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 7 with SnapshotState

use of com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState in project photon-model by vmware.

the class BaseVSphereAdapterTest method querySnapshotState.

private SnapshotState querySnapshotState(String computeReferenceLink, Boolean isCurrent) {
    List<SnapshotState> snapshotStates = new ArrayList<>();
    QueryTask.Query querySnapshot = QueryTask.Query.Builder.create().addKindFieldClause(SnapshotState.class).addFieldClause(SnapshotState.FIELD_NAME_COMPUTE_LINK, computeReferenceLink).addFieldClause(SnapshotState.FIELD_NAME_IS_CURRENT, isCurrent).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()));
    }
    if (!snapshotStates.isEmpty()) {
        return snapshotStates.get(0);
    } else {
        return null;
    }
}
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 8 with SnapshotState

use of com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState 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 9 with SnapshotState

use of com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState 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 10 with SnapshotState

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

Aggregations

SnapshotState (com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState)17 Operation (com.vmware.xenon.common.Operation)10 QueryTask (com.vmware.xenon.services.common.QueryTask)9 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)8 QueryResultsProcessor (com.vmware.xenon.common.QueryResultsProcessor)8 DeferredResult (com.vmware.xenon.common.DeferredResult)7 ArrayList (java.util.ArrayList)7 ResourceOperationRequest (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)6 List (java.util.List)6 TestRequestSender (com.vmware.xenon.common.test.TestRequestSender)5 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)4 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 TaskInfo (com.vmware.vim25.TaskInfo)4 UriUtils (com.vmware.xenon.common.UriUtils)4 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)3 IAAS_API_ENABLED (com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED)3 ResourceOperationSpecService (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService)3 TargetCriteria (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.TargetCriteria)3 ResourceOperationUtils.handleAdapterResourceOperationRegistration (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration)3