Search in sources :

Example 1 with RemoveTransitionCallback

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) {
        }
    }
}
Also used : TException(org.apache.thrift.TException) StormTopology(backtype.storm.generated.StormTopology) RemoveTransitionCallback(com.alibaba.jstorm.callback.impl.RemoveTransitionCallback) IOException(java.io.IOException) AlreadyAliveException(backtype.storm.generated.AlreadyAliveException) InvalidParameterException(java.security.InvalidParameterException) FailedAssignTopologyException(com.alibaba.jstorm.utils.FailedAssignTopologyException) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(backtype.storm.generated.AlreadyAliveException) TopologyAssignException(backtype.storm.generated.TopologyAssignException) FileNotFoundException(java.io.FileNotFoundException) NotAliveException(backtype.storm.generated.NotAliveException) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) NotAliveException(backtype.storm.generated.NotAliveException) Map(java.util.Map) TreeMap(java.util.TreeMap) TimeCacheMap(com.alibaba.jstorm.utils.TimeCacheMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) File(java.io.File)

Aggregations

AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)1 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)1 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)1 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)1 NotAliveException (backtype.storm.generated.NotAliveException)1 StormTopology (backtype.storm.generated.StormTopology)1 TopologyAssignException (backtype.storm.generated.TopologyAssignException)1 RemoveTransitionCallback (com.alibaba.jstorm.callback.impl.RemoveTransitionCallback)1 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)1 FailedAssignTopologyException (com.alibaba.jstorm.utils.FailedAssignTopologyException)1 TimeCacheMap (com.alibaba.jstorm.utils.TimeCacheMap)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvalidParameterException (java.security.InvalidParameterException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TException (org.apache.thrift.TException)1