예제 #1
0
  /** checks the resources and pauses crawls if necessary */
  public void resourceObserverJob() {
    MemoryControl.setDHTMbyte(getMinFreeMemory());

    normalizedDiskFree = getNormalizedDiskFree();
    normalizedMemoryFree = getNormalizedMemoryFree();

    if (normalizedDiskFree.compareTo(Space.HIGH) < 0
        || normalizedMemoryFree.compareTo(Space.HIGH) < 0) {

      if (normalizedDiskFree.compareTo(Space.HIGH) < 0) { // pause crawls
        if (!sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)) {
          log.logInfo("pausing local crawls");
          sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
        }
        if (!sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL)) {
          log.logInfo("pausing remote triggered crawls");
          sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
        }
      }

      if ((normalizedDiskFree == Space.LOW || normalizedMemoryFree.compareTo(Space.HIGH) < 0)
          && sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false)) {
        log.logInfo("disabling index receive");
        sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false);
        sb.peers.mySeed().setFlagAcceptRemoteIndex(false);
        sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, true);
      }
    } else {
      if (sb.getConfigBool(
          SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, false)) { // we were wrong!
        log.logInfo("enabling index receive");
        sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true);
        sb.peers.mySeed().setFlagAcceptRemoteIndex(true);
        sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, false);
      }
      log.logInfo("resources ok");
    }
  }
예제 #2
0
  public static serverObjects respond(
      final RequestHeader header, final serverObjects post, final serverSwitch env) {
    final Switchboard sb = (Switchboard) env;
    final serverObjects prop = new serverObjects();

    final boolean authenticated = sb.adminAuthenticated(header) >= 2;
    final int display = ((post == null) || (!authenticated)) ? 0 : post.getInt("display", 0);
    prop.put("display", display);

    final boolean showScore = ((post != null) && (post.containsKey("score")));

    // access control
    final boolean publicPage = sb.getConfigBool("publicSurftips", true);
    final boolean authorizedAccess = sb.verifyAuthentication(header, false);

    if ((publicPage) || (authorizedAccess)) {

      // read voting
      String hash;
      if ((post != null) && ((hash = post.get("voteNegative", null)) != null)) {
        if (!sb.verifyAuthentication(header, false)) {
          prop.put("AUTHENTICATE", "admin log-in"); // force log-in
          return prop;
        }
        // make new news message with voting
        if (!sb.isRobinsonMode()) {
          final HashMap<String, String> map = new HashMap<String, String>();
          map.put("urlhash", hash);
          map.put("vote", "negative");
          map.put("refid", post.get("refid", ""));
          sb.peers.newsPool.publishMyNews(
              sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map);
        }
      }
      if ((post != null) && ((hash = post.get("votePositive", null)) != null)) {
        if (!sb.verifyAuthentication(header, false)) {
          prop.put("AUTHENTICATE", "admin log-in"); // force log-in
          return prop;
        }
        // make new news message with voting
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put("urlhash", hash);
        map.put("url", crypt.simpleDecode(post.get("url", ""), null));
        map.put("title", crypt.simpleDecode(post.get("title", ""), null));
        map.put("description", crypt.simpleDecode(post.get("description", ""), null));
        map.put("vote", "positive");
        map.put("refid", post.get("refid", ""));
        map.put("comment", post.get("comment", ""));
        sb.peers.newsPool.publishMyNews(
            sb.peers.mySeed(), yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD, map);
      }

      // create Supporter
      final HashMap<String, Integer> negativeHashes =
          new HashMap<String, Integer>(); // a mapping from an url hash to Integer (count of votes)
      final HashMap<String, Integer> positiveHashes =
          new HashMap<String, Integer>(); // a mapping from an url hash to Integer (count of votes)
      accumulateVotes(sb, negativeHashes, positiveHashes, yacyNewsPool.INCOMING_DB);
      // accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);
      // accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);
      final ScoreMap<String> ranking =
          new ConcurrentScoreMap<String>(); // score cluster for url hashes
      final Row rowdef =
          new Row(
              "String url-255, String title-120, String description-120, String refid-"
                  + (GenericFormatter.PATTERN_SHORT_SECOND.length() + 12),
              NaturalOrder.naturalOrder);
      final HashMap<String, Entry> Supporter =
          new HashMap<
              String,
              Entry>(); // a mapping from an url hash to a kelondroRow.Entry with display properties
      accumulateSupporter(
          sb, Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.INCOMING_DB);
      // accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes,
      // yacyNewsPool.OUTGOING_DB);
      // accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes,
      // yacyNewsPool.PUBLISHED_DB);

      // read out surftipp array and create property entries
      final Iterator<String> k = ranking.keys(false);
      int i = 0;
      Row.Entry row;
      String url, urlhash, refid, title, description;
      boolean voted;
      while (k.hasNext()) {
        urlhash = k.next();
        if (urlhash == null) continue;

        row = Supporter.get(urlhash);
        if (row == null) continue;

        url = row.getColString(0);
        try {
          if (Switchboard.urlBlacklist.isListed(
              Blacklist.BLACKLIST_SURFTIPS, new DigestURI(url, urlhash.getBytes()))) continue;
        } catch (final MalformedURLException e) {
          continue;
        }
        title = row.getColString(1);
        description = row.getColString(2);
        if ((url == null) || (title == null) || (description == null)) continue;
        refid = row.getColString(3);
        voted =
            (sb.peers.newsPool.getSpecific(
                        yacyNewsPool.OUTGOING_DB,
                        yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD,
                        "refid",
                        refid)
                    != null)
                || (sb.peers.newsPool.getSpecific(
                        yacyNewsPool.PUBLISHED_DB,
                        yacyNewsPool.CATEGORY_SURFTIPP_VOTE_ADD,
                        "refid",
                        refid)
                    != null);
        prop.put("supporter_results_" + i + "_authorized", authenticated ? "1" : "0");
        prop.put("supporter_results_" + i + "_authorized_recommend", voted ? "0" : "1");

        prop.put("supporter_results_" + i + "_authorized_recommend_urlhash", urlhash);
        prop.put("supporter_results_" + i + "_authorized_recommend_refid", refid);
        prop.put(
            "supporter_results_" + i + "_authorized_recommend_url",
            crypt.simpleEncode(url, null, 'b'));
        prop.putHTML(
            "supporter_results_" + i + "_authorized_recommend_title",
            crypt.simpleEncode(title, null, 'b'));
        prop.putHTML(
            "supporter_results_" + i + "_authorized_recommend_description",
            crypt.simpleEncode(description, null, 'b'));
        prop.put("supporter_results_" + i + "_authorized_recommend_display", display);
        prop.put(
            "supporter_results_" + i + "_authorized_recommend_showScore", showScore ? "1" : "0");

        prop.put("supporter_results_" + i + "_authorized_urlhash", urlhash);
        prop.put("supporter_results_" + i + "_url", url);
        prop.put("supporter_results_" + i + "_urlname", nxTools.shortenURLString(url, 60));
        prop.put("supporter_results_" + i + "_urlhash", urlhash);
        prop.putHTML(
            "supporter_results_" + i + "_title",
            (showScore) ? ("(" + ranking.get(urlhash) + ") " + title) : title);
        prop.putHTML("supporter_results_" + i + "_description", description);
        i++;

        if (i >= 50) break;
      }
      prop.put("supporter_results", i);
      prop.put("supporter", "1");
    } else {
      prop.put("supporter", "0");
    }

    return prop;
  }