Search in sources :

Example 11 with BlueprintTextProcessor

use of com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor in project cloudbreak by hortonworks.

the class CloudStorageConfigDetails method queryParameters.

public Set<ConfigQueryEntry> queryParameters(BlueprintTextProcessor blueprintTextProcessor, ConfigQueryEntries configQueryEntries, FileSystemConfigQueryObject request) {
    Set<ConfigQueryEntry> filtered = new HashSet<>();
    Map<String, Set<String>> componentsByHostGroup = blueprintTextProcessor.getComponentsByHostGroup();
    boolean attachedCluster = request.isAttachedCluster();
    for (Map.Entry<String, Set<String>> serviceHostgroupEntry : componentsByHostGroup.entrySet()) {
        for (String service : serviceHostgroupEntry.getValue()) {
            Set<ConfigQueryEntry> collectedEntries = configQueryEntries.getEntries().stream().filter(configQueryEntry -> configQueryEntry.getRelatedServices().stream().anyMatch(relatedService -> relatedService.equalsIgnoreCase(service))).filter(configQueryEntry -> {
                if ((configQueryEntry.isRequiredForAttachedCluster() && attachedCluster) || !attachedCluster) {
                    return true;
                }
                return false;
            }).filter(configQueryEntry -> configQueryEntry.getSupportedStorages().contains(request.getFileSystemType().toUpperCase())).collect(Collectors.toSet());
            filtered.addAll(collectedEntries);
        }
    }
    Set<ConfigQueryEntry> collectedEntries = configQueryEntries.getEntries().stream().filter(configQueryEntry -> blueprintDoesNotContainActual(configQueryEntry.getRelatedMissingServices(), componentsByHostGroup)).collect(Collectors.toSet());
    filtered.addAll(collectedEntries);
    String fileSystemTypeRequest = request.getFileSystemType();
    FileSystemType fileSystemType = FileSystemType.valueOf(fileSystemTypeRequest);
    String protocol = fileSystemType.getProtocol();
    Map<String, Object> templateObject = getTemplateObject(request, protocol);
    for (ConfigQueryEntry configQueryEntry : filtered) {
        try {
            boolean secure = request.isSecure();
            configQueryEntry.setProtocol(secure ? protocol + "s" : protocol);
            configQueryEntry.setSecure(secure);
            configQueryEntry.setDefaultPath(generateConfigWithParameters(configQueryEntry.getDefaultPath(), fileSystemType, templateObject));
        } catch (IOException e) {
        }
    }
    filtered = filtered.stream().sorted(Comparator.comparing(ConfigQueryEntry::getPropertyName)).collect(Collectors.toCollection(LinkedHashSet::new));
    return filtered;
}
Also used : Logger(org.slf4j.Logger) HandlebarTemplate(com.sequenceiq.cloudbreak.handlebar.HandlebarTemplate) ConfigQueryEntries(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntries) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) Service(org.springframework.stereotype.Service) Map(java.util.Map) FileSystemType(com.sequenceiq.common.model.FileSystemType) ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) HandlebarUtils(com.sequenceiq.cloudbreak.handlebar.HandlebarUtils) Handlebars(com.github.jknack.handlebars.Handlebars) Comparator(java.util.Comparator) LinkedHashSet(java.util.LinkedHashSet) Template(com.github.jknack.handlebars.Template) LinkedHashSet(java.util.LinkedHashSet) ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) IOException(java.io.IOException) FileSystemType(com.sequenceiq.common.model.FileSystemType) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with BlueprintTextProcessor

use of com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor in project cloudbreak by hortonworks.

the class StackScaleV4RequestToUpdateClusterV4RequestConverter method convert.

