@Test public void testPrepareClusterExposedServices() { Cluster cluster = createClusterWithComponents(new ExposedService[]{exposedService("ATLAS")}, new ExposedService[]{exposedService("HIVE_SERVER"), exposedService("WEBHDFS")}, GatewayType.INDIVIDUAL); cluster.getGateway().setGatewayPort(443); mockBlueprintTextProcessor(); mockComponentLocator(Lists.newArrayList("10.0.0.1")); Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServicesMap = underTest.prepareClusterExposedServices(cluster, "10.0.0.1"); assertEquals(4L, clusterExposedServicesMap.keySet().size()); Collection<ClusterExposedServiceV4Response> topology2ClusterExposedServiceV4Responses = clusterExposedServicesMap.get("topology2"); Optional<ClusterExposedServiceV4Response> webHDFS = topology2ClusterExposedServiceV4Responses.stream().filter(service -> "WEBHDFS".equals(service.getKnoxService())).findFirst(); if (webHDFS.isPresent()) { assertEquals("https: assertEquals("WEBHDFS", webHDFS.get().getKnoxService()); assertEquals("WebHDFS", webHDFS.get().getDisplayName()); assertEquals("NAMENODE", webHDFS.get().getServiceName()); assertTrue(webHDFS.get().isOpen()); } Optional<ClusterExposedServiceV4Response> sparkHistoryUI = topology2ClusterExposedServiceV4Responses.stream().filter(service -> "SPARKHISTORYUI".equals(service.getKnoxService())).findFirst(); if (sparkHistoryUI.isPresent()) { assertEquals("https: assertEquals("SPARKHISTORYUI", sparkHistoryUI.get().getKnoxService()); assertEquals("Spark 1.x History Server", sparkHistoryUI.get().getDisplayName()); assertEquals("SPARK_YARN_HISTORY_SERVER", sparkHistoryUI.get().getServiceName()); assertFalse(sparkHistoryUI.get().isOpen()); } Optional<ClusterExposedServiceV4Response> hiveServer = topology2ClusterExposedServiceV4Responses.stream().filter(service -> "HIVE".equals(service.getKnoxService())).findFirst(); if (hiveServer.isPresent()) { assertEquals("jdbc:hive2: + "transportMode=http;httpPath=gateway-path/topology2/hive", hiveServer.get().getServiceUrl()); assertEquals("HIVE", hiveServer.get().getKnoxService()); assertEquals("Hive Server", hiveServer.get().getDisplayName()); assertEquals("HIVE_SERVER", hiveServer.get().getServiceName()); assertTrue(hiveServer.get().isOpen()); } }
public Map<String, Collection<ClusterExposedServiceV4Response>> prepareClusterExposedServices(Cluster cluster, String managerIp) { if (cluster.getBlueprint() != null) { String blueprintText = cluster.getBlueprint().getBlueprintText(); if (isNotEmpty(blueprintText)) { BlueprintTextProcessor processor = cmTemplateProcessorFactory.get(blueprintText); Collection<ExposedService> knownExposedServices = getExposedServices(cluster.getBlueprint()); Gateway gateway = cluster.getGateway(); Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServiceMap = new HashMap<>(); Map<String, List<String>> privateIps = componentLocatorService.getComponentLocation(cluster.getId(), processor, knownExposedServices.stream().map(ExposedService::getServiceName).collect(Collectors.toSet())); if (privateIps.containsKey(exposedServiceCollector.getImpalaService().getServiceName())) { setImpalaDebugUIToCoordinator(cluster, privateIps); } if (gateway != null) { for (GatewayTopology gatewayTopology : gateway.getTopologies()) { Set<String> exposedServicesInTopology = gateway.getTopologies().stream() .flatMap(this::getExposedServiceStream) .filter(Objects::nonNull) .collect(Collectors.toSet()); List<ClusterExposedServiceV4Response> uiServices = new ArrayList<>(); List<ClusterExposedServiceV4Response> apiServices = new ArrayList<>(); boolean autoTlsEnabled = cluster.getAutoTlsEnabled(); SecurityConfig securityConfig = cluster.getStack().getSecurityConfig(); String managerServerUrl = getManagerServerUrl(cluster, managerIp); for (ExposedService exposedService : knownExposedServices) { if (exposedService.isCmProxied()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createCmProxiedServiceEntries(exposedService, gateway, gatewayTopology, managerServerUrl, cluster.getName()); uiServices.addAll(uiServiceOnPrivateIps); } else { if (!exposedService.isApiOnly()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, false, autoTlsEnabled, securityConfig); uiServices.addAll(uiServiceOnPrivateIps); } if (exposedService.isApiIncluded()) { List<ClusterExposedServiceV4Response> apiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, true, autoTlsEnabled, securityConfig); apiServices.addAll(apiServiceOnPrivateIps); } } } clusterExposedServiceMap.put(gatewayTopology.getTopologyName(), uiServices); clusterExposedServiceMap.put(gatewayTopology.getTopologyName() + API_TOPOLOGY_POSTFIX, apiServices); } } return clusterExposedServiceMap; } } return Collections.emptyMap(); }
ServiceEndpointCollector { public Map<String, Collection<ClusterExposedServiceV4Response>> prepareClusterExposedServices(Cluster cluster, String managerIp) { if (cluster.getBlueprint() != null) { String blueprintText = cluster.getBlueprint().getBlueprintText(); if (isNotEmpty(blueprintText)) { BlueprintTextProcessor processor = cmTemplateProcessorFactory.get(blueprintText); Collection<ExposedService> knownExposedServices = getExposedServices(cluster.getBlueprint()); Gateway gateway = cluster.getGateway(); Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServiceMap = new HashMap<>(); Map<String, List<String>> privateIps = componentLocatorService.getComponentLocation(cluster.getId(), processor, knownExposedServices.stream().map(ExposedService::getServiceName).collect(Collectors.toSet())); if (privateIps.containsKey(exposedServiceCollector.getImpalaService().getServiceName())) { setImpalaDebugUIToCoordinator(cluster, privateIps); } if (gateway != null) { for (GatewayTopology gatewayTopology : gateway.getTopologies()) { Set<String> exposedServicesInTopology = gateway.getTopologies().stream() .flatMap(this::getExposedServiceStream) .filter(Objects::nonNull) .collect(Collectors.toSet()); List<ClusterExposedServiceV4Response> uiServices = new ArrayList<>(); List<ClusterExposedServiceV4Response> apiServices = new ArrayList<>(); boolean autoTlsEnabled = cluster.getAutoTlsEnabled(); SecurityConfig securityConfig = cluster.getStack().getSecurityConfig(); String managerServerUrl = getManagerServerUrl(cluster, managerIp); for (ExposedService exposedService : knownExposedServices) { if (exposedService.isCmProxied()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createCmProxiedServiceEntries(exposedService, gateway, gatewayTopology, managerServerUrl, cluster.getName()); uiServices.addAll(uiServiceOnPrivateIps); } else { if (!exposedService.isApiOnly()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, false, autoTlsEnabled, securityConfig); uiServices.addAll(uiServiceOnPrivateIps); } if (exposedService.isApiIncluded()) { List<ClusterExposedServiceV4Response> apiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, true, autoTlsEnabled, securityConfig); apiServices.addAll(apiServiceOnPrivateIps); } } } clusterExposedServiceMap.put(gatewayTopology.getTopologyName(), uiServices); clusterExposedServiceMap.put(gatewayTopology.getTopologyName() + API_TOPOLOGY_POSTFIX, apiServices); } } return clusterExposedServiceMap; } } return Collections.emptyMap(); } }
ServiceEndpointCollector { public Map<String, Collection<ClusterExposedServiceV4Response>> prepareClusterExposedServices(Cluster cluster, String managerIp) { if (cluster.getBlueprint() != null) { String blueprintText = cluster.getBlueprint().getBlueprintText(); if (isNotEmpty(blueprintText)) { BlueprintTextProcessor processor = cmTemplateProcessorFactory.get(blueprintText); Collection<ExposedService> knownExposedServices = getExposedServices(cluster.getBlueprint()); Gateway gateway = cluster.getGateway(); Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServiceMap = new HashMap<>(); Map<String, List<String>> privateIps = componentLocatorService.getComponentLocation(cluster.getId(), processor, knownExposedServices.stream().map(ExposedService::getServiceName).collect(Collectors.toSet())); if (privateIps.containsKey(exposedServiceCollector.getImpalaService().getServiceName())) { setImpalaDebugUIToCoordinator(cluster, privateIps); } if (gateway != null) { for (GatewayTopology gatewayTopology : gateway.getTopologies()) { Set<String> exposedServicesInTopology = gateway.getTopologies().stream() .flatMap(this::getExposedServiceStream) .filter(Objects::nonNull) .collect(Collectors.toSet()); List<ClusterExposedServiceV4Response> uiServices = new ArrayList<>(); List<ClusterExposedServiceV4Response> apiServices = new ArrayList<>(); boolean autoTlsEnabled = cluster.getAutoTlsEnabled(); SecurityConfig securityConfig = cluster.getStack().getSecurityConfig(); String managerServerUrl = getManagerServerUrl(cluster, managerIp); for (ExposedService exposedService : knownExposedServices) { if (exposedService.isCmProxied()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createCmProxiedServiceEntries(exposedService, gateway, gatewayTopology, managerServerUrl, cluster.getName()); uiServices.addAll(uiServiceOnPrivateIps); } else { if (!exposedService.isApiOnly()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, false, autoTlsEnabled, securityConfig); uiServices.addAll(uiServiceOnPrivateIps); } if (exposedService.isApiIncluded()) { List<ClusterExposedServiceV4Response> apiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, true, autoTlsEnabled, securityConfig); apiServices.addAll(apiServiceOnPrivateIps); } } } clusterExposedServiceMap.put(gatewayTopology.getTopologyName(), uiServices); clusterExposedServiceMap.put(gatewayTopology.getTopologyName() + API_TOPOLOGY_POSTFIX, apiServices); } } return clusterExposedServiceMap; } } return Collections.emptyMap(); }  }
ServiceEndpointCollector { public Map<String, Collection<ClusterExposedServiceV4Response>> prepareClusterExposedServices(Cluster cluster, String managerIp) { if (cluster.getBlueprint() != null) { String blueprintText = cluster.getBlueprint().getBlueprintText(); if (isNotEmpty(blueprintText)) { BlueprintTextProcessor processor = cmTemplateProcessorFactory.get(blueprintText); Collection<ExposedService> knownExposedServices = getExposedServices(cluster.getBlueprint()); Gateway gateway = cluster.getGateway(); Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServiceMap = new HashMap<>(); Map<String, List<String>> privateIps = componentLocatorService.getComponentLocation(cluster.getId(), processor, knownExposedServices.stream().map(ExposedService::getServiceName).collect(Collectors.toSet())); if (privateIps.containsKey(exposedServiceCollector.getImpalaService().getServiceName())) { setImpalaDebugUIToCoordinator(cluster, privateIps); } if (gateway != null) { for (GatewayTopology gatewayTopology : gateway.getTopologies()) { Set<String> exposedServicesInTopology = gateway.getTopologies().stream() .flatMap(this::getExposedServiceStream) .filter(Objects::nonNull) .collect(Collectors.toSet()); List<ClusterExposedServiceV4Response> uiServices = new ArrayList<>(); List<ClusterExposedServiceV4Response> apiServices = new ArrayList<>(); boolean autoTlsEnabled = cluster.getAutoTlsEnabled(); SecurityConfig securityConfig = cluster.getStack().getSecurityConfig(); String managerServerUrl = getManagerServerUrl(cluster, managerIp); for (ExposedService exposedService : knownExposedServices) { if (exposedService.isCmProxied()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createCmProxiedServiceEntries(exposedService, gateway, gatewayTopology, managerServerUrl, cluster.getName()); uiServices.addAll(uiServiceOnPrivateIps); } else { if (!exposedService.isApiOnly()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, false, autoTlsEnabled, securityConfig); uiServices.addAll(uiServiceOnPrivateIps); } if (exposedService.isApiIncluded()) { List<ClusterExposedServiceV4Response> apiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, true, autoTlsEnabled, securityConfig); apiServices.addAll(apiServiceOnPrivateIps); } } } clusterExposedServiceMap.put(gatewayTopology.getTopologyName(), uiServices); clusterExposedServiceMap.put(gatewayTopology.getTopologyName() + API_TOPOLOGY_POSTFIX, apiServices); } } return clusterExposedServiceMap; } } return Collections.emptyMap(); }  Collection<ExposedServiceV4Response> getKnoxServices(Long workspaceId, String blueprintName); String getManagerServerUrl(Cluster cluster, String managerIp); Map<String, Collection<ClusterExposedServiceV4Response>> prepareClusterExposedServices(Cluster cluster, String managerIp); Map<String, Collection<ClusterExposedServiceView>> prepareClusterExposedServicesViews(Cluster cluster, String managerIp); List<GatewayTopologyV4Response> filterByStackType(StackType stackType, List<GatewayTopologyV4Response> topologies); }
ServiceEndpointCollector { public Map<String, Collection<ClusterExposedServiceV4Response>> prepareClusterExposedServices(Cluster cluster, String managerIp) { if (cluster.getBlueprint() != null) { String blueprintText = cluster.getBlueprint().getBlueprintText(); if (isNotEmpty(blueprintText)) { BlueprintTextProcessor processor = cmTemplateProcessorFactory.get(blueprintText); Collection<ExposedService> knownExposedServices = getExposedServices(cluster.getBlueprint()); Gateway gateway = cluster.getGateway(); Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServiceMap = new HashMap<>(); Map<String, List<String>> privateIps = componentLocatorService.getComponentLocation(cluster.getId(), processor, knownExposedServices.stream().map(ExposedService::getServiceName).collect(Collectors.toSet())); if (privateIps.containsKey(exposedServiceCollector.getImpalaService().getServiceName())) { setImpalaDebugUIToCoordinator(cluster, privateIps); } if (gateway != null) { for (GatewayTopology gatewayTopology : gateway.getTopologies()) { Set<String> exposedServicesInTopology = gateway.getTopologies().stream() .flatMap(this::getExposedServiceStream) .filter(Objects::nonNull) .collect(Collectors.toSet()); List<ClusterExposedServiceV4Response> uiServices = new ArrayList<>(); List<ClusterExposedServiceV4Response> apiServices = new ArrayList<>(); boolean autoTlsEnabled = cluster.getAutoTlsEnabled(); SecurityConfig securityConfig = cluster.getStack().getSecurityConfig(); String managerServerUrl = getManagerServerUrl(cluster, managerIp); for (ExposedService exposedService : knownExposedServices) { if (exposedService.isCmProxied()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createCmProxiedServiceEntries(exposedService, gateway, gatewayTopology, managerServerUrl, cluster.getName()); uiServices.addAll(uiServiceOnPrivateIps); } else { if (!exposedService.isApiOnly()) { List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, false, autoTlsEnabled, securityConfig); uiServices.addAll(uiServiceOnPrivateIps); } if (exposedService.isApiIncluded()) { List<ClusterExposedServiceV4Response> apiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, true, autoTlsEnabled, securityConfig); apiServices.addAll(apiServiceOnPrivateIps); } } } clusterExposedServiceMap.put(gatewayTopology.getTopologyName(), uiServices); clusterExposedServiceMap.put(gatewayTopology.getTopologyName() + API_TOPOLOGY_POSTFIX, apiServices); } } return clusterExposedServiceMap; } } return Collections.emptyMap(); }  Collection<ExposedServiceV4Response> getKnoxServices(Long workspaceId, String blueprintName); String getManagerServerUrl(Cluster cluster, String managerIp); Map<String, Collection<ClusterExposedServiceV4Response>> prepareClusterExposedServices(Cluster cluster, String managerIp); Map<String, Collection<ClusterExposedServiceView>> prepareClusterExposedServicesViews(Cluster cluster, String managerIp); List<GatewayTopologyV4Response> filterByStackType(StackType stackType, List<GatewayTopologyV4Response> topologies);  }