use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilder method checkInstances.
@Override
public List<CloudVmInstanceStatus> checkInstances(GcpContext context, AuthenticatedContext auth, List<CloudInstance> instances) {
CloudInstance cloudInstance = instances.get(0);
try {
LOGGER.info("Checking instance: {}", cloudInstance);
Operation operation = check(context, cloudInstance);
boolean finished = operation == null || GcpStackUtil.isOperationFinished(operation);
InstanceStatus status = finished ? context.isBuild() ? InstanceStatus.STARTED : InstanceStatus.STOPPED : InstanceStatus.IN_PROGRESS;
LOGGER.info("Instance: {} status: {}", instances, status);
return Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, status));
} catch (Exception ignored) {
LOGGER.info("Failed to check instance state of {}", cloudInstance);
return Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class GcpInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
CloudCredential credential = ac.getCloudCredential();
CloudContext cloudContext = ac.getCloudContext();
Compute compute = GcpStackUtil.buildCompute(credential);
for (CloudInstance instance : vms) {
InstanceStatus status = InstanceStatus.UNKNOWN;
try {
Instance executeInstance = getInstance(cloudContext, credential, compute, instance.getInstanceId());
if ("RUNNING".equals(executeInstance.getStatus())) {
status = InstanceStatus.STARTED;
} else if ("TERMINATED".equals(executeInstance.getStatus())) {
status = InstanceStatus.STOPPED;
}
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
status = InstanceStatus.TERMINATED;
} else {
LOGGER.warn(String.format("Instance %s is not reachable", instance), e);
}
} catch (IOException e) {
LOGGER.warn(String.format("Instance %s is not reachable", instance), e);
}
statuses.add(new CloudVmInstanceStatus(instance, status));
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class InstanceStateHandler method accept.
@Override
public void accept(Event<GetInstancesStateRequest> event) {
LOGGER.info("Received event: {}", event);
GetInstancesStateRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
GetInstancesStateResult result;
try {
List<CloudVmInstanceStatus> instanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses(request.getCloudCredential(), cloudContext, request.getInstances());
result = new GetInstancesStateResult(request, instanceStatuses);
} catch (RuntimeException e) {
result = new GetInstancesStateResult("Instance state synchronizing failed", e, request);
}
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus 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.CloudVmInstanceStatus 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));
}
}
Aggregations