use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class EC2ClientActions method listTagsByInstanceId.
public Map<String, Map<String, String>> listTagsByInstanceId(List<String> instanceIds) {
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceIds);
DescribeInstancesResult describeInstancesResult = buildEC2Client().describeInstances(describeInstancesRequest);
return describeInstancesResult.getReservations().stream().flatMap(reservation -> reservation.getInstances().stream()).collect(Collectors.toMap(Instance::getInstanceId, this::getTagsForInstance));
}
use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class EC2ClientActions method stopHostGroupInstances.
public void stopHostGroupInstances(List<String> instanceIds) {
AmazonEC2 ec2Client = buildEC2Client();
StopInstancesResult stopInstancesResult = ec2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instanceIds));
for (String instanceId : instanceIds) {
try {
Log.log(LOGGER, format(" EC2 instance [%s] state is [%s] ", instanceId, Objects.requireNonNull(stopInstancesResult.getStoppingInstances().stream().filter(instance -> instance.getInstanceId().equals(instanceId)).findAny().orElse(null)).getCurrentState().getName()));
ec2Client.waiters().instanceStopped().run(new WaiterParameters<DescribeInstancesRequest>(new DescribeInstancesRequest().withInstanceIds(instanceId)).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(80), new FixedDelayStrategy(30))));
DescribeInstancesResult describeInstanceResult = ec2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId));
InstanceState actualInstanceState = describeInstanceResult.getReservations().get(0).getInstances().get(0).getState();
if (STOPPED_STATE.equals(actualInstanceState.getName())) {
Log.log(LOGGER, format(" EC2 Instance: %s state is: %s ", instanceId, STOPPED_STATE));
} else {
LOGGER.error("EC2 Instance: {} stop has not been successful. So the actual state is: {} ", instanceId, actualInstanceState.getName());
throw new TestFailException(" EC2 Instance: " + instanceId + " stop has not been successful, because of the actual state is: " + actualInstanceState.getName());
}
} catch (WaiterUnrecoverableException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of WaiterUnrecoverableException: {}", instanceId, e);
} catch (WaiterTimedOutException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of WaiterTimedOutException: {}", instanceId, e);
} catch (EC2UnexpectedException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of EC2UnexpectedException: {}", instanceId, e);
}
}
}
use of com.google.api.services.notebooks.v1.model.Instance in project incubator-gobblin by apache.
the class AWSSdkClient method getInstancesForGroup.
/**
* Get list of EC2 {@link Instance}s for a auto scaling group
*
* @param groupName Auto scaling group name
* @param status Instance status (eg. running)
* @return List of EC2 instances found for the input auto scaling group
*/
public List<Instance> getInstancesForGroup(String groupName, String status) {
final AmazonEC2 amazonEC2 = getEc2Client();
final DescribeInstancesResult instancesResult = amazonEC2.describeInstances(new DescribeInstancesRequest().withFilters(new Filter().withName("tag:aws:autoscaling:groupName").withValues(groupName)));
final List<Instance> instances = new ArrayList<>();
for (Reservation reservation : instancesResult.getReservations()) {
for (Instance instance : reservation.getInstances()) {
if (null == status || null == instance.getState() || status.equals(instance.getState().getName())) {
instances.add(instance);
LOGGER.info("Found instance: " + instance + " which qualified filter: " + status);
} else {
LOGGER.info("Found instance: " + instance + " but did not qualify for filter: " + status);
}
}
}
return instances;
}
use of com.google.api.services.notebooks.v1.model.Instance in project druid by apache.
the class EC2AutoScalerTest method setUp.
@Before
public void setUp() {
amazonEC2Client = EasyMock.createMock(AmazonEC2Client.class);
describeInstancesResult = EasyMock.createMock(DescribeInstancesResult.class);
reservation = EasyMock.createMock(Reservation.class);
instance = new Instance().withInstanceId(INSTANCE_ID).withLaunchTime(new Date()).withImageId(AMI_ID).withPrivateIpAddress(IP);
managementConfig = new SimpleWorkerProvisioningConfig().setWorkerPort(8080).setWorkerVersion("");
}
use of com.google.api.services.notebooks.v1.model.Instance in project openvidu-loadtest by OpenVidu.
the class Ec2Client method terminateAllInstances.
public void terminateAllInstances() {
Filter workerTagFilter = getTagWorkerFilter();
List<Instance> instancesToTerminate = getInstanceWithFilters(workerTagFilter);
List<String> instancesToTerminateIds = getInstanceIds(instancesToTerminate);
terminateInstance(instancesToTerminateIds);
}
Aggregations