Example #1
0
  private void doFetch(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {
    String fetchUrl = getRequired(req, "dir");
    String storeName = getRequired(req, "store");
    String pushVersionString = getOptional(req, "pushVersion");

    ReadOnlyStorageEngine store = this.getStore(storeName);
    if (store == null)
      throw new ServletException("'" + storeName + "' is not a registered read-only store.");

    long pushVersion;
    if (pushVersionString == null) {
      pushVersion = store.getCurrentVersionId() + 1;
    } else {
      pushVersion = Long.parseLong(pushVersionString);
      if (pushVersion <= store.getCurrentVersionId())
        throw new ServletException(
            "Version of push specified ("
                + pushVersion
                + ") should be greater than current version "
                + store.getCurrentVersionId());
    }

    // fetch the files if necessary
    File fetchDir = null;
    if (fileFetcher == null) {

      logger.warn("File fetcher class has not instantiated correctly");
      fetchDir = new File(fetchUrl);

    } else {
      logger.info("Executing fetch of " + fetchUrl);

      try {
        fetchDir =
            fileFetcher.fetch(
                fetchUrl, store.getStoreDirPath() + File.separator + "version-" + pushVersion);

        if (fetchDir == null) {
          throw new ServletException(
              "File fetcher failed for "
                  + fetchUrl
                  + " and store name = "
                  + storeName
                  + " due to incorrect input path/checksum error");
        } else {
          logger.info("Fetch complete.");
        }

      } catch (Exception e) {
        throw new ServletException("Exception in Fetcher = " + e.getMessage());
      }
    }
    resp.getWriter().write(fetchDir.getAbsolutePath());
  }
Example #2
0
  private void doRollback(HttpServletRequest req) throws ServletException {
    String storeName = getRequired(req, "store");
    long pushVersion = Long.parseLong(getRequired(req, "pushVersion"));

    ReadOnlyStorageEngine store = getStore(storeName);
    if (store == null)
      throw new ServletException("'" + storeName + "' is not a registered read-only store.");

    try {
      File rollbackVersionDir = new File(store.getStoreDirPath(), "version-" + pushVersion);

      store.rollback(rollbackVersionDir);
    } catch (Exception e) {
      throw new ServletException("Exception in Fetcher = " + e.getMessage());
    }
  }