private void ensureTopicCreated(ZkUtils zkUtils, Set<String> allTopics, String topic, long retentionMs, int replicationFactor, int partitionCount) { Properties props = new Properties(); props.setProperty(LogConfig.RetentionMsProp(), Long.toString(retentionMs)); props.setProperty(LogConfig.CleanupPolicyProp(), DEFAULT_CLEANUP_POLICY); if (!allTopics.contains(topic)) { AdminUtils.createTopic(zkUtils, topic, partitionCount, replicationFactor, props, RackAwareMode.Safe$.MODULE$); } else { try { AdminUtils.changeTopicConfig(zkUtils, topic, props); MetadataResponse.TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(JavaConversions.asScalaSet(Collections.singleton(topic)), zkUtils, ListenerName.forSecurityProtocol(SecurityProtocol.PLAINTEXT)).head(); maybeIncreaseTopicReplicationFactor(zkUtils, topicMetadata, replicationFactor, topic); maybeIncreaseTopicPartitionCount(zkUtils, topic, topicMetadata, partitionCount); } catch (RuntimeException re) { LOG.error("Skip updating topic " + topic + " configuration due to failure:" + re.getMessage() + "."); } } }
scala.collection.Set<TopicMetadata> topicMetadatas = AdminUtils .fetchTopicMetadataFromZk(JavaConversions.asScalaSet(Collections.singleton(topicName)), zkClient); if (topicMetadatas != null && topicMetadatas.size() > 0) { return JavaConversions.asJavaSet(topicMetadatas).iterator().next().partitionsMetadata().size(); } else {
Tuple4<Set<Sentence>, Sort, K, Boolean> myResult = computeSentencesOfWellFormedCell(isLeafCell, isStream, kore, multiplicity, cfgAtt, m, cellName, cellProperties, childResult._2(), childResult._3(), ensures, hasConfigOrRegularVariable(cellContents)); return Tuple4.apply((Set<Sentence>)childResult._1().$bar(myResult._1()), Lists.newArrayList(myResult._2()), myResult._3(), false); if (initializerProduction.isDefined()) { Set<Production> realProds = stream(initializerProduction.get()).filter(p -> !p.att().contains("recordPrd", Production.class)).collect(Collections.toSet()); if (realProds.size() == 1) { // should be only a single initializer if (realProds.head().items().size() == 1) { } else if (realProds.head().items().size() == 4) { accumSentences = (Set<Sentence>)accumSentences.$bar(childResult._1()); sorts.addAll(childResult._2()); initializers.add(childResult._3());
private boolean isPriorityWrong(ProductionReference outer, ProductionReference inner) { Tag parentLabel = new Tag(outer.production().klabel().get().name()); Tag localLabel = new Tag(inner.production().klabel().get().name()); if (m.priorities().lessThan(parentLabel, localLabel)) { return true; } if (m.leftAssoc().contains(new Tuple2<>(parentLabel, localLabel))) { return true; } if (m.rightAssoc().contains(new Tuple2<>(parentLabel, localLabel))) { return true; } return false; }
KApply freshCell = KApply(KLabel("#configCell"), counterCellLabel, KApply(KLabel("#cellPropertyListTerminator")), KToken("0", Sorts.Int()), counterCellLabel); if (m.equals(def.mainModule()) && kore) { if (!m.definedKLabels().contains(KLabels.GENERATED_TOP_CELL)) { RuleGrammarGenerator gen = new RuleGrammarGenerator(def); ParseInModule mod = RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), true); Sort topCellSort = configInfo.topCell(); KLabel topCellLabel = configInfo.getCellLabel(topCellSort); Production prod = m.productionsFor().apply(topCellLabel).head(); KToken cellName = KToken(prod.att().get("cellName"), Sort("#CellName")); K generatedTop = KApply(KLabel("#configCell"), topCellToken, KApply(KLabel("#cellPropertyListTerminator")), KApply(KLabels.CELLS, KApply(KLabel("#externalCell"), cellName), freshCell), topCellToken); Set<Sentence> newSentences = GenerateSentencesFromConfigDecl.gen(generatedTop, BooleanUtils.TRUE, Att.empty(), mod.getExtensionModule(), true); sentences = (Set<Sentence>) sentences.$bar(newSentences); if (kore && m.localKLabels().contains(KLabels.GENERATED_TOP_CELL)) { RuleGrammarGenerator gen = new RuleGrammarGenerator(def); ParseInModule mod = RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), true); Set<Sentence> newSentences = GenerateSentencesFromConfigDecl.gen(freshCell, BooleanUtils.TRUE, Att.empty(), mod.getExtensionModule(), true); sentences = (Set<Sentence>) sentences.$bar(newSentences);
boolean needNewScanner = !scanner.getModule().importedModuleNames().contains(module.name()); final Scanner realScanner = needNewScanner ? parser.getScanner() : scanner; stream((Set<Sentence>) module.localSentences().$bar(ruleSet).$bar(contextSet)).filter(b -> !(b instanceof Bubble)).collect(Collections.toSet()), module.att());
if (mod.importedModuleNames().contains(AUTO_CASTS)) { // create the diamond Set<Sentence> temp; for (Sort srt : iterable(mod.definedSorts())) { if (mod.importedModuleNames().contains(RECORD_PRODS)) { for (Production p : iterable(mod.productions())) { if (p.isPrefixProduction()) { if (mod.importedModuleNames().contains(RULE_CELLS)) { // prepare cell productions for rule parsing addRuleCells = mod.sentences().exists(p -> p instanceof Production && ((Production) p).att().contains("cell")); } else { addRuleCells = false; boolean addConfigCells = mod.importedModuleNames().contains(CONFIG_CELLS); Set<Sentence> parseProds; if (addRuleCells) { if (mod.importedModuleNames().contains(AUTO_FOLLOW)) { Object PRESENT = new Object(); PatriciaTrie<Object> terminals = new PatriciaTrie<>(); // collect all terminals so we can do automatic follow restriction for prefix terminals if (mod.importedModuleNames().contains(PROGRAM_LISTS)) { Set<Sentence> prods3 = new HashSet<>(); if (!isParserSort(srt) && !mod.listSorts().contains(srt)) { if (mod.importedModuleNames().contains(RULE_LISTS)) { java.util.Set<Sentence> res = new HashSet<>();
public Module resolve(Module input) { Set<Sentence> rulesToAdd = stream(input.sentences()) .filter(s -> s instanceof Context) .map(s -> (Context) s) .flatMap(c -> this.resolve(c, input)).collect(Collectors.toCollection(HashSet::new)); if (!rulesToAdd.isEmpty()) { rulesToAdd.add(SyntaxSort(Sorts.K())); } return Module(input.name(), input.imports(), (scala.collection.Set<Sentence>) stream(input.localSentences()).filter(s -> !(s instanceof Context)).collect(Collections.toSet()).$bar(immutable(rulesToAdd)), input.att()); }
private boolean isInternalKLabel(String name, Module m) { return name.startsWith("#SemanticCastTo") || internalNames.contains(name) || (name.startsWith("is") && m.definedSorts().apply(Outer.parseSort(name.substring(2)))); } }
/** * Returns the set of all partitions in the Kafka cluster * * @return unmodifiable set of all partitions in the Kafka cluster * @throws AdminOperationException * if there is an issue reading partitions from Kafka */ public Set<TopicAndPartition> getPartitions() { LOG.debug("Retrieving all partitions"); long start = System.currentTimeMillis(); do { // The zkUtils.getAllPartitions(..) can throw ZkNoNodeException if a topic's partitions have not been added to // zookeeper but the topic is listed in zookeeper. Any other zookeeper exception is assumed to be non-transient and // will be rethrown. try { return Collections.unmodifiableSet(convertToJavaSet(zkUtils.getAllPartitions().iterator())); } catch (ZkNoNodeException e) { LOG.debug("Reading partitions had an error", e); } catch (ZkException e) { throw new AdminOperationException("Unable to retrieve all partitions", e); } LOG.debug("Sleeping for {} ms before trying to get all partitions again", operationSleep); try { Thread.sleep(operationSleep); } catch (InterruptedException e) { throw new AdminOperationException("Interrupted while getting partitions", e); } } while (!operationTimedOut(start)); throw new AdminOperationException("Operation timed out trying to get partitions"); }
); assertEquals("Produced unexpected productions", Set(), gen.$amp$tilde(reference)); assertEquals("Missing expected productions", Set(), reference.$amp$tilde(gen));
@Override public Either<java.util.Set<ParseFailedException>, Term> apply(Ambiguity amb) { // if the ambiguity has rewrites at the top, prefer them, and eliminate the rest scala.collection.Set<Term> rewrites = amb.items().stream().filter(o -> o instanceof TermCons && ((TermCons) o).production().klabel().isDefined() && ((TermCons) o).production().klabel().get().name().equals("#KRewrite")).collect(Collections.toSet()); if (rewrites.size() == 0 || rewrites.size() == amb.items().size()) return super.apply(amb); if (rewrites.size() == 1) return Right.apply(rewrites.head()); return super.apply(Ambiguity.apply(mutable(rewrites))); }
private boolean isLeftAssoc(ProductionReference outer, ProductionReference inner) { Tag parentLabel = new Tag(outer.production().klabel().get().name()); Tag localLabel = new Tag(inner.production().klabel().get().name()); if (m.leftAssoc().contains(new Tuple2<>(parentLabel, localLabel))) { return true; } return false; }
public Module gen(Module mod) { Set<Sentence> res = new HashSet<>(); for (Sort sort : iterable(mod.definedSorts())) { Production prod = Production(KLabel("is" + sort.toString()), Sorts.Bool(), Seq(Terminal("is" + sort.toString()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add(Attribute.FUNCTION_KEY).add(Attribute.PREDICATE_KEY, Sort.class, sort)); if (!mod.productions().contains(prod)) res.add(prod); } if (!res.isEmpty()) { res.add(SyntaxSort(Sorts.K())); } return Module(mod.name(), mod.imports(), (scala.collection.Set<Sentence>) mod.localSentences().$bar(immutable(res)), mod.att()); } }
public Module gen(Module mod) { this.mod = mod; predicateRules = stream(mod.rules()).filter(this::isPredicate).collect(Collectors.toSet()); return Module(mod.name(), mod.imports(), (Set<Sentence>) mod.localSentences().$bar(stream(mod.definedSorts()) .flatMap(this::gen).collect(Collections.toSet())), mod.att()); }
private void apply(KLabel klabel, K k) { if (klabel instanceof KVariable) return; if (!m.definedKLabels().apply(klabel) && !isInternalKLabel(klabel.name(), m)) { errors.add(KEMException.compilerError("Found klabel " + klabel.name() + " not defined in any production.", k)); } } };
@Override public Either<java.util.Set<ParseFailedException>, Term> apply(Ambiguity amb) { // if the ambiguity has KSeq at the top, prefer them, and eliminate the rest scala.collection.Set<Term> rewrites = amb.items().stream().filter(o -> o instanceof TermCons && ((TermCons) o).production().klabel().isDefined() && ((TermCons) o).production().klabel().get().name().equals("#KSequence")).collect(Collections.toSet()); if (rewrites.size() == 0 || rewrites.size() == amb.items().size()) return super.apply(amb); if (rewrites.size() == 1) return Right.apply(rewrites.head()); return super.apply(Ambiguity.apply(mutable(rewrites))); }
/** * Gather sort information from a module. * Populates the close operators only for sorts which only have a single associative production. */ public static SortInfo fromModule(Module module) { Multimap<Sort, KLabel> joinOps = HashMultimap.create(); Collections.stream(module.productionsFor()).forEach(x -> { if (Collections.stream(x._2()).anyMatch(p -> p.att().contains("assoc") && Collections.stream(p.items()).filter(i -> i instanceof NonTerminal).count() == 2)) { joinOps.put(x._2().head().sort(), x._1()); } }); SortInfo info = new SortInfo(); joinOps.asMap().forEach((sort, labels) -> { info.closeOperators.put(sort, Iterators.getNext(labels.iterator(), null)); }); return info; } }
private boolean isRightAssoc(ProductionReference outer, ProductionReference inner) { Tag parentLabel = new Tag(outer.production().klabel().get().name()); Tag localLabel = new Tag(inner.production().klabel().get().name()); if (m.rightAssoc().contains(new Tuple2<>(parentLabel, localLabel))) { return true; } return false; }