use of com.vmware.xenon.common.test.TestRequestSender in project photon-model by vmware.
the class BaseVSphereAdapterTest method rebootVSphereVMAndWait.
protected void rebootVSphereVMAndWait(ComputeState computeState) {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest rebootVMRequest = getResourceOperationRequest("Reboot", computeState.documentSelfLink, taskLink);
Operation rebootOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterD2PowerOpsService.SELF_LINK)).setBody(rebootVMRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
Assert.assertNull(e);
});
TestRequestSender sender = new TestRequestSender(this.host);
sender.sendRequest(rebootOp);
this.host.log("Waiting for the machine to be rebooted");
ComputeState[] cState = new ComputeState[1];
this.host.waitFor("Reboot request failed", () -> {
cState[0] = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
if (cState[0].powerState.equals(ComputeService.PowerState.ON)) {
return true;
} else {
return false;
}
});
assertEquals(ComputeService.PowerState.ON, cState[0].powerState);
assertNotNull(cState[0].address);
this.host.log("Reboot operation completed successfully");
}
use of com.vmware.xenon.common.test.TestRequestSender 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.xenon.common.test.TestRequestSender 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.xenon.common.test.TestRequestSender in project photon-model by vmware.
the class AWSComputeDiskDay2ServiceTest method performDiskOperationAndVerify.
private void performDiskOperationAndVerify(String computeStateLink, List<String> diskLinks, String requestType, DiskTaskService.DiskTaskState.SubStage expectedTerminalState) throws Throwable {
List<String> taskServiceLinks = new ArrayList<>();
diskLinks.forEach(diskLink -> {
DiskTaskService.DiskTaskState diskOpTask = new DiskTaskService.DiskTaskState();
diskOpTask.taskSubStage = DiskTaskService.DiskTaskState.SubStage.STARTED;
try {
diskOpTask = TestUtils.doPost(this.host, diskOpTask, DiskTaskService.DiskTaskState.class, UriUtils.buildUri(this.host, DiskTaskService.FACTORY_LINK));
} catch (Throwable throwable) {
throwable.printStackTrace();
}
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = requestType;
request.payload = new HashMap<>();
request.payload.put(PhotonModelConstants.DISK_LINK, diskLink);
request.resourceReference = UriUtils.buildUri(this.host, computeStateLink);
request.taskReference = UriUtils.buildUri(this.host, diskOpTask.documentSelfLink);
Operation diskOp = Operation.createPatch(UriUtils.buildUri(this.host, AWSComputeDiskDay2Service.SELF_LINK)).setBody(request).setReferer(this.host.getReferer());
TestRequestSender sender = new TestRequestSender(this.host);
sender.sendRequest(diskOp);
this.host.log("Waiting for disk operation to complete");
taskServiceLinks.add(diskOpTask.documentSelfLink);
});
taskServiceLinks.forEach(taskServiceLink -> {
this.host.waitFor("disk Operation failed.", () -> {
DiskTaskService.DiskTaskState diskTaskState = this.host.getServiceState(null, DiskTaskService.DiskTaskState.class, UriUtils.buildUri(this.host, taskServiceLink));
// Check if the disk operation is successful or not.
if (diskTaskState.taskSubStage == DiskTaskService.DiskTaskState.SubStage.FINISHED || diskTaskState.taskSubStage == DiskTaskService.DiskTaskState.SubStage.FAILED) {
assertEquals("diskOperation Task did not terminate as expected.", expectedTerminalState, diskTaskState.taskSubStage);
return true;
} else {
return false;
}
});
});
}
use of com.vmware.xenon.common.test.TestRequestSender in project photon-model by vmware.
the class ResourceOperationSpecServiceTest method testRegisterAndPatchExtensions.
@Test
public void testRegisterAndPatchExtensions() {
ResourceOperationSpec[] states = registerResourceOperation(this.endpointType, ResourceType.COMPUTE, "testRegisterAndPatchExtensions");
ResourceOperationSpec requestedState = states[0];
ResourceOperationSpec persistedState = states[1];
Assert.assertTrue(persistedState.documentSelfLink.endsWith(ResourceOperationSpecFactoryService.generateSelfLink(requestedState)));
this.logger.info("Persisted: " + persistedState);
String E_2 = "e2";
ResourceOperationSpec specWithExtension = new ResourceOperationSpec();
specWithExtension.documentSelfLink = ResourceOperationSpecFactoryService.generateSelfLink(requestedState.endpointType, requestedState.resourceType, requestedState.operation);
specWithExtension.extensions = new HashMap<>();
specWithExtension.extensions.put(E_2, "v2");
Operation patchOne = Operation.createPatch(super.host, specWithExtension.documentSelfLink).setBodyNoCloning(specWithExtension);
TestRequestSender sender = super.host.getTestRequestSender();
sender.sendAndWait(patchOne);
ResourceOperationSpec patchedSpec = sender.sendGetAndWait(UriUtils.buildUri(super.host, specWithExtension.documentSelfLink), ResourceOperationSpec.class);
Assert.assertNotNull(patchedSpec);
Assert.assertNotNull(patchedSpec.extensions);
Assert.assertNotNull(patchedSpec.extensions.get(E_2));
specWithExtension.name = "tryNewName";
Operation patchTwo = Operation.createPatch(super.host, specWithExtension.documentSelfLink).setBodyNoCloning(specWithExtension);
try {
sender.sendAndWait(patchTwo);
} catch (RuntimeException rte) {
Throwable[] allSuppressed = rte.getSuppressed();
Assert.assertNotNull(allSuppressed);
Assert.assertEquals(1, allSuppressed.length);
Throwable suppressed = allSuppressed[0];
this.logger.info("Suppressed error: " + suppressed.getMessage());
Assert.assertTrue(suppressed instanceof IllegalArgumentException);
}
}
Aggregations