From d5397068c1607b705a92d743acad63d87244c6ec Mon Sep 17 00:00:00 2001 From: Jonathan Shook Date: Mon, 10 Jan 2022 22:25:06 -0600 Subject: [PATCH] allow driver adapters to directly specify docs resources --- .../activityimpl/uniform/DriverAdapter.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/adapters-api/src/main/java/io/nosqlbench/engine/api/activityimpl/uniform/DriverAdapter.java b/adapters-api/src/main/java/io/nosqlbench/engine/api/activityimpl/uniform/DriverAdapter.java index 9a52616db..58d64be57 100644 --- a/adapters-api/src/main/java/io/nosqlbench/engine/api/activityimpl/uniform/DriverAdapter.java +++ b/adapters-api/src/main/java/io/nosqlbench/engine/api/activityimpl/uniform/DriverAdapter.java @@ -1,12 +1,19 @@ package io.nosqlbench.engine.api.activityimpl.uniform; +import io.nosqlbench.docapi.Docs; +import io.nosqlbench.docapi.DocsBinder; import io.nosqlbench.engine.api.activityimpl.OpDispenser; import io.nosqlbench.engine.api.activityimpl.OpMapper; import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op; import io.nosqlbench.engine.api.templating.ParsedOp; +import io.nosqlbench.nb.annotations.Maturity; +import io.nosqlbench.nb.annotations.Service; import io.nosqlbench.nb.api.config.standard.NBConfiguration; +import io.nosqlbench.nb.api.content.Content; +import io.nosqlbench.nb.api.content.NBIO; import java.util.Map; +import java.util.Optional; import java.util.function.Function; /** @@ -109,7 +116,7 @@ public interface DriverAdapter { * construction of operations. * * See {@link DriverSpaceCache} for details on when and how to use this function. - + * *

During Adapter Initialization, Op Mapping, Op Synthesis, or Op Execution, * you may need access to the objects in (the or a) space cache. You can build the * type of context needed and then provide this function to provide new instances @@ -127,4 +134,38 @@ public interface DriverAdapter { } NBConfiguration getConfiguration(); + + /** + * The standard way to provide docs for a driver adapter is to put them in one of two common places: + *

+ * path <resources>/docs/<adaptername>. Specifically, the file + * + * @return A {@link DocsBinder} which describes docs to include for a given adapter. + */ + default DocsBinder getBundledDocs() { + Docs docs = new Docs().namespace("adapter-"+this.getAdapterName()); + + String dev_docspath = "adapter-" + this.getAdapterName() + "/src/main/resources/docs/" + this.getAdapterName(); + String cp_docspath = "docs/" + this.getAdapterName(); + Optional> bundled_docs = NBIO.local().name(dev_docspath, cp_docspath).first(); + bundled_docs.map(Content::asPath).ifPresent(docs::addContentsOf); + + Optional> maindoc = NBIO.local().name("/src/main/resources/" + this.getAdapterName() + ".md", this.getAdapterName() + ".md").first(); + maindoc.map(Content::asPath).ifPresent(docs::addPath); + + return docs.asDocsBinder(); + } + + default String getAdapterName() { + return this.getClass().getAnnotation(Service.class).selector(); + } + + default Maturity getAdapterMaturity() { + return this.getClass().getAnnotation(Service.class).maturity(); + } }