Search in sources :

Example 21 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class UIUtils method flushClusterCache.

private static void flushClusterCache() {
    NimbusClient client = null;
    Map<String, ClusterEntity> clusterEntities = new HashMap<>();
    for (String name : UIUtils.clusterConfig.keySet()) {
        try {
            client = NimbusClientManager.getNimbusClient(name);
            clusterEntities.put(name, getClusterEntity(client.getClient().getClusterInfo(), name));
        } catch (Exception e) {
            NimbusClientManager.removeClient(name);
            LOG.error(e.getMessage(), e);
        }
    }
    clustersCache = clusterEntities;
}
Also used : NimbusClient(backtype.storm.utils.NimbusClient) FileNotFoundException(java.io.FileNotFoundException)

Example 22 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class JStormHelper method cleanCluster.

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);
    }
    return;
}
Also used : ClusterSummary(backtype.storm.generated.ClusterSummary) NimbusClient(backtype.storm.utils.NimbusClient) TopologySummary(backtype.storm.generated.TopologySummary) KillOptions(backtype.storm.generated.KillOptions)

Example 23 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class restart method main.

public static void main(String[] args) {
    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);
        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();
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) NimbusClient(backtype.storm.utils.NimbusClient) Map(java.util.Map) InvalidParameterException(java.security.InvalidParameterException)

Example 24 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class StormSubmitter method submitTopology.

/**
     * Submits a topology to run on the cluster. A topology runs forever or until explicitly killed.
     * 
     * 
     * @param name the name of the storm.
     * @param stormConf the topology-specific configuration. See {@link Config}.
     * @param topology the processing to execute.
     * @throws AlreadyAliveException if a topology with this name is already running
     * @throws InvalidTopologyException if an invalid topology was submitted
     */
public static void submitTopology(String name, Map stormConf, StormTopology topology, SubmitOptions opts) throws AlreadyAliveException, InvalidTopologyException {
    if (!Utils.isValidConf(stormConf)) {
        throw new IllegalArgumentException("Storm conf is not valid. Must be json-serializable");
    }
    stormConf = new HashMap(stormConf);
    stormConf.putAll(Utils.readCommandLineOpts());
    Map conf = Utils.readStormConfig();
    conf.putAll(stormConf);
    putUserInfo(conf, stormConf);
    try {
        String serConf = Utils.to_json(stormConf);
        if (localNimbus != null) {
            LOG.info("Submitting topology " + name + " in local mode");
            localNimbus.submitTopology(name, null, serConf, topology);
        } else {
            NimbusClient client = NimbusClient.getConfiguredClient(conf);
            try {
                boolean enableDeploy = ConfigExtension.getTopologyHotDeplogyEnable(stormConf);
                if (topologyNameExists(client, conf, name) != enableDeploy) {
                    if (enableDeploy) {
                        throw new RuntimeException("Topology with name `" + name + "` not exists on cluster");
                    } else {
                        throw new RuntimeException("Topology with name `" + name + "` already exists on cluster");
                    }
                }
                submitJar(client, conf);
                LOG.info("Submitting topology " + name + " in distributed mode with conf " + serConf);
                if (opts != null) {
                    client.getClient().submitTopologyWithOpts(name, path, serConf, topology, opts);
                } else {
                    // this is for backwards compatibility
                    client.getClient().submitTopology(name, path, serConf, topology);
                }
            } finally {
                client.close();
            }
        }
        LOG.info("Finished submitting topology: " + name);
    } catch (InvalidTopologyException e) {
        LOG.warn("Topology submission exception", e);
        throw e;
    } catch (AlreadyAliveException e) {
        LOG.warn("Topology already alive exception", e);
        throw e;
    } catch (TopologyAssignException e) {
        LOG.warn("Failed to assign " + e.get_msg(), e);
        throw new RuntimeException(e);
    } catch (TException e) {
        LOG.warn("Failed to assign ", e);
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) HashMap(java.util.HashMap) NimbusClient(backtype.storm.utils.NimbusClient) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class deactivate method main.

public static void main(String[] args) {
    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);
        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();
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) NimbusClient(backtype.storm.utils.NimbusClient) Map(java.util.Map) InvalidParameterException(java.security.InvalidParameterException)

Aggregations

NimbusClient (backtype.storm.utils.NimbusClient)38 Map (java.util.Map)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 HashMap (java.util.HashMap)9 InvalidParameterException (java.security.InvalidParameterException)6 IOException (java.io.IOException)4 TException (org.apache.thrift.TException)4 ModelMap (org.springframework.ui.ModelMap)4 ClusterSummary (backtype.storm.generated.ClusterSummary)3 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)3 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)3 NimbusInfo (backtype.storm.nimbus.NimbusInfo)3 FileNotFoundException (java.io.FileNotFoundException)3 TTransportException (org.apache.thrift.transport.TTransportException)3 KillOptions (backtype.storm.generated.KillOptions)2 MetricInfo (backtype.storm.generated.MetricInfo)2 TopologyInfo (backtype.storm.generated.TopologyInfo)2 UITaskMetric (com.alibaba.jstorm.ui.model.UITaskMetric)2 UIWorkerMetric (com.alibaba.jstorm.ui.model.UIWorkerMetric)2 ChartSeries (com.alibaba.jstorm.ui.model.graph.ChartSeries)2