Search in sources :

Example 26 with CloudContext

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;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Instance(com.google.api.services.compute.model.Instance) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Compute(com.google.api.services.compute.Compute) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) IOException(java.io.IOException) AccessConfig(com.google.api.services.compute.model.AccessConfig)

Example 27 with CloudContext

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();
    }
}
Also used : State(org.openstack4j.model.network.State) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)

Example 28 with CloudContext

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));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) DownscaleStackCollectResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DownscaleStackCollectResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)

Example 29 with CloudContext

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());
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) CloudPlatformRequest(com.sequenceiq.cloudbreak.cloud.event.CloudPlatformRequest) Before(org.aspectj.lang.annotation.Before)

Example 30 with CloudContext

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));
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)100 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)43 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)34 Test (org.junit.Test)34 Group (com.sequenceiq.cloudbreak.cloud.model.Group)33 HashMap (java.util.HashMap)33 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)32 Location (com.sequenceiq.cloudbreak.cloud.model.Location)31 Network (com.sequenceiq.cloudbreak.cloud.model.Network)31 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)31 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)25 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)19 Matchers.containsString (org.hamcrest.Matchers.containsString)18 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)16 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)15 ArrayList (java.util.ArrayList)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14