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);
}
});
}
});
}
use of com.amazonaws.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);
});
}
});
}
use of com.amazonaws.services.ec2.model.StartInstancesRequest in project cloudbreak by hortonworks.
the class AwsInstanceConnectorTest method testStartPollingWithSuccess.
@Test
public void testStartPollingWithSuccess() {
String status = "Running";
InstanceStatus stopped1 = AwsInstanceStatusMapper.getInstanceStatusByAwsStatus(status);
int lastStatusCode = 16;
// given
mockDescribeInstances(POLLING_LIMIT - 2, status, lastStatusCode);
ArgumentCaptor<StartInstancesRequest> captorStart = ArgumentCaptor.forClass(StartInstancesRequest.class);
// then
List<CloudVmInstanceStatus> result = underTest.start(authenticatedContext, List.of(), inputList);
// then
verify(amazonEC2Client, times(1)).startInstances(captorStart.capture());
Assertions.assertTrue(captorStart.getValue().getInstanceIds().size() == inputList.size());
Assert.assertThat(result, hasItem(allOf(hasProperty("status", is(stopped1)))));
}
use of com.amazonaws.services.ec2.model.StartInstancesRequest in project cloud-pipeline by epam.
the class EC2Helper method startInstance.
public void startInstance(String instanceId, String awsRegion) {
AmazonEC2 client = getEC2Client(awsRegion);
StartInstancesRequest startInstancesRequest = new StartInstancesRequest().withInstanceIds(instanceId);
client.startInstances(startInstancesRequest);
Waiter<DescribeInstancesRequest> waiter = client.waiters().instanceRunning();
waiter.run(new WaiterParameters<>(new DescribeInstancesRequest().withInstanceIds(instanceId)));
}
use of com.amazonaws.services.ec2.model.StartInstancesRequest in project solarnetwork-central by SolarNetwork.
the class AwsVirtualMachineBiz method changeVirtualMachinesState.
@Override
public void changeVirtualMachinesState(Set<String> machineIds, VirtualMachineState desiredState) {
AmazonEC2 client = getEc2Client();
List<InstanceStateChange> results = null;
if (desiredState == VirtualMachineState.Running) {
StartInstancesRequest req = new StartInstancesRequest().withInstanceIds(machineIds);
StartInstancesResult res = client.startInstances(req);
results = res.getStartingInstances();
} else if (desiredState == VirtualMachineState.Stopped) {
StopInstancesRequest req = new StopInstancesRequest().withInstanceIds(machineIds);
StopInstancesResult res = client.stopInstances(req);
results = res.getStoppingInstances();
} else {
throw new IllegalArgumentException("Desired state not supported: " + desiredState);
}
log.info("Changed EC2 instances {} desired state to {}: {}", machineIds, desiredState, results);
}
Aggregations