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