Search in sources :

Example 6 with NotAliveException

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);
    }
}
Also used : TException(org.apache.thrift.TException) StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) LocalFsBlobStore(com.alibaba.jstorm.blobstore.LocalFsBlobStore) 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) BlobStore(com.alibaba.jstorm.blobstore.BlobStore) LocalFsBlobStore(com.alibaba.jstorm.blobstore.LocalFsBlobStore) 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) NimbusInfo(backtype.storm.nimbus.NimbusInfo)

Example 7 with NotAliveException

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);
    }
}
Also used : TException(org.apache.thrift.TException) 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) 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)

Example 8 with NotAliveException

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";
}
Also used : UIWorkerMetric(com.alibaba.jstorm.ui.model.UIWorkerMetric) NimbusClient(backtype.storm.utils.NimbusClient) NotAliveException(backtype.storm.generated.NotAliveException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotAliveException(backtype.storm.generated.NotAliveException) ModelMap(org.springframework.ui.ModelMap) TopologyInfo(backtype.storm.generated.TopologyInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with NotAliveException

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);
}
Also used : StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) NotAliveException(backtype.storm.generated.NotAliveException)

Example 10 with NotAliveException

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) {
        }
    }
}
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

NotAliveException (backtype.storm.generated.NotAliveException)14 IOException (java.io.IOException)12 AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)11 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)11 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)11 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)11 TopologyAssignException (backtype.storm.generated.TopologyAssignException)11 FailedAssignTopologyException (com.alibaba.jstorm.utils.FailedAssignTopologyException)11 FileNotFoundException (java.io.FileNotFoundException)11 InvalidParameterException (java.security.InvalidParameterException)11 TException (org.apache.thrift.TException)11 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)7 HashMap (java.util.HashMap)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 TreeMap (java.util.TreeMap)6 TimeCacheMap (com.alibaba.jstorm.utils.TimeCacheMap)5 Map (java.util.Map)5 StormTopology (backtype.storm.generated.StormTopology)3 TopologyInfo (backtype.storm.generated.TopologyInfo)2 TopologySummary (backtype.storm.generated.TopologySummary)2