use of backtype.storm.generated.NotAliveException in project jstorm by alibaba.
the class ServiceHandler method updateTopology.
@Override
public void updateTopology(String name, String uploadedLocation, String updateConf) throws NotAliveException, InvalidTopologyException, TException {
try {
//firstly update jar and conf
checkTopologyActive(data, name, true);
String topologyId = null;
StormClusterState stormClusterState = data.getStormClusterState();
topologyId = Cluster.get_topology_id(stormClusterState, name);
if (topologyId == null) {
throw new NotAliveException(name);
}
BlobStore blobStore = data.getBlobStore();
StormClusterState clusterState = data.getStormClusterState();
NimbusInfo nimbusInfo = data.getNimbusHostPortInfo();
if (uploadedLocation != null) {
setupJar(uploadedLocation, topologyId, blobStore, clusterState, nimbusInfo, true);
}
Map topoConf = StormConfig.read_nimbus_topology_conf(topologyId, data.getBlobStore());
Map<Object, Object> config = (Map<Object, Object>) JStormUtils.from_json(updateConf);
topoConf.putAll(config);
String confKey = StormConfig.master_stormconf_key(topologyId);
BlobStoreUtils.updateBlob(blobStore, confKey, Utils.serialize(topoConf));
if (blobStore instanceof LocalFsBlobStore) {
clusterState.setup_blobstore(confKey, nimbusInfo, BlobStoreUtils.getVersionForKey(confKey, nimbusInfo, conf));
}
NimbusUtils.transitionName(data, name, true, StatusType.update_topology, config);
LOG.info("update topology " + name + " successfully");
notifyTopologyActionListener(name, "updateTopology");
} catch (NotAliveException e) {
String errMsg = "Error, no this topology " + name;
LOG.error(errMsg, e);
throw new NotAliveException(errMsg);
} catch (Exception e) {
String errMsg = "Failed to update topology " + name;
LOG.error(errMsg, e);
throw new TException(errMsg);
}
}
use of backtype.storm.generated.NotAliveException in project jstorm by alibaba.
the class ServiceHandler method rebalance.
/**
* rebalance one topology
*
* @param topologyName topology name
* @param options RebalanceOptions
* @@@ rebalance options hasn't implements
* <p/>
* It is used to let workers wait several seconds to finish jobs
*/
@Override
public void rebalance(String topologyName, RebalanceOptions options) throws TException, NotAliveException {
try {
checkTopologyActive(data, topologyName, true);
Integer wait_amt = null;
String jsonConf = null;
Boolean reassign = false;
if (options != null) {
if (options.is_set_wait_secs())
wait_amt = options.get_wait_secs();
if (options.is_set_reassign())
reassign = options.is_reassign();
if (options.is_set_conf())
jsonConf = options.get_conf();
}
LOG.info("Begin to rebalance " + topologyName + "wait_time:" + wait_amt + ", reassign: " + reassign + ", new worker/bolt configuration:" + jsonConf);
Map<Object, Object> conf = (Map<Object, Object>) JStormUtils.from_json(jsonConf);
NimbusUtils.transitionName(data, topologyName, true, StatusType.rebalance, wait_amt, reassign, conf);
notifyTopologyActionListener(topologyName, "rebalance");
} catch (NotAliveException e) {
String errMsg = "Rebalance Error, no this topology " + topologyName;
LOG.error(errMsg, e);
throw new NotAliveException(errMsg);
} catch (Exception e) {
String errMsg = "Failed to rebalance topology " + topologyName;
LOG.error(errMsg, e);
throw new TException(errMsg);
}
}
use of backtype.storm.generated.NotAliveException in project jstorm by alibaba.
the class LogController method deepSearch.
@RequestMapping(value = "/deepSearch", method = RequestMethod.GET)
public String deepSearch(@RequestParam(value = "cluster", required = true) String clusterName, @RequestParam(value = "tid", required = true) String topologyId, @RequestParam(value = "key", required = false) String keyword, @RequestParam(value = "caseIgnore", required = false) String caseIgnore, ModelMap model) {
clusterName = StringEscapeUtils.escapeHtml(clusterName);
topologyId = StringEscapeUtils.escapeHtml(topologyId);
boolean _caseIgnore = !StringUtils.isBlank(caseIgnore);
int port = UIUtils.getSupervisorPort(clusterName);
model.addAttribute("keyword", keyword);
List<Future<?>> futures = new ArrayList<>();
ConcurrentLinkedQueue<Map> result = new ConcurrentLinkedQueue<>();
if (filterKeyword(model, keyword)) {
NimbusClient client = null;
try {
// encode space and url characters
keyword = URLEncoder.encode(keyword, "UTF-8");
client = NimbusClientManager.getNimbusClient(clusterName);
TopologyInfo info = client.getClient().getTopologyInfo(topologyId);
String topologyName = info.get_topology().get_name();
List<UIWorkerMetric> workerData = UIMetricUtils.getWorkerMetrics(info.get_metrics().get_workerMetric(), topologyId, 60);
String dir = "." + File.separator + topologyName;
for (UIWorkerMetric metric : workerData) {
String logFile = topologyName + "-worker-" + metric.getPort() + ".log";
String url = String.format("http://%s:%s/logview?cmd=searchLog&file=%s&key=%s&offset=%s&case_ignore=%s", metric.getHost(), port, getFullFile(dir, logFile), keyword, 0, _caseIgnore);
futures.add(_backround.submit(new SearchRequest(url, metric.getHost(), metric.getPort(), dir, logFile, result)));
}
JStormServerUtils.checkFutures(futures);
model.addAttribute("result", result);
} catch (NotAliveException nae) {
model.addAttribute("tip", String.format("The topology: %s is dead.", topologyId));
} catch (Exception e) {
NimbusClientManager.removeClient(clusterName);
LOG.error(e.getMessage(), e);
UIUtils.addErrorAttribute(model, e);
}
}
model.addAttribute("clusterName", clusterName);
model.addAttribute("topologyId", topologyId);
model.addAttribute("logServerPort", port);
model.addAttribute("caseIgnore", _caseIgnore);
UIUtils.addTitleAttribute(model, "DeepSearch");
return "deepSearch";
}
use of backtype.storm.generated.NotAliveException in project jstorm by alibaba.
the class NimbusUtils method transitionName.
public static <T> void transitionName(NimbusData data, String topologyName, boolean errorOnNoTransition, StatusType transition_status, T... args) throws Exception {
StormClusterState stormClusterState = data.getStormClusterState();
String topologyId = Cluster.get_topology_id(stormClusterState, topologyName);
if (topologyId == null) {
throw new NotAliveException(topologyName);
}
transition(data, topologyId, errorOnNoTransition, transition_status, args);
}
use of backtype.storm.generated.NotAliveException in project jstorm by alibaba.
the class ServiceHandler method restart.
@Override
public void restart(String name, String jsonConf) throws TException, NotAliveException, InvalidTopologyException, TopologyAssignException {
LOG.info("Begin to restart " + name + ", new configuration:" + jsonConf);
// 1. get topologyId
StormClusterState stormClusterState = data.getStormClusterState();
String topologyId;
try {
topologyId = Cluster.get_topology_id(stormClusterState, name);
} catch (Exception e2) {
topologyId = null;
}
if (topologyId == null) {
LOG.info("No topology of " + name);
throw new NotAliveException("No topology of " + name);
}
// Restart the topology: Deactivate -> Kill -> Submit
// 2. Deactivate
deactivate(name);
JStormUtils.sleepMs(5000);
LOG.info("Deactivate " + name);
// 3. backup old jar/configuration/topology
StormTopology topology;
Map topologyConf;
String topologyCodeLocation = null;
try {
topology = StormConfig.read_nimbus_topology_code(topologyId, data.getBlobStore());
topologyConf = StormConfig.read_nimbus_topology_conf(topologyId, data.getBlobStore());
if (jsonConf != null) {
Map<Object, Object> newConf = (Map<Object, Object>) JStormUtils.from_json(jsonConf);
topologyConf.putAll(newConf);
}
// copy storm files back to inbox from blob store
String parent = StormConfig.masterInbox(conf);
topologyCodeLocation = parent + PathUtils.SEPERATOR + topologyId;
FileUtils.forceMkdir(new File(topologyCodeLocation));
FileUtils.cleanDirectory(new File(topologyCodeLocation));
copyBackToInbox(topologyId, topologyCodeLocation);
LOG.info("Successfully read old jar/conf/topology " + name);
notifyTopologyActionListener(name, "restart");
} catch (Exception e) {
LOG.error("Failed to read old jar/conf/topology", e);
if (topologyCodeLocation != null) {
try {
PathUtils.rmr(topologyCodeLocation);
} catch (IOException ignored) {
}
}
throw new TException("Failed to read old jar/conf/topology ");
}
// 4. Kill
// directly use remove command to kill, more stable than issue kill cmd
RemoveTransitionCallback killCb = new RemoveTransitionCallback(data, topologyId);
killCb.execute(new Object[0]);
LOG.info("Successfully kill the topology " + name);
// send metric events
KillTopologyEvent.pushEvent(topologyId);
// 5. submit
try {
submitTopology(name, topologyCodeLocation, JStormUtils.to_json(topologyConf), topology);
} catch (AlreadyAliveException e) {
LOG.info("Failed to kill the topology" + name);
throw new TException("Failed to kill the topology" + name);
} finally {
try {
PathUtils.rmr(topologyCodeLocation);
} catch (IOException ignored) {
}
}
}
Aggregations