Exemplo n.º 1
0
 private void logSevereProblem(String message, Exception e) {
   if (commandLineArgs.isStackTraceDump()) {
     commandLineContext.getLogger().log(Level.SEVERE, message, e);
   } else {
     commandLineContext.getLogger().severe(message);
   }
 }
Exemplo n.º 2
0
 private void printHelp() {
   if (commandLineArgs.getOperatorName() != null) {
     commandLineContext.print(
         CommandLineUsage.getUsageTextForOperator(commandLineArgs.getOperatorName()));
   } else if (commandLineArgs.getGraphFilePath() != null) {
     commandLineContext.print(
         CommandLineUsage.getUsageTextForGraph(
             commandLineArgs.getGraphFilePath(), commandLineContext));
   } else {
     commandLineContext.print(CommandLineUsage.getUsageText());
   }
 }
Exemplo n.º 3
0
  private void runVelocityTemplates() {
    String velocityDirPath = commandLineArgs.getVelocityTemplateDirPath();
    File velocityDir;
    if (velocityDirPath != null) {
      velocityDir = new File(velocityDirPath);
    } else {
      velocityDir = new File(CommandLineArgs.DEFAULT_VELOCITY_TEMPLATE_DIRPATH);
    }

    String[] templateNames =
        velocityDir.list(
            new FilenameFilter() {
              @Override
              public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(CommandLineArgs.VELOCITY_TEMPLATE_EXTENSION);
              }
            });

    Logger logger = commandLineContext.getLogger();
    if (templateNames == null) {
      String msgPattern = "Velocity template directory '%s' does not exist or inaccessible";
      logger.severe(String.format(msgPattern, velocityDir));
      return;
    }
    if (templateNames.length == 0) {
      String msgPattern = "Velocity template directory '%s' does not contain any templates (*.vm)";
      logger.warning(String.format(msgPattern, velocityDir));
      return;
    }

    // It can happen that we have no target file when the operator implements the Output interface
    if (!commandLineContext.isFile(commandLineArgs.getTargetFilePath())) {
      String msgPattern =
          "Target file '%s' does not exist, but is required to process velocity templates";
      logger.warning(String.format(msgPattern, commandLineArgs.getTargetFilePath()));
      return;
    }

    for (String templateName : templateNames) {
      try {
        metadataResourceEngine.writeRelatedResource(
            velocityDir + "/" + templateName, commandLineArgs.getTargetFilePath());
      } catch (IOException e) {
        String msgPattern = "Can't write related resource using template file '%s': %s";
        logSevereProblem(String.format(msgPattern, templateName, e.getMessage()), e);
      }
    }
  }
Exemplo n.º 4
0
 private void readMetadata(String path, boolean fail) throws Exception {
   try {
     metadataResourceEngine.readResource("metadata", path);
   } catch (Exception e) {
     if (fail) {
       throw e;
     }
     final String message =
         String.format("Failed to read metadata file '%s': %s", path, e.getMessage());
     if (commandLineContext.fileExists(path)) {
       logSevereProblem(message, e);
     } else {
       commandLineContext.getLogger().warning(message);
     }
   }
 }
Exemplo n.º 5
0
 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));
 }
Exemplo n.º 6
0
 private Product createOpProduct(
     String opName, Map<String, Object> parameters, Map<String, Product> sourceProducts)
     throws OperatorException {
   return commandLineContext.createOpProduct(opName, parameters, sourceProducts);
 }
Exemplo n.º 7
0
 void executeGraph(Graph graph) throws GraphException {
   commandLineContext.executeGraph(graph, this);
 }
Exemplo n.º 8
0
 Graph readGraph(String filePath, Map<String, String> templateVariables)
     throws IOException, GraphException {
   return commandLineContext.readGraph(filePath, templateVariables);
 }
Exemplo n.º 9
0
 void writeProduct(
     Product targetProduct, String filePath, String formatName, boolean clearCacheAfterRowWrite)
     throws IOException {
   commandLineContext.writeProduct(targetProduct, filePath, formatName, clearCacheAfterRowWrite);
 }
Exemplo n.º 10
0
 Product readProduct(String filePath) throws IOException {
   return commandLineContext.readProduct(filePath);
 }