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;
}
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;
}
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();
}
}
}
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);
}
}
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();
}
}
}
Aggregations