Package com.cloudera.flume.conf

Examples of com.cloudera.flume.conf.PatternMatch


   *
   */
  static CommonTree substBEChains(String sink, List<String> collectors)
      throws RecognitionException, FlumeSpecException {

    PatternMatch bePat = recursive(var("be", FlumePatterns.sink(AUTO_BE)));
    CommonTree sinkTree = FlumeBuilder.parseSink(sink);
    Map<String, CommonTree> beMatches = bePat.match(sinkTree);

    ArrayList<String> collSnks = new ArrayList<String>();
    for (String coll : collectors) {
      collSnks.add("{ lazyOpen => logicalSink(\"" + coll + "\") }");
    }
    collSnks.add("null");

    if (beMatches == null) {
      // bail out early
      return sinkTree;
    }

    while (beMatches != null) {
      // found a autoBEChain, replace it with the chain.
      CommonTree beTree = beMatches.get("be");

      // generate
      CommonTree beFailChain = buildFailChainAST("%s", collSnks);

      // Check if beFailChain is null
      if (beFailChain == null) {
        beFailChain = FlumeBuilder
            .parseSink("fail(\"no physical collectors\")");
      }

      // subst
      int idx = beTree.getChildIndex();
      CommonTree parent = beTree.parent;
      if (parent == null) {
        sinkTree = beFailChain;
      } else {
        parent.replaceChildren(idx, idx, beFailChain);
      }
      // patern match again.
      beMatches = bePat.match(sinkTree);
    }
    return sinkTree;
  }
View Full Code Here


   * second failure -- the insistentAppend wrapping it ensures that it will
   * continue retrying while the sink is open.
   */
  static CommonTree substDFOChainsNoLet(String sink, List<String> collectors)
      throws RecognitionException, FlumeSpecException {
    PatternMatch dfoPat = recursive(var("dfo", FlumePatterns.sink(AUTO_DFO)));

    CommonTree sinkTree = FlumeBuilder.parseSink(sink);
    Map<String, CommonTree> dfoMatches = dfoPat.match(sinkTree);
    if (dfoMatches == null) {
      return sinkTree;
    }

    while (dfoMatches != null) {
      // found a autoDFOChain, replace it with the chain.
      CommonTree dfoTree = dfoMatches.get("dfo");

      // All the logical sinks are lazy individually
      CommonTree dfoPrimaryChain = buildFailChainAST(
          "{ lazyOpen => logicalSink(\"%s\") }", collectors);
      // Check if dfo is null
      if (dfoPrimaryChain == null) {
        dfoPrimaryChain = FlumeBuilder.parseSink("fail(\"no collectors\")");
      }

      // diskfailover's subsink needs to never give up. So we wrap it with an
      // insistentAppend. But append can fail if its subsink is not open. So
      // we add a stubborn append (it closes and reopens a subsink) and retries
      // opening the chain using the insistentOpen
      String dfo = "< " + FlumeSpecGen.genEventSink(dfoPrimaryChain)
          + "  ? {diskFailover => "
          + "{ insistentAppend => { stubbornAppend => { insistentOpen =>"
          + FlumeSpecGen.genEventSink(dfoPrimaryChain) + " } } } } >";
      CommonTree newDfoTree = FlumeBuilder.parseSink(dfo);

      // subst
      int idx = dfoTree.getChildIndex();
      CommonTree parent = dfoTree.parent;
      if (parent == null) {
        sinkTree = newDfoTree;
      } else {
        parent.replaceChildren(idx, idx, newDfoTree);
      }
      // pattern match again.
      dfoMatches = dfoPat.match(sinkTree);
    }
    return sinkTree;
  }
