private void runGraphOrOperator() throws Exception { VelocityContext velocityContext = metadataResourceEngine.getVelocityContext(); velocityContext.put("processingStartTime", DATETIME_FORMAT.format(new Date())); if (commandLineArgs.getOperatorName() != null) { // Operator name given: parameters and sources are parsed from command-line args runOperator(); } else if (commandLineArgs.getGraphFilePath() != null) { // Path to Graph XML given: parameters and sources are parsed from command-line args runGraph(); } velocityContext.put("processingStopTime", DATETIME_FORMAT.format(new Date())); }
@Test public void testMetadataFileOption() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject"); assertEquals(null, lineArgs.getMetadataFilePath()); lineArgs = parseArgs("Reproject", "-m", "metadata/reproject-md.properties"); assertEquals("metadata/reproject-md.properties", lineArgs.getMetadataFilePath()); }
private Map<String, String> getRawParameterMap() throws Exception { Map<String, String> parameterMap; String parameterFilePath = commandLineArgs.getParameterFilePath(); if (parameterFilePath != null) { // put command line parameters in the Velocity context so that we can reference them in the parameters file VelocityContext velocityContext = metadataResourceEngine.getVelocityContext(); velocityContext.put("parameters", commandLineArgs.getParameterMap()); Resource parameterFile = metadataResourceEngine.readResource("parameterFile", parameterFilePath); Map<String, String> configFilemap = parameterFile.getMap(); if (!parameterFile.isXml()) { configFilemap.putAll(commandLineArgs.getParameterMap()); } parameterMap = configFilemap; } else { parameterMap = new HashMap<>(); } // CLI parameters shall always overwrite file parameters parameterMap.putAll(commandLineArgs.getParameterMap()); metadataResourceEngine.getVelocityContext().put("parameters", parameterMap); return parameterMap; }
private void initVelocityContext() throws Exception { VelocityContext velocityContext = metadataResourceEngine.getVelocityContext(); velocityContext.put("system", System.getProperties()); velocityContext.put("softwareName", "BEAM gpt"); velocityContext.put("softwareVersion", System.getProperty("beam.version", "")); velocityContext.put("commandLineArgs", commandLineArgs); // Derived properties (shortcuts). // Check if we really want them, if so, we have to maintain them in the future (nf) File targetFile = new File(commandLineArgs.getTargetFilePath()); File parentFile = targetFile.getParentFile(); velocityContext.put("targetFile", targetFile); velocityContext.put("targetDir", parentFile != null ? parentFile : new File(".")); velocityContext.put("targetBaseName", FileUtils.getFilenameWithoutExtension(targetFile)); velocityContext.put("targetName", targetFile.getName()); velocityContext.put("targetFormat", commandLineArgs.getTargetFormatName()); // Check if we also put the following into the context? // Actually no, because this puts the ontext in an unknown state, because we don't know which are the key's names (nf) //velocityContext.putAll(commandLineArgs.getParameterMap()); //velocityContext.putAll(commandLineArgs.getTargetFilePathMap()); //velocityContext.putAll(commandLineArgs.getSourceFilePathMap()); }
@Test public void testGraphOnly() throws Exception { CommandLineArgs lineArgs = parseArgs("./map-proj.xml"); assertEquals(null, lineArgs.getOperatorName()); assertEquals("./map-proj.xml", lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); }
templateVariables.putAll(sourceNodeIdMap); Graph graph = readGraph(commandLineArgs.getGraphFilePath(), templateVariables); Node lastNode = graph.getNode(graph.getNodeCount() - 1); SortedMap<String, String> sourceFilePathsMap = commandLineArgs.getSourceFilePathMap(); configuration.createChild("file").setValue(commandLineArgs.getTargetFilePath()); configuration.createChild("formatName").setValue(commandLineArgs.getTargetFormatName()); configuration.createChild("clearCacheAfterRowWrite").setValue( Boolean.toString(commandLineArgs.isClearCacheAfterRowWrite())); File graphFile = new File(commandLineArgs.getGraphFilePath()); velocityContext.put("graph", graph);
private void runOperator() throws Exception { Map<String, String> parameterMap = getRawParameterMap(); String operatorName = commandLineArgs.getOperatorName(); Map<String, Product> sourceProducts = getSourceProductMap(); Map<String, Object> parameters = convertParameterMap(operatorName, parameterMap, sourceProducts); } else { String filePath = commandLineArgs.getTargetFilePath(); String formatName = commandLineArgs.getTargetFormatName(); writeProduct(targetProduct, filePath, formatName, commandLineArgs.isClearCacheAfterRowWrite());
@Test public void testTargetOptions() throws Exception { CommandLineArgs lineArgs = parseArgs("./map-proj.xml", "-Tndvi=./out/ndviProduct.dim", "-Tsnow=./out/snowMask.dim", "source.dim"); SortedMap<String, String> targetMap = lineArgs.getTargetFilePathMap(); assertNotNull(targetMap); assertEquals(2, targetMap.size()); assertEquals("./out/ndviProduct.dim", targetMap.get("ndvi")); assertEquals("./out/snowMask.dim", targetMap.get("snow")); assertEquals(null, lineArgs.getTargetFilePath()); SortedMap<String, String> sourceMap = lineArgs.getSourceFilePathMap(); assertEquals(3, sourceMap.size()); assertEquals("source.dim", sourceMap.get("sourceProduct")); assertEquals("source.dim", sourceMap.get("sourceProduct.1")); assertEquals("source.dim", sourceMap.get("sourceProduct1")); // test for backward compatibility }
lineArgs = parseArgs("Reproject", "source.dim"); assertEquals(512 * M, lineArgs.getTileCacheCapacity()); assertEquals(CommandLineArgs.DEFAULT_TILE_SCHEDULER_PARALLELISM, lineArgs.getTileSchedulerParallelism()); lineArgs = parseArgs("Reproject", "source.dim", "-c", "16M"); assertEquals(16 * M, lineArgs.getTileCacheCapacity()); assertEquals(CommandLineArgs.DEFAULT_TILE_SCHEDULER_PARALLELISM, lineArgs.getTileSchedulerParallelism()); lineArgs = parseArgs("Reproject", "source.dim", "-q", "1", "-c", "16000K"); assertEquals(16000 * K, lineArgs.getTileCacheCapacity()); assertEquals(1, lineArgs.getTileSchedulerParallelism()); lineArgs = parseArgs("Reproject", "source.dim", "-c", "16000002", "-q", "3"); assertEquals(16000002, lineArgs.getTileCacheCapacity()); assertEquals(3, lineArgs.getTileSchedulerParallelism()); lineArgs = parseArgs("Reproject", "source.dim", "-c", "0", "-q", "10"); assertEquals(0, lineArgs.getTileCacheCapacity()); assertEquals(10, lineArgs.getTileSchedulerParallelism()); parseArgs("Reproject", "source.dim", "-c", "-6"); fail("Exception expected"); } catch (Exception e) {
@Test public void testSourceOptions() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-SndviProduct=./inp/NDVI.dim", "-ScloudProduct=./inp/cloud-mask.dim", "-Pthreshold=5.0", "source.dim"); SortedMap<String, String> sourceMap = lineArgs.getSourceFilePathMap(); assertNotNull(sourceMap); assertEquals("./inp/NDVI.dim", sourceMap.get("ndviProduct")); assertEquals("./inp/cloud-mask.dim", sourceMap.get("cloudProduct")); }
@Test public void testFormatOption() throws Exception { CommandLineArgs lineArgs; lineArgs = parseArgs("Reproject", "-t", "target.h5", "-f", "HDF-5", "source.dim"); assertEquals("HDF-5", lineArgs.getTargetFormatName()); lineArgs = parseArgs("Reproject", "-f", "GeoTIFF", "-t", "target.tif", "source.dim"); assertEquals("GeoTIFF", lineArgs.getTargetFormatName()); lineArgs = parseArgs("Reproject", "-f", "BEAM-DIMAP", "-t", "target.dim", "source.dim"); assertEquals("BEAM-DIMAP", lineArgs.getTargetFormatName()); }
private void runVelocityTemplates() { String velocityDirPath = commandLineArgs.getVelocityTemplateDirPath(); File velocityDir; boolean velocityDirPathGiven; if (!commandLineContext.isFile(commandLineArgs.getTargetFilePath())) { if (velocityDirPathGiven) { String msgPattern = "Target file '%s' does not exist, but is required to process velocity templates"; logger.warning(String.format(msgPattern, commandLineArgs.getTargetFilePath())); logger.info(String.format(msgPattern, commandLineArgs.getTargetFilePath())); commandLineArgs.getTargetFilePath()); } catch (IOException e) { String msgPattern = "Can't write related resource using template file '%s': %s";
@Test public void testParametersFileOption() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "source.dim", "-p", "param.properties"); assertEquals("param.properties", lineArgs.getParameterFilePath()); }
@Test public void testParameterOptions() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-PpixelSizeX=0.02", "-PpixelSizeY=0.03", "-PpixelOffsetX=0.5", "-PpixelOffsetY=1.0", "source.dim"); SortedMap<String, String> parameterMap = lineArgs.getParameterMap(); assertEquals("0.02", parameterMap.get("pixelSizeX")); assertEquals("0.03", parameterMap.get("pixelSizeY")); assertEquals("0.5", parameterMap.get("pixelOffsetX")); assertEquals("1.0", parameterMap.get("pixelOffsetY")); }
@Test public void testSystemProperties() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-Dfoo=bar", "-Dbeam.performance=lightning"); Map<String, String> systemPropertiesMap = lineArgs.getSystemPropertiesMap(); assertNotNull(systemPropertiesMap); assertEquals(2, systemPropertiesMap.size()); assertEquals("bar", systemPropertiesMap.get("foo")); assertEquals("lightning", systemPropertiesMap.get("beam.performance")); }
private void initializeJAI() { long tileCacheCapacity = commandLineArgs.getTileCacheCapacity(); int tileSchedulerParallelism = commandLineArgs.getTileSchedulerParallelism(); if (tileCacheCapacity > 0) { JAI.enableDefaultTileCache(); JAI.getDefaultInstance().getTileCache().setMemoryCapacity(tileCacheCapacity); } else { JAI.getDefaultInstance().getTileCache().setMemoryCapacity(0L); JAI.disableDefaultTileCache(); } if (tileSchedulerParallelism > 0) { JAI.getDefaultInstance().getTileScheduler().setParallelism(tileSchedulerParallelism); } final long tileCacheSize = JAI.getDefaultInstance().getTileCache().getMemoryCapacity() / (1024L * 1024L); commandLineContext.getLogger().info(MessageFormat.format("JAI tile cache size is {0} MB", tileCacheSize)); final int schedulerParallelism = JAI.getDefaultInstance().getTileScheduler().getParallelism(); commandLineContext.getLogger().info( MessageFormat.format("JAI tile scheduler parallelism is {0}", schedulerParallelism)); }
private Map<String, Product> getSourceProductMap() throws IOException { SortedMap<File, Product> fileToProductMap = new TreeMap<>(); SortedMap<String, Product> productMap = new TreeMap<>(); SortedMap<String, String> sourceFilePathsMap = commandLineArgs.getSourceFilePathMap(); for (Entry<String, String> entry : sourceFilePathsMap.entrySet()) { String sourceId = entry.getKey(); String sourceFilePath = entry.getValue(); Product product = addProduct(sourceFilePath, fileToProductMap); productMap.put(sourceId, product); } return productMap; }
private void initializeSystemProperties() { Map<String, String> systemPropertiesMap = commandLineArgs.getSystemPropertiesMap(); for (Entry<String, String> properties : systemPropertiesMap.entrySet()) { System.setProperty(properties.getKey(), properties.getValue()); } }
private void readMetadata() throws Exception { if (commandLineArgs.getMetadataFilePath() != null) { readMetadata(commandLineArgs.getMetadataFilePath(), true); } else { readMetadata(CommandLineArgs.DEFAULT_METADATA_FILEPATH, false); } readSourceMetadataFiles(); }
@Test public void testHelpOption() throws Exception { CommandLineArgs lineArgs = parseArgs("Reproject", "-h"); assertEquals(true, lineArgs.isHelpRequested()); assertEquals("Reproject", lineArgs.getOperatorName()); assertEquals(null, lineArgs.getGraphFilePath()); assertEquals(CommandLineArgs.DEFAULT_TARGET_FILEPATH, lineArgs.getTargetFilePath()); assertEquals(CommandLineArgs.DEFAULT_FORMAT_NAME, lineArgs.getTargetFormatName()); SortedMap<String, String> map = lineArgs.getSourceFilePathMap(); assertNotNull(map); assertEquals(0, map.size()); }