use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsNativeMetadataCollector method describeInstances.
private List<CloudVmMetaDataStatus> describeInstances(List<CloudInstance> vms, List<String> instanceIdList, Map<String, CloudResource> resourcesByInstanceId, AmazonEc2Client ec2Client) {
LOGGER.info("Collecting metadata for instance IDs: '{}'", String.join(", ", instanceIdList));
List<CloudVmMetaDataStatus> result = new ArrayList<>();
DescribeInstancesRequest instancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceIdList);
DescribeInstancesResult instancesResult = ec2Client.describeInstances(instancesRequest);
List<Instance> instances = instancesResult.getReservations().stream().flatMap(reservation -> reservation.getInstances().stream()).collect(Collectors.toList());
for (Instance instance : instances) {
String instanceId = instance.getInstanceId();
CloudResource connectedResource = findCloudResourceByInstanceId(resourcesByInstanceId, instanceId);
CloudInstance matchedInstance = findCloudInstanceByPrivateId(vms, connectedResource);
CloudInstance updatedInstance = new CloudInstance(connectedResource.getInstanceId(), matchedInstance.getTemplate(), matchedInstance.getAuthentication(), matchedInstance.getSubnetId(), matchedInstance.getAvailabilityZone());
CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(instance.getPrivateIpAddress(), instance.getPublicIpAddress(), awsLifeCycleMapper.getLifeCycle(instance));
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(updatedInstance, updatedInstance.getTemplate().getStatus());
CloudVmMetaDataStatus newMetadataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
result.add(newMetadataStatus);
}
return result;
}
use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsMetaDataCollectorTest method getReservation.
private Reservation getReservation(Instance... instance) {
List<Instance> instances = Arrays.asList(instance);
Reservation r = new Reservation();
r.setInstances(instances);
return r;
}
use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsInstanceConnector method instanceIdsWhichAreNotInCorrectState.
private Collection<String> instanceIdsWhichAreNotInCorrectState(List<CloudInstance> vms, AmazonEc2Client amazonEC2Client, String state) {
Set<String> instances = vms.stream().map(CloudInstance::getInstanceId).collect(Collectors.toCollection(HashSet::new));
DescribeInstancesResult describeInstances = amazonEC2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instances));
for (Reservation reservation : describeInstances.getReservations()) {
for (Instance instance : reservation.getInstances()) {
if (state.equalsIgnoreCase(instance.getState().getName())) {
instances.remove(instance.getInstanceId());
}
}
}
return instances;
}
use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsInstanceConnector method fillCloudVmInstanceStatuses.
private List<CloudVmInstanceStatus> fillCloudVmInstanceStatuses(AuthenticatedContext ac, List<CloudInstance> cloudIntancesWithInstanceId, String region, DescribeInstancesResult result) {
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
for (Reservation reservation : result.getReservations()) {
for (Instance instance : reservation.getInstances()) {
Optional<CloudInstance> cloudInstanceForInstanceId = cloudIntancesWithInstanceId.stream().filter(cloudInstance -> cloudInstance.getInstanceId().equals(instance.getInstanceId())).findFirst();
if (cloudInstanceForInstanceId.isPresent()) {
CloudInstance cloudInstance = cloudInstanceForInstanceId.get();
LOGGER.debug("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(cloudInstance, AwsInstanceStatusMapper.getInstanceStatusByAwsStateAndReason(instance.getState(), instance.getStateReason())));
}
}
}
return cloudVmInstanceStatuses;
}
use of com.google.api.services.notebooks.v1.model.Instance in project terra-cli by DataBiosphere.
the class GoogleNotebooks method stop.
public void stop(InstanceName instanceName) {
try {
Operation stopOperation = notebooks.instances().stop(instanceName).execute();
pollForSuccess(stopOperation, "Error stopping notebook instance: ");
} catch (InterruptedException | IOException e) {
checkFor409BadState(e);
throw new SystemException("Error stopping notebook instance", e);
}
}
Aggregations