public UpdateClusterV4Request convert(StackScaleV4Request source) {
    try {
        return transactionService.required(() -> {
            UpdateClusterV4Request updateStackJson = new UpdateClusterV4Request();
            Stack stack = stackService.getByIdWithListsInTransaction(source.getStackId());
            stack.getInstanceGroups().stream().filter(instanceGroup -> source.getGroup().equals(instanceGroup.getGroupName())).findFirst().ifPresentOrElse(instanceGroup -> {
                String blueprintText = stack.getCluster().getBlueprint().getBlueprintText();
                BlueprintTextProcessor blueprintTextProcessor = clusterDefinitionTextProcessorFactory.createBlueprintTextProcessor(blueprintText);
                boolean dataNodeComponentInHostGroup = blueprintTextProcessor.isComponentExistsInHostGroup("DATANODE", instanceGroup.getGroupName());
                HostGroupAdjustmentV4Request hostGroupAdjustmentJson = new HostGroupAdjustmentV4Request();
                hostGroupAdjustmentJson.setWithStackUpdate(true);
                hostGroupAdjustmentJson.setValidateNodeCount(dataNodeComponentInHostGroup);
                hostGroupAdjustmentJson.setHostGroup(source.getGroup());
                hostGroupAdjustmentJson.setForced(source.getForced());
                int scaleNumber = source.getDesiredCount() - instanceGroup.getNotTerminatedInstanceMetaDataSet().size();
                hostGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
                updateStackJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
            }, () -> {
                throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
            });
            return updateStackJson;
        });
    } catch (TransactionExecutionException e) {
        throw e.getCause();
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 13 with BlueprintTextProcessor

use of com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor in project cloudbreak by hortonworks.

the class ComponentLocatorServiceTest method testGetComponentLocation.

@Test
void testGetComponentLocation() {
    HostGroup master1 = new HostGroup();
    master1.setName(MASTER_1);
    InstanceGroup ig1 = new InstanceGroup();
    InstanceMetaData imd1 = new InstanceMetaData();
    imd1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    imd1.setDiscoveryFQDN(MASTER1_FQDN);
    ig1.setInstanceMetaData(Set.of(imd1));
    master1.setInstanceGroup(ig1);
    HostGroup master2 = new HostGroup();
    master2.setName(MASTER_2);
    InstanceGroup ig2 = new InstanceGroup();
    InstanceMetaData imd2 = new InstanceMetaData();
    imd2.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    imd2.setDiscoveryFQDN(MASTER2_FQDN);
    ig2.setInstanceMetaData(Set.of(imd2));
    master2.setInstanceGroup(ig2);
    HostGroup master3 = new HostGroup();
    master3.setName(MASTER_3);
    InstanceGroup ig3 = new InstanceGroup();
    InstanceMetaData imd3 = new InstanceMetaData();
    imd3.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    imd3.setDiscoveryFQDN(MASTER3_FQDN);
    ig3.setInstanceMetaData(Set.of(imd3));
    master3.setInstanceGroup(ig3);
    HostGroup executor = new HostGroup();
    executor.setName(EXECUTOR);
    InstanceGroup ig4 = new InstanceGroup();
    Set<InstanceMetaData> imd4 = EXECUTOR_FQDNS.stream().map(fqdn -> {
        InstanceMetaData imd = new InstanceMetaData();
        imd.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
        imd.setDiscoveryFQDN(fqdn);
        return imd;
    }).collect(Collectors.toSet());
    ig4.setInstanceMetaData(imd4);
    executor.setInstanceGroup(ig4);
    HostGroup coordinator = new HostGroup();
    coordinator.setName(COORDINATOR);
    InstanceGroup ig5 = new InstanceGroup();
    Set<InstanceMetaData> imd5 = COORDINATOR_FQDNS.stream().map(fqdn -> {
        InstanceMetaData imd = new InstanceMetaData();
        imd.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
        imd.setDiscoveryFQDN(fqdn);
        return imd;
    }).collect(Collectors.toSet());
    ig5.setInstanceMetaData(imd5);
    coordinator.setInstanceGroup(ig5);
    Set<HostGroup> hostGroups = new LinkedHashSet<>(List.of(master1, master2, master3, executor, coordinator));
    when(blueprintTextProcessor.getComponentsInHostGroup(MASTER_1)).thenReturn(MASTER1_COMPONENTS);
    when(blueprintTextProcessor.getComponentsInHostGroup(MASTER_2)).thenReturn(MASTER2_COMPONENTS);
    when(blueprintTextProcessor.getComponentsInHostGroup(MASTER_3)).thenReturn(MASTER3_COMPONENTS);
    when(blueprintTextProcessor.getComponentsInHostGroup(EXECUTOR)).thenReturn(EXECUTOR_COMPONENTS);
    when(blueprintTextProcessor.getComponentsInHostGroup(COORDINATOR)).thenReturn(COORDINATOR_COMPONENTS);
    when(hostGroupService.getByCluster(CLUSTER_ID)).thenReturn(hostGroups);
    Map<String, List<String>> result = underTest.getComponentLocation(CLUSTER_ID, blueprintTextProcessor, COMPONENT_NAMES);
    assertEquals(1, result.get(NAMENODE).size());
    assertEquals(MASTER1_FQDN, result.get(NAMENODE).get(0));
    assertEquals(3, result.get(KUDU_MASTER).size());
    assertEquals(1, result.get(SPARK_YARN_HISTORY_SERVER).size());
    assertEquals(6, result.size());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) Mockito.when(org.mockito.Mockito.when) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) List(java.util.List) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 14 with BlueprintTextProcessor

use of com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor in project cloudbreak by hortonworks.

the class ServiceEndpointCollector method prepareClusterExposedServices.

public Map<String, Collection<ClusterExposedServiceV4Response>> prepareClusterExposedServices(Cluster cluster, String managerIp) {
    String blueprintText = getBlueprintString(cluster);
    Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServiceMap = new HashMap<>();
    if (!Strings.isNullOrEmpty(blueprintText)) {
        BlueprintTextProcessor processor = cmTemplateProcessorFactory.get(blueprintText);
        Collection<ExposedService> knownExposedServices = getExposedServices(blueprintText, entitlementService.getEntitlements(cluster.getWorkspace().getTenant().getName()));
        Gateway gateway = cluster.getGateway();
        Optional<String> version = Optional.ofNullable(cluster.getBlueprint()).map(Blueprint::getStackVersion);
        Map<String, List<String>> privateIps = componentLocatorService.getComponentLocation(cluster.getId(), processor, knownExposedServices.stream().map(ExposedService::getServiceName).collect(Collectors.toSet()));
        LOGGER.debug("The private IPs in the cluster {}", privateIps);
        if (privateIps.containsKey(exposedServiceCollector.getImpalaService().getServiceName())) {
            setImpalaDebugUIToCoordinator(cluster, privateIps);
        }
        if (gateway != null) {
            for (GatewayTopology gatewayTopology : gateway.getTopologies()) {
                generateGatewayTopology(cluster, managerIp, clusterExposedServiceMap, knownExposedServices, gateway, privateIps, gatewayTopology, version);
            }
        }
    }
    return clusterExposedServiceMap;
}
Also used : HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) GatewayTopology(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.GatewayTopology) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) ExposedService(com.sequenceiq.cloudbreak.api.service.ExposedService) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with BlueprintTextProcessor

