use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse 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.adapterapi.ResourceOperationResponse 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);
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class AWSRebootServiceTest method testReboot.
// Test the reboot operation.
@Test
public void testReboot() throws Throwable {
provisionSingleAWS();
// check that the VM has been created
ProvisioningUtils.queryComputeInstances(this.host, 2);
ComputeState compute = getCompute(this.host, this.vmState.documentSelfLink);
if (!this.isMock) {
List<Instance> instances = getAwsInstancesByIds(this.client, this.host, Collections.singletonList(compute.id));
Instance instance = instances.get(0);
ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
assertAndSetVMSecurityGroupsToBeDeleted(instance, vm);
}
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = ResourceOperation.REBOOT.operation;
request.payload = new HashMap<>();
request.resourceReference = UriUtils.buildUri(this.host, compute.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, taskLink);
TestContext ctx = this.host.testCreate(2);
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 if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
Operation rebootOp = Operation.createPatch(UriUtils.buildUri(this.host, AWSRebootService.SELF_LINK)).setBody(request).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(rebootOp);
ctx.await();
ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
assertEquals(ComputeService.PowerState.ON, vm.powerState);
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse in project photon-model by vmware.
the class AWSResetServiceTest method testReset.
// Test the reset operation.
@Test
public void testReset() throws Throwable {
provisionSingleAWS();
// check that the VM has been created
ProvisioningUtils.queryComputeInstances(this.host, 2);
ComputeState compute = getCompute(this.host, this.vmState.documentSelfLink);
if (!this.isMock) {
List<Instance> instances = getAwsInstancesByIds(this.client, this.host, Collections.singletonList(compute.id));
Instance instance = instances.get(0);
ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
setVMSecurityGroupsToBeDeleted(instance, vm);
}
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = ResourceOperation.RESET.operation;
request.payload = new HashMap<>();
request.resourceReference = UriUtils.buildUri(this.host, compute.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, 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 if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
TestContext ctx2 = this.host.testCreate(1);
Operation resetOp = Operation.createPatch(UriUtils.buildUri(this.host, AWSResetService.SELF_LINK)).setBody(request).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
if (e != null) {
ctx2.failIteration(e);
return;
}
ctx2.completeIteration();
});
this.host.send(resetOp);
ctx2.await();
// in EC2 documentation
if (!this.isMock) {
// Waiting for power off
this.host.waitFor("Timed out waiting for EC2 to power off", () -> {
String state = getVMState(this.client, compute.id);
if (("stopping".equals(state) || "stopped".equals(state))) {
this.host.log(Level.INFO, "EC2 is being powered off");
return true;
} else {
return false;
}
});
// Waiting for power on
this.host.waitFor("Timed out waiting for EC2 to power on", () -> {
String state = getVMState(this.client, compute.id);
if ("running".equals(state)) {
this.host.log(Level.INFO, "EC2 is being powered on");
return true;
} else {
return false;
}
});
}
}
use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse 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);
}
Aggregations