Search in sources :

Example 6 with KillOptions

use of org.apache.storm.generated.KillOptions in project storm by apache.

the class UIHelpers method putTopologyKill.

/**
 * putTopologyKill.
 * @param client client
 * @param id id
 * @param waitTime waitTime
 * @return putTopologyKill
 * @throws TException TException
 */
public static Map<String, Object> putTopologyKill(Nimbus.Iface client, String id, String waitTime) throws TException {
    GetInfoOptions getInfoOptions = new GetInfoOptions();
    getInfoOptions.set_num_err_choice(NumErrorsChoice.NONE);
    TopologyInfo topologyInfo = client.getTopologyInfoWithOpts(id, getInfoOptions);
    KillOptions killOptions = new KillOptions();
    killOptions.set_wait_secs(Integer.parseInt(waitTime));
    client.killTopologyWithOpts(topologyInfo.get_name(), killOptions);
    return getTopologyOpResponse(id, "kill");
}
Also used : GetInfoOptions(org.apache.storm.generated.GetInfoOptions) KillOptions(org.apache.storm.generated.KillOptions) TopologyInfo(org.apache.storm.generated.TopologyInfo)

Example 7 with KillOptions

use of org.apache.storm.generated.KillOptions in project storm by apache.

the class KillTopology method main.

public static void main(String[] args) throws Exception {
    Map<String, Object> cl = CLI.opt("w", "wait", null, CLI.AS_INT).boolOpt("i", "ignore-errors").arg("TOPO", CLI.INTO_LIST).parse(args);
    @SuppressWarnings("unchecked") final List<String> names = (List<String>) cl.get("TOPO");
    // if '-i' is set, we'll try to kill every topology listed, even if an error occurs
    Boolean continueOnError = (Boolean) cl.get("i");
    errorCount = 0;
    Iterator<String> iterator = names.iterator();
    while (iterator.hasNext()) {
        String name = iterator.next();
        try {
            Utils.validateTopologyName(name);
        } catch (IllegalArgumentException e) {
            if (!continueOnError) {
                throw e;
            } else {
                iterator.remove();
                errorCount += 1;
                LOG.error("Format of topology name {} is not valid ", name);
            }
        }
    }
    if (names.isEmpty()) {
        throw new RuntimeException("Failed to successfully kill " + errorCount + " topologies.");
    }
    // Wait this many seconds after deactivating topology before killing
    Integer wait = (Integer) cl.get("w");
    final KillOptions opts = new KillOptions();
    if (wait != null) {
        opts.set_wait_secs(wait);
    }
    NimbusClient.withConfiguredClient(new NimbusClient.WithNimbus() {

        @Override
        public void run(Nimbus.Iface nimbus) throws Exception {
            for (String name : names) {
                try {
                    nimbus.killTopologyWithOpts(name, opts);
                    LOG.info("Killed topology: {}", name);
                } catch (Exception e) {
                    errorCount += 1;
                    if (!continueOnError) {
                        throw e;
                    } else {
                        LOG.error("Caught error killing topology '{}'; continuing as -i was passed.", name, e);
                    }
                }
            }
            // If we failed to kill any topology, still exit with failure status
            if (errorCount > 0) {
                throw new RuntimeException("Failed to successfully kill " + errorCount + " topologies.");
            }
        }
    });
}
Also used : NimbusClient(org.apache.storm.utils.NimbusClient) List(java.util.List) Nimbus(org.apache.storm.generated.Nimbus) KillOptions(org.apache.storm.generated.KillOptions)

Example 8 with KillOptions

use of org.apache.storm.generated.KillOptions in project storm by apache.

the class Helper method kill.

public static void kill(Nimbus.Iface client, String topoName) throws Exception {
    KillOptions opts = new KillOptions();
    opts.set_wait_secs(0);
    client.killTopologyWithOpts(topoName, opts);
}
Also used : KillOptions(org.apache.storm.generated.KillOptions)

Example 9 with KillOptions

use of org.apache.storm.generated.KillOptions in project storm by apache.

the class HdfsSpoutTopology method kill.

// main
private static void kill(Nimbus.Iface client, String topologyName) throws Exception {
    KillOptions opts = new KillOptions();
    opts.set_wait_secs(0);
    client.killTopologyWithOpts(topologyName, opts);
}
Also used : KillOptions(org.apache.storm.generated.KillOptions)

Example 10 with KillOptions

use of org.apache.storm.generated.KillOptions in project metron by apache.

the class ParserTopologyComponent method killTopology.

protected void killTopology() {
    KillOptions ko = new KillOptions();
    ko.set_wait_secs(0);
    stormCluster.killTopologyWithOpts(getTopologyName(), ko);
    try {
        // Actually wait for it to die.
        Thread.sleep(2000);
    } catch (InterruptedException e) {
    // Do nothing
    }
}
Also used : KillOptions(org.apache.storm.generated.KillOptions)

Aggregations

KillOptions (org.apache.storm.generated.KillOptions)15 List (java.util.List)2 TException (org.apache.storm.thrift.TException)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 IStormClusterState (org.apache.storm.cluster.IStormClusterState)1 Bolt (org.apache.storm.generated.Bolt)1 GetInfoOptions (org.apache.storm.generated.GetInfoOptions)1 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)1 Grouping (org.apache.storm.generated.Grouping)1 Nimbus (org.apache.storm.generated.Nimbus)1 SpoutSpec (org.apache.storm.generated.SpoutSpec)1