Search in sources :

Example 86 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack 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 87 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class ClusterUpgradeFailedCmSyncHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeFailedCmSyncRequest> event) {
    ClusterUpgradeFailedCmSyncRequest request = event.getData();
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        cmSyncerService.syncFromCmToDb(stack, request.getCandidateImages());
    } catch (Exception e) {
        LOGGER.warn("Error during syncing CM version to DB, syncing skipped.", e);
    }
    return new ClusterUpgradeFailHandledRequest(request.getResourceId(), request.getException(), request.getDetailedStatus());
}
Also used : ClusterUpgradeFailHandledRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest) ClusterUpgradeFailedCmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedCmSyncRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 88 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class ClusterUpgradeHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeRequest> event) {
    LOGGER.debug("Accepting Cluster upgrade event..");
    ClusterUpgradeRequest request = event.getData();
    Long stackId = request.getResourceId();
    Selectable result;
    try {
        Stack stack = stackService.getByIdWithClusterInTransaction(stackId);
        Optional<String> remoteDataContext = getRemoteDataContext(stack);
        ClusterApi connector = clusterApiConnectors.getConnector(stack);
        Set<ClusterComponent> components = parcelService.getParcelComponentsByBlueprint(stack);
        connector.upgradeClusterRuntime(components, request.isPatchUpgrade(), remoteDataContext);
        ParcelOperationStatus parcelOperationStatus = parcelService.removeUnusedParcelComponents(stack, components);
        if (parcelOperationStatus.getFailed().isEmpty()) {
            result = new ClusterUpgradeSuccess(request.getResourceId());
        } else {
            LOGGER.info("There are failed parcel removals: {}", parcelOperationStatus);
            CloudbreakException exception = new CloudbreakException(format("Failed to remove the following parcels: %s", parcelOperationStatus.getFailed()));
            result = new ClusterUpgradeFailedEvent(request.getResourceId(), exception, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
        }
    } catch (Exception e) {
        LOGGER.error("Cluster upgrade event failed", e);
        result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
    }
    return result;
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) ClusterUpgradeRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeRequest) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) ClusterUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeSuccess) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException)

Example 89 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class LdapSSOConfigurationHandler method accept.

@Override
public void accept(Event<LdapSSOConfigurationRequest> ldapConfigurationRequestEvent) {
    Long stackId = ldapConfigurationRequestEvent.getData().getResourceId();
    Selectable response;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(stackId);
        GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
        LdapView ldapView = ldapConfigService.get(stack.getEnvironmentCrn(), stack.getName()).orElse(null);
        String environmentCrnForVirtualGroups = environmentConfigProvider.getParentEnvironmentCrn(stack.getEnvironmentCrn());
        VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(environmentCrnForVirtualGroups, ldapView != null ? ldapView.getAdminGroup() : "");
        clusterApiConnectors.getConnector(stack).clusterSecurityService().setupLdapAndSSO(primaryGatewayConfig.getPublicAddress(), ldapView, virtualGroupRequest);
        response = new LdapSSOConfigurationSuccess(stackId);
    } catch (Exception e) {
        LOGGER.info("Error during LDAP configuration, stackId: " + stackId, e);
        response = new LdapSSOConfigurationFailed(stackId, e);
    }
    eventBus.notify(response.selector(), new Event<>(ldapConfigurationRequestEvent.getHeaders(), response));
}
Also used : LdapSSOConfigurationFailed(com.sequenceiq.cloudbreak.reactor.api.event.ldap.LdapSSOConfigurationFailed) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) VirtualGroupRequest(com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest) LdapView(com.sequenceiq.cloudbreak.dto.LdapView) LdapSSOConfigurationSuccess(com.sequenceiq.cloudbreak.reactor.api.event.ldap.LdapSSOConfigurationSuccess) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 90 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class ClouderaManagerClusterCreationSetupService method filterParcelsIfNecessary.

private Set<ClouderaManagerProduct> filterParcelsIfNecessary(Cluster cluster, Set<ClouderaManagerProduct> products) {
    Stack stack = cluster.getStack();
    if (stack.isDatalake()) {
        return Set.of(clouderaManagerProductsProvider.getCdhProducts(products));
    } else {
        LOGGER.info("Product list before filter out products by blueprint: {}", products);
        Set<ClouderaManagerProduct> filteredProducts = parcelFilterService.filterParcelsByBlueprint(stack.getId(), products, cluster.getBlueprint());
        LOGGER.info("Product list after filter out products by blueprint: {}", filteredProducts);
        return filteredProducts;
    }
}
Also used : ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1041 Test (org.junit.jupiter.api.Test)326 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)255 Test (org.junit.Test)208 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)158 Map (java.util.Map)114 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)113 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)112 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)111 List (java.util.List)101 Set (java.util.Set)101 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)100 Collectors (java.util.stream.Collectors)84 Optional (java.util.Optional)83 HashSet (java.util.HashSet)82 Inject (javax.inject.Inject)80 Logger (org.slf4j.Logger)78 LoggerFactory (org.slf4j.LoggerFactory)78 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)69 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)67