View Full Code Here

   * expressions semantics are not clear in the face of failures.
   */
  @Deprecated
  static CommonTree substDFOChains(String sink, List<String> collectors)
      throws RecognitionException, FlumeSpecException {
    PatternMatch dfoPat = recursive(var("dfo", FlumePatterns.sink(AUTO_DFO)));

    CommonTree sinkTree = FlumeBuilder.parseSink(sink);
    Map<String, CommonTree> dfoMatches = dfoPat.match(sinkTree);
    if (dfoMatches == null) {
      return sinkTree;
    }

    while (dfoMatches != null) {
      // found a autoDFOChain, replace it with the chain.
      CommonTree dfoTree = dfoMatches.get("dfo");
      CommonTree dfoFailChain = buildFailChainAST(
          "{ lazyOpen => { stubbornAppend => logicalSink(\"%s\") } }  ",
          collectors);

      // Check if dfo is null
      if (dfoFailChain == null) {
        dfoFailChain = FlumeBuilder.parseSink("fail(\"no collectors\")");
      }

      String dfo = "let primary := " + FlumeSpecGen.genEventSink(dfoFailChain)
          + " in "
          + "< primary ? {diskFailover => { insistentOpen =>  primary} } >";
      CommonTree newDfoTree = FlumeBuilder.parseSink(dfo);

      // subst
      int idx = dfoTree.getChildIndex();
      CommonTree parent = dfoTree.parent;
      if (parent == null) {
        sinkTree = newDfoTree;
      } else {
        parent.replaceChildren(idx, idx, newDfoTree);
      }
      // pattern match again.
      dfoMatches = dfoPat.match(sinkTree);
    }
    return sinkTree;
  }
View Full Code Here

   */
  @Deprecated
  static CommonTree substE2EChains(String sink, List<String> collectors)
      throws RecognitionException, FlumeSpecException {

    PatternMatch e2ePat = recursive(var("e2e", FlumePatterns.sink(AUTO_E2E)));
    CommonTree sinkTree = FlumeBuilder.parseSink(sink);
    Map<String, CommonTree> e2eMatches = e2ePat.match(sinkTree);

    if (e2eMatches == null) {
      // bail out early.
      return sinkTree;
    }

    while (e2eMatches != null) {
      // found a autoE2EChain, replace it with the chain.
      CommonTree beTree = e2eMatches.get("e2e");

      // generate
      CommonTree beFailChain = buildFailChainAST("logicalSink(\"%s\") ",
          collectors);

      // Check if beFailChain is null
      if (beFailChain == null) {
        beFailChain = FlumeBuilder.parseSink("fail(\"no collectors\")");
      }

      // subst
      int idx = beTree.getChildIndex();
      CommonTree parent = beTree.parent;
      if (parent == null) {
        sinkTree = beFailChain;
      } else {
        parent.replaceChildren(idx, idx, beFailChain);
      }

      // pattern match again.
      e2eMatches = e2ePat.match(sinkTree);

    }

    // wrap the sink with the ackedWriteAhead
    CommonTree wrapper = FlumeBuilder
        .parseSink("{ ackedWriteAhead => { stubbornAppend => { insistentOpen => null } } }");
    PatternMatch nullPath = recursive(var("x", FlumePatterns.sink("null")));
    CommonTree replace = nullPath.match(wrapper).get("x");
    int idx = replace.getChildIndex();
    replace.parent.replaceChildren(idx, idx, sinkTree);
    return wrapper;
  }
View Full Code Here

   * they are tried again after an backing off.
   */
  static CommonTree substE2EChainsSimple(String sink, List<String> collectors)
      throws RecognitionException, FlumeSpecException {

    PatternMatch e2ePat = recursive(var("e2e", FlumePatterns.sink(AUTO_E2E)));
    CommonTree sinkTree = FlumeBuilder.parseSink(sink);
    Map<String, CommonTree> e2eMatches = e2ePat.match(sinkTree);

    if (e2eMatches == null) {
      // bail out early.
      return sinkTree;
    }

    while (e2eMatches != null) {
      // found a autoE2EChain, replace it with the chain.
      CommonTree e2eTree = e2eMatches.get("e2e");

      // generate
      CommonTree e2eFailChain = buildFailChainAST("logicalSink(\"%s\") ",
          collectors);

      // Check if beFailChain is null
      if (e2eFailChain == null) {
        e2eFailChain = FlumeBuilder.parseSink("fail(\"no collectors\")");
      }

      // now lets wrap the beFailChain with the ackedWriteAhead
      String translated = "{ ackedWriteAhead => { stubbornAppend => { insistentOpen => "
          + FlumeSpecGen.genEventSink(e2eFailChain) + " } } }";
      CommonTree wrapper = FlumeBuilder.parseSink(translated);

      // subst
      int idx = e2eTree.getChildIndex();
      CommonTree parent = e2eTree.parent;
      if (parent == null) {
        sinkTree = wrapper;
      } else {
        parent.replaceChildren(idx, idx, wrapper);
      }

      // pattern match again.
      e2eMatches = e2ePat.match(sinkTree);
    }

    // wrap the sink with the ackedWriteAhead
    return sinkTree;
  }
