Search in sources :

Example 76 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class HostAttributeDecoratorTest method testAddHostAttributes.

@Test
public void testAddHostAttributes() {
    Blueprint blueprint = mock(Blueprint.class);
    when(stack.getCluster()).thenReturn(cluster);
    when(cluster.getBlueprint()).thenReturn(blueprint);
    when(stackUtil.collectNodes(any())).thenReturn(Set.of(new Node(null, null, null, null, "fqdn1", "hg1"), new Node(null, null, null, null, "fqdn2", "hg2"), new Node(null, null, null, null, "fqdn3", "hg3"), new Node(null, null, null, null, "fqdn4", null)));
    when(blueprint.getBlueprintText()).thenReturn("");
    Map<String, Map<String, ServiceAttributes>> yarnAttrs = new HashMap<>();
    yarnAttrs.put("hg3", Collections.singletonMap(YarnRoles.YARN, new ServiceAttributes(ServiceComponent.of(YarnRoles.YARN, YarnRoles.NODEMANAGER), Collections.singletonMap(YarnConstants.ATTRIBUTE_NAME_NODE_INSTANCE_TYPE, YarnConstants.ATTRIBUTE_NODE_INSTANCE_TYPE_COMPUTE))));
    CmTemplateProcessor blueprintTextProcessor = mock(CmTemplateProcessor.class);
    when(blueprintTextProcessor.getHostGroupBasedServiceAttributes(any())).thenReturn(yarnAttrs);
    when(cmTemplateProcessorFactory.get(any(String.class))).thenReturn(blueprintTextProcessor);
    Map<String, SaltPillarProperties> result = underTest.createHostAttributePillars(stack);
    SaltPillarProperties resultPillar = result.get("hostattrs");
    assertEquals("/nodes/hostattrs.sls", resultPillar.getPath());
    Map<String, Object> props = resultPillar.getProperties();
    Map<String, Object> values = (Map<String, Object>) props.get("hostattrs");
    assertEquals(4, values.size());
    assertNotNull(values.get("fqdn1"));
    assertNotNull(values.get("fqdn2"));
    assertNotNull(values.get("fqdn3"));
    assertNotNull(values.get("fqdn4"));
    Map<String, Object> nodeValue;
    Map<String, Map<String, String>> attrs = null;
    nodeValue = (Map<String, Object>) values.get("fqdn1");
    assertEquals(2, nodeValue.size());
    assertEquals("hg1", nodeValue.get("hostGroup"));
    attrs = (Map<String, Map<String, String>>) nodeValue.get("attributes");
    assertEquals(0, attrs.size());
    nodeValue = (Map<String, Object>) values.get("fqdn2");
    assertEquals(2, nodeValue.size());
    assertEquals("hg2", nodeValue.get("hostGroup"));
    attrs = (Map<String, Map<String, String>>) nodeValue.get("attributes");
    assertEquals(0, attrs.size());
    nodeValue = (Map<String, Object>) values.get("fqdn3");
    assertEquals(2, nodeValue.size());
    assertEquals("hg3", nodeValue.get("hostGroup"));
    attrs = (Map<String, Map<String, String>>) nodeValue.get("attributes");
    assertEquals(1, attrs.size());
    assertEquals(1, attrs.get(YarnRoles.YARN).size());
    assertEquals(YarnConstants.ATTRIBUTE_NAME_NODE_INSTANCE_TYPE, attrs.get(YarnRoles.YARN).entrySet().iterator().next().getKey());
    assertEquals(YarnConstants.ATTRIBUTE_NODE_INSTANCE_TYPE_COMPUTE, attrs.get(YarnRoles.YARN).entrySet().iterator().next().getValue());
    nodeValue = (Map<String, Object>) values.get("fqdn4");
    assertEquals(1, nodeValue.size());
    attrs = (Map<String, Map<String, String>>) nodeValue.get("attributes");
    assertEquals(0, attrs.size());
}
Also used : HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) ServiceAttributes(com.sequenceiq.cloudbreak.template.model.ServiceAttributes) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 77 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class ServiceEndpointCollector method getExposedServices.

/**
 * Get all exposed services for blueprint, there are filtered by visibility
 *
 * @param blueprintText given blueprintText
 * @return all visible exposed services for the given blueprint
 */
private Collection<ExposedService> getExposedServices(String blueprintText, List<String> entitlements) {
    CmTemplateProcessor processor = cmTemplateProcessorFactory.get(blueprintText);
    List<String> components = processor.getAllComponents().stream().map(ServiceComponent::getComponent).collect(Collectors.toList());
    return exposedServiceCollector.knoxServicesForComponents(processor.getVersion(), components).stream().filter(ExposedService::isVisible).filter(e -> serviceEndpointCollectorEntitlementComparator.entitlementSupported(entitlements, e.getEntitlement())).collect(Collectors.toList());
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ClusterExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CmTemplateProcessorFactory(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessorFactory) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) Service(org.springframework.stereotype.Service) Map(java.util.Map) ExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.ExposedServiceV4Response) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) ExposedServiceCollector(com.sequenceiq.cloudbreak.api.service.ExposedServiceCollector) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ClusterExposedServiceView(com.sequenceiq.cloudbreak.template.views.ClusterExposedServiceView) Logger(org.slf4j.Logger) YARN(com.sequenceiq.cloudbreak.common.type.OrchestratorConstants.YARN) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) ExposedService(com.sequenceiq.cloudbreak.api.service.ExposedService) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) GatewayTopologyV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.GatewayTopologyV4Response) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ServiceComponent(com.sequenceiq.cloudbreak.template.model.ServiceComponent) List(java.util.List) GatewayType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.GatewayType) Stream(java.util.stream.Stream) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) GatewayTopology(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.GatewayTopology) Optional(java.util.Optional) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) ExposedServices(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.ExposedServices) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) SSOType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.SSOType) ComponentLocatorService(com.sequenceiq.cloudbreak.service.blueprint.ComponentLocatorService) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) ExposedService(com.sequenceiq.cloudbreak.api.service.ExposedService) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)

