/** * Get the replica assignment for a given topic partition. This information should be retrieved * from zookeeper as topic metadata that we get from kafkaConsumer.listTopic() does not specify * the preferred leader for topic partitions. * * @param tp topic partition * @return the list of brokers that host the replica */ private List<Integer> getReplicaAssignment(TopicPartition tp) { scala.collection.Map<Object, Seq<Object>> replicaAssignmentMap = getReplicaAssignmentForTopic(zkUtils, tp.topic()); scala.Option<Seq<Object>> replicasOption = replicaAssignmentMap.get(tp.partition()); Seq<Object> replicas = replicasOption.get(); List<Object> replicasList = scala.collection.JavaConverters.seqAsJavaList(replicas); return replicasList.stream().map(obj -> (Integer) obj).collect(Collectors.toList()); }
public List<PartitionInfo> getPartitionInfos(String group, String topic) { Seq<String> singleTopic = JavaConversions.asScalaBuffer(Collections.singletonList(topic)).toSeq(); scala.collection.Map<String, Seq<Object>> pidMap = ZkUtils.getPartitionsForTopics(zkClient, singleTopic); Option<Seq<Object>> partitions = pidMap.get(topic); if (partitions.get() == null) { return Collections.emptyList(); } List<PartitionInfo> infos = Lists.newArrayList(); for (Object o : JavaConversions.asJavaList(partitions.get())) { PartitionInfo info = getPartitionInfo(group, topic, Int.unbox(o)); if (info != null) { infos.add(info); } } return infos; }
@Override public void apply(KToken k) { sb.append("\\dv{"); convert(k.sort(), false); sb.append("}("); if (module.sortAttributesFor().get(k.sort()).getOrElse(() -> Att.empty()).getOptional("hook").orElse("").equals("STRING.String")) { sb.append(k.s()); } else { sb.append(StringUtil.enquoteKString(k.s())); } sb.append(")"); }
@Override public void apply(KApply k) { String hook = module.attributesFor().get(k.klabel()).getOrElse(() -> Att.empty()).getOptional("hook").orElse(""); if (hook.equals("SET.element") || hook.equals("LIST.element") || hook.equals("LIST.concat") || hook.equals("MAP.concat") || hook.equals("SET.concat")) { return; } if (hook.equals("MAP.element")) { apply(k.items().get(1)); return; } super.apply(k); } }.apply(term);
private void verifySchemaTopic() { Set<String> topics = new HashSet<String>(); topics.add(topic); // check # partition and the replication factor scala.collection.Map partitionAssignment = zkUtils.getPartitionAssignmentForTopics( JavaConversions.asScalaSet(topics).toSeq()) .get(topic).get(); if (partitionAssignment.size() != 1) { log.warn("The schema topic " + topic + " should have only 1 partition."); } if (((Seq) partitionAssignment.get(0).get()).size() < desiredReplicationFactor) { log.warn("The replication factor of the schema topic " + topic + " is less than the " + "desired one of " + desiredReplicationFactor + ". If this is a production " + "environment, it's crucial to add more brokers and increase the replication " + "factor of the topic."); } // check the retention policy Properties prop = AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic(), topic); String retentionPolicy = prop.getProperty(LogConfig.CleanupPolicyProp()); if (retentionPolicy == null || "compact".compareTo(retentionPolicy) != 0) { log.warn("The retention policy of the schema topic " + topic + " may be incorrect. " + "Please configure it with compact."); } }
private void check(Production p) { if (p.att().contains(Attribute.CELL_KEY)) { for (ProductionItem i : mutable(p.items())) { if (i instanceof NonTerminal) { Sort sort = ((NonTerminal) i).sort(); if (sort.name().endsWith("Cell")) { if (cells.contains(sort)) { Production cell = new ConfigurationInfoFromModule(module).cellProductionsFor().get(sort).get().head(); errors.add(KEMException.compilerError("Cell " + cell.klabel().get() + " found twice in configuration.", p)); } cells.add(sort); } } } } } }
public static K toKASTTerm(Module mod, KApply kapp) { String kastTerm = ToKast.apply(kapp); Sort finalSort = Sorts.K(); Option<Sort> termSort = mod.sortFor().get(kapp.klabel()); if (! termSort.isEmpty()) { finalSort = termSort.get(); } return KToken(kastTerm, finalSort); } }
@Override public K apply(KVariable k) { if (freshVars.contains(k)) { Optional<Sort> s = k.att().getOptional(Sort.class); if (!s.isPresent()) { throw KEMException.compilerError("Fresh constant used without a declared sort.", k); } Option<KLabel> lbl = m.freshFunctionFor().get(s.get()); if (!lbl.isDefined()) { throw KEMException.compilerError("No fresh generator defined for sort " + s, k); } return KApply(lbl.get(), KApply(KLabel("_+Int_"), FRESH, KToken(offsets.get(k).toString(), Sorts.Int()))); } return super.apply(k); } }.apply(term);
Seq<Object> seq = partitionAssignments.get(topic).get().get(partitionId).get(); Node[] nodes = JavaConverters.seqAsJavaList(seq).stream() .map(val -> new Node((Integer) val, "", -1)).toArray(Node[]::new);
Optional<KLabel> optLabel = klabelFromTerm(labelTerm); if (optLabel.isPresent() && m.productionsFor().contains(optLabel.get())) { Collection<Production> productions = mutable(m.productionsFor().get(optLabel.get()).get()); List<Term> rawArgs = lowerKList(((TermCons) child).get(1)); assert rawArgs.stream().allMatch(ProductionReference.class::isInstance);
private static K omitTerm(Module mod, KApply kapp) { Sort finalSort = Sorts.K(); Option<Sort> termSort = mod.sortFor().get(kapp.klabel()); if (! termSort.isEmpty()) { finalSort = termSort.get(); } return KToken(kapp.klabel().name(), finalSort); }
private K tokenizeTerm(Module mod, KApply kapp) { Module unparsingModule = RuleGrammarGenerator.getCombinedGrammar(mod, false).getExtensionModule(); String tokenizedTerm = unparseTerm(kapp, unparsingModule, ColorSetting.OFF); Sort finalSort = Sorts.K(); Option<Sort> termSort = mod.sortFor().get(kapp.klabel()); if (! termSort.isEmpty()) { finalSort = termSort.get(); } return KToken(tokenizedTerm, finalSort); }
if (threadsCellSet instanceof KApply) { KLabel collectionLabel = collectionFor.get(((KApply)threadsCellSet).klabel()); KLabel unitLabel = KLabel(m.attributesFor().get(collectionLabel).get().get("unit")); List<K> threads = Assoc.flatten(collectionLabel, Collections.singletonList(threadsCellSet), unitLabel); K firstConcreteThread = null;
klabelsForEachPredicate = new HashMap<>(); for (KLabel functionLabel : rules.keySet()) { if (mainModule.attributesFor().get(functionLabel).getOrElse(() -> Att()).contains("klabelPredicate")) { klabelsForEachPredicate.put(functionLabel.name(), computeKLabelsForPredicate(functionRules.get(functionLabel))); String hook = mainModule.attributesFor().get(functionLabel).getOrElse(() -> Att()).<String>getOptional(Attribute.HOOK_KEY).orElse("."); if (hook.equals("KREFLECTION.fresh")) { sb.append(conn).append("freshFunction (sort: string) (config: k) (counter: Z.t) : k = match sort with \n");
list = newDotVariable(m.productionsFor().get(collectionLabel).get().head().sort());
continue; if (m.attributesFor().get(k.klabel()).getOrElse(() -> Att()).contains("klabelPredicate")) { if (k.klist().size() == 1 && k.klist().items().get(0) instanceof InjectedKLabel) { InjectedKLabel injection = (InjectedKLabel) k.klist().items().get(0);
sb.append("\n"); for (Sort sort : iterable(module.definedSorts())) { Att att = module.sortAttributesFor().get(sort).getOrElse(() -> KORE.Att()); collectAttributes(attributes, att); Att att = module.sortAttributesFor().get(sort).getOrElse(() -> KORE.Att()); if (att.contains(Attribute.HOOK_KEY)) { if (collectionSorts.contains(att.get(Attribute.HOOK_KEY))) { Set<Production> overloads = new HashSet<>(); for (Production lesser : iterable(module.overloads().elements())) { for (Production greater : iterable(module.overloads().relations().get(lesser).getOrElse(() -> Collections.<Production>Set()))) { overloads.add(greater); Att sortAtt = module.sortAttributesFor().get(sort).getOrElse(() -> KORE.Att()); if (!hasToken && sortAtt.contains("token")) { numTerms++; for (Production greater : iterable(module.overloads().relations().get(lesser).getOrElse(() -> Collections.<Production>Set()))) { sb.append(" axiom{R} \\equals{"); convert(greater.sort(), greater);
String hookAtt = mod.sortAttributesFor().get(expectedSort).getOrElse(() -> Att()).getOptional("hook").orElse(""); if (hookAtt.equals("MAP.Map") || hookAtt.equals("SET.Set") || hookAtt.equals("LIST.List")) { for (KLabel collectionLabel : collectionFor.keySet()) {
String cellName = label.s(); Sort sort = Sort(getSortOfCell(cellName)); Option<Set<Production>> initializerProduction = m.productionsFor().get(KLabel(getInitLabel(sort))); if (initializerProduction.isDefined()) { Set<Production> realProds = stream(initializerProduction.get()).filter(p -> !p.att().contains("recordPrd", Production.class)).collect(Collections.toSet());