View Full Code Here

   **/
  CommonTree substLogicalSink(String sink) throws RecognitionException,
      FlumeSpecException {
    CommonTree lsnkTree = FlumeBuilder.parseSink(sink);
    LOG.debug(lsnkTree.toStringTree());
    PatternMatch p = recursive(var("lsnk", kind("DECO").child(
        kind("SINK").child(kind("logicalSink")))));
    Map<String, CommonTree> matches = p.match(lsnkTree);

    if (matches == null) {
      // do nothing,
      return lsnkTree;
    }
View Full Code Here

   */
  CommonTree substLogicalSource(String ln, String source)
      throws RecognitionException {
    CommonTree lsrcTree = FlumeBuilder.parseSource(source);
    LOG.debug(lsrcTree.toStringTree());
    PatternMatch p = FlumePatterns.source("logicalSource");
    Map<String, CommonTree> matches = p.match(lsrcTree);

    if (matches == null) {
      // if was previously a logical source, unregister it.
      nameMan.setPhysicalNode(ln, null);

View Full Code Here

   **/
  CommonTree substLogicalSink(String sink) throws RecognitionException,
      FlumeSpecException {
    CommonTree lsnkTree = FlumeBuilder.parseSink(sink);
    LOG.debug(lsnkTree.toStringTree());
    PatternMatch p = recursive(var("lsnk", kind("DECO").child(
        kind("SINK").child(kind("logicalSink")))));
    Map<String, CommonTree> matches = p.match(lsnkTree);

    if (matches == null) {
      // do nothing,
      return lsnkTree;
    }
View Full Code Here

   */
  CommonTree substLogicalSource(String ln, String source)
      throws RecognitionException {
    CommonTree lsrcTree = FlumeBuilder.parseSource(source);
    LOG.debug(lsrcTree.toStringTree());
    PatternMatch p = FlumePatterns.source("logicalSource");
    Map<String, CommonTree> matches = p.match(lsrcTree);

    if (matches == null) {
      // if was previously a logical source, unregister it.
      nameMan.setPhysicalNode(ln, null);

View Full Code Here

   *
   */
  static CommonTree substBEChains(String sink, List<String> collectors)
      throws RecognitionException, FlumeSpecException {

    PatternMatch bePat = recursive(var("be", FlumePatterns.sink(AUTO_BE)));
    CommonTree sinkTree = FlumeBuilder.parseSink(sink);
    Map<String, CommonTree> beMatches = bePat.match(sinkTree);

    ArrayList<String> collSnks = new ArrayList<String>();
    for (String coll : collectors) {
      collSnks.add("{ lazyOpen => logicalSink(\"" + coll + "\") }");
    }
    collSnks.add("null");

    if (beMatches == null) {
      // bail out early
      return sinkTree;
    }

    while (beMatches != null) {
      // found a autoBEChain, replace it with the chain.
      CommonTree beTree = beMatches.get("be");

      // generate
      CommonTree beFailChain = buildFailChainAST("%s", collSnks);

      // Check if beFailChain is null
      if (beFailChain == null) {
        beFailChain = FlumeBuilder
            .parseSink("fail(\"no physical collectors\")");
      }

      // subst
      int idx = beTree.getChildIndex();
      CommonTree parent = beTree.parent;
      if (parent == null) {
        sinkTree = beFailChain;
      } else {
        parent.replaceChildren(idx, idx, beFailChain);
      }
      // patern match again.
      beMatches = bePat.match(sinkTree);
    }
    return sinkTree;
  }
View Full Code Here

TOP

Related Classes of com.cloudera.flume.conf.PatternMatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.