Example 78 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class LoadBalancerConfigService method getOozieHAInstanceGroup.

private Optional<InstanceGroup> getOozieHAInstanceGroup(Stack stack) {
    Cluster cluster = stack.getCluster();
    if (cluster != null) {
        CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(cluster.getBlueprint().getBlueprintText());
        String cdhVersion = cmTemplateProcessor.getStackVersion();
        if (cdhVersion != null && isVersionNewerOrEqualThanLimited(cdhVersion, CLOUDERA_STACK_VERSION_7_2_11)) {
            Set<String> oozieGroupNames = getOozieGroups(cmTemplateProcessor);
            return stack.getInstanceGroups().stream().filter(ig -> oozieGroupNames.contains(ig.getGroupName())).filter(ig -> ig.getNodeCount() > 1).findFirst();
        }
    }
    return Optional.empty();
}
Also used : Arrays(java.util.Arrays) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) OozieRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.oozie.OozieRoles) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) ProviderParameterCalculator(com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SubnetSelector(com.sequenceiq.cloudbreak.converter.v4.environment.network.SubnetSelector) AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) Set(java.util.Set) LoadBalancerSku(com.sequenceiq.common.api.type.LoadBalancerSku) Collectors(java.util.stream.Collectors) KnoxRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.knox.KnoxRoles) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) Optional(java.util.Optional) GCP(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.GCP) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) CLOUDERA_STACK_VERSION_7_2_11(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERA_STACK_VERSION_7_2_11) OOZIE_HTTPS_PORT(com.sequenceiq.cloudbreak.cmtemplate.configproviders.oozie.OozieHAConfigProvider.OOZIE_HTTPS_PORT) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AWS(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AWS) Service(org.springframework.stereotype.Service) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) NetworkV4Base(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.NetworkV4Base) Map.entry(java.util.Map.entry) AzureInstanceGroupParameters(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceGroupParameters) LoadBalancerCreation(com.sequenceiq.common.api.type.LoadBalancerCreation) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) AvailabilitySetNameService(com.sequenceiq.cloudbreak.cloud.model.instance.AvailabilitySetNameService) TargetGroupType(com.sequenceiq.common.api.type.TargetGroupType) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) Preconditions(com.google.common.base.Preconditions) AZURE(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AZURE) Collections(java.util.Collections) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)

Example 79 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class ComponentLocatorService method getImpalaCoordinatorLocations.

public Map<String, List<String>> getImpalaCoordinatorLocations(Cluster cluster) {
    Map<String, List<String>> result = new HashMap<>();
    String blueprintText = cluster.getBlueprint().getBlueprintText();
    CmTemplateProcessor processor = cmTemplateProcessorFactory.get(blueprintText);
    for (HostGroup hg : hostGroupService.getByCluster(cluster.getId())) {
        Set<String> hgComponents = new HashSet<>(processor.getImpalaCoordinatorsInHostGroup(hg.getName()));
        fillList(result, hg, hgComponents);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) HashSet(java.util.HashSet)

Example 80 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class ClusterDiagnosticsService method getClusterComponents.

public List<String> getClusterComponents(String stackCrn) {
    List<String> components = new ArrayList<>();
    Stack stack = stackService.getByCrn(stackCrn);
    if (stack != null) {
        Cluster cluster = stack.getCluster();
        if (cluster != null && cluster.getBlueprint() != null) {
            CmTemplateProcessor cmTemplateProcessor = cmTemplateProcessorFactory.get(cluster.getBlueprint().getBlueprintText());
            components = cmTemplateProcessor.getAllComponents().stream().map(ServiceComponent::getComponent).collect(Collectors.toCollection(ArrayList::new));
        }
    }
    return components;
}
Also used : ServiceComponent(com.sequenceiq.cloudbreak.template.model.ServiceComponent) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

CmTemplateProcessor (com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)149 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)115 Test (org.junit.Test)84 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)75 List (java.util.List)46 ArrayList (java.util.ArrayList)33 Test (org.junit.jupiter.api.Test)19 HostgroupView (com.sequenceiq.cloudbreak.template.views.HostgroupView)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 BlueprintView (com.sequenceiq.cloudbreak.template.views.BlueprintView)13 HashSet (java.util.HashSet)12 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)10 Builder (com.sequenceiq.cloudbreak.template.TemplatePreparationObject.Builder)10 Set (java.util.Set)10 ApiClusterTemplateService (com.cloudera.api.swagger.model.ApiClusterTemplateService)9 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)8 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)8 Map (java.util.Map)8 BaseFileSystemConfigurationsView (com.sequenceiq.cloudbreak.template.filesystem.BaseFileSystemConfigurationsView)7 Collectors (java.util.stream.Collectors)7