use of com.amazonaws.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 com.amazonaws.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 com.amazonaws.services.ec2.model.StartInstancesRequest in project camel by apache.
the class AmazonEC2ClientMock method startInstances.
@Override
public StartInstancesResult startInstances(StartInstancesRequest startInstancesRequest) {
StartInstancesResult result = new StartInstancesResult();
if (startInstancesRequest.getInstanceIds().get(0).equals("test-1")) {
Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
InstanceStateChange sc = new InstanceStateChange();
InstanceState previousState = new InstanceState();
previousState.setCode(80);
previousState.setName(InstanceStateName.Stopped);
InstanceState newState = new InstanceState();
newState.setCode(16);
newState.setName(InstanceStateName.Running);
sc.setPreviousState(previousState);
sc.setCurrentState(newState);
sc.setInstanceId("test-1");
coll.add(sc);
result.setStartingInstances(coll);
} else {
throw new AmazonServiceException("The image-id doesn't exists");
}
return result;
}
use of com.amazonaws.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 com.amazonaws.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);
}
});
}
});
}
Aggregations