Java Code Examples for backtype.storm.utils.NimbusClient#getConfiguredClient()

The following examples show how to use backtype.storm.utils.NimbusClient#getConfiguredClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StormSubmitter.java    From eagle with Apache License 2.0 6 votes vote down vote up
private static boolean topologyNameExists(Map conf, String name) {
    NimbusClient client = NimbusClient.getConfiguredClient(conf);
    try {
        ClusterSummary summary = client.getClient().getClusterInfo();
        for (TopologySummary s : summary.get_topologies()) {
            if (s.get_name().equals(name)) {
                return true;
            }
        }
        return false;

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}
 
Example 2
Source File: NimbusClientManager.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static NimbusClient getNimbusClient(String clusterName) throws Exception {
    Map conf = UIUtils.readUiConfig();
    NimbusClient client = clientManager.get(clusterName);
    if (client != null) {
        try {
            client.getClient().getVersion();
            LOG.info("get Nimbus Client from clientManager");
        } catch (Exception e) {
            LOG.info("Nimbus has been restarted, it begin to reconnect");
            client = null;
        }
    }

    if (client == null) {
        conf = UIUtils.resetZKConfig(conf, clusterName);
        client = NimbusClient.getConfiguredClient(conf);
        clientManager.put(clusterName, client);
    }

    return client;
}
 
Example 3
Source File: activate.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
}
 
Example 4
Source File: list.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
}
 
Example 5
Source File: complete_upgrade.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
}
 
Example 6
Source File: rebalance.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
}
 
Example 7
Source File: rollback_topology.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
}
 
Example 8
Source File: deactivate.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
}
 
