diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-07-25 14:30:45 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-07-25 15:13:15 +0200 |
commit | d615f74168ffccf8be8eda4b39b1e9bf9ba06bda (patch) | |
tree | baf83d0cc2f62781afaefecb226f2fe8d2be93d5 /vpp-integration/api-docs | |
parent | 0fcc92079bc63bfe01861140783dcf1598244cf2 (diff) |
Api docs: unify handling of writers and subtree writers
Change-Id: Ib0bd217c92f39052cc24f6324b5d33aa0443d002
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-integration/api-docs')
3 files changed, 55 insertions, 99 deletions
diff --git a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CollectingWriterBuilder.java b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CollectingWriterBuilder.java index b8fcc8b03..6abb6a80b 100644 --- a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CollectingWriterBuilder.java +++ b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CollectingWriterBuilder.java @@ -36,39 +36,46 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; */ public class CollectingWriterBuilder implements ModifiableWriterRegistryBuilder { - private final List<Writer<? extends DataObject>> singleNodeHandlers; - private final List<MultiNodeWriteHandler> multiNodeWriteHandlers; + private final List<WriteHandler> writeHandlers; public CollectingWriterBuilder() { - singleNodeHandlers = new LinkedList<>(); - multiNodeWriteHandlers = new LinkedList<>(); + writeHandlers = new LinkedList<>(); + } + + private void addHandler(final Writer<? extends DataObject> handler) { + writeHandlers.add(new WriteHandler(handler)); + } + + private void addHandler(final Writer<? extends DataObject> handler, + final Set<InstanceIdentifier<?>> handledChildren) { + writeHandlers.add(new WriteHandler(handler, handledChildren)); } @Override public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> add( @Nonnull Writer<? extends DataObject> handler) { - singleNodeHandlers.add(handler); + addHandler(handler); return this; } @Override public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> subtreeAdd( @Nonnull Set<InstanceIdentifier<?>> handledChildren, @Nonnull Writer<? extends DataObject> handler) { - multiNodeWriteHandlers.add(new MultiNodeWriteHandler(handler, handledChildren)); + addHandler(handler, handledChildren); return this; } @Override public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> addBefore( @Nonnull Writer<? extends DataObject> handler, @Nonnull InstanceIdentifier<?> relatedType) { - multiNodeWriteHandlers.add(new MultiNodeWriteHandler(handler, Collections.singleton(relatedType))); + addHandler(handler, Collections.singleton(relatedType)); return this; } @Override public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> addBefore( @Nonnull Writer<? extends DataObject> handler, @Nonnull Collection<InstanceIdentifier<?>> relatedTypes) { - singleNodeHandlers.add(handler); + addHandler(handler); return this; } @@ -76,7 +83,7 @@ public class CollectingWriterBuilder implements ModifiableWriterRegistryBuilder public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> subtreeAddBefore( @Nonnull Set<InstanceIdentifier<?>> handledChildren, @Nonnull Writer<? extends DataObject> handler, @Nonnull InstanceIdentifier<?> relatedType) { - multiNodeWriteHandlers.add(new MultiNodeWriteHandler(handler, handledChildren)); + addHandler(handler, handledChildren); return null; } @@ -84,21 +91,21 @@ public class CollectingWriterBuilder implements ModifiableWriterRegistryBuilder public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> subtreeAddBefore( @Nonnull Set<InstanceIdentifier<?>> handledChildren, @Nonnull Writer<? extends DataObject> handler, @Nonnull Collection<InstanceIdentifier<?>> relatedTypes) { - multiNodeWriteHandlers.add(new MultiNodeWriteHandler(handler, handledChildren)); + addHandler(handler, handledChildren); return this; } @Override public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> addAfter( @Nonnull Writer<? extends DataObject> handler, @Nonnull InstanceIdentifier<?> relatedType) { - singleNodeHandlers.add(handler); + addHandler(handler); return this; } @Override public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> addAfter( @Nonnull Writer<? extends DataObject> handler, @Nonnull Collection<InstanceIdentifier<?>> relatedTypes) { - singleNodeHandlers.add(handler); + addHandler(handler); return this; } @@ -106,7 +113,7 @@ public class CollectingWriterBuilder implements ModifiableWriterRegistryBuilder public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> subtreeAddAfter( @Nonnull Set<InstanceIdentifier<?>> handledChildren, @Nonnull Writer<? extends DataObject> handler, @Nonnull InstanceIdentifier<?> relatedType) { - multiNodeWriteHandlers.add(new MultiNodeWriteHandler(handler, Collections.singleton(relatedType))); + addHandler(handler, handledChildren); return this; } @@ -114,40 +121,41 @@ public class CollectingWriterBuilder implements ModifiableWriterRegistryBuilder public ModifiableSubtreeManagerRegistryBuilder<Writer<? extends DataObject>> subtreeAddAfter( @Nonnull Set<InstanceIdentifier<?>> handledChildren, @Nonnull Writer<? extends DataObject> handler, @Nonnull Collection<InstanceIdentifier<?>> relatedTypes) { - multiNodeWriteHandlers.add(new MultiNodeWriteHandler(handler, handledChildren)); + addHandler(handler, handledChildren); return this; } - public List<Writer<? extends DataObject>> getSingleNodeHandlers() { - return singleNodeHandlers; + public List<WriteHandler> getWriteHandlers() { + return writeHandlers; } - public List<MultiNodeWriteHandler> getMultiNodeWriteHandlers() { - return multiNodeWriteHandlers; - } - - public static class MultiNodeWriteHandler { + public static class WriteHandler { private final Writer<? extends DataObject> writer; - private final Set<String> handledChildren; - + private final Set<String> handledNodes; - public MultiNodeWriteHandler(Writer<? extends DataObject> writer, Set<InstanceIdentifier<?>> handledChildren) { + public WriteHandler(Writer<? extends DataObject> writer, Set<InstanceIdentifier<?>> handledChildren) { this.writer = writer; - this.handledChildren = ImmutableSet.<String>builder() - .add(writer.getManagedDataObjectType().getTargetType().getName()) - .addAll(handledChildren.stream() - .map(InstanceIdentifier::getTargetType) - .map(Class::getName) - .collect(Collectors.toSet())) - .build(); + this.handledNodes = ImmutableSet.<String>builder() + // add node managed by writer + .add(writer.getManagedDataObjectType().getTargetType().getName()) + // and set of handled children (may be empty in case of non subtree writers) + .addAll(handledChildren.stream() + .map(InstanceIdentifier::getTargetType) + .map(Class::getName) + .collect(Collectors.toSet())) + .build(); + } + + public WriteHandler(final Writer<? extends DataObject> writer) { + this(writer, Collections.emptySet()); } public Writer<? extends DataObject> getWriter() { return writer; } - public Set<String> getHandledChildren() { - return handledChildren; + public Set<String> getHandledNodes() { + return handledNodes; } } } diff --git a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java index 4b6ab776c..4a8a77827 100644 --- a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java +++ b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/CoverageGenerator.java @@ -34,7 +34,6 @@ import io.fd.hc2vpp.docs.api.PluginCoverage; import io.fd.hc2vpp.docs.api.YangType; import io.fd.honeycomb.translate.write.WriterFactory; import java.lang.reflect.Field; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -59,14 +58,13 @@ public class CoverageGenerator implements VppApiUtils { final List<Module> scannedModules, final YangTypeLinkIndex yangTypeIndex, final ClassPathTypeIndex classPathIndex) { - LOG.info("Generating config coverage for plugin {}", pluginClass); + LOG.info("Generating config VPP API to Yang mapping for plugin {}", pluginClass); getInjectedWriterFactories(scannedModules).forEach(writerFactory -> writerFactory.init(writerBuilder)); - LOG.info("Processing single node handlers"); - final Set<CoverageUnit> singleNodeCoverageUnits = writerBuilder.getSingleNodeHandlers().stream() - .flatMap(writer -> { + final Set<CoverageUnit> coverageUnits = writerBuilder.getWriteHandlers().stream() + .flatMap(handler -> { // extracts customizer class from handler - final Class<?> customizerClass = getCustomizerClass(writer); + final Class<?> customizerClass = getCustomizerClass(handler.getWriter()); // scans within write method final Set<PluginMethodReference> writeReferences = @@ -81,62 +79,19 @@ public class CoverageGenerator implements VppApiUtils { new CoverageScanner(customizerClass, DELETE, pluginClass).scan(); return Stream.of(writeReferences.stream(), updateReferences.stream(), deleteReferences.stream()) - .flatMap(pluginMethodReferences -> pluginMethodReferences) + .flatMap(pluginMethodReferenceStream -> pluginMethodReferenceStream) .map(reference -> { final CoverageUnit.CoverageUnitBuilder builder = new CoverageUnit.CoverageUnitBuilder(); // binds vpp api name and generateLink bind with version - builder.setVppApi(fromJvppApi(version, reference)); + builder.setVppApi(fromJvppApi(version, reference.getName())); //binds java api reference builder.setJavaApi(new JavaApiMessage(reference.getName())); - //binds Yang types with links from pre-build index - // TODO - use deserialized yii - final String typeName = writer.getManagedDataObjectType().getTargetType().getTypeName(); - builder.setYangTypes(Collections.singletonList(new YangType( - typeName, - yangTypeIndex.getLinkForType(typeName)))); - - final List<Operation> supportedOperations = new LinkedList<>(); - - final String callerClassLink = classPathIndex.linkForClass(reference.getCaller()); - if (writeReferences.contains(reference)) { - supportedOperations.add(new Operation(callerClassLink, WRITE)); - } - - if (updateReferences.contains(reference)) { - supportedOperations.add(new Operation(callerClassLink, UPDATE)); - } - - if (deleteReferences.contains(reference)) { - supportedOperations.add(new Operation(callerClassLink, DELETE)); - } - return builder.setSupportedOperations(supportedOperations).build(); - }); - }).collect(Collectors.toSet()); - - LOG.info("Processing multi node handlers"); - final Set<CoverageUnit> multiNodeCoverageUnits = writerBuilder.getMultiNodeWriteHandlers().stream() - .flatMap(handler -> { - final Class<?> customizerClass = getCustomizerClass(handler.getWriter()); - final Set<PluginMethodReference> writeReferences = - new CoverageScanner(customizerClass, WRITE, pluginClass).scan(); - - final Set<PluginMethodReference> updateReferences = - new CoverageScanner(customizerClass, UPDATE, pluginClass).scan(); - - final Set<PluginMethodReference> deleteReferences = - new CoverageScanner(customizerClass, DELETE, pluginClass).scan(); - - return Stream.of(writeReferences.stream(), updateReferences.stream(), deleteReferences.stream()) - .flatMap(pluginMethodReferenceStream -> pluginMethodReferenceStream) - .map(reference -> { - final CoverageUnit.CoverageUnitBuilder builder = new CoverageUnit.CoverageUnitBuilder(); - builder.setVppApi(fromJvppApi(version, reference)); - builder.setJavaApi(new JavaApiMessage(reference.getName())); - - builder.setYangTypes(handler.getHandledChildren().stream() + // binds Yang types with links from pre-build index + // TODO - use deserialized yii e.g. /module:parent-node/child-node + builder.setYangTypes(handler.getHandledNodes().stream() .map(type -> new YangType(type, yangTypeIndex.getLinkForType(type))) .collect(Collectors.toList())); @@ -157,10 +112,7 @@ public class CoverageGenerator implements VppApiUtils { }); }).collect(Collectors.toSet()); - return new PluginCoverage(pluginClass.getSimpleName(), - Stream.of(singleNodeCoverageUnits.stream(), multiNodeCoverageUnits.stream()) - .flatMap(coverageUnitStream -> coverageUnitStream) - .collect(Collectors.toSet()), true); + return new PluginCoverage(pluginClass.getSimpleName(), coverageUnits, true); } private static Class<?> getCustomizerClass(final Object handler) { diff --git a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/VppApiUtils.java b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/VppApiUtils.java index f21cc2660..c978abae5 100644 --- a/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/VppApiUtils.java +++ b/vpp-integration/api-docs/core/src/main/java/io/fd/hc2vpp/docs/core/VppApiUtils.java @@ -22,11 +22,7 @@ import io.fd.hc2vpp.docs.api.VppApiMessage; public interface VppApiUtils { - static String vppApiFromJavaApi(final String jvppApi) { - return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, jvppApi); - } - - static String generateVppApiDocLink(final String version, final String vppApi) { + static String generateVppApiDocLink(final String version, final String vppMessageName) { //https://docs.fd.io/vpp/17.07/d9/d1d/structvl__api__create__subif__t.html // links are using double underscore //final String doubleUnderscoreApiName = vppApi.replace("_", "__"); @@ -36,8 +32,8 @@ public interface VppApiUtils { return "https://docs.fd.io/vpp/17.07/annotated.html"; } - default VppApiMessage fromJvppApi(final String version, final PluginMethodReference jvppApi) { - final String vppApi = vppApiFromJavaApi(jvppApi.getName()); - return new VppApiMessage(vppApi, generateVppApiDocLink(version, vppApi)); + default VppApiMessage fromJvppApi(final String version, final String jvppMethodName) { + final String vppMessageName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, jvppMethodName); + return new VppApiMessage(vppMessageName, generateVppApiDocLink(version, vppMessageName)); } } |