DruidSinkBundleHintProvider extends AbstractBundleHintProvider { @Override public Map<String, Object> getHintsOnCluster(Cluster cluster, SecurityContext securityContext, Subject subject) { Map<String, Object> hintMap = new HashMap<>(); try { Service druid = environmentService.getServiceByName(cluster.getId(), Constants.Druid.SERVICE_NAME); if (druid == null) { throw new ServiceNotFoundException(Constants.Druid.SERVICE_NAME); } ServiceConfiguration commonRuntime = environmentService.getServiceConfigurationByName(druid.getId(), Constants.Druid.CONF_TYPE_COMMON_RUNTIME); if (commonRuntime == null) { throw new ServiceConfigurationNotFoundException(Constants.Druid.CONF_TYPE_COMMON_RUNTIME); } Map<String, String> configurationMap = commonRuntime.getConfigurationMap(); putToHintMapIfAvailable(configurationMap, hintMap, Constants.Druid.PROPERTY_KEY_ZK_SERVICE_HOSTS, FIELD_NAME_ZK_CONNECT); putToHintMapIfAvailable(configurationMap, hintMap, Constants.Druid.PROPERTY_KEY_INDEXING_SERVICE_NAME, FIELD_NAME_INDEX_SERVICE); putToHintMapIfAvailable(configurationMap, hintMap, Constants.Druid.PROPERTY_KEY_DISCOVERY_CURATOR_PATH, FIELD_NAME_DISCOVERY_PATH); if (!hintMap.containsKey(FIELD_NAME_INDEX_SERVICE)) { ServiceConfiguration druidOverload = environmentService.getServiceConfigurationByName(druid.getId(), Constants.Druid.CONF_TYPE_DRUID_OVERLOAD); if (druidOverload != null) { putToHintMapIfAvailable(druidOverload.getConfigurationMap(), hintMap, Constants.Druid.PROPERTY_KEY_SERVICE_NAME, FIELD_NAME_INDEX_SERVICE); } } } catch (ServiceNotFoundException e) { throw new IllegalStateException("Service " + Constants.Druid.SERVICE_NAME + " in cluster " + cluster.getName() + " not found but mapping information exists."); } catch (ServiceConfigurationNotFoundException e) { } catch (Exception e) { throw new RuntimeException(e); } return hintMap; }  @Override String getServiceName(); @Override Map<String, Object> getHintsOnCluster(Cluster cluster, SecurityContext securityContext, Subject subject); static final String FIELD_NAME_ZK_CONNECT; static final String FIELD_NAME_INDEX_SERVICE; static final String FIELD_NAME_DISCOVERY_PATH; }
@Test public void getHintsOnCluster() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); Cluster cluster = new Cluster(); cluster.setId(1L); cluster.setName("cluster1"); Service service = new Service(); service.setId(1L); service.setName(Constants.Druid.SERVICE_NAME); Map<String, String> confMap = new HashMap<>(); confMap.put(Constants.Druid.PROPERTY_KEY_ZK_SERVICE_HOSTS, "svr1:2181,svr2:2181"); confMap.put(Constants.Druid.PROPERTY_KEY_INDEXING_SERVICE_NAME, "druid/overlord"); confMap.put(Constants.Druid.PROPERTY_KEY_DISCOVERY_CURATOR_PATH, "/discovery"); ServiceConfiguration serviceConfiguration = new ServiceConfiguration(); serviceConfiguration.setId(1L); serviceConfiguration.setName(Constants.Druid.CONF_TYPE_COMMON_RUNTIME); serviceConfiguration.setConfiguration(objectMapper.writeValueAsString(confMap)); new Expectations() {{ environmentService.getServiceByName(cluster.getId(), Constants.Druid.SERVICE_NAME); result = service; environmentService.getServiceConfigurationByName(service.getId(), Constants.Druid.CONF_TYPE_COMMON_RUNTIME); result = serviceConfiguration; }}; provider.init(environmentService); Map<String, Object> hints = provider.getHintsOnCluster(cluster, null, null); Assert.assertNotNull(hints); Assert.assertEquals("svr1:2181,svr2:2181", hints.get(DruidSinkBundleHintProvider.FIELD_NAME_ZK_CONNECT)); Assert.assertEquals("druid/overlord", hints.get(DruidSinkBundleHintProvider.FIELD_NAME_INDEX_SERVICE)); Assert.assertEquals("/discovery", hints.get(DruidSinkBundleHintProvider.FIELD_NAME_DISCOVERY_PATH)); }