@Override public void shutdown() { if (client != null) { client.close(); client = null; } } }
@Override public void cleanup() { invalidate(); if (remoteClient != null) { remoteClient.close(); } }
public static void main(String[] args) { if (args == null || args.length == 0) { throw new InvalidParameterException("Please input topology name"); } String topologyName = args[0]; NimbusClient client = null; try { Map conf = Utils.readStormConfig(); client = NimbusClient.getConfiguredClient(conf); client.getClient().deactivate(topologyName); System.out.println("Successfully submit command deactivate " + topologyName); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { if (client != null) { client.close(); } } }
public static void main(String[] args) { if (args == null || args.length == 0) { throw new InvalidParameterException("Please input topology name"); } String topologyName = args[0]; NimbusClient client = null; try { Map conf = Utils.readStormConfig(); client = NimbusClient.getConfiguredClient(conf); client.getClient().activate(topologyName); System.out.println("Successfully submit command activate " + topologyName); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { if (client != null) { client.close(); } } }
public static void main(String[] args) { if (args == null || args.length <= 1) { throw new InvalidParameterException("Please input topology name and enable flag"); } String topologyName = args[0]; NimbusClient client = null; try { Map conf = Utils.readStormConfig(); client = NimbusClient.getConfiguredClient(conf); boolean isEnable = Boolean.valueOf(args[1]); MonitorOptions options = new MonitorOptions(); options.set_isEnable(isEnable); client.getClient().metricMonitor(topologyName, options); String str = (isEnable) ? "enable" : "disable"; System.out.println("Successfully submit command to " + str + " the monitor of " + topologyName); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { if (client != null) { client.close(); } } }
} finally { if (client != null) { client.close();
public static List<String> getSupervisorHosts() throws Exception { try { List<String> hosts = new ArrayList<>(); NimbusClient client = getNimbusClient(null); ClusterSummary clusterSummary = client.getClient().getClusterInfo(); List<SupervisorSummary> supervisorSummaries = clusterSummary.get_supervisors(); Collections.sort(supervisorSummaries, new Comparator<SupervisorSummary>() { @Override public int compare(SupervisorSummary o1, SupervisorSummary o2) { int o1Left = o1.get_numWorkers() - o1.get_numUsedWorkers(); int o2Left = o2.get_numWorkers() - o2.get_numUsedWorkers(); return o1Left - o2Left; } }); for (SupervisorSummary supervisorSummary : supervisorSummaries) { hosts.add(supervisorSummary.get_host()); } return hosts; } catch (Exception e) { if (client != null) { client.close(); client = null; } LOG.error("Failed to kill all topologies ", e); throw new RuntimeException(e); } }
private static void rollbackTopology(String topologyName) { Map conf = Utils.readStormConfig(); NimbusClient client = NimbusClient.getConfiguredClient(conf); try { // update jar client.getClient().rollbackTopology(topologyName); CommandLineUtil.success("Successfully submit command rollback_topology " + topologyName); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { if (client != null) { client.close(); } } }
public static void submitRebalance(String topologyName, RebalanceOptions options, Map conf) throws Exception { Map stormConf = Utils.readStormConfig(); if (conf != null) { stormConf.putAll(conf); } NimbusClient client = null; try { client = NimbusClient.getConfiguredClient(stormConf); client.getClient().rebalance(topologyName, options); } catch (Exception e) { throw e; } finally { if (client != null) { client.close(); } } }
public static void main(String[] args) { NimbusClient client = null; try { Map conf = Utils.readStormConfig(); client = NimbusClient.getConfiguredClient(conf); if (args.length > 0 && !StringUtils.isBlank(args[0])) { String topologyName = args[0]; TopologyInfo info = client.getClient().getTopologyInfoByName(topologyName); System.out.println("Successfully get topology info \n" + Utils.toPrettyJsonString(info)); } else { ClusterSummary clusterSummary = client.getClient().getClusterInfo(); System.out.println("Successfully get cluster info \n" + Utils.toPrettyJsonString(clusterSummary)); } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { if (client != null) { client.close(); } } }
public static void main(String[] args) { if (args == null || args.length == 0) { throw new InvalidParameterException("Please input topology name!"); } String topologyName = args[0]; NimbusClient client = null; try { Map conf = Utils.readStormConfig(); client = NimbusClient.getConfiguredClient(conf); System.out.println("It will take 15 ~ 100 seconds to restart, please wait patiently\n"); if (args.length == 1) { client.getClient().restart(topologyName, null); } else { Map loadConf = Utils.loadConf(args[1]); String jsonConf = Utils.to_json(loadConf); System.out.println("New configuration:\n" + jsonConf); client.getClient().restart(topologyName, jsonConf); } System.out.println("Successfully submit command restart " + topologyName); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { if (client != null) { client.close(); } } }
public static void main(String[] args) { if (args == null || args.length == 0) { throw new InvalidParameterException("Please input topology name"); } String topologyName = args[0]; NimbusClient client = null; try { Map conf = Utils.readStormConfig(); client = NimbusClient.getConfiguredClient(conf); if (args.length == 1) { client.getClient().killTopology(topologyName); } else { int delaySeconds = Integer.parseInt(args[1]); KillOptions options = new KillOptions(); options.set_wait_secs(delaySeconds); client.getClient().killTopologyWithOpts(topologyName, options); } System.out.println("Successfully submit command kill " + topologyName); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { if (client != null) { client.close(); } } }
private static void completeTopology(String topologyName) throws Exception { Map conf = Utils.readStormConfig(); NimbusClient client = NimbusClient.getConfiguredClient(conf); try { client.getClient().completeUpgrade(topologyName); CommandLineUtil.success("Successfully submit command complete_upgrade " + topologyName); } catch (Exception ex) { CommandLineUtil.error("Failed to perform complete_upgrade: " + ex.getMessage()); ex.printStackTrace(); } finally { if (client != null) { client.close(); } } }
public static void downloadFromMaster(Map conf, String file, String localFile) throws IOException, TException { WritableByteChannel out = null; NimbusClient client = null; try { client = NimbusClient.getConfiguredClient(conf, 10 * 1000); String id = client.getClient().beginFileDownload(file); out = Channels.newChannel(new FileOutputStream(localFile)); while (true) { ByteBuffer chunk = client.getClient().downloadChunk(id); int written = out.write(chunk); if (written == 0) { client.getClient().finishFileDownload(id); break; } } } finally { if (out != null) out.close(); if (client != null) client.close(); } }
} finally { if (client != null) { client.close();
client.getClient().submitTopology(name, submittedJar, serConf, topology); } finally { client.close();
client.close();
public static String submitJar(Map conf, String localJar) { NimbusClient client = NimbusClient.getConfiguredClient(conf); try { String uploadLocation = client.getClient().beginFileUpload(); LOG.info("Uploading topology jar " + localJar + " to assigned location: " + uploadLocation); BufferFileInputStream is = new BufferFileInputStream(localJar); while(true) { byte[] toSubmit = is.read(); if(toSubmit.length==0) break; client.getClient().uploadChunk(uploadLocation, ByteBuffer.wrap(toSubmit)); } client.getClient().finishFileUpload(uploadLocation); LOG.info("Successfully uploaded topology jar to assigned location: " + uploadLocation); return uploadLocation; } catch(Exception e) { throw new RuntimeException(e); } finally { client.close(); } } }
public static void cleanCluster() { try { NimbusClient client = getNimbusClient(null); ClusterSummary clusterSummary = client.getClient().getClusterInfo(); List<TopologySummary> topologySummaries = clusterSummary.get_topologies(); KillOptions killOption = new KillOptions(); killOption.set_wait_secs(1); for (TopologySummary topologySummary : topologySummaries) { client.getClient().killTopologyWithOpts(topologySummary.get_name(), killOption); LOG.info("Successfully kill " + topologySummary.get_name()); } } catch (Exception e) { if (client != null) { client.close(); client = null; } LOG.error("Failed to kill all topology ", e); } }
} finally { if (client != null) { client.close();