@Test public void testClustersNames() { ClustersNames clustersNames = ClustersNames.getInstance(); Assert.assertEquals(clustersNames.getClusterName("http: "cluster1"); Assert.assertEquals(clustersNames.getClusterName("http: "cluster2"); Assert.assertEquals(clustersNames.getClusterName("cluster1-rm.some.company.com"), "cluster1-rm.some.company.com"); Assert.assertEquals(clustersNames.getClusterName("http: "cluster3-rm.some.company.com"); Assert.assertEquals(clustersNames.getClusterName("file: "file"); Assert.assertEquals(clustersNames.getClusterName("uri:fancy-uri"), "uri_fancy-uri"); }
protected ClustersNames() { try (Closer closer = Closer.create()) { InputStream propsInput = closer.register(getClass().getResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); if (null == propsInput) { propsInput = closer.register(ClassLoader.getSystemResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); } if (null != propsInput) { try { this.urlToNameMap.load(propsInput); LOG.info("Loaded cluster names map:" + this.urlToNameMap); } catch (IOException e) { LOG.warn("Unable to load cluster names map: " + e, e); } } else { LOG.info("no default cluster mapping found"); } } catch (IOException e) { LOG.warn("unable to close resource input stream for " + URL_TO_NAME_MAP_RESOURCE_NAME + ":" + e, e); } }
ClustersNames { protected ClustersNames() { try (Closer closer = Closer.create()) { InputStream propsInput = closer.register(getClass().getResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); if (null == propsInput) { propsInput = closer.register(ClassLoader.getSystemResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); } if (null != propsInput) { try { this.urlToNameMap.load(propsInput); LOG.info("Loaded cluster names map:" + this.urlToNameMap); } catch (IOException e) { LOG.warn("Unable to load cluster names map: " + e, e); } } else { LOG.info("no default cluster mapping found"); } } catch (IOException e) { LOG.warn("unable to close resource input stream for " + URL_TO_NAME_MAP_RESOURCE_NAME + ":" + e, e); } } }
ClustersNames { protected ClustersNames() { try (Closer closer = Closer.create()) { InputStream propsInput = closer.register(getClass().getResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); if (null == propsInput) { propsInput = closer.register(ClassLoader.getSystemResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); } if (null != propsInput) { try { this.urlToNameMap.load(propsInput); LOG.info("Loaded cluster names map:" + this.urlToNameMap); } catch (IOException e) { LOG.warn("Unable to load cluster names map: " + e, e); } } else { LOG.info("no default cluster mapping found"); } } catch (IOException e) { LOG.warn("unable to close resource input stream for " + URL_TO_NAME_MAP_RESOURCE_NAME + ":" + e, e); } } protected  ClustersNames(); }
ClustersNames { protected ClustersNames() { try (Closer closer = Closer.create()) { InputStream propsInput = closer.register(getClass().getResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); if (null == propsInput) { propsInput = closer.register(ClassLoader.getSystemResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); } if (null != propsInput) { try { this.urlToNameMap.load(propsInput); LOG.info("Loaded cluster names map:" + this.urlToNameMap); } catch (IOException e) { LOG.warn("Unable to load cluster names map: " + e, e); } } else { LOG.info("no default cluster mapping found"); } } catch (IOException e) { LOG.warn("unable to close resource input stream for " + URL_TO_NAME_MAP_RESOURCE_NAME + ":" + e, e); } } protected  ClustersNames(); String getClusterName(String clusterUrl); void addClusterMapping(String clusterUrl, String clusterName); void addClusterMapping(URL clusterUrl, String clusterName); String getClusterName(); String getClusterName(Configuration conf); static ClustersNames getInstance(); }
ClustersNames { protected ClustersNames() { try (Closer closer = Closer.create()) { InputStream propsInput = closer.register(getClass().getResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); if (null == propsInput) { propsInput = closer.register(ClassLoader.getSystemResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME)); } if (null != propsInput) { try { this.urlToNameMap.load(propsInput); LOG.info("Loaded cluster names map:" + this.urlToNameMap); } catch (IOException e) { LOG.warn("Unable to load cluster names map: " + e, e); } } else { LOG.info("no default cluster mapping found"); } } catch (IOException e) { LOG.warn("unable to close resource input stream for " + URL_TO_NAME_MAP_RESOURCE_NAME + ":" + e, e); } } protected  ClustersNames(); String getClusterName(String clusterUrl); void addClusterMapping(String clusterUrl, String clusterName); void addClusterMapping(URL clusterUrl, String clusterName); String getClusterName(); String getClusterName(Configuration conf); static ClustersNames getInstance(); static final String URL_TO_NAME_MAP_RESOURCE_NAME; }