Example 9
Source File: restart.java    From jstorm with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 10
Source File: metrics_monitor.java    From jstorm with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 11
Source File: blacklist.java    From jstorm with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 12
Source File: kill_topology.java    From jstorm with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 13
Source File: gray_upgrade.java    From jstorm with Apache License 2.0 5 votes vote down vote up
private static void upgradeTopology(String topologyName, String component, List<String> workers, int workerNum)
        throws Exception {
    Map conf = Utils.readStormConfig();
    NimbusClient client = NimbusClient.getConfiguredClient(conf);
    try {
        String topologyId = client.getClient().getTopologyId(topologyName);
        Map stormConf = (Map) Utils.from_json(client.getClient().getTopologyConf(topologyId));
        // check if TM is a separate worker
        TopologyInfo topologyInfo = client.getClient().getTopologyInfo(topologyId);
        for (TaskSummary taskSummary : topologyInfo.get_tasks()) {
            if (!taskSummary.get_status().equalsIgnoreCase("active")) {
                CommandLineUtil.error("Some of the tasks are not in ACTIVE state, cannot perform the upgrade!");
                return;
            }
        }

        if (!ConfigExtension.isTmSingleWorker(stormConf, topologyInfo.get_topology().get_numWorkers())) {
            CommandLineUtil.error("Gray upgrade requires that topology master to be a single worker, " +
                    "cannot perform the upgrade!");
            return;
        }

        client.getClient().grayUpgrade(topologyName, component, workers, workerNum);
        CommandLineUtil.success("Successfully submit command gray_upgrade " + topologyName);
    } catch (Exception ex) {
        CommandLineUtil.error("Failed to perform gray_upgrade: " + ex.getMessage());
        ex.printStackTrace();
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
 
Example 14
Source File: NimbusBlobStore.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Map conf) {
    this.client = NimbusClient.getConfiguredClient(conf);
    if (conf != null) {
        this.bufferSize = JStormUtils.parseInt(conf.get(Config.STORM_BLOBSTORE_INPUTSTREAM_BUFFER_SIZE_BYTES), bufferSize);
    }
}
 
Example 15
Source File: JStormHelper.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public static NimbusClient getNimbusClient(Map conf) {
    if (client != null) {
        return client;
    }

    if (conf == null) {
        conf = Utils.readStormConfig();

    }
    client = NimbusClient.getConfiguredClient(conf);
    return client;
}
 
Example 16
Source File: ClusterInfoBolt.java    From jstorm with Apache License 2.0 4 votes vote down vote up
private void initClient(Map map) {
    nimbusClient = NimbusClient.getConfiguredClient(map);
    client = nimbusClient.getClient();
}
 
Example 17
Source File: StormTopologySubmitter.java    From incubator-samoa with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
  Properties props = StormSamoaUtils.getProperties();

  String uploadedJarLocation = props.getProperty(StormJarSubmitter.UPLOADED_JAR_LOCATION_KEY);
  if (uploadedJarLocation == null) {
    logger.error("Invalid properties file. It must have key {}",
        StormJarSubmitter.UPLOADED_JAR_LOCATION_KEY);
    return;
  }

  List<String> tmpArgs = new ArrayList<String>(Arrays.asList(args));
  int numWorkers = StormSamoaUtils.numWorkers(tmpArgs);

  args = tmpArgs.toArray(new String[0]);
  StormTopology stormTopo = StormSamoaUtils.argsToTopology(args);

  Config conf = new Config();
  conf.putAll(Utils.readStormConfig());
  conf.putAll(Utils.readCommandLineOpts());
  conf.setDebug(false);
  conf.setNumWorkers(numWorkers);

  String profilerOption =
      props.getProperty(StormTopologySubmitter.YJP_OPTIONS_KEY);
  if (profilerOption != null) {
    String topoWorkerChildOpts = (String) conf.get(Config.TOPOLOGY_WORKER_CHILDOPTS);
    StringBuilder optionBuilder = new StringBuilder();
    if (topoWorkerChildOpts != null) {
      optionBuilder.append(topoWorkerChildOpts);
      optionBuilder.append(' ');
    }
    optionBuilder.append(profilerOption);
    conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, optionBuilder.toString());
  }

  Map<String, Object> myConfigMap = new HashMap<String, Object>(conf);
  StringWriter out = new StringWriter();

  try {
    JSONValue.writeJSONString(myConfigMap, out);
  } catch (IOException e) {
    System.out.println("Error in writing JSONString");
    e.printStackTrace();
    return;
  }

  Config config = new Config();
  config.putAll(Utils.readStormConfig());

  NimbusClient nc = NimbusClient.getConfiguredClient(config);
  String topologyName = stormTopo.getTopologyName();
  try {
    System.out.println("Submitting topology with name: "
        + topologyName);
    nc.getClient().submitTopology(topologyName, uploadedJarLocation,
        out.toString(), stormTopo.getStormBuilder().createTopology());
    System.out.println(topologyName + " is successfully submitted");

  } catch (AlreadyAliveException aae) {
    System.out.println("Fail to submit " + topologyName
        + "\nError message: " + aae.get_msg());
  } catch (InvalidTopologyException ite) {
    System.out.println("Invalid topology for " + topologyName);
    ite.printStackTrace();
  } catch (TException te) {
    System.out.println("Texception for " + topologyName);
    te.printStackTrace();
  }
}
 
Example 18
Source File: StormSubmitter.java    From eagle with Apache License 2.0 4 votes vote down vote up
/**
 * Submit jar file
 * @param conf the topology-specific configuration. See {@link Config}.
 * @param localJar file path of the jar file to submit
 * @param listener progress listener to track the jar file upload
 * @return the remote location of the submitted jar
 */
public static String submitJar(Map conf, String localJar, ProgressListener listener) {
    if (localJar == null) {
        throw new RuntimeException("Must submit topologies using the 'storm' client script so that StormSubmitter knows which jar to upload.");
    }

    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, THRIFT_CHUNK_SIZE_BYTES);

        long totalSize = new File(localJar).length();
        if (listener != null) {
            listener.onStart(localJar, uploadLocation, totalSize);
        }

        long bytesUploaded = 0;
        while (true) {
            byte[] toSubmit = is.read();
            bytesUploaded += toSubmit.length;
            if (listener != null) {
                listener.onProgress(localJar, uploadLocation, bytesUploaded, totalSize);
            }

            if (toSubmit.length == 0) {
                break;
            }
            client.getClient().uploadChunk(uploadLocation, ByteBuffer.wrap(toSubmit));
        }
        client.getClient().finishFileUpload(uploadLocation);

        if (listener != null) {
            listener.onCompleted(localJar, uploadLocation, totalSize);
        }

        LOG.info("Successfully uploaded topology jar to assigned location: " + uploadLocation);
        return uploadLocation;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}