Пример #1
0
 private void handleAdmin(SolrQueryRequest req, SolrQueryResponse rsp, SolrParams params) {
   String action = params.get("action");
   if ("stop".equalsIgnoreCase(action)) {
     String id = params.get("id");
     DaemonStream d = daemons.get(id);
     if (d != null) {
       d.close();
       rsp.add("result-set", new DaemonResponseStream("Deamon:" + id + " stopped on " + coreName));
     } else {
       rsp.add(
           "result-set", new DaemonResponseStream("Deamon:" + id + " not found on " + coreName));
     }
   } else if ("start".equalsIgnoreCase(action)) {
     String id = params.get("id");
     DaemonStream d = daemons.get(id);
     d.open();
     rsp.add("result-set", new DaemonResponseStream("Deamon:" + id + " started on " + coreName));
   } else if ("list".equalsIgnoreCase(action)) {
     Collection<DaemonStream> vals = daemons.values();
     rsp.add("result-set", new DaemonCollectionStream(vals));
   } else if ("kill".equalsIgnoreCase(action)) {
     String id = params.get("id");
     DaemonStream d = daemons.remove(id);
     if (d != null) {
       d.close();
     }
     rsp.add("result-set", new DaemonResponseStream("Deamon:" + id + " killed on " + coreName));
   }
 }
Пример #2
0
  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    SolrParams params = req.getParams();
    params = adjustParams(params);
    req.setParams(params);

    if (params.get("action") != null) {
      handleAdmin(req, rsp, params);
      return;
    }

    TupleStream tupleStream;

    try {
      tupleStream = this.streamFactory.constructStream(params.get("expr"));
    } catch (Exception e) {
      // Catch exceptions that occur while the stream is being created. This will include streaming
      // expression parse rules.
      SolrException.log(logger, e);
      rsp.add("result-set", new DummyErrorStream(e));

      return;
    }

    int worker = params.getInt("workerID", 0);
    int numWorkers = params.getInt("numWorkers", 1);
    StreamContext context = new StreamContext();
    context.workerID = worker;
    context.numWorkers = numWorkers;
    context.setSolrClientCache(clientCache);
    context.setModelCache(modelCache);
    context.put("core", this.coreName);
    context.put("solr-core", req.getCore());
    tupleStream.setStreamContext(context);

    // if asking for explanation then go get it
    if (params.getBool("explain", false)) {
      rsp.add("explanation", tupleStream.toExplanation(this.streamFactory));
    }

    if (tupleStream instanceof DaemonStream) {
      DaemonStream daemonStream = (DaemonStream) tupleStream;
      if (daemons.containsKey(daemonStream.getId())) {
        daemons.remove(daemonStream.getId()).close();
      }
      daemonStream.setDaemons(daemons);
      daemonStream.open(); // This will start the deamonStream
      daemons.put(daemonStream.getId(), daemonStream);
      rsp.add(
          "result-set",
          new DaemonResponseStream("Deamon:" + daemonStream.getId() + " started on " + coreName));
    } else {
      rsp.add("result-set", new TimerStream(new ExceptionStream(tupleStream)));
    }
  }