use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class BaseVSphereAdapterTest method createSnapshotAndWaitFailure.
protected void createSnapshotAndWaitFailure(ComputeState vm) 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));
TestContext ctx2 = 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)) {
ctx2.completeIteration();
return true;
} else {
ctx2.completeIteration();
return false;
}
});
this.host.send(createSnapshotOp);
ctx2.await();
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class BaseVSphereAdapterTest method getResizeComputeRequest.
private ResourceOperationRequest getResizeComputeRequest(String operation, String documentSelfLink, String taskLink) {
Map<String, String> payload = new HashMap<>();
// update "__cpuCount" to 4 from 2
payload.put(COMPUTE_CPU_COUNT, "4");
payload.put(REBOOT_VM_FLAG, // reboot vm flag to true (not expecting hot-plug to be enabled in the provisioned machine)
"true");
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 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.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class BaseVSphereAdapterTest method resetVSphereVM.
protected void resetVSphereVM(ComputeState computeState) {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest resetVMRequest = getResourceOperationRequest("Reset", 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 resetOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterD2PowerOpsService.SELF_LINK)).setBody(resetVMRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
if (e != null) {
ctx2.failIteration(e);
return;
}
ctx2.completeIteration();
});
this.host.send(resetOp);
ctx2.await();
ComputeState[] cState = new ComputeState[1];
this.host.waitFor("Reset VM request failed", () -> {
cState[0] = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
if (ComputeService.PowerState.ON.equals(cState[0].powerState)) {
return true;
} else {
return false;
}
});
assertEquals(ComputeService.PowerState.ON, cState[0].powerState);
}
use of com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest in project photon-model by vmware.
the class BaseVSphereAdapterTest method shutdownGuestOS.
protected void shutdownGuestOS(ComputeState computeState) {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest shutdownGuestRequest = getResourceOperationRequest("Shutdown", 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 shutdownOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterD2PowerOpsService.SELF_LINK)).setBody(shutdownGuestRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
if (e != null) {
ctx2.failIteration(e);
return;
}
ctx2.completeIteration();
});
this.host.send(shutdownOp);
ctx2.await();
ComputeState[] cState = new ComputeState[1];
this.host.waitFor("Guest shutdown request failed", () -> {
cState[0] = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
if (cState[0].powerState.equals(ComputeService.PowerState.OFF)) {
assertTrue(cState[0].address.isEmpty());
return true;
} else {
return false;
}
});
assertEquals(ComputeService.PowerState.OFF, cState[0].powerState);
}
Aggregations