use of software.amazon.awssdk.services.ec2.model.StartInstancesRequest in project GNS by MobilityFirst.
the class AWSEC2 method startInstance.
/**
* Start an instance
*
* @param ec2
* @param createdInstanceId
*/
public static void startInstance(AmazonEC2 ec2, String createdInstanceId) {
System.out.println("Starting Instance:" + createdInstanceId);
List<String> instanceIds = new LinkedList<>();
instanceIds.add(createdInstanceId);
StartInstancesRequest startIR = new StartInstancesRequest(instanceIds);
ec2.startInstances(startIR);
}
use of software.amazon.awssdk.services.ec2.model.StartInstancesRequest in project camel by apache.
the class EC2Producer method startInstances.
private void startInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
StartInstancesRequest request = new StartInstancesRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withInstanceIds(instanceIds);
} else {
throw new IllegalArgumentException("Instances Ids must be specified");
}
StartInstancesResult result;
try {
result = ec2Client.startInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Start Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Starting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of software.amazon.awssdk.services.ec2.model.StartInstancesRequest 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 software.amazon.awssdk.services.ec2.model.StartInstancesRequest 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 software.amazon.awssdk.services.ec2.model.StartInstancesRequest 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);
});
}
});
}
Aggregations