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");
}
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;
}
}
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");
}
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");
}
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;
}
Aggregations