Пример #1
0
  public void init() throws javax.servlet.ServletException {
    super.init();

    org.slf4j.Logger logServerStartup = org.slf4j.LoggerFactory.getLogger("serverStartup");
    logServerStartup.info(
        getClass().getName() + " initialization start - " + UsageLog.setupNonRequestContext());

    this.ascLimit = ThreddsConfig.getInt("Opendap.ascLimit", ascLimit);
    this.binLimit = ThreddsConfig.getInt("Opendap.binLimit", binLimit);

    this.odapVersionString = ThreddsConfig.get("Opendap.serverVersion", odapVersionString);
    logServerStartup.info(
        getClass().getName()
            + " version= "
            + odapVersionString
            + " ascLimit = "
            + ascLimit
            + " binLimit = "
            + binLimit);

    // debugging actions
    makeDebugActions();

    logServerStartup.info(
        getClass().getName()
            + " initialization done - "
            + UsageLog.closingMessageNonRequestContext());
  }
Пример #2
0
  /**
   * ************************************************************************ Prints the Bad URL
   * Page page to the passed PrintWriter
   *
   * @param pw PrintWriter stream to which to dump the bad URL page.
   */
  private void printBadURLPage(PrintWriter pw) {

    String serverContactName = ThreddsConfig.get("serverInformation.contact.name", "UNKNOWN");
    String serverContactEmail = ThreddsConfig.get("serverInformation.contact.email", "UNKNOWN");
    pw.println("<h3>Error in URL</h3>");
    pw.println("The URL extension did not match any that are known by this");
    pw.println("server. Below is a list of the five extensions that are be recognized by");
    pw.println("all OPeNDAP servers. If you think that the server is broken (that the URL you");
    pw.println("submitted should have worked), then please contact the");
    pw.println("administrator of this server [" + serverContactName + "] at: ");
    pw.println("<a href='mailto:" + serverContactEmail + "'>" + serverContactEmail + "</a><p>");
  }
