@Override public void uncaughtException(Thread t, Throwable e) { try { reportError.report(e); } catch (Exception ex) { LOG.error("Error while reporting error to cluster, proceeding with shutdown", ex); } if (Utils.exceptionCauseIsInstanceOf(InterruptedException.class, e) || (Utils.exceptionCauseIsInstanceOf(java.io.InterruptedIOException.class, e) && !Utils.exceptionCauseIsInstanceOf(java.net.SocketTimeoutException.class, e))) { LOG.info("Got interrupted exception shutting thread down..."); } else { suicideFn.run(); } } }
@Override protected boolean matchesSafely(Throwable throwable) { return Utils.exceptionCauseIsInstanceOf(exceptionCause, throwable); }
@Override public void run() { while (running.get()) { try { Runnable r = queue.take(); if (r == null) { return; } r.run(); proccessInc(); } catch (Throwable t) { if (Utils.exceptionCauseIsInstanceOf(InterruptedIOException.class, t)) { LOG.info("Event manager interrupted while doing IO"); } else if (Utils.exceptionCauseIsInstanceOf(ClosedByInterruptException.class, t)) { LOG.info("Event manager interrupted while doing NIO"); } else if (Utils.exceptionCauseIsInstanceOf(InterruptedException.class, t)) { LOG.info("Event manager interrupted"); } else { LOG.error("{} Error when processing event", t); Utils.exitProcess(20, "Error when processing an event"); } } } } };
/** * Kill all processes */ public static void killAllProcesses() { Set<String> pids = processMap.keySet(); for (String pid : pids) { try { killProcess(pid); } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(InterruptedException.class, e)) { LOG.warn("process {} not killed (Ignoring InterruptedException)", pid, e); } else if (Utils.exceptionCauseIsInstanceOf(ClosedByInterruptException.class, e)) { LOG.warn("process {} not killed (Ignoring ClosedByInterruptException)", pid, e); } else if (e instanceof RuntimeException) { throw e; } else { //TODO once everything is in java this should not be possible any more throw new RuntimeException(e); } } } } }
public void run() { try { final Callable<Long> fn = isFactory ? (Callable<Long>) afn.call() : afn; while (true) { if (Thread.interrupted()) { throw new InterruptedException(); } final Long s = fn.call(); if (s == null) { // then stop running it break; } if (s > 0) { Time.sleep(s); } } } catch (Throwable t) { if (Utils.exceptionCauseIsInstanceOf( InterruptedException.class, t)) { LOG.info("Async loop interrupted!"); return; } LOG.error("Async loop died!", t); throw new RuntimeException(t); } } });
@Override public void removeBackpressure(String stormId) { try { stateStorage.delete_node(ClusterUtils.backpressureStormRoot(stormId)); } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.class, e)) { // do nothing LOG.warn("Could not teardown backpressure node for {}.", stormId); } else { throw e; } } }
@Override public void teardownHeartbeats(String stormId) { try { stateStorage.delete_worker_hb(ClusterUtils.workerbeatStormRoot(stormId)); } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.class, e)) { // do nothing LOG.warn("Could not teardown heartbeats for {}.", stormId); } else { throw e; } } }
@Override public void teardownTopologyErrors(String stormId) { try { stateStorage.delete_node(ClusterUtils.errorStormRoot(stormId)); } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.class, e)) { // do nothing LOG.warn("Could not teardown errors for {}.", stormId); } else { throw e; } } }
public void cleanupBefore(long txid) { SortedMap<Long, Object> toDelete = _curr.headMap(txid); for (long tx : new HashSet<Long>(toDelete.keySet())) { _curr.remove(tx); try { _state.delete(txPath(tx)); } catch (RuntimeException e) { // Ignore NoNodeExists exceptions because when sync() it may populate _curr with stale data since // zookeeper reads are eventually consistent. if (!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { throw e; } } } }
@Override public Set<String> idsOfTopologiesWithPrivateWorkerKeys() { HashSet<String> ret = new HashSet<>(); for (WorkerTokenServiceType type : WorkerTokenServiceType.values()) { String path = ClusterUtils.secretKeysPath(type); try { ret.addAll(stateStorage.get_children(path, false)); } catch (RuntimeException e) { //If the node does not exist it is fine/expected... if (!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { throw e; } } } return ret; } }
@Override public long getNextPrivateWorkerKeyVersion(WorkerTokenServiceType type, String topologyId) { String path = ClusterUtils.secretKeysPath(type, topologyId); try { List<String> versions = stateStorage.get_children(path, false); return versions.stream().mapToLong(Long::valueOf).max().orElse(0); } catch (RuntimeException e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { //If the node does not exist, then the version must be 0 return 0; } throw e; } }
@Override public void removeAllPrivateWorkerKeys(String topologyId) { for (WorkerTokenServiceType type : WorkerTokenServiceType.values()) { String path = ClusterUtils.secretKeysPath(type, topologyId); try { LOG.info("Removing worker keys under {}", path); stateStorage.delete_node(path); } catch (RuntimeException e) { //This should never happen because only the primary nimbus is active, but just in case // declare the race safe, even if we lose it. if (!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { throw e; } } } }
public void mkdirsImpl(CuratorFramework zk, String path, List<ACL> acls) { String npath = ClientZookeeper.normalizePath(path); if (npath.equals("/")) { return; } if (ClientZookeeper.existsNode(zk, npath, false)) { return; } byte[] byteArray = new byte[1]; byteArray[0] = (byte) 7; try { ClientZookeeper.createNode(zk, npath, byteArray, CreateMode.PERSISTENT, acls); } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.NodeExistsException.class, e)) { // this can happen when multiple clients doing mkdir at same time } } }
public static void deleteNode(CuratorFramework zk, String path) { try { String npath = normalizePath(path); if (existsNode(zk, npath, false)) { zk.delete().deletingChildrenIfNeeded().forPath(normalizePath(path)); } } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.NodeExistsException.class, e)) { // do nothing LOG.info("delete {} failed.", path, e); } else { throw Utils.wrapInRuntime(e); } } }
public static void verifyIncorrectJaasConf(ThriftServer server, Map<String, Object> conf, String jaas, Class<? extends Exception> expectedException) { Map<String, Object> badConf = new HashMap<>(conf); badConf.put("java.security.auth.login.config", jaas); try (NimbusClient client = new NimbusClient(badConf, "localhost", server.getPort(), NIMBUS_TIMEOUT)) { client.getClient().activate("bad_auth_test_topology"); fail("An exception should have been thrown trying to connect."); } catch (Exception e) { LOG.info("Got Exception...", e); assert (Utils.exceptionCauseIsInstanceOf(expectedException, e)); } }
public void getConfiguredClientThrowsRuntimeExceptionOnBadArgsTest() throws TTransportException { Map<String, Object> config = ConfigUtils.readStormConfig(); config.put(Config.STORM_NIMBUS_RETRY_TIMES, 0); try { new NimbusClient(config, "", 65535); Assert.fail("Expected exception to be thrown"); } catch (RuntimeException e) { Assert.assertTrue( "Cause is not TTransportException " + e, Utils.exceptionCauseIsInstanceOf(TTransportException.class, e)); } }
@Override public void set_ephemeral_node(String path, byte[] data, List<ACL> acls) { ClientZookeeper.mkdirs(zkWriter, ClientZookeeper.parentPath(path), acls); if (ClientZookeeper.exists(zkWriter, path, false)) { try { ClientZookeeper.setData(zkWriter, path, data); } catch (RuntimeException e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { ClientZookeeper.createNode(zkWriter, path, data, CreateMode.EPHEMERAL, acls); } else { throw e; } } } else { ClientZookeeper.createNode(zkWriter, path, data, CreateMode.EPHEMERAL, acls); } }
@Override public void set_data(String path, byte[] data, List<ACL> acls) { if (ClientZookeeper.exists(zkWriter, path, false)) { ClientZookeeper.setData(zkWriter, path, data); } else { ClientZookeeper.mkdirs(zkWriter, ClientZookeeper.parentPath(path), acls); try { ClientZookeeper.createNode(zkWriter, path, data, CreateMode.PERSISTENT, acls); } catch (RuntimeException e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.NodeExistsException.class, e)) { ClientZookeeper.setData(zkWriter, path, data); } else { throw e; } } } }
@Test public void simpleAuthTest() throws Exception { Nimbus.Iface impl = mock(Nimbus.Iface.class); withServer(SimpleTransportPlugin.class, impl, (ThriftServer server, Map<String, Object> conf) -> { try (NimbusClient client = new NimbusClient(conf, "localhost", server.getPort(), NIMBUS_TIMEOUT)) { client.getClient().activate("security_auth_test_topology"); } //Verify digest is rejected... Map<String, Object> badConf = new HashMap<>(conf); badConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN, DigestSaslTransportPlugin.class.getName()); badConf.put("java.security.auth.login.config", DIGEST_JAAS_CONF); badConf.put(Config.STORM_NIMBUS_RETRY_TIMES, 0); try (NimbusClient client = new NimbusClient(badConf, "localhost", server.getPort(), NIMBUS_TIMEOUT)) { client.getClient().activate("bad_security_auth_test_topology"); fail("An exception should have been thrown trying to connect."); } catch (Exception te) { LOG.info("Got Exception...", te); assert (Utils.exceptionCauseIsInstanceOf(TTransportException.class, te)); } }); verify(impl).activate("security_auth_test_topology"); verify(impl, never()).activate("bad_security_auth_test_topology"); }
public static byte[] getData(CuratorFramework zk, String path, boolean watch) { try { String npath = normalizePath(path); if (existsNode(zk, npath, watch)) { if (watch) { return zk.getData().watched().forPath(npath); } else { return zk.getData().forPath(npath); } } } catch (Exception e) { if (Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { // this is fine b/c we still have a watch from the successful exists call } else { throw Utils.wrapInRuntime(e); } } return null; }