예제 #1
0
 public UserCacheRecord next() {
   try {
     UserCacheRecord returnBean = null;
     while (returnBean == null && this.storageKeyIterator.hasNext()) {
       UserCacheService.StorageKey key = this.storageKeyIterator.next();
       returnBean = userCacheService.readStorageKey(key);
       if (returnBean != null) {
         if (returnBean.getCacheTimestamp() == null) {
           LOGGER.debug(
               PwmConstants.REPORTING_SESSION_LABEL,
               "purging record due to missing cache timestamp: "
                   + JsonUtil.serialize(returnBean));
           userCacheService.removeStorageKey(key);
         } else if (TimeDuration.fromCurrent(returnBean.getCacheTimestamp())
             .isLongerThan(settings.getMaxCacheAge())) {
           LOGGER.debug(
               PwmConstants.REPORTING_SESSION_LABEL,
               "purging record due to old age timestamp: " + JsonUtil.serialize(returnBean));
           userCacheService.removeStorageKey(key);
         } else {
           return returnBean;
         }
       }
     }
   } catch (LocalDBException e) {
     throw new IllegalStateException(
         "unexpected iterator traversal error while reading LocalDB: " + e.getMessage());
   }
   return null;
 }
예제 #2
0
    protected ConfigSaveState updatePartial(String xmlPartial, final String md5) throws Exception {
      LOGGER.debug("[Config Save] Updating partial");
      org.dom4j.Document document = documentRoot();
      Element root = document.getRootElement();

      Element configElement = ((Element) root.selectSingleNode(getXpath()));
      List nodes = configElement.getParent().content();
      int index = nodes.indexOf(configElement);

      LOGGER.debug("[Config Save] Converting to object");
      Element newConfigElement = reader.read(new StringReader(xmlPartial)).getRootElement();
      nodes.set(index, newConfigElement);

      return saveConfig(document.asXML(), md5);
    }
예제 #3
0
 protected Audit waitForAuditToComplete(Audit audit) {
   LOGGER.debug(
       "WAIT FOR AUDIT TO COMPLETE:"
           + audit
           + ","
           + (long) (audit.getDateOfCreation().getTime() / 1000));
   Long token = new Date().getTime();
   this.getAuditExecutionList().put(audit, token);
   // while the audit is not seen as completed or crashed
   while (!this.getAuditCompletedList().containsKey(token)
       && !this.getAuditCrashedList().containsKey(token)) {
     try {
       Thread.sleep(500);
     } catch (InterruptedException ex) {
       LOGGER.error("", ex);
     }
   }
   if ((audit = this.getAuditCompletedList().get(token)) != null) {
     this.getAuditCompletedList().remove(token);
     return audit;
   }
   if ((audit = this.getAuditCrashedList().get(token).getKey()) != null) {
     this.getAuditCrashedList().remove(token);
     return audit;
   }
   return null;
 }
예제 #4
0
 @Override
 public void auditCompleted(Audit audit) {
   LOGGER.debug(
       "AUDIT COMPLETED:"
           + audit
           + ","
           + audit.getSubject().getURL()
           + ","
           + (long) (audit.getDateOfCreation().getTime() / 1000)
           + audit.getId());
   Audit auditCompleted = null;
   for (Audit auditRunning : this.auditExecutionList.keySet()) {
     if (auditRunning.getId().equals(audit.getId())
         && (long) (auditRunning.getDateOfCreation().getTime() / 1000)
             == (long) (audit.getDateOfCreation().getTime() / 1000)) {
       auditCompleted = auditRunning;
       break;
     }
   }
   if (auditCompleted != null) {
     Long token = this.auditExecutionList.get(auditCompleted);
     this.auditExecutionList.remove(auditCompleted);
     this.auditCompletedList.put(token, audit);
   }
 }
    public void process(WatchedEvent event) {
      LOGGER.debug(
          "Watcher fired on path: "
              + event.getPath()
              + " state: "
              + event.getState()
              + " type "
              + event.getType());

      latchIfNoChange.countDown();

      // ignore any children except valid children for a queue
      if (keyHandler.hasValidName(ZkUtils.getPathEnd(event.getPath()))) {

        if (highestPriorityChanged == null) {
          highestPriorityChanged = keyHandler.getPriority(event.getPath());
        } else {
          synchronized (highestPriorityChanged) {
            PRIORITY changedPriority = keyHandler.getPriority(event.getPath());
            if (changedPriority != null && changedPriority.compareTo(highestPriorityChanged) < 0) {
              highestPriorityChanged = changedPriority;
            }
          }
        }
      }
    }
