/** * Get a map of version to worker main from the conf Config.SUPERVISOR_WORKER_VERSION_MAIN_MAP * * @param conf what to read it out of * @return the map */ public static NavigableMap<SimpleVersion, String> getConfiguredWorkerMainVersions(Map<String, Object> conf) { TreeMap<SimpleVersion, String> ret = new TreeMap<>(); Map<String, String> fromConf = (Map<String, String>) conf.getOrDefault(Config.SUPERVISOR_WORKER_VERSION_MAIN_MAP, Collections.emptyMap()); for (Map.Entry<String, String> entry : fromConf.entrySet()) { ret.put(new SimpleVersion(entry.getKey()), entry.getValue()); } ret.put(VersionInfo.OUR_VERSION, "org.apache.storm.daemon.worker.Worker"); return ret; }
public static <T> T getCompatibleVersion(NavigableMap<SimpleVersion, T> versionedMap, SimpleVersion desiredVersion, String what, T defaultValue) { Entry<SimpleVersion, T> ret = versionedMap.ceilingEntry(desiredVersion); if (ret == null || ret.getKey().getMajor() != desiredVersion.getMajor()) { //Could not find a "fully" compatible version. Look to see if there is a possibly compatible version right below it ret = versionedMap.floorEntry(desiredVersion); if (ret == null || ret.getKey().getMajor() != desiredVersion.getMajor()) { if (defaultValue != null) { LOG.warn("Could not find any compatible {} falling back to using {}", what, defaultValue); } return defaultValue; } LOG.warn("Could not find a higer compatible version for {} {}, using {} instead", what, desiredVersion, ret.getKey()); } return ret.getValue(); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof SimpleVersion)) { return false; } return compareTo((SimpleVersion) o) == 0; }
@Test public void testParseStorm0xSnapshot() { SimpleVersion version = new SimpleVersion("0.10.3-SNAPSHOT"); Assert.assertEquals(0, version.getMajor()); Assert.assertEquals(10, version.getMinor()); }
topoVersionString = (String) _conf.getOrDefault(Config.SUPERVISOR_WORKER_DEFAULT_VERSION, VersionInfo.getVersion()); final SimpleVersion topoVersion = new SimpleVersion(topoVersionString); if ((topoVersion.getMajor() == -1 && topoVersion.getMinor() == -1) || topoVersion.compareTo(MIN_VERSION_SUPPORT_RPC_HEARTBEAT) >= 0) { commandList.add(String.valueOf(_supervisorPort));
private boolean supportRpcHeartbeat(TopologyDetails topo) { if (!topo.getTopology().is_set_storm_version()) { // current version supports RPC heartbeat return true; } String stormVersionStr = topo.getTopology().get_storm_version(); SimpleVersion stormVersion = new SimpleVersion(stormVersionStr); return stormVersion.compareTo(MIN_VERSION_SUPPORT_RPC_HEARTBEAT) >= 0; }
@Test public void testParseStorm1x() { SimpleVersion version = new SimpleVersion("1.0.4"); Assert.assertEquals(1, version.getMajor()); Assert.assertEquals(0, version.getMinor()); }
@Test public void testParseStorm1xSnapshot() { SimpleVersion version = new SimpleVersion("1.0.4-SNAPSHOT"); Assert.assertEquals(1, version.getMajor()); Assert.assertEquals(0, version.getMinor()); }
/** * Get a map of version to classpath from the conf Config.SUPERVISOR_WORKER_VERSION_CLASSPATH_MAP * * @param conf what to read it out of * @param currentCP the current classpath for this version of storm (not included in the conf, but returned by this) * @return the map */ public static NavigableMap<SimpleVersion, List<String>> getConfiguredClasspathVersions(Map<String, Object> conf, List<String> currentCP) { TreeMap<SimpleVersion, List<String>> ret = new TreeMap<>(); Map<String, String> fromConf = (Map<String, String>) conf.getOrDefault(Config.SUPERVISOR_WORKER_VERSION_CLASSPATH_MAP, Collections.emptyMap()); for (Map.Entry<String, String> entry : fromConf.entrySet()) { ret.put(new SimpleVersion(entry.getKey()), Arrays.asList(entry.getValue().split(File.pathSeparator))); } ret.put(VersionInfo.OUR_VERSION, currentCP); return ret; }
protected String getWorkerMain(SimpleVersion topoVersion) { String defaultWorkerGuess = "org.apache.storm.daemon.worker.Worker"; if (topoVersion.getMajor() == 0) { //Prior to the org.apache change defaultWorkerGuess = "backtype.storm.daemon.worker"; } else if (topoVersion.getMajor() == 1) { //Have not moved to a java worker yet defaultWorkerGuess = "org.apache.storm.daemon.worker"; } NavigableMap<SimpleVersion, String> mains = Utils.getConfiguredWorkerMainVersions(_conf); return Utils.getCompatibleVersion(mains, topoVersion, "worker main class", defaultWorkerGuess); }
@Test public void testParseStorm2x() { SimpleVersion version = new SimpleVersion("2.1.2"); Assert.assertEquals(2, version.getMajor()); Assert.assertEquals(1, version.getMinor()); }
/** * Get a map of version to worker log writer from the conf Config.SUPERVISOR_WORKER_VERSION_LOGWRITER_MAP * * @param conf what to read it out of * @return the map */ public static NavigableMap<SimpleVersion, String> getConfiguredWorkerLogWriterVersions(Map<String, Object> conf) { TreeMap<SimpleVersion, String> ret = new TreeMap<>(); Map<String, String> fromConf = (Map<String, String>) conf.getOrDefault(Config.SUPERVISOR_WORKER_VERSION_LOGWRITER_MAP, Collections.emptyMap()); for (Map.Entry<String, String> entry : fromConf.entrySet()) { ret.put(new SimpleVersion(entry.getKey()), entry.getValue()); } ret.put(VersionInfo.OUR_VERSION, "org.apache.storm.LogWriter"); return ret; }
protected String getWorkerLogWriter(SimpleVersion topoVersion) { String defaultGuess = "org.apache.storm.LogWriter"; if (topoVersion.getMajor() == 0) { //Prior to the org.apache change defaultGuess = "backtype.storm.LogWriter"; } NavigableMap<SimpleVersion, String> mains = Utils.getConfiguredWorkerLogWriterVersions(_conf); return Utils.getCompatibleVersion(mains, topoVersion, "worker log writer class", defaultGuess); }
@Test public void testParseStorm0x() { SimpleVersion version = new SimpleVersion("0.10.3"); Assert.assertEquals(0, version.getMajor()); Assert.assertEquals(10, version.getMinor()); }
SimpleVersion topoVersion = new SimpleVersion(topoVersionString); List<String> cp = Utils.getCompatibleVersion(supervisorClasspaths, topoVersion, "classpath", null); if (cp == null) {
@Test public void testParseStorm2xSnapshot() { SimpleVersion version = new SimpleVersion("2.1.2-SNAPSHOT"); Assert.assertEquals(2, version.getMajor()); Assert.assertEquals(1, version.getMinor()); }