use of com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext in project photon-model by vmware.
the class AWSResetService method reset.
private void reset(AmazonEC2AsyncClient client, ResourceOperationRequest pr, DefaultAdapterContext c) {
if (!c.child.powerState.equals(ComputeService.PowerState.ON)) {
logWarning(() -> String.format("Cannot perform a reset on this EC2 instance. " + "The machine should be in powered on state"));
c.taskManager.patchTaskToFailure(new IllegalStateException("Incorrect power state. Expected the machine " + "to be powered on "));
return;
}
// The stop action for reset is a force stop. So we use the withForce method to set the force parameter to TRUE
// This is similar to unplugging the machine from the power circuit.
// The OS and the applications are forcefully stopped.
StopInstancesRequest stopRequest = new StopInstancesRequest();
stopRequest.withInstanceIds(c.child.id).withForce(Boolean.TRUE);
client.stopInstancesAsync(stopRequest, new AWSAsyncHandler<StopInstancesRequest, StopInstancesResult>() {
@Override
protected void handleError(Exception e) {
c.taskManager.patchTaskToFailure(e);
}
@Override
protected void handleSuccess(StopInstancesRequest request, StopInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(), result.getStoppingInstances(), "stopped", client, (is, e) -> {
if (e != null) {
onError(e);
return;
}
// Instances will be started only if they're successfully stopped
startInstance(client, c);
});
}
});
}
Aggregations