public void killTopologyWithOpts(final String name, final KillOptions options) throws NotAliveException { final JobID jobId = this.getTopologyJobId(name); if (jobId == null) { throw new NotAliveException("Storm topology with name " + name + " not found."); } if (options != null) { try { Thread.sleep(1000 * options.get_wait_secs()); } catch (final InterruptedException e) { throw new RuntimeException(e); } } final Configuration configuration = GlobalConfiguration.getConfiguration(); configuration.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, this.jobManagerHost); configuration.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, this.jobManagerPort); final Client client; try { client = new Client(configuration); } catch (final IOException e) { throw new RuntimeException("Could not establish a connection to the job manager", e); } try { client.cancel(jobId); } catch (final Exception e) { throw new RuntimeException("Cannot stop job.", e); } }
@Override public void killTopologyWithOpts(String topologyName, KillOptions options) throws NotAliveException, TException { try { checkTopologyActive(data, topologyName, true); Integer wait_amt = null; if (options.is_set_wait_secs()) { wait_amt = options.get_wait_secs(); } NimbusUtils.transitionName(data, topologyName, true, StatusType.kill, wait_amt); } catch (NotAliveException e) { String errMsg = "KillTopology Error, no this topology " + topologyName; LOG.error(errMsg, e); throw new NotAliveException(errMsg); } catch (Exception e) { String errMsg = "Failed to kill topology " + topologyName; LOG.error(errMsg, e); throw new TException(errMsg); } }
public int compareTo(KillOptions other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; KillOptions typedOther = (KillOptions) other; lastComparison = Boolean.valueOf(is_set_wait_secs()).compareTo(typedOther.is_set_wait_secs()); if (lastComparison != 0) { return lastComparison; } if (is_set_wait_secs()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.wait_secs, typedOther.wait_secs); if (lastComparison != 0) { return lastComparison; } } return 0; }
public boolean equals(KillOptions that) { if (that == null) return false; boolean this_present_wait_secs = true && this.is_set_wait_secs(); boolean that_present_wait_secs = true && that.is_set_wait_secs(); if (this_present_wait_secs || that_present_wait_secs) { if (!(this_present_wait_secs && that_present_wait_secs)) return false; if (this.wait_secs != that.wait_secs) return false; } return true; }
@Override public void stop( Application<StormEnvironment, StormTopology> executor, com.typesafe.config.Config config) { String appId = config.getString("appId"); LOG.info("Stopping topology {} ..." + appId); if (Objects.equals(config.getString("mode"), ApplicationEntity.Mode.CLUSTER.name())) { Nimbus.Client stormClient = NimbusClient.getConfiguredClient(getStormConfig(config)).getClient(); try { stormClient.killTopology(appId); } catch (NotAliveException | TException e) { LOG.error( "Failed to kill topology named {}, due to: {}", appId, e.getMessage(), e.getCause()); } } else { KillOptions killOptions = new KillOptions(); killOptions.set_wait_secs(0); getLocalCluster().killTopologyWithOpts(appId, killOptions); } LOG.info("Stopped topology {} ..." + appId); }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub if (args == null || args.length == 0) { throw new InvalidParameterException("Should 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(); } } }
public void realMain(String[] args) throws Exception { Map clusterConf = Utils.readStormConfig(); clusterConf.putAll(Utils.readCommandLineOpts()); Nimbus.Client client = NimbusClient.getConfiguredClient(clusterConf).getClient(); CmdLineParser parser = new CmdLineParser(this); parser.setUsageWidth(80); try { // parse the arguments. parser.parseArgument(args); } catch (CmdLineException e) { // if there's a problem in the command line, // you'll get this exception. this will report // an error message. System.err.println(e.getMessage()); _help = true; } if (_help) { parser.printUsage(System.err); System.err.println(); return; } if (_numWorkers <= 0) { throw new IllegalArgumentException("Need at least one worker"); } if (_name == null || _name.isEmpty()) { throw new IllegalArgumentException("name must be something"); } if (!_ackEnabled) { _ackers = 0; } try { for (int topoNum = 0; topoNum < _numTopologies; topoNum++) { int multiplier = 4; int totalSpout = _spoutParallel * _localGroup * multiplier; int totalLocalBolt = _boltLocalParallel * _localGroup * multiplier; int totalLocalResultBolt = _localGroup * multiplier; int totalGlobalBolt = _boltGlobalParallel * multiplier; int totalGlobalResultBolt = _boltGlobalParallel * multiplier; TopologyBuilder builder = new TopologyBuilder(); builder .setSpout("messageSpoutLocal1", new SOESpout(_messageSize, _ackEnabled), totalSpout) .addConfiguration("group-name", "Local1") .addConfiguration("TaskPerCloud", _spoutParallel); // builder.setBolt("messageBoltLocal1_1", new SOEBolt(), // totalLocalBolt).shuffleGrouping("messageSpoutLocal1").addConfiguration("group-name", // "Local1"); // builder.setBolt("messageBoltLocal1_LocalResult", new SOEFinalBolt(), // totalLocalResultBolt).shuffleGrouping("messageBoltLocal1_1").addConfiguration("group-name", "Local1"); builder .setBolt("messageBoltLocal1_1", new SOEBolt(), totalLocalBolt) .customGrouping("messageSpoutLocal1", new ZoneShuffleGrouping()) .addConfiguration("group-name", "Local1") .addConfiguration("TaskPerCloud", _boltLocalParallel); builder .setBolt("messageBoltLocal1_LocalResult", new SOEFinalBolt(), totalLocalResultBolt) .customGrouping("messageBoltLocal1_1", new ZoneShuffleGrouping()) .addConfiguration("group-name", "Local1"); builder .setSpout("messageSpoutLocal2", new SOESpout(_messageSize, _ackEnabled), totalSpout) .addConfiguration("group-name", "Local2") .addConfiguration("TaskPerCloud", _spoutParallel); // builder.setBolt("messageBoltLocal2_1", new SOEBolt(), // totalLocalBolt).shuffleGrouping("messageSpoutLocal2").addConfiguration("group-name", // "Local2"); // builder.setBolt("messageBoltLocal2_LocalResult", new SOEFinalBolt(), // totalLocalResultBolt).shuffleGrouping("messageBoltLocal2_1").addConfiguration("group-name", "Local2"); builder .setBolt("messageBoltLocal2_1", new SOEBolt(), totalLocalBolt) .customGrouping("messageSpoutLocal2", new ZoneShuffleGrouping()) .addConfiguration("group-name", "Local2") .addConfiguration("TaskPerCloud", _boltLocalParallel); builder .setBolt("messageBoltLocal2_LocalResult", new SOEFinalBolt(), totalLocalResultBolt) .customGrouping("messageBoltLocal2_1", new ZoneShuffleGrouping()) .addConfiguration("group-name", "Local2"); builder .setBolt("messageBoltGlobal1_1A", new SOEBolt(), totalGlobalBolt) .shuffleGrouping("messageBoltLocal1_1") .addConfiguration("group-name", "Global1") .addConfiguration("TaskPerCloud", _boltGlobalParallel); builder .setBolt("messageBoltGlobal1_1B", new SOEBolt(), totalGlobalBolt) .shuffleGrouping("messageBoltLocal2_1") .addConfiguration("group-name", "Global1") .addConfiguration("TaskPerCloud", _boltGlobalParallel); builder .setBolt("messageBoltGlobal1_FG", new SOEBolt(), 2) .fieldsGrouping("messageBoltGlobal1_1A", new Fields("fieldValue")) .fieldsGrouping("messageBoltGlobal1_1B", new Fields("fieldValue")) .addConfiguration("group-name", "Global1") .addConfiguration("TaskPerCloud", _boltGlobalParallel); builder .setBolt("messageBoltGlobal1_GlobalResult", new SOEFinalBolt(), totalGlobalResultBolt) .shuffleGrouping("messageBoltGlobal1_FG") .addConfiguration("group-name", "Global1"); Config conf = new Config(); conf.setDebug(_debug); conf.setNumWorkers(_numWorkers); conf.setNumAckers(_ackers); conf.setStatsSampleRate(_sampleRate); if (_maxSpoutPending > 0) { conf.setMaxSpoutPending(_maxSpoutPending); } StormSubmitter.submitTopology(_name + "_" + topoNum, conf, builder.createTopology()); } metrics(client, _messageSize, _pollFreqSec, _testRunTimeSec); } finally { // Kill it right now!!! KillOptions killOpts = new KillOptions(); killOpts.set_wait_secs(0); for (int topoNum = 0; topoNum < _numTopologies; topoNum++) { LOG.info("KILLING " + _name + "_" + topoNum); try { client.killTopologyWithOpts(_name + "_" + topoNum, killOpts); } catch (Exception e) { LOG.error("Error trying to kill " + _name + "_" + topoNum, e); } } } }
public void realMain(String[] args) throws Exception { Map clusterConf = Utils.readStormConfig(); clusterConf.putAll(Utils.readCommandLineOpts()); Client client = NimbusClient.getConfiguredClient(clusterConf).getClient(); CmdLineParser parser = new CmdLineParser(this); parser.setUsageWidth(80); try { // parse the arguments. parser.parseArgument(args); } catch (CmdLineException e) { // if there's a problem in the command line, // you'll get this exception. this will report // an error message. System.err.println(e.getMessage()); _help = true; } if (_help) { parser.printUsage(System.err); System.err.println(); return; } if (_numWorkers <= 0) { throw new IllegalArgumentException("Need at least one worker"); } if (_name == null || _name.isEmpty()) { throw new IllegalArgumentException("name must be something"); } if (!_ackEnabled) { _ackers = 0; } try { int totalSpout = _spoutParallel * _localGroup; int totalLocalBolt = _boltLocalParallel * _localGroup; int totalLocalResultBolt = _localGroup; int totalGlobalBolt = _boltGlobalParallel; int totalGlobalResultBolt = 1; int _clusteringGroupSize = 4; double _clusteringErrorRate = 0.2; long _expireTime = 5000; TopologyBuilder builder = new TopologyBuilder(); builder .setSpout("KmeansSpout", new ClusteringSpout(_ackEnabled), totalSpout) .addConfiguration("group-name", "local1"); builder .setBolt( "ClusteringBoltLocal", new ClusteringBoltLocal( _clusteringGroupSize, _clusteringErrorRate, _expireTime, _ackEnabled), totalLocalBolt) .customGrouping("KmeansSpout", new ZoneShuffleGrouping()) .addConfiguration("group-name", "local1"); builder .setBolt("resultBoltLocal", new ResultBolt(_ackEnabled), totalLocalResultBolt) .customGrouping("ClusteringBoltLocal", new ZoneShuffleGrouping()) .addConfiguration("group-name", "local1"); builder .setBolt( "ClusteringBoltGlobal", new ClusteringBoltGlobal(_clusteringGroupSize, _clusteringErrorRate, -1, _ackEnabled), totalGlobalBolt) .customGrouping("ClusteringBoltLocal", new ZoneShuffleGrouping()) .addConfiguration("group-name", "global1"); builder .setBolt("resultBoltGlobal", new ResultBolt(_ackEnabled), totalGlobalResultBolt) .shuffleGrouping("ClusteringBoltGlobal") .addConfiguration("group-name", "global1"); Config conf = new Config(); conf.setDebug(_debug); conf.setNumWorkers(_numWorkers); conf.setNumAckers(_ackers); conf.setStatsSampleRate(_sampleRate); StormSubmitter.submitTopology(_name, conf, builder.createTopology()); metrics(client, _pollFreqSec, _testRunTimeSec); } finally { // Kill it right now!!! KillOptions killOpts = new KillOptions(); killOpts.set_wait_secs(0); LOG.info("KILLING " + _name); try { client.killTopologyWithOpts(_name, killOpts); } catch (Exception e) { LOG.error("Error tying to kill " + _name, e); } } }