use of com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext in project photon-model by vmware.
the class AWSPowerService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
ComputePowerRequest pr = op.getBody(ComputePowerRequest.class);
op.complete();
if (pr.isMockRequest) {
updateComputeState(pr, new DefaultAdapterContext(this, pr));
} else {
new DefaultAdapterContext(this, pr).populateBaseContext(BaseAdapterStage.VMDESC).whenComplete((c, e) -> {
this.clientManager.getOrCreateEC2ClientAsync(c.endpointAuth, c.child.description.regionId, this).whenComplete((client, t) -> {
if (t != null) {
c.taskManager.patchTaskToFailure(t);
return;
}
applyPowerOperation(client, pr, c);
});
});
}
}
use of com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext in project photon-model by vmware.
the class AWSPowerService method updateComputeState.
private void updateComputeState(ComputePowerRequest pr, DefaultAdapterContext c) {
ComputeState state = new ComputeState();
state.powerState = pr.powerState;
if (OFF.equals(pr.powerState)) {
// clear IP address in case of power-off
state.address = "";
}
Operation.createPatch(pr.resourceReference).setBody(state).setCompletion((o, e) -> {
if (e != null) {
c.taskManager.patchTaskToFailure(e);
return;
}
c.taskManager.finishTask();
}).sendWith(this);
}
use of com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext in project photon-model by vmware.
the class AWSPowerService method powerOn.
private void powerOn(AmazonEC2AsyncClient client, ComputePowerRequest pr, DefaultAdapterContext c) {
OperationContext opContext = OperationContext.getOperationContext();
StartInstancesRequest request = new StartInstancesRequest();
request.withInstanceIds(c.child.id);
client.startInstancesAsync(request, new AsyncHandler<StartInstancesRequest, StartInstancesResult>() {
@Override
public void onSuccess(StartInstancesRequest request, StartInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(), result.getStartingInstances(), "running", 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.adapters.util.BaseAdapterContext.DefaultAdapterContext in project photon-model by vmware.
the class AWSRebootService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
ResourceOperationRequest request = op.getBody(ResourceOperationRequest.class);
op.complete();
logInfo("Handle operation %s for compute %s.", request.operation, request.resourceLink());
if (request.isMockRequest) {
updateComputeState(request, new DefaultAdapterContext(this, request));
} else {
new DefaultAdapterContext(this, request).populateBaseContext(BaseAdapterStage.VMDESC).whenComplete((c, e) -> {
this.clientManager.getOrCreateEC2ClientAsync(c.endpointAuth, c.child.description.regionId, this).whenComplete((client, t) -> {
if (t != null) {
c.taskManager.patchTaskToFailure(t);
return;
}
reboot(client, request, c);
});
});
}
}
use of com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext in project photon-model by vmware.
the class AWSRebootService method updateComputeState.
private void updateComputeState(ResourceOperationRequest ror, DefaultAdapterContext c) {
ComputeState state = new ComputeState();
state.powerState = ComputeService.PowerState.ON;
Operation.createPatch(ror.resourceReference).setBody(state).setCompletion((o, e) -> {
if (e != null) {
c.taskManager.patchTaskToFailure(e);
return;
}
c.taskManager.finishTask();
}).sendWith(this);
}
Aggregations