use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class GcpMetadataCollector method getCloudVmMetaDataStatus.
private CloudVmMetaDataStatus getCloudVmMetaDataStatus(AuthenticatedContext authenticatedContext, CloudResource cloudResource, CloudInstance matchedInstance) {
CloudVmMetaDataStatus cloudVmMetaDataStatus;
if (cloudResource != null) {
CloudInstance cloudInstance = new CloudInstance(cloudResource.getName(), matchedInstance.getTemplate(), matchedInstance.getAuthentication());
try {
CloudCredential credential = authenticatedContext.getCloudCredential();
CloudContext cloudContext = authenticatedContext.getCloudContext();
Compute compute = GcpStackUtil.buildCompute(credential);
Instance executeInstance = getInstance(cloudContext, credential, compute, cloudResource.getName());
String privateIp = executeInstance.getNetworkInterfaces().get(0).getNetworkIP();
String publicIp = null;
List<AccessConfig> acl = executeInstance.getNetworkInterfaces().get(0).getAccessConfigs();
if (acl != null && acl.get(0) != null) {
publicIp = executeInstance.getNetworkInterfaces().get(0).getAccessConfigs().get(0).getNatIP();
}
CloudInstanceMetaData metaData = new CloudInstanceMetaData(privateIp, publicIp);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, metaData);
} catch (IOException e) {
LOGGER.warn(String.format("Instance %s is not reachable", cloudResource.getName()), e);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.UNKNOWN);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, CloudInstanceMetaData.EMPTY_METADATA);
}
} else {
CloudVmInstanceStatus status = new CloudVmInstanceStatus(matchedInstance, InstanceStatus.TERMINATED);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, CloudInstanceMetaData.EMPTY_METADATA);
}
return cloudVmMetaDataStatus;
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class OpenStackNetworkResourceBuilder method checkStatus.
@Override
protected boolean checkStatus(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) {
CloudContext cloudContext = auth.getCloudContext();
OSClient<?> osClient = createOSClient(auth);
org.openstack4j.model.network.Network osNetwork = osClient.networking().network().get(resource.getReference());
if (osNetwork != null && context.isBuild()) {
State networkStatus = osNetwork.getStatus();
if (State.ERROR == networkStatus) {
throw new OpenStackResourceException("Network in failed state", resource.getType(), resource.getName(), cloudContext.getId(), networkStatus.name());
}
return networkStatus == State.ACTIVE;
} else {
return osNetwork == null && !context.isBuild();
}
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class DownscaleStackCollectResourcesHandler method accept.
@Override
public void accept(Event<DownscaleStackCollectResourcesRequest> collectResourcesRequestEvent) {
LOGGER.info("Received event: {}", collectResourcesRequestEvent);
DownscaleStackCollectResourcesRequest request = collectResourcesRequestEvent.getData();
DownscaleStackCollectResourcesResult result;
try {
CloudContext cloudContext = request.getCloudContext();
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
Object resourcesToScale = connector.resources().collectResourcesToRemove(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances());
LOGGER.info("Collect resources successfully finished for {}", cloudContext);
result = new DownscaleStackCollectResourcesResult(request, resourcesToScale);
} catch (RuntimeException e) {
LOGGER.error("Failed to handle DownscaleStackCollectResourcesRequest.", e);
result = new DownscaleStackCollectResourcesResult(e.getMessage(), e, request);
}
request.getResult().onNext(result);
LOGGER.info("DownscaleStackCollectResourcesRequest finished");
eventBus.notify(result.selector(), new Event<>(collectResourcesRequestEvent.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class LogContextAspects method buildLogContextForCloudPlatformEventHandler.
@Before("com.sequenceiq.cloudbreak.logger.LogContextAspects.interceptCloudPlatformEventHandlersAcceptMethod()")
public void buildLogContextForCloudPlatformEventHandler(JoinPoint joinPoint) {
Event<CloudPlatformRequest> event = (Event<CloudPlatformRequest>) joinPoint.getArgs()[0];
CloudPlatformRequest cloudPlatformRequest = event.getData();
CloudContext cloudContext = cloudPlatformRequest.getCloudContext();
buildMdcContext(cloudContext, event);
LOGGER.info("A CloudPlatformEventHandler's 'accept' method has been intercepted: {}, MDC logger context is built.", joinPoint.toShortString());
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AbstractStackUpscaleAction method createFlowContext.
@Override
protected StackScalingFlowContext createFlowContext(String flowId, StateContext<StackUpscaleState, StackUpscaleEvent> stateContext, P payload) {
Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
Stack stack = stackService.getByIdWithLists(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
CloudStack cloudStack = cloudStackConverter.convert(stack);
return new StackScalingFlowContext(flowId, stack, cloudContext, cloudCredential, cloudStack, getInstanceGroupName(variables), Collections.emptySet(), getAdjustment(variables), getHostNames(variables));
}
Aggregations