use of com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor in project cloudbreak by hortonworks.

the class BlueprintViewProvider method getBlueprintView.

public BlueprintView getBlueprintView(@Nonnull Blueprint blueprint) {
    String blueprintText = blueprint.getBlueprintText();
    BlueprintStackInfo blueprintStackInfo = stackInfoService.blueprintStackInfo(blueprintText);
    BlueprintTextProcessor processor = blueprintTextProcessorFactory.createBlueprintTextProcessor(blueprintText);
    return new BlueprintView(blueprintText, blueprintStackInfo.getVersion(), blueprintStackInfo.getType(), processor);
}
Also used : BlueprintStackInfo(com.sequenceiq.cloudbreak.template.model.BlueprintStackInfo) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) BlueprintView(com.sequenceiq.cloudbreak.template.views.BlueprintView)

Aggregations

BlueprintTextProcessor (com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor)22 BlueprintView (com.sequenceiq.cloudbreak.template.views.BlueprintView)13 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)12 GeneralClusterConfigs (com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs)11 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)7 Test (org.junit.jupiter.api.Test)7 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)6 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)6 DatalakeView (com.sequenceiq.cloudbreak.template.views.DatalakeView)6 VirtualGroupRequest (com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest)5 IdBroker (com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker)5 Gateway (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 GatewayTopology (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.GatewayTopology)3 AutoscaleRecommendation (com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation)2 ResizeRecommendation (com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation)2 ExposedServices (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.ExposedServices)2 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)2