Beispiel #1
0
  /**
   * Adjust the command to suit the environment.
   *
   * @param command The command to run.
   * @return The adjusted command.
   */
  public List<String> prepareCommand(List<String> command) {
    ApplicationContext appContext = ApplicationContextProvider.getApplicationContext();
    NdgConfigManager ndgConfigManager = (NdgConfigManager) appContext.getBean("ndgConfigManager");

    String loc = ndgConfigManager.getConfig().getGdalLocation();
    if (loc == null) throw new IllegalStateException("GDAL location is not configured.");

    Path gdalBinDir = Paths.get(loc, "bin");
    Path gdalCmdPath = gdalBinDir.resolve(command.get(0));

    // Patch in path to GDAL, if appropriate.
    ArrayList<String> cmd = new ArrayList<String>();
    cmd.add(gdalCmdPath.toString());

    log.trace("cma [0] = {}", command.get(0));

    // Remove windows-style backslashes.
    for (int i = 1; i < command.size(); ++i) {
      log.trace("cma [{}] = {}", i, command.get(i));
      String s = command.get(i).replace('\\', '/');
      cmd.add(s);
    }

    String commandStr = StringUtils.join(cmd, " ");
    log.debug("Attempting to run: " + commandStr);

    return cmd;
  }
Beispiel #2
0
  @Override
  public NetcdfDataset open(
      String uri,
      String referential,
      BoxReal boundsHint,
      DateTime timeMin,
      DateTime timeMax,
      List<String> bands)
      throws IOException {

    NetcdfDataset ds;
    VectorReal min = boundsHint.getMin();
    VectorReal max = boundsHint.getMax();
    Box bounds = new Box(min.getX(), min.getY(), max.getX(), max.getY());

    Dataset dataset = findDataset(uri, referential);
    if (dataset == null) {
      throw new IOException(String.format("Could not find dataset %s", uri));
    }

    if (ndgConfigManager.getConfig().isFilelockingOn()) {
      ReadWriteLock lock = getLock(dataset);

      // If filelockingOn, then ensure can get all required read locks
      if (lock.readLock().tryLock()) {
        try {
          ds = open(uri, dataset, bounds, timeMin, timeMax, bands);
          try {
            ds = new RsaNetcdfDataset(ds, lock);
          } catch (IOException | RuntimeException e) {
            if (ds != null) ds.close();
            throw e;
          }
        } catch (IOException | RuntimeException e) {
          lock.readLock().unlock();
          throw e;
        }
      } else {
        throw new IOException(String.format("Could not lock dataset %s", uri));
      }

    } else {
      ds = open(uri, dataset, bounds, timeMin, timeMax, bands);
    }
    return ds;
  }