use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class GcpMetadataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
List<CloudVmMetaDataStatus> instanceMetaData = new ArrayList<>();
Map<String, CloudResource> instanceNameMap = groupByInstanceName(resources);
Map<Long, CloudResource> privateIdMap = groupByPrivateId(resources);
for (CloudInstance cloudInstance : vms) {
String instanceId = cloudInstance.getInstanceId();
CloudResource cloudResource;
cloudResource = instanceId != null ? instanceNameMap.get(instanceId) : privateIdMap.get(cloudInstance.getTemplate().getPrivateId());
CloudVmMetaDataStatus cloudVmMetaDataStatus = getCloudVmMetaDataStatus(authenticatedContext, cloudResource, cloudInstance);
instanceMetaData.add(cloudVmMetaDataStatus);
}
return instanceMetaData;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class GetSSHFingerprintsHandler method accept.
@Override
public void accept(Event<GetSSHFingerprintsRequest> getSSHFingerprintsRequestEvent) {
LOGGER.info("Received event: {}", getSSHFingerprintsRequestEvent);
GetSSHFingerprintsRequest fingerprintsRequest = getSSHFingerprintsRequestEvent.getData();
try {
CloudContext cloudContext = fingerprintsRequest.getCloudContext();
CloudInstance cloudInstance = fingerprintsRequest.getCloudInstance();
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, fingerprintsRequest.getCloudCredential());
GetSSHFingerprintsResult fingerprintsResult;
try {
String initialConsoleOutput = connector.instances().getConsoleOutput(ac, cloudInstance);
InstanceConsoleOutputResult consoleOutputResult = new InstanceConsoleOutputResult(cloudContext, cloudInstance, initialConsoleOutput);
PollTask<InstanceConsoleOutputResult> outputPollerTask = statusCheckFactory.newPollConsoleOutputTask(connector.instances(), ac, cloudInstance);
if (!outputPollerTask.completed(consoleOutputResult)) {
consoleOutputResult = syncPollingScheduler.schedule(outputPollerTask);
}
Set<String> sshFingerprints = FingerprintParserUtil.parseFingerprints(consoleOutputResult.getConsoleOutput());
if (sshFingerprints.isEmpty()) {
throw new RuntimeException("Failed to get SSH fingerprints from the specified VM instance.");
} else {
fingerprintsResult = new GetSSHFingerprintsResult(fingerprintsRequest, sshFingerprints);
}
} catch (CloudOperationNotSupportedException ignored) {
fingerprintsResult = new GetSSHFingerprintsResult(fingerprintsRequest, new HashSet<>());
}
fingerprintsRequest.getResult().onNext(fingerprintsResult);
eventBus.notify(fingerprintsResult.selector(), new Event<>(getSSHFingerprintsRequestEvent.getHeaders(), fingerprintsResult));
LOGGER.info("GetSSHFingerprintsHandler finished");
} catch (Exception e) {
GetSSHFingerprintsResult failure = new GetSSHFingerprintsResult("Failed to get ssh fingerprints!", e, fingerprintsRequest);
fingerprintsRequest.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(getSSHFingerprintsRequestEvent.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class ComputeResourceService method stopStart.
private List<CloudVmInstanceStatus> stopStart(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, Iterable<CloudInstance> instances) {
List<CloudVmInstanceStatus> results = new ArrayList<>();
Collection<Future<ResourceRequestResult<List<CloudVmInstanceStatus>>>> futures = new ArrayList<>();
Platform platform = auth.getCloudContext().getPlatform();
List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
if (!context.isBuild()) {
Collections.reverse(builders);
}
for (ComputeResourceBuilder builder : builders) {
List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
for (CloudResource cloudResource : resourceList) {
CloudInstance instance = getCloudInstance(cloudResource, instances);
if (instance != null) {
ResourceStopStartThread thread = createThread(ResourceStopStartThread.NAME, context, auth, cloudResource, instance, builder);
Future<ResourceRequestResult<List<CloudVmInstanceStatus>>> future = resourceBuilderExecutor.submit(thread);
futures.add(future);
if (isRequestFull(futures.size(), context)) {
results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
}
} else {
break;
}
}
}
results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
return results;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class StopStackHandler method accept.
@Override
public void accept(Event<StopInstancesRequest> event) {
LOGGER.info("Received event: {}", event);
StopInstancesRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
List<CloudInstance> instances = request.getCloudInstances();
AuthenticatedContext authenticatedContext = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = connector.instances().stop(authenticatedContext, request.getResources(), instances);
PollTask<InstancesStatusResult> task = statusCheckFactory.newPollInstanceStateTask(authenticatedContext, instances, Sets.newHashSet(InstanceStatus.STOPPED, InstanceStatus.FAILED));
InstancesStatusResult statusResult = new InstancesStatusResult(cloudContext, cloudVmInstanceStatuses);
if (!task.completed(statusResult)) {
statusResult = syncPollingScheduler.schedule(task);
}
StopInstancesResult result = new StopInstancesResult(request, cloudContext, statusResult);
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
} catch (Exception e) {
StopInstancesResult failure = new StopInstancesResult("Failed to stop stack", e, request);
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class YarnMetadataCollector method groupInstancesByInstanceGroup.
private ListMultimap<String, CloudInstance> groupInstancesByInstanceGroup(Iterable<CloudInstance> vms) {
ListMultimap<String, CloudInstance> groupByInstanceGroup = ArrayListMultimap.create();
for (CloudInstance vm : vms) {
String groupName = vm.getTemplate().getGroupName();
groupByInstanceGroup.put(groupName, vm);
}
return groupByInstanceGroup;
}
Aggregations