Пример #3
0
  public void afterPropertiesSet() {

    // ToDo Instead of stdout, use servletContext.log( "...") [NOTE: it writes to localhost.*.log
    // rather than catalina.out].
    if (servletContext == null)
      throw new IllegalArgumentException("ServletContext must not be null.");

    // ToDo LOOK - Are we still using this.
    ServletUtil.initDebugging(servletContext);

    // Set the webapp name.
    this.webappName = servletContext.getServletContextName();

    // Set the context path.
    // Servlet 2.5 allows the following.
    // contextPath = servletContext.getContextPath();
    String tmpContextPath =
        servletContext.getInitParameter(
            "ContextPath"); // cannot be overridden in the ThreddsConfig file
    if (tmpContextPath == null) tmpContextPath = "thredds";
    contextPath = "/" + tmpContextPath;
    // ToDo LOOK - Get rid of need for setting contextPath in ServletUtil.
    ServletUtil.setContextPath(contextPath);

    // Set the root directory and source.
    String rootPath = servletContext.getRealPath("/");
    if (rootPath == null) {
      String msg =
          "Webapp ["
              + this.webappName
              + "] must run with exploded deployment directory (not from .war).";
      System.out.println("ERROR - TdsContext.init(): " + msg);
      // logServerStartup.error( "TdsContext.init(): " + msg );
      throw new IllegalStateException(msg);
    }
    this.rootDirectory = new File(rootPath);
    this.rootDirSource = new BasicDescendantFileSource(this.rootDirectory);
    this.rootDirectory = this.rootDirSource.getRootDirectory();
    // ToDo LOOK - Get rid of need for setting rootPath in ServletUtil.
    ServletUtil.setRootPath(this.rootDirSource.getRootDirectoryPath());

    // Set the startup (initial install) content directory and source.
    this.startupContentDirectory = new File(this.rootDirectory, this.startupContentPath);
    this.startupContentDirSource = new BasicDescendantFileSource(this.startupContentDirectory);
    this.startupContentDirectory = this.startupContentDirSource.getRootDirectory();

    this.webinfPath = this.rootDirectory + "/WEB-INF";

    // set the tomcat logging directory
    try {
      String base = System.getProperty("catalina.base");
      if (base != null) {
        this.tomcatLogDir = new File(base, "logs").getCanonicalFile();
        if (!this.tomcatLogDir.exists()) {
          String msg = "'catalina.base' directory not found";
          System.out.println("WARN - TdsContext.init(): " + msg);
          // logServerStartup.error( "TdsContext.init(): " + msg );
        }
      } else {
        String msg = "'catalina.base' property not found - probably not a tomcat server";
        System.out.println("WARN - TdsContext.init(): " + msg);
        // logServerStartup.warn( "TdsContext.init(): " + msg );
      }

    } catch (IOException e) {
      String msg = "tomcatLogDir could not be created";
      System.out.println("WARN - TdsContext.init(): " + msg);
      // logServerStartup.error( "TdsContext.init(): " + msg );
    }

    // Set the content directory and source.
    File contentRootDir = new File(this.contentRootPath);
    if (!contentRootDir.isAbsolute())
      this.contentDirectory =
          new File(new File(this.rootDirectory, this.contentRootPath), this.contentPath);
    else {
      if (contentRootDir.isDirectory())
        this.contentDirectory = new File(contentRootDir, this.contentPath);
      else {
        String msg = "Content root directory [" + this.contentRootPath + "] not a directory.";
        System.out.println("ERROR - TdsContext.init(): " + msg);
        // logServerStartup.error( "TdsContext.init(): " + msg );
        throw new IllegalStateException(msg);
      }
    }
    // If the content directory doesn't exist, try to copy startup content directory.
    if (!this.contentDirectory.exists()) {
      try {
        IO.copyDirTree(this.startupContentDirectory.getPath(), this.contentDirectory.getPath());
      } catch (IOException e) {
        String tmpMsg = "Content directory does not exist and could not be created";
        System.out.println(
            "ERROR - TdsContext.init(): "
                + tmpMsg
                + " ["
                + this.contentDirectory.getAbsolutePath()
                + "].");
        // logServerStartup.error( "TdsContext.init(): " + tmpMsg + " [" +
        // this.contentDirectory.getAbsolutePath() + "]" );
        throw new IllegalStateException(tmpMsg);
      }
    }

    // If content directory exists, make sure it is a directory.
    if (this.contentDirectory.isDirectory()) {
      this.contentDirSource =
          new BasicDescendantFileSource(
              StringUtils.cleanPath(this.contentDirectory.getAbsolutePath()));
      this.contentDirectory = this.contentDirSource.getRootDirectory();
    } else {
      String tmpMsg = "Content directory not a directory";
      System.out.println(
          "ERROR - TdsContext.init(): "
              + tmpMsg
              + " ["
              + this.contentDirectory.getAbsolutePath()
              + "].");
      // logServerStartup.error( "TdsContext.init(): " + tmpMsg + " [" +
      // this.contentDirectory.getAbsolutePath() + "]" );
      throw new IllegalStateException(tmpMsg);
    }
    ServletUtil.setContentPath(this.contentDirSource.getRootDirectoryPath());

    File logDir = new File(this.contentDirectory, "logs");
    if (!logDir.exists()) {
      if (!logDir.mkdirs()) {
        String msg = "Couldn't create TDS log directory [" + logDir.getPath() + "].";
        // System.out.println( "ERROR - TdsContext.init(): " + msg);
        logServerStartup.error("TdsContext.init(): " + msg);
        throw new IllegalStateException(msg);
      }
    }
    String loggingDirectory = StringUtil2.substitute(logDir.getPath(), "\\", "/");
    System.setProperty("tds.log.dir", loggingDirectory); // variable substitution

    // LOOK Remove log4j init JC 6/13/2012
    // which is used in log4j.xml file loaded here.
    Log4jWebConfigurer.initLogging(servletContext);
    logServerStartup.info("TdsConfigContextListener.contextInitialized() start[2]: ");
    logServerStartup.info("TdsContext.init()  intializating logging...");

    // read in persistent user-defined params from threddsConfig.xml
    File tdsConfigFile = this.contentDirSource.getFile(this.getTdsConfigFileName());
    String tdsConfigFilename = tdsConfigFile != null ? tdsConfigFile.getPath() : "";
    ThreddsConfig.init(tdsConfigFilename);

    this.publicContentDirectory = new File(this.contentDirectory, "public");
    if (!publicContentDirectory.exists()) {
      if (!publicContentDirectory.mkdirs()) {
        String msg =
            "Couldn't create TDS public directory [" + publicContentDirectory.getPath() + "].";
        // System.out.println( "ERROR - TdsContext.init(): " + msg);
        logServerStartup.error("TdsContext.init(): " + msg);
        throw new IllegalStateException(msg);
      }
    }
    this.publicContentDirSource = new BasicDescendantFileSource(this.publicContentDirectory);

    this.iddContentDirectory = new File(this.rootDirectory, this.iddContentPath);
    this.iddContentPublicDirSource = new BasicDescendantFileSource(this.iddContentDirectory);

    this.motherlodeContentDirectory = new File(this.rootDirectory, this.motherlodeContentPath);
    this.motherlodeContentPublicDirSource =
        new BasicDescendantFileSource(this.motherlodeContentDirectory);

    List<DescendantFileSource> chain = new ArrayList<DescendantFileSource>();
    DescendantFileSource contentMinusPublicSource =
        new BasicWithExclusionsDescendantFileSource(
            this.contentDirectory, Collections.singletonList("public"));
    chain.add(contentMinusPublicSource);
    for (String curContentRoot : ThreddsConfig.getContentRootList()) {
      if (curContentRoot.equalsIgnoreCase("idd")) chain.add(this.iddContentPublicDirSource);
      else if (curContentRoot.equalsIgnoreCase("motherlode"))
        chain.add(this.motherlodeContentPublicDirSource);
      else {
        try {
          chain.add(new BasicDescendantFileSource(StringUtils.cleanPath(curContentRoot)));
        } catch (IllegalArgumentException e) {
          String msg = "Couldn't add content root [" + curContentRoot + "]: " + e.getMessage();
          // System.out.println( "WARN - TdsContext.init(): " + msg );
          logServerStartup.warn("TdsContext.init(): " + msg, e);
        }
      }
    }
    this.configSource = new ChainedFileSource(chain);
    this.publicDocSource = this.publicContentDirSource;

    // ToDo LOOK Find a better way once thredds.catalog2 is used.
    InvDatasetScan.setContext(contextPath);
    InvDatasetScan.setCatalogServletName("/catalog");
    InvDatasetFeatureCollection.setContext(contextPath);
    // GridServlet.setContextPath( contextPath ); // Won't need when switch GridServlet to use Swing
    // MVC and TdsContext

    jspRequestDispatcher = servletContext.getNamedDispatcher("jsp");
    defaultRequestDispatcher = servletContext.getNamedDispatcher("default");

    TdsConfigMapper tdsConfigMapper = new TdsConfigMapper();
    tdsConfigMapper.setTdsServerInfo(this.serverInfo);
    tdsConfigMapper.setHtmlConfig(this.htmlConfig);
    tdsConfigMapper.setWmsConfig(this.wmsConfig);
    tdsConfigMapper.init(this);
  }
