Search in sources :

Example 31 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class ConfigureClusterManagerSupportTagsHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ConfigureClusterManagerSupportTagsRequest> event) {
    Long stackId = event.getData().getResourceId();
    Selectable response;
    try {
        clusterBuilderService.configureSupportTags(stackId);
        response = new ConfigureClusterManagerSupportTagsSuccess(stackId);
    } catch (RuntimeException e) {
        LOGGER.error("ConfigureClusterManagerSupportTagsHandler step failed with the following message: {}", e.getMessage());
        response = new ConfigureClusterManagerSupportTagsFailed(stackId, e);
    }
    return response;
}
Also used : ConfigureClusterManagerSupportTagsFailed(com.sequenceiq.cloudbreak.reactor.api.event.cluster.install.ConfigureClusterManagerSupportTagsFailed) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ConfigureClusterManagerSupportTagsSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.install.ConfigureClusterManagerSupportTagsSuccess)

Example 32 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class RegisterPublicDnsHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RegisterPublicDnsRequest> event) {
    RegisterPublicDnsRequest request = event.getData();
    Stack stack = request.getStack();
    if (gatewayPublicEndpointManagementService.isCertRenewalTriggerable(stack)) {
        try {
            LOGGER.debug("Fetching instance group and instance metadata for stack.");
            InstanceGroup instanceGroup = instanceGroupService.getPrimaryGatewayInstanceGroupByStackId(stack.getId());
            List<InstanceMetaData> instanceMetaData = instanceMetaDataService.findAliveInstancesInInstanceGroup(instanceGroup.getId());
            if (!instanceMetaData.isEmpty()) {
                stack.getInstanceGroups().stream().filter(ig -> ig.getId().equals(instanceGroup.getId())).forEach(ig -> ig.setInstanceMetaData(Set.copyOf(instanceMetaData)));
                LOGGER.debug("Registering load balancer public DNS entry");
                boolean success = clusterPublicEndpointManagementService.provisionLoadBalancer(stack);
                if (!success) {
                    throw new CloudbreakException("Public DNS registration resulted in failed state. Please consult DNS registration logs.");
                }
                LOGGER.debug("Load balancer public DNS registration was successful");
                return new RegisterPublicDnsSuccess(stack);
            } else {
                throw new CloudbreakException("Unable to find instance metadata for primary instance group. Certificates cannot " + "be updated.");
            }
        } catch (Exception e) {
            LOGGER.warn("Failed to register load balancer public DNS entries.", e);
            return new RegisterPublicDnsFailure(request.getResourceId(), e);
        }
    } else {
        LOGGER.info("Certificates and DNS are not managed by PEM for stack {}. Skipping public DNS registration.", stack.getName());
        return new RegisterPublicDnsSuccess(stack);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Logger(org.slf4j.Logger) RegisterPublicDnsRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsRequest) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) RegisterPublicDnsSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsSuccess) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) GatewayPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.GatewayPublicEndpointManagementService) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) Event(reactor.bus.Event) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) RegisterPublicDnsFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsFailure) RegisterPublicDnsRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsRequest) RegisterPublicDnsSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsSuccess) RegisterPublicDnsFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsFailure) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 33 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class CreateCloudLoadBalancersHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<CreateCloudLoadBalancersRequest> event) {
    CreateCloudLoadBalancersRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        LOGGER.info("Updating cloud stack with load balancer network information");
        CloudStack origCloudStack = request.getCloudStack();
        Stack stack = request.getStack();
        CloudStack updatedCloudStack = new CloudStack(origCloudStack.getGroups(), cloudStackConverter.buildNetwork(stack), origCloudStack.getImage(), origCloudStack.getParameters(), origCloudStack.getTags(), origCloudStack.getTemplate(), origCloudStack.getInstanceAuthentication(), origCloudStack.getLoginUserName(), origCloudStack.getPublicKey(), origCloudStack.getFileSystem().orElse(null), origCloudStack.getLoadBalancers());
        CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        LOGGER.debug("Initiating cloud load balancer creation");
        List<CloudResourceStatus> resourceStatus = connector.resources().launchLoadBalancers(ac, updatedCloudStack, persistenceNotifier);
        LOGGER.debug("Waiting for cloud load balancers to be fully created");
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            syncPollingScheduler.schedule(task);
        }
        if (resourceStatus.stream().anyMatch(CloudResourceStatus::isFailed)) {
            Set<String> names = resourceStatus.stream().filter(CloudResourceStatus::isFailed).map(r -> r.getCloudResource().getName()).collect(Collectors.toSet());
            throw new CloudbreakException("Creation failed for load balancers: " + names);
        }
        Set<String> types = updatedCloudStack.getLoadBalancers().stream().map(CloudLoadBalancer::getType).map(LoadBalancerType::toString).collect(Collectors.toSet());
        LOGGER.info("Cloud load balancer creation for load balancer types {} successful", types);
        return new CreateCloudLoadBalancersSuccess(stack);
    } catch (Exception e) {
        LOGGER.warn("Failed to created cloud load balance resources.", e);
        return new CreateCloudLoadBalancersFailure(request.getResourceId(), e);
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceLists(com.sequenceiq.cloudbreak.cloud.transform.ResourceLists) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Event(reactor.bus.Event) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) PollTask(com.sequenceiq.cloudbreak.cloud.task.PollTask) CreateCloudLoadBalancersSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersSuccess) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PollTaskFactory(com.sequenceiq.cloudbreak.cloud.task.PollTaskFactory) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourcesStatePollerResults(com.sequenceiq.cloudbreak.cloud.transform.ResourcesStatePollerResults) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) CreateCloudLoadBalancersFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersFailure) Collectors(java.util.stream.Collectors) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Component(org.springframework.stereotype.Component) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) SyncPollingScheduler(com.sequenceiq.cloudbreak.cloud.scheduler.SyncPollingScheduler) CreateCloudLoadBalancersRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreateCloudLoadBalancersRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersRequest) CreateCloudLoadBalancersFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersFailure) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CreateCloudLoadBalancersSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersSuccess) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 34 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class CreateLoadBalancerEntityHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<CreateLoadBalancerEntityRequest> event) {
    CreateLoadBalancerEntityRequest request = event.getData();
    Stack stack = stackService.getById(request.getResourceId());
    try {
        LOGGER.debug("Creating load balancer entity objects for stack {}", stack.getId());
        DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
        if (environment != null && environment.getNetwork() != null && PublicEndpointAccessGateway.ENABLED.equals(environment.getNetwork().getPublicEndpointAccessGateway())) {
            enableEndpointGateway(stack, environment);
        }
        Set<InstanceGroup> instanceGroups = instanceGroupService.getByStackAndFetchTemplates(stack.getId());
        instanceGroups.forEach(ig -> ig.setTargetGroups(targetGroupPersistenceService.findByInstanceGroupId(ig.getId())));
        Set<LoadBalancer> existingLoadBalancers = loadBalancerPersistenceService.findByStackId(stack.getId());
        stack.setInstanceGroups(instanceGroups);
        Set<LoadBalancer> newLoadBalancers = loadBalancerConfigService.createLoadBalancers(stack, environment, null);
        Stack savedStack;
        if (doLoadBalancersAlreadyExist(existingLoadBalancers, newLoadBalancers)) {
            LOGGER.debug("Load balancer entities already exist. Continuing flow.");
            savedStack = stack;
        } else {
            LOGGER.debug("Persisting stack and load balancer objects to database.");
            stack.setLoadBalancers(newLoadBalancers);
            String stackName = stack.getName();
            savedStack = measure(() -> stackService.save(stack), LOGGER, "Stackrepository save took {} ms for stack {}", stackName);
            measure(() -> loadBalancerPersistenceService.saveAll(newLoadBalancers), LOGGER, "Load balancers saved in {} ms for stack {}", stackName);
            measure(() -> targetGroupPersistenceService.saveAll(newLoadBalancers.stream().flatMap(lb -> lb.getTargetGroupSet().stream()).collect(Collectors.toSet())), LOGGER, "Target groups saved in {} ms for stack {}", stackName);
            measure(() -> instanceGroupService.saveAll(newLoadBalancers.stream().flatMap(lb -> lb.getAllInstanceGroups().stream()).collect(Collectors.toSet())), LOGGER, "Instance groups saved in {} ms for stack {}", stackName);
            if (stack.getNetwork() != null) {
                measure(() -> networkService.pureSave(stack.getNetwork()), LOGGER, "Network saved in {} ms for stack {}", stackName);
            }
        }
        LOGGER.debug("Load balancer entities successfully persisted.");
        savedStack.setInstanceGroups(newLoadBalancers.stream().flatMap(lb -> lb.getAllInstanceGroups().stream()).collect(Collectors.toSet()));
        savedStack.setNetwork(stack.getNetwork());
        return new CreateLoadBalancerEntitySuccess(request.getResourceId(), savedStack);
    } catch (Exception e) {
        LOGGER.warn("Failed create load balancer entities and persist them to the database.", e);
        return new CreateLoadBalancerEntityFailure(request.getResourceId(), e);
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CreateLoadBalancerEntityFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateLoadBalancerEntityFailure) CreateLoadBalancerEntitySuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateLoadBalancerEntitySuccess) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) LoadBalancerConfigService(com.sequenceiq.cloudbreak.service.LoadBalancerConfigService) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ENDPOINT_GATEWAY_SUBNET_ID(com.sequenceiq.cloudbreak.common.network.NetworkConstants.ENDPOINT_GATEWAY_SUBNET_ID) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) Inject(javax.inject.Inject) SUBNET_ID(com.sequenceiq.cloudbreak.common.network.NetworkConstants.SUBNET_ID) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) Event(reactor.bus.Event) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) NetworkService(com.sequenceiq.cloudbreak.service.network.NetworkService) TargetGroupPersistenceService(com.sequenceiq.cloudbreak.service.stack.TargetGroupPersistenceService) CreateLoadBalancerEntityRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateLoadBalancerEntityRequest) SubnetSelector(com.sequenceiq.cloudbreak.converter.v4.environment.network.SubnetSelector) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) Collectors(java.util.stream.Collectors) Json(com.sequenceiq.cloudbreak.common.json.Json) Component(org.springframework.stereotype.Component) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Collections(java.util.Collections) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) CreateLoadBalancerEntityFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateLoadBalancerEntityFailure) CreateLoadBalancerEntityRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateLoadBalancerEntityRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) CreateLoadBalancerEntitySuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateLoadBalancerEntitySuccess)

