use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class BaseVSphereAdapterTest method suspendVSphereVM.
protected void suspendVSphereVM(ComputeState computeState) {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest suspendVMRequest = getResourceOperationRequest("Suspend", computeState.documentSelfLink, taskLink);
TestContext ctx = this.host.testCreate(1);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Service.Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else {
ctx.completeIteration();
}
return true;
});
TestContext ctx2 = this.host.testCreate(1);
Operation suspendOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterD2PowerOpsService.SELF_LINK)).setBody(suspendVMRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
if (e != null) {
ctx2.failIteration(e);
return;
}
ctx2.completeIteration();
});
this.host.send(suspendOp);
ctx2.await();
ComputeState[] cstate = new ComputeState[1];
this.host.waitFor("Suspend request failed", () -> {
cstate[0] = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
if (cstate[0].powerState.equals(ComputeService.PowerState.SUSPEND)) {
assertTrue(cstate[0].address.isEmpty());
return true;
} else {
return false;
}
});
assertEquals(ComputeService.PowerState.SUSPEND, cstate[0].powerState);
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class BaseVSphereAdapterTest method getCreateSnapshotRequest.
private ResourceOperationRequest getCreateSnapshotRequest(String operation, String documentSelfLink, String taskLink) {
Map<String, String> payload = new HashMap<>();
payload.put(VSphereConstants.VSPHERE_SNAPSHOT_REQUEST_TYPE, "CREATE");
payload.put(VSphereConstants.VSPHERE_SNAPSHOT_MEMORY, "false");
ResourceOperationRequest resourceOperationRequest = new ResourceOperationRequest();
resourceOperationRequest.operation = operation;
resourceOperationRequest.isMockRequest = isMock();
resourceOperationRequest.resourceReference = UriUtils.buildUri(this.host, documentSelfLink);
resourceOperationRequest.taskReference = UriUtils.buildUri(this.host, taskLink);
resourceOperationRequest.payload = payload;
return resourceOperationRequest;
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest 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.adapters.registry.operations.ResourceOperationRequest 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.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class TestVSphereComputeDiskDay2Service method testComputePersistentDisk.
@Test
public /**
* 1. Create a VM
* 2. Create a HDD persistent disk
* 3. Attach HDD disk created in Step 2 to VM.
* 4. Delete VM.
* 5. Verify HDD disk still remains
* 6. Delete HDD disk
*/
void testComputePersistentDisk() throws Throwable {
DiskService.DiskState diskState = null;
try {
// Step 1: Create VM
prepareEnvironment();
if (isMock()) {
createNetwork(networkId);
}
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
this.vm = createVmState(vmDescription, true, null, false);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(this.vm);
awaitTaskEnd(provisionTask);
this.vm = getComputeState(this.vm);
// put fake moref in the vm
if (isMock()) {
ManagedObjectReference moref = new ManagedObjectReference();
moref.setValue("vm-0");
moref.setType(VimNames.TYPE_VM);
CustomProperties.of(this.vm).put(MOREF, moref);
this.vm = doPost(this.host, this.vm, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
return;
}
// Step 2: Create Disk
diskState = createDiskWithDatastore("AdditionalDisk1", DiskService.DiskType.HDD, ADDITIONAL_DISK_SIZE, buildCustomProperties(), true);
// start provision task to do the actual disk creation
String documentSelfLink = performDiskRequest(diskState, ProvisionDiskTaskService.ProvisionDiskTaskState.SubStage.CREATING_DISK);
this.host.waitForFinishedTask(ProvisionDiskTaskService.ProvisionDiskTaskState.class, documentSelfLink);
// Step 3: Attach Disk created in step 2
ResourceOperationRequest request = createResourceOperationRequest(diskState, createComputeDiskTaskService(), ResourceOperation.ATTACH_DISK);
sendRequest(request, DiskService.DiskType.HDD, computeAttachWaitHandler());
this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
// Step 4: Delete VM
cleanUpVm(this.vm, null);
// Get the latest state of the detached disk
diskState = this.host.getServiceState(null, DiskService.DiskState.class, UriUtils.buildUri(this.host, diskState.documentSelfLink));
assertEquals(DiskService.DiskStatus.AVAILABLE, diskState.status);
} finally {
if (!isMock()) {
// Step 8: Delete disk
if (diskState != null) {
String documentSelfLink = performDiskRequest(diskState, ProvisionDiskTaskService.ProvisionDiskTaskState.SubStage.DELETING_DISK);
this.host.waitForFinishedTask(ProvisionDiskTaskService.ProvisionDiskTaskState.class, documentSelfLink);
}
}
}
}
Aggregations