예제 #6
0
    protected ConfigSaveState saveConfig(final String xmlString, final String md5)
        throws Exception {
      LOGGER.debug("[Config Save] Started saving XML");
      final MagicalGoConfigXmlLoader configXmlLoader =
          new MagicalGoConfigXmlLoader(configCache, registry);

      LOGGER.debug("[Config Save] Updating config");
      final CruiseConfig deserializedConfig = configXmlLoader.deserializeConfig(xmlString);

      ConfigSaveState configSaveState =
          systemEnvironment.optimizeFullConfigSave()
              ? saveConfigNewFlow(deserializedConfig, md5)
              : saveConfigOldFlow(deserializedConfig, md5);

      LOGGER.debug("[Config Save] Finished saving XML");
      return configSaveState;
    }
예제 #7
0
    private ConfigSaveState saveConfigOldFlow(
        final CruiseConfig deserializedConfig, final String md5) {
      LOGGER.debug("[Config Save] Updating config using the old flow");
      return goConfigDao.updateConfig(
          new NoOverwriteUpdateConfigCommand() {
            public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
              deserializedConfig.setPartials(cruiseConfig.getPartials());
              return deserializedConfig;
            }

            public String unmodifiedMd5() {
              return md5;
            }
          });
    }
예제 #8
0
 /**
  * Since the columns should only be read once, copy them into a HashMap and consider that to be
  * the "record"
  *
  * @return a HashMap mapping column names with values
  */
 public Map<String, Object> getColumnValues() throws SQLException {
   ResultSetMetaData mdata = rs.getMetaData();
   int count = mdata.getColumnCount();
   Map<String, Object> nativeItem = new HashMap<String, Object>(count);
   for (int i = 1; i <= count; ++i) {
     String fieldName =
         new StringBuilder()
             .append(mdata.getTableName(i))
             .append(".")
             .append(mdata.getColumnName(i))
             .toString();
     nativeItem.put(fieldName, rs.getObject(i));
     LOGGER.debug(fieldName + "=" + nativeItem.get(fieldName));
   }
   return nativeItem;
 }
예제 #9
0
 private ConfigSaveState saveConfigNewFlow(CruiseConfig cruiseConfig, String md5) {
   LOGGER.debug("[Config Save] Updating config using the new flow");
   return goConfigDao.updateFullConfig(new FullConfigUpdateCommand(cruiseConfig, md5));
 }
예제 #10
0
    private void reduceWordDB() throws LocalDBException {

      if (localDB == null || localDB.status() != LocalDB.Status.OPEN) {
        return;
      }

      final long oldestEntryAge = System.currentTimeMillis() - oldestEntry;
      if (oldestEntryAge < settings.maxAgeMs) {
        LOGGER.debug(
            "skipping wordDB reduce operation, eldestEntry="
                + TimeDuration.asCompactString(oldestEntryAge)
                + ", maxAge="
                + TimeDuration.asCompactString(settings.maxAgeMs));
        return;
      }

      final long startTime = System.currentTimeMillis();
      final int initialSize = size();
      int removeCount = 0;
      long localOldestEntry = System.currentTimeMillis();

      LOGGER.debug(
          "beginning wordDB reduce operation, examining "
              + initialSize
              + " words for entries older than "
              + TimeDuration.asCompactString(settings.maxAgeMs));

      LocalDB.LocalDBIterator<String> keyIterator = null;
      try {
        keyIterator = localDB.iterator(WORDS_DB);
        while (status == STATUS.OPEN && keyIterator.hasNext()) {
          final String key = keyIterator.next();
          final String value = localDB.get(WORDS_DB, key);
          final long timeStamp = Long.parseLong(value);
          final long entryAge = System.currentTimeMillis() - timeStamp;

          if (entryAge > settings.maxAgeMs) {
            localDB.remove(WORDS_DB, key);
            removeCount++;

            if (removeCount % 1000 == 0) {
              LOGGER.trace(
                  "wordDB reduce operation in progress, removed="
                      + removeCount
                      + ", total="
                      + (initialSize - removeCount));
            }
          } else {
            localOldestEntry = timeStamp < localOldestEntry ? timeStamp : localOldestEntry;
          }
          sleeper.sleep();
        }
      } finally {
        try {
          if (keyIterator != null) {
            keyIterator.close();
          }
        } catch (Exception e) {
          LOGGER.warn("error returning LocalDB iterator: " + e.getMessage());
        }
      }

      // update the oldest entry
      if (status == STATUS.OPEN) {
        oldestEntry = localOldestEntry;
        localDB.put(META_DB, KEY_OLDEST_ENTRY, Long.toString(oldestEntry));
      }

      final StringBuilder sb = new StringBuilder();
      sb.append("completed wordDB reduce operation");
      sb.append(", removed=").append(removeCount);
      sb.append(", totalRemaining=").append(size());
      sb.append(", oldestEntry=").append(TimeDuration.asCompactString(oldestEntry));
      sb.append(" in ")
          .append(TimeDuration.asCompactString(System.currentTimeMillis() - startTime));
      LOGGER.debug(sb.toString());
    }