Example 35 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class ClusterManagerUpgradeHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterManagerUpgradeRequest> event) {
    LOGGER.debug("Accepting Cluster Manager upgrade event..");
    ClusterManagerUpgradeRequest request = event.getData();
    Selectable result;
    try {
        clusterManagerUpgradeService.upgradeClusterManager(request.getResourceId(), request.isRuntimeServicesStartNeeded());
        result = new ClusterManagerUpgradeSuccess(request.getResourceId());
    } catch (Exception e) {
        LOGGER.info("Cluster Manager upgrade event failed", e);
        result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_MANAGER_UPGRADE_FAILED);
    }
    return result;
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ClusterManagerUpgradeRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterManagerUpgradeRequest) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) ClusterManagerUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterManagerUpgradeSuccess)

Aggregations

Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)283 Test (org.junit.jupiter.api.Test)93 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)48 Map (java.util.Map)47 List (java.util.List)36 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)35 Collectors (java.util.stream.Collectors)35 PollerException (com.dyngr.exception.PollerException)32 PollerStoppedException (com.dyngr.exception.PollerStoppedException)32 UserBreakException (com.dyngr.exception.UserBreakException)32 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)30 Optional (java.util.Optional)30 Set (java.util.Set)30 Bean (org.springframework.context.annotation.Bean)28 Event (reactor.bus.Event)28 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)27 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)27 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)27 Inject (javax.inject.Inject)24 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)23