コード例 #1
0
 @Override
 public String invoke(final CallingContext context) {
   PurgeInfoReader ps = new PurgeInfoReader();
   final long now = System.currentTimeMillis();
   List<Class<? extends StorablePurgeInfo>> all = ps.readAll();
   log.info(String.format("Found %s classes that have a TTL", all.size()));
   for (final Class<? extends StorablePurgeInfo> psClass : all) {
     StorablePurgeInfo purgeInfo = null;
     try {
       purgeInfo = psClass.newInstance();
     } catch (InstantiationException | IllegalAccessException e) {
       log.error(ExceptionToString.format(e));
     }
     if (purgeInfo != null) {
       try {
         purgeStorable(context, now, purgeInfo);
       } catch (ClassNotFoundException
           | NoSuchMethodException
           | IllegalAccessException
           | InvocationTargetException e) {
         log.error(
             String.format(
                 "Error purging class %s: %s",
                 purgeInfo.getStorableClass(), ExceptionToString.format(e)));
       }
     }
   }
   return "next";
 }
コード例 #2
0
 private String getContentFromPart(Part p) {
   String contentType = p.getContentType();
   InputStream inputStream = null;
   try {
     if (contentType == null || contentType.startsWith("text/plain")) {
       inputStream = p.getInputStream();
     } else if (contentType.equals("application/octet-stream")) {
       inputStream = new GZIPInputStream(p.getInputStream());
     } else {
       log.error(String.format("Unknown content type %s", contentType));
       return null;
     }
     return getStringFromInputStream(inputStream);
   } catch (IOException e) {
     log.error("Could not parse input " + ExceptionToString.format(e));
     return null;
   } finally {
     if (inputStream != null) {
       try {
         inputStream.close();
       } catch (IOException e) {
         log.error("Error closing input stream " + ExceptionToString.format(e));
       }
     }
   }
 }
コード例 #3
0
 // for testing only
 public static void main(String[] args) {
   Throwable t = new Throwable("FOO", new Throwable("Bar", new Throwable("Baz")));
   System.out.println(ExceptionToString.format(t));
 }
コード例 #4
0
ファイル: GenApi.java プロジェクト: yanwang-incapture/Rapture
  public static void main(String[] args) {
    Options options = new Options();
    options.addOption("l", true, "Language to generate");
    options.addOption("o", true, "Output root folder for kernel files");
    options.addOption("a", true, "Output root folder for api files");
    options.addOption("d", true, "Template dir to use (use either this or 't')");
    options.addOption("t", true, "Template file to use (use either this or 'd')");
    options.addOption(
        "g", true, "The type of grammar to generate, current options are 'SDK' or 'API'");
    options.addOption("mainApiFile", true, "FileName specifying the api");
    options.addOption(
        "codeSamplesJava", true, "A path to search for files that have Java code samples");
    options.addOption(
        "codeSamplesPython", true, "A path to search for files that have Python code samples");

    CommandLineParser cparser = new PosixParser();
    try {
      CommandLine cmd = cparser.parse(options, args);
      String mainApiFile = cmd.getOptionValue("mainApiFile");
      String outputKernelFolder = cmd.getOptionValue('o');
      String outputApiFolder = cmd.getOptionValue('a');
      String codeSamplesJava = cmd.getOptionValue("codeSamplesJava");
      String codeSamplesPython = cmd.getOptionValue("codeSamplesPython");

      GenType genType = GenType.valueOf(cmd.getOptionValue('g'));

      // The language will ultimately choose the walker class
      String language = cmd.getOptionValue('l');
      if (cmd.hasOption('d') && cmd.hasOption('t')) {
        throw new IllegalArgumentException(
            "Cannot define both a template folder ('d') and file ('t'). Please use one OR the other.");
      }

      // And off we go

      TLexer lexer = new TLexer();
      ResourceBasedApiReader apiReader = new ResourceBasedApiReader();
      lexer.setApiReader(apiReader);
      lexer.setCharStream(apiReader.read(mainApiFile));

      // Using the lexer as the token source, we create a token
      // stream to be consumed by the parser
      //
      CommonTokenStream tokens = new CommonTokenStream(lexer);

      // Now we need an instance of our parser
      //
      TParser parser = new TParser(tokens);

      hmxdef_return psrReturn = parser.hmxdef();

      // load in T.stg template group, put in templates variable
      StringTemplateGroup templates = null;

      if (!isSlateMd(language)) {
        templates = TemplateRepo.getTemplates(language, genType);
      }
      Tree t = psrReturn.getTree();

      CommonTreeNodeStream ns = new CommonTreeNodeStream(t);
      ns.setTokenStream(tokens);
      if (templates != null) {
        templates.registerRenderer(String.class, new UpCaseRenderer());
      }
      AbstractTTree walker = TreeFactory.createTreeWalker(ns, templates, language);
      System.out.println("Generating files with a " + walker.getClass().getName());
      if (walker instanceof TTree) {
        if (genType.equals(GenType.API)) {
          ((TTree) walker).apiGen();
        } else {
          ((TTree) walker).sdkGen();
        }
      } else if (walker instanceof TTreeRuby) {
        System.out.println("Running for Ruby");
        /* TTreeRuby.hmxdef_return out = */
        ((TTreeRuby) walker).hmxdef();
      } else if (walker instanceof TTreeJS) {
        System.out.println("Running for JavaScript");
        /* TTreeJS.hmxdef_return out = */
        ((TTreeJS) walker).hmxdef();
      } else if (walker instanceof TTreeDoc) {
        System.out.println("Running for Documentation");
        /* TTreeDoc.hmxdef_return out = */
        ((TTreeDoc) walker).hmxdef();
      } else if (walker instanceof TTreeVB) {
        System.out.println("Running for VB");
        /* TTreeVB.hmxdef_return out = */
        ((TTreeVB) walker).hmxdef();
      } else if (walker instanceof TTreeGo) {
        System.out.println("Running for Go");
        /* TTreeGo.hmxdef_return out = */
        ((TTreeGo) walker).hmxdef();
      } else if (walker instanceof TTreePython) {
        System.out.println("Running for Python");
        /* TTreePython.hmxdef_return out = */
        ((TTreePython) walker).hmxdef();
      } else if (walker instanceof TTreeSlateMd) {
        System.out.println("Running for Slate Markdown");
        TTreeSlateMd slateMdWalker = (TTreeSlateMd) walker;
        slateMdWalker.setupCodeParser(codeSamplesJava, codeSamplesPython);
        slateMdWalker.hmxdef();
      } else if (walker instanceof TTreeDotNet) {
        System.out.println("Running for DotNet");
        ((TTreeDotNet) walker).apiGen();
      } else if (walker instanceof TTreeCurtisDoc) {
        System.out.println("Running for CurtisDoc");
        ((TTreeCurtisDoc) walker).apiGen();
      }
      // Now dump the files out
      System.out.println("Dumping files to " + outputKernelFolder + " and " + outputApiFolder);
      walker.dumpFiles(outputKernelFolder, outputApiFolder);

    } catch (ParseException e) {
      System.err.println("Error parsing command line - " + e.getMessage());
      System.out.println("Usage: " + options.toString());
    } catch (IOException | RecognitionException e) {
      System.err.println("Error running GenApi: " + ExceptionToString.format(e));
    }
  }