Пример #4
0
  void init(TdsContext tdsContext) {
    // new for 4.2 - feature collection caching
    String fcCache =
        ThreddsConfig.get(
            "FeatureCollection.cacheDirectory",
            tdsContext.getContentDirectory().getPath() + "/collectionCache/");
    try {
      thredds.inventory.bdb.MetadataManager.setCacheDirectory(fcCache);
      startupLog.info("CdmInit: FeatureCollection.cacheDirectory= " + fcCache);
    } catch (Exception e) {
      startupLog.error("CdmInit: Failed to open FeatureCollection.cacheDirectory= " + fcCache, e);
    }

    // new for 4.1 - ehcache object caching
    String ehConfig =
        ThreddsConfig.get("ehcache.configFile", tdsContext.getWebinfPath() + "/ehcache.xml");
    String ehDirectory =
        ThreddsConfig.get(
            "ehcache.directory", tdsContext.getContentDirectory().getPath() + "/ehcache/");
    try {
      cacheManager =
          thredds.filesystem.ControllerCaching.makeStandardController(ehConfig, ehDirectory);
      thredds.inventory.DatasetCollectionManager.setController(cacheManager);
      startupLog.info("CdmInit: ehcache.config= " + ehConfig + " directory= " + ehDirectory);

    } catch (IOException ioe) {
      startupLog.error("CdmInit: Cant read ehcache config file " + ehConfig, ioe);
    }

    boolean useBytesForDataSize =
        ThreddsConfig.getBoolean("catalogWriting.useBytesForDataSize", false);
    InvCatalogFactory10.useBytesForDataSize(useBytesForDataSize);

    ////////////////////////////////////
    // AggregationFmrc.setDefinitionDirectory(new File(tdsContext.getRootDirectory(),
    // fmrcDefinitionDirectory));
    FmrcInventoryServlet.setDefinitionDirectory(
        new File(tdsContext.getRootDirectory(), fmrcDefinitionDirectory));

    // NetcdfFileCache : default is allow 200 - 400 open files, cleanup every 10 minutes
    int min = ThreddsConfig.getInt("NetcdfFileCache.minFiles", 200);
    int max = ThreddsConfig.getInt("NetcdfFileCache.maxFiles", 400);
    int secs = ThreddsConfig.getSeconds("NetcdfFileCache.scour", 10 * 60);
    if (max > 0) {
      NetcdfDataset.initNetcdfFileCache(min, max, secs);
    }

    // HTTP file access : // allow 20 - 40 open datasets, cleanup every 10 minutes
    min = ThreddsConfig.getInt("HTTPFileCache.minFiles", 25);
    max = ThreddsConfig.getInt("HTTPFileCache.maxFiles", 40);
    secs = ThreddsConfig.getSeconds("HTTPFileCache.scour", 10 * 60);
    if (max > 0) {
      ServletUtil.setFileCache(new FileCacheRaf(min, max, secs));
    }

    // for backwards compatibility - should be replaced by direct specifying of the IndexExtendMode
    // turn off Grib extend indexing; indexes are automatically done every 10 minutes externally
    boolean extendIndex = ThreddsConfig.getBoolean("GribIndexing.setExtendIndex", false);
    GridServiceProvider.IndexExtendMode mode =
        extendIndex
            ? GridServiceProvider.IndexExtendMode.extendwrite
            : GridServiceProvider.IndexExtendMode.readonly;
    ucar.nc2.iosp.grid.GridServiceProvider.setIndexFileModeOnOpen(mode);
    ucar.nc2.iosp.grid.GridServiceProvider.setIndexFileModeOnSync(mode);

    boolean alwaysUseCache = ThreddsConfig.getBoolean("GribIndexing.alwaysUseCache", false);
    ucar.nc2.iosp.grid.GridServiceProvider.setIndexAlwaysInCache(alwaysUseCache);

    // optimization: netcdf-3 files can only grow, not have metadata changes
    ucar.nc2.NetcdfFile.setProperty("syncExtendOnly", "true");

    // persist joinNew aggregations. default every 24 hours, delete stuff older than 90 days
    String dir =
        ThreddsConfig.get(
            "AggregationCache.dir",
            new File(tdsContext.getContentDirectory().getPath(), "cacheAged").getPath());
    int scourSecs = ThreddsConfig.getSeconds("AggregationCache.scour", 24 * 60 * 60);
    int maxAgeSecs = ThreddsConfig.getSeconds("AggregationCache.maxAge", 90 * 24 * 60 * 60);
    aggCache = new DiskCache2(dir, false, maxAgeSecs / 60, scourSecs / 60);
    Aggregation.setPersistenceCache(aggCache);

    // how to choose the typical dataset ?
    String typicalDataset = ThreddsConfig.get("Aggregation.typicalDataset", "penultimate");
    Aggregation.setTypicalDatasetMode(typicalDataset);

    // Nj22 disk cache
    dir =
        ThreddsConfig.get(
            "DiskCache.dir", new File(tdsContext.getContentDirectory(), "cache").getPath());
    boolean alwaysUse = ThreddsConfig.getBoolean("DiskCache.alwaysUse", false);
    scourSecs = ThreddsConfig.getSeconds("DiskCache.scour", 60 * 60);
    long maxSize = ThreddsConfig.getBytes("DiskCache.maxSize", (long) 1000 * 1000 * 1000);
    DiskCache.setRootDirectory(dir);
    DiskCache.setCachePolicy(alwaysUse);

    Calendar c = Calendar.getInstance(); // contains current startup time
    c.add(Calendar.SECOND, scourSecs / 2); // starting in half the scour time
    timer = new Timer();
    timer.scheduleAtFixedRate(new CacheScourTask(maxSize), c.getTime(), (long) 1000 * scourSecs);

    startupLog.info("CdmInit complete");
  }