use of com.alibaba.jstorm.callback.impl.RemoveTransitionCallback 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