use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class TestVSphereComputeDiskDay2Service method createResourceOperationRequest.
private ResourceOperationRequest createResourceOperationRequest(DiskService.DiskState diskState, String taskLink, ResourceOperation resourceOperation) {
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = isMock();
request.operation = resourceOperation.operation;
request.payload = new HashMap<>();
request.payload.put("diskLink", diskState.documentSelfLink);
request.resourceReference = UriUtils.buildUri(this.host, this.vm.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, taskLink);
return request;
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class TestVSphereComputeDiskDay2Service method testCDRomInsertOnCompute.
@Test
public void testCDRomInsertOnCompute() throws Throwable {
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;
}
this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
assertNotNull(CustomProperties.of(this.vm).getString(COMPUTE_HOST_LINK_PROP_NAME, null));
assertEquals(3, this.vm.diskLinks.size());
this.vm.diskLinks.stream().forEach(link -> {
DiskService.DiskState diskState = this.host.getServiceState(null, DiskService.DiskState.class, UriUtils.buildUri(this.host, link));
if (diskState.type == DiskService.DiskType.CDROM) {
this.CDDiskState = diskState;
}
});
// Step 1: Attach a CD-ROM disk
// prepare a disk with CD-ROM type
DiskService.DiskState cdDiskState = createCDromWithIso("cdrom-1", DiskService.DiskType.CDROM, 0, null, 1024, null, true, false);
ResourceOperationRequest request = createResourceOperationRequest(cdDiskState, createComputeDiskTaskService(), ResourceOperation.ATTACH_DISK);
sendRequest(request, DiskService.DiskType.CDROM, insertCDRomHandler());
this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
assertNotNull(this.vm.diskLinks);
assertEquals(3, this.vm.diskLinks.size());
} finally {
if (!isMock()) {
cleanUpVm(this.vm, null);
}
}
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class VSphereVMContextTest method beforeTest.
@Before
public void beforeTest() {
final URI mockUri = UriUtils.buildUri(this.host, UUID.randomUUID().toString());
ResourceOperationRequest resourceOperationRequest = new ResourceOperationRequest();
resourceOperationRequest.resourceReference = mockUri;
// reboot operation
resourceOperationRequest.operation = "Reboot";
resourceOperationRequest.taskReference = mockUri;
StatelessService mockService = new StatelessService();
mockService.setHost(this.host);
// create context calling the constructor, it should have errorHandler populated by default (i.e. errorHandler != null)
this.context = new VSphereVMContext(mockService, resourceOperationRequest);
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest 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.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class AzureLifecycleOperationServiceTest method triggerRestart.
private void triggerRestart() {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = ResourceOperation.RESTART.operation;
request.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, taskLink);
TestContext ctx = this.host.testCreate(2);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
Operation restartOp = Operation.createPatch(UriUtils.buildUri(this.host, AzureLifecycleOperationService.SELF_LINK)).setBody(request).setReferer("/tests").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(restartOp);
ctx.await();
}
Aggregations