コード例 #5
0
  @Override
  public String invoke(CallingContext ctx) {
    DecisionApi decision = Kernel.getDecision();
    String workOrderUri = new RaptureURI(getWorkerURI(), Scheme.WORKORDER).toShortString();
    String config =
        StringUtils.stripToNull(decision.getContextValue(ctx, workOrderUri, "CONFIGURATION"));

    try {
      decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());

      String docPath = new RaptureURI(workOrderUri).getDocPath();
      int lio = docPath.lastIndexOf('/');
      if (lio < 0) lio = 0;

      StringBuilder externalUrl = new StringBuilder();
      String host = System.getenv("HOST");
      String port = System.getenv("PORT");
      externalUrl
          .append("http://")
          .append((host != null) ? host : LOCALHOST)
          .append(":")
          .append((port != null) ? port : DEFAULT_RIM_PORT)
          .append("/process/")
          .append(docPath.substring(0, lio))
          .append(WORKORDER_DELIMETER)
          .append(docPath.substring(lio + 1));
      decision.setContextLiteral(
          ctx, workOrderUri, EXTERNAL_RIM_WORKORDER_URL, externalUrl.toString());

      Map<String, String> view = new HashMap<>();
      DocApi docApi = Kernel.getDoc();

      if (config == null) {
        decision.writeWorkflowAuditEntry(
            ctx, getWorkerURI(), "No configuration document specified", false);
        return this.getNextTransition();
      }
      List<String> configs;
      try {
        // Could be a list or a single entry.
        configs = JacksonUtil.objectFromJson(config, ArrayList.class);
      } catch (Exception e) {
        configs = ImmutableList.of(config);
      }

      for (String conf : configs) {
        if (docApi.docExists(ctx, conf)) {
          String doc = docApi.getDoc(ctx, conf);
          Map<String, Object> map = JacksonUtil.getMapFromJson(doc);
          for (Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = StringUtils.stripToNull(entry.getValue().toString());
            ContextValueType type = ContextValueType.getContextValueType(value.charAt(0));
            if (type == ContextValueType.NULL) {
              type = ContextValueType.LITERAL;
            } else value = value.substring(1);
            ExecutionContextUtil.setValueECF(ctx, workOrderUri, view, key, type, value);
            decision.writeWorkflowAuditEntry(
                ctx,
                getWorkerURI(),
                getStepName() + ": Read configuration data from " + conf,
                false);
          }
        } else {
          decision.writeWorkflowAuditEntry(
              ctx,
              getWorkerURI(),
              getStepName() + ": Cannot locate configuration document " + conf,
              true);
        }
      }
      return Steps.NEXT.toString();
    } catch (Exception e) {
      decision.setContextLiteral(
          ctx, getWorkerURI(), getStepName(), "Exception in workflow : " + e.getLocalizedMessage());
      decision.setContextLiteral(ctx, getWorkerURI(), getErrName(), ExceptionToString.summary(e));
      log.error(ExceptionToString.format(ExceptionToString.getRootCause(e)));
      decision.writeWorkflowAuditEntry(
          ctx,
          getWorkerURI(),
          "Problem in " + getStepName() + ": unable to read the configuration document " + config,
          true);
      decision.writeWorkflowAuditEntry(
          ctx,
          getWorkerURI(),
          ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
          true);

      return getErrorTransition();
    }
  }