use of com.amazonaws.services.ec2.model.StartInstancesResult in project photon-model by vmware.
the class AWSResetService method startInstance.
private void startInstance(AmazonEC2AsyncClient client, DefaultAdapterContext c) {
StartInstancesRequest startRequest = new StartInstancesRequest();
startRequest.withInstanceIds(c.child.id);
client.startInstancesAsync(startRequest, new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {
@Override
protected void handleError(Exception e) {
c.taskManager.patchTaskToFailure(e);
}
@Override
protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(), result.getStartingInstances(), "running", client, (is, e) -> {
if (e == null) {
c.taskManager.finishTask();
} else {
c.taskManager.patchTaskToFailure(e);
}
});
}
});
}
use of com.amazonaws.services.ec2.model.StartInstancesResult in project photon-model by vmware.
the class AWSComputeDiskDay2Service method startInstance.
/**
* start the instance and on success updates the disk and compute state to reflect the detach information.
*/
private void startInstance(AmazonEC2AsyncClient client, DiskContext c, DeferredResult<DiskContext> dr, OperationContext opCtx) {
StartInstancesRequest startRequest = new StartInstancesRequest();
startRequest.withInstanceIds(c.baseAdapterContext.child.id);
client.startInstancesAsync(startRequest, new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {
@Override
protected void handleError(Exception e) {
service.logSevere(() -> String.format("[AWSComputeDiskDay2Service] Failed to start the instance %s. %s", c.baseAdapterContext.child.id, Utils.toString(e)));
OperationContext.restoreOperationContext(opCtx);
c.error = e;
dr.complete(c);
}
@Override
protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(), result.getStartingInstances(), "running", client, (is, e) -> {
if (e != null) {
service.logSevere(() -> String.format("[AWSComputeDiskDay2Service] Instance %s failed to reach " + "running state. %s", c.baseAdapterContext.child.id, Utils.toString(e)));
OperationContext.restoreOperationContext(opCtx);
c.error = e;
dr.complete(c);
return;
}
logInfo(() -> String.format("[AWSComputeDiskDay2Service] Successfully started the " + "instance %s", result.getStartingInstances().get(0).getInstanceId()));
updateComputeAndDiskState(dr, c, opCtx);
});
}
});
}
use of com.amazonaws.services.ec2.model.StartInstancesResult in project onebusaway-application-modules by camsys.
the class BundleServerServiceImpl method start.
@Override
public String start(String instanceId) {
if (!_isAws) {
return LOCAL_HOST;
}
if (LOCAL_HOST.equalsIgnoreCase(instanceId)) {
return instanceId;
}
List<String> instances = new ArrayList<String>();
instances.add(instanceId);
StartInstancesRequest startInstancesRequest = new StartInstancesRequest(instances);
StartInstancesResult startInstancesResult = _ec2.startInstances(startInstancesRequest);
InstanceStateChange change = null;
if (!startInstancesResult.getStartingInstances().isEmpty()) {
change = startInstancesResult.getStartingInstances().get(0);
_log.info("from state=" + change.getPreviousState() + " to state=" + change.getCurrentState());
return change.getInstanceId();
}
return null;
}
Aggregations