Search in sources :

Example 1 with NimbusClient

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

the class JStormHelper method getSupervisorHosts.

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);
    }
}
Also used : ClusterSummary(backtype.storm.generated.ClusterSummary) ArrayList(java.util.ArrayList) NimbusClient(backtype.storm.utils.NimbusClient) SupervisorSummary(backtype.storm.generated.SupervisorSummary)

Example 2 with NimbusClient

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

the class blacklist method main.

public static void main(String[] args) {
    if (args == null || args.length < 2) {
        throw new InvalidParameterException("Please input action and hostname");
    }
    String action = args[0];
    String hostname = args[1];
    NimbusClient client = null;
    try {
        Map conf = Utils.readStormConfig();
        client = NimbusClient.getConfiguredClient(conf);
        if (action.equals("add"))
            client.getClient().setHostInBlackList(hostname);
        else {
            client.getClient().removeHostOutBlackList(hostname);
        }
        System.out.println("Successfully submit command blacklist with action:" + action + " and hostname :" + hostname);
    } 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 3 with NimbusClient

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

the class list method main.

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();
        }
    }
}
Also used : ClusterSummary(backtype.storm.generated.ClusterSummary) NimbusClient(backtype.storm.utils.NimbusClient) Map(java.util.Map) TopologyInfo(backtype.storm.generated.TopologyInfo)

Example 4 with NimbusClient

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

the class rebalance method submitRebalance.

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();
        }
    }
}
Also used : NimbusClient(backtype.storm.utils.NimbusClient) Map(java.util.Map)

Example 5 with NimbusClient

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

the class activate method main.

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();
        }
    }
}
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)42 Map (java.util.Map)20 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 HashMap (java.util.HashMap)9 TException (org.apache.thrift.TException)8 InvalidParameterException (java.security.InvalidParameterException)6 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)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 TopologyInfo (backtype.storm.generated.TopologyInfo)3 NimbusInfo (backtype.storm.nimbus.NimbusInfo)3 FileExistsException (org.apache.commons.io.FileExistsException)3 TTransportException (org.apache.thrift.transport.TTransportException)3 KillOptions (backtype.storm.generated.KillOptions)2 MetricInfo (backtype.storm.generated.MetricInfo)2 UITaskMetric (com.alibaba.jstorm.ui.model.UITaskMetric)2 UIWorkerMetric (com.alibaba.jstorm.ui.model.UIWorkerMetric)2