Search in sources :

Example 76 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method removeInstances.

public Set<String> removeInstances(Stack stack, Set<String> instanceIds, String instanceGroup) {
    LOGGER.debug("Assembling downscale stack event for stack: {}", 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());
    List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
    List<CloudInstance> instances = new ArrayList<>();
    InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(instanceGroup);
    for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
        if (instanceIds.contains(metaData.getInstanceId())) {
            CloudInstance cloudInstance = metadataConverter.convert(metaData);
            instances.add(cloudInstance);
        }
    }
    CloudStack cloudStack = cloudStackConverter.convertForDownscale(stack, instanceIds);
    DownscaleStackRequest downscaleRequest = new DownscaleStackRequest(cloudContext, cloudCredential, cloudStack, resources, instances);
    LOGGER.info("Triggering downscale stack event: {}", downscaleRequest);
    eventBus.notify(downscaleRequest.selector(), eventFactory.createEvent(downscaleRequest));
    try {
        DownscaleStackResult res = downscaleRequest.await();
        LOGGER.info("Downscale stack result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to downscale the stack", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return instanceIds;
    } catch (InterruptedException e) {
        LOGGER.error("Error while downscaling the stack", e);
        throw new OperationException(e);
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 77 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method checkAndGetPlatformVariant.

public Variant checkAndGetPlatformVariant(Stack stack) {
    LOGGER.debug("Get platform variant for: {}", 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());
    CheckPlatformVariantRequest checkPlatformVariantRequest = new CheckPlatformVariantRequest(cloudContext, cloudCredential);
    eventBus.notify(checkPlatformVariantRequest.selector(), eventFactory.createEvent(checkPlatformVariantRequest));
    try {
        CheckPlatformVariantResult res = checkPlatformVariantRequest.await();
        LOGGER.info("Platform variant result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to get platform variant", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return res.getDefaultPlatformVariant();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting the platform variant: " + cloudContext, e);
        throw new OperationException(e);
    }
}
Also used : CheckPlatformVariantRequest(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckPlatformVariantResult(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 78 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class ServiceProviderMetadataAdapter method getState.

public InstanceSyncState getState(Stack stack, InstanceGroup instanceGroup, String instanceId) {
    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());
    InstanceGroup ig = stack.getInstanceGroupByInstanceGroupName(instanceGroup.getGroupName());
    CloudInstance instance = null;
    for (InstanceMetaData metaData : ig.getAllInstanceMetaData()) {
        if (instanceId.equalsIgnoreCase(metaData.getInstanceId())) {
            instance = metadataConverter.convert(metaData);
            break;
        }
    }
    if (instance != null) {
        GetInstancesStateRequest<GetInstancesStateResult> stateRequest = new GetInstancesStateRequest<>(cloudContext, cloudCredential, Collections.singletonList(instance));
        LOGGER.info("Triggering event: {}", stateRequest);
        eventBus.notify(stateRequest.selector(), eventFactory.createEvent(stateRequest));
        try {
            GetInstancesStateResult res = stateRequest.await();
            LOGGER.info("Result: {}", res);
            if (res.isFailed()) {
                LOGGER.error("Failed to retrieve instance state", res.getErrorDetails());
                throw new OperationException(res.getErrorDetails());
            }
            return transform(res.getStatuses().get(0).getStatus());
        } catch (InterruptedException e) {
            LOGGER.error(format("Error while retrieving instance state of: %s", cloudContext), e);
            throw new OperationException(e);
        }
    } else {
        return InstanceSyncState.DELETED;
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) GetInstancesStateRequest(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) GetInstancesStateResult(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 79 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class DownscaleStackHandler method accept.

@Override
public void accept(Event<DownscaleStackRequest> downscaleStackRequestEvent) {
    LOGGER.info("Received event: {}", downscaleStackRequestEvent);
    DownscaleStackRequest request = downscaleStackRequestEvent.getData();
    DownscaleStackResult result;
    try {
        CloudContext cloudContext = request.getCloudContext();
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().downscale(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances(), request.getResourcesToScale());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        LOGGER.info("Downscale successfully finished for {}", cloudContext);
        result = new DownscaleStackResult(request, ResourceLists.transform(statePollerResult.getResults()));
    } catch (Exception e) {
        LOGGER.error("Failed to handle DownscaleStackRequest.", e);
        result = new DownscaleStackResult(e.getMessage(), e, request);
    }
    request.getResult().onNext(result);
    eventBus.notify(result.selector(), new Event<>(downscaleStackRequestEvent.getHeaders(), result));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 80 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class OpenStackRouterResourceBuilder method checkStatus.

@Override
protected boolean checkStatus(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) {
    CloudContext cloudContext = auth.getCloudContext();
    OSClient<?> osClient = createOSClient(auth);
    Router osRouter = osClient.networking().router().get(resource.getReference());
    if (osRouter != null && context.isBuild()) {
        State routerStatus = osRouter.getStatus();
        if (State.ERROR == routerStatus) {
            throw new OpenStackResourceException("Router in failed state", resource.getType(), utils.getStackName(auth), cloudContext.getId(), resource.getName());
        }
        return routerStatus == State.ACTIVE;
    } else {
        return osRouter == 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) Router(org.openstack4j.model.network.Router)

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