use of com.vmware.photon.controller.model.adapterapi.ComputePowerRequest in project photon-model by vmware.
the class AWSPowerService method powerOff.
private void powerOff(AmazonEC2AsyncClient client, ComputePowerRequest pr, DefaultAdapterContext c) {
OperationContext opContext = OperationContext.getOperationContext();
StopInstancesRequest request = new StopInstancesRequest();
request.withInstanceIds(c.child.id);
client.stopInstancesAsync(request, new AsyncHandler<StopInstancesRequest, StopInstancesResult>() {
@Override
public void onSuccess(StopInstancesRequest request, StopInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(), result.getStoppingInstances(), "stopped", client, (is, e) -> {
OperationContext.restoreOperationContext(opContext);
if (e != null) {
onError(e);
return;
}
updateComputeState(pr, c);
});
}
@Override
public void onError(Exception e) {
OperationContext.restoreOperationContext(opContext);
c.taskManager.patchTaskToFailure(e);
}
});
}
use of com.vmware.photon.controller.model.adapterapi.ComputePowerRequest in project photon-model by vmware.
the class AzurePowerServiceTest method triggerPowerChange.
private void triggerPowerChange(PowerState powerState, URI powerAdapterReference) {
String taskLink = UUID.randomUUID().toString();
ComputePowerRequest powerRequest = new ComputePowerRequest();
powerRequest.isMockRequest = this.isMock;
powerRequest.powerState = powerState;
powerRequest.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
powerRequest.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 powerOp = Operation.createPatch(powerAdapterReference).setBody(powerRequest).setReferer("/tests").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(powerOp);
ctx.await();
}
use of com.vmware.photon.controller.model.adapterapi.ComputePowerRequest in project photon-model by vmware.
the class VSphereAdapterPowerService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
ComputePowerRequest request = op.getBody(ComputePowerRequest.class);
op.setStatusCode(Operation.STATUS_CODE_CREATED);
op.complete();
ProvisionContext.populateContextThen(this, createInitialContext(request, op), ctx -> {
if (request.isMockRequest) {
patchComputeAndCompleteRequest(request, ctx);
return;
}
handlePowerRequest(ctx, request);
});
}
Aggregations