mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
remove endpoints which are no longer needed
This commit is contained in:
@@ -17,12 +17,7 @@
|
|||||||
package io.nosqlbench.docsys.api;
|
package io.nosqlbench.docsys.api;
|
||||||
|
|
||||||
import io.nosqlbench.api.docsapi.DocsBinder;
|
import io.nosqlbench.api.docsapi.DocsBinder;
|
||||||
import io.nosqlbench.docsys.endpoints.DocsysMarkdownEndpoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* At runtime, any instances of this service will be used to find
|
|
||||||
* paths to be shared via the {@link DocsysMarkdownEndpoint}.
|
|
||||||
*/
|
|
||||||
public interface DocsysDynamicManifest {
|
public interface DocsysDynamicManifest {
|
||||||
DocsBinder getDocs();
|
DocsBinder getDocs();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package io.nosqlbench.docsys.core;
|
package io.nosqlbench.docsys.core;
|
||||||
|
|
||||||
import io.nosqlbench.api.spi.BundledApp;
|
import io.nosqlbench.api.spi.BundledApp;
|
||||||
import io.nosqlbench.docsys.endpoints.DocsysMarkdownEndpoint;
|
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -56,28 +55,6 @@ public class NBWebServerApp implements BundledApp {
|
|||||||
|
|
||||||
logger.info(() -> "generating to directory " + dirpath);
|
logger.info(() -> "generating to directory " + dirpath);
|
||||||
|
|
||||||
|
|
||||||
DocsysMarkdownEndpoint dds = new DocsysMarkdownEndpoint();
|
|
||||||
String markdownList = dds.getMarkdownList(true);
|
|
||||||
|
|
||||||
Path markdownCsvPath = dirpath.resolve(Path.of("services/docs/markdown.csv"));
|
|
||||||
logger.info(() -> "markdown.csv located at " + markdownCsvPath);
|
|
||||||
|
|
||||||
Files.createDirectories(markdownCsvPath.getParent());
|
|
||||||
Files.writeString(markdownCsvPath, markdownList, OVERWRITE);
|
|
||||||
|
|
||||||
String[] markdownFileArray = markdownList.split("\n");
|
|
||||||
|
|
||||||
for (String markdownFile : markdownFileArray) {
|
|
||||||
Path relativePath = dirpath.resolve(Path.of("services/docs", markdownFile));
|
|
||||||
logger.info(() -> "Creating " + relativePath);
|
|
||||||
|
|
||||||
Path path = dds.findPath(markdownFile);
|
|
||||||
// String markdown = dds.getFileByPath(markdownFile);
|
|
||||||
// Files.writeString(relativePath, markdown, OVERWRITE);
|
|
||||||
Files.createDirectories(relativePath.getParent());
|
|
||||||
Files.write(relativePath,Files.readAllBytes(path),OVERWRITE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void runServer(String[] serverArgs) {
|
private static void runServer(String[] serverArgs) {
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 nosqlbench
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.nosqlbench.docsys.endpoints;
|
|
||||||
|
|
||||||
import io.nosqlbench.docsys.api.WebServiceObject;
|
|
||||||
import io.nosqlbench.docsys.core.NBWebServer;
|
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
|
||||||
import io.nosqlbench.nb.annotations.Maturity;
|
|
||||||
import jakarta.inject.Singleton;
|
|
||||||
import jakarta.ws.rs.GET;
|
|
||||||
import jakarta.ws.rs.Path;
|
|
||||||
import jakarta.ws.rs.Produces;
|
|
||||||
import jakarta.ws.rs.core.Configuration;
|
|
||||||
import jakarta.ws.rs.core.Context;
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
@Service(value = WebServiceObject.class, selector = "docserver-status", maturity = Maturity.Deprecated)
|
|
||||||
@Singleton
|
|
||||||
@Path("_")
|
|
||||||
public class DocServerStatusEndpoint implements WebServiceObject {
|
|
||||||
|
|
||||||
private final static Logger logger =
|
|
||||||
LogManager.getLogger(DocServerStatusEndpoint.class);
|
|
||||||
|
|
||||||
@Context
|
|
||||||
private Configuration config;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("status")
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
public String getStats() {
|
|
||||||
NBWebServer s = (NBWebServer) config.getProperty("server");
|
|
||||||
return s.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 nosqlbench
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.nosqlbench.docsys.endpoints;
|
|
||||||
|
|
||||||
import io.nosqlbench.api.docsapi.Docs;
|
|
||||||
import io.nosqlbench.api.docsapi.DocsBinder;
|
|
||||||
import io.nosqlbench.api.docsapi.DocsNameSpace;
|
|
||||||
import io.nosqlbench.docsys.api.WebServiceObject;
|
|
||||||
import io.nosqlbench.docsys.core.DocsysPathLoader;
|
|
||||||
import io.nosqlbench.docsys.core.PathWalker;
|
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
|
||||||
import io.nosqlbench.nb.annotations.Maturity;
|
|
||||||
import jakarta.inject.Singleton;
|
|
||||||
import jakarta.ws.rs.*;
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
|
||||||
import jakarta.ws.rs.core.Response;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
@Service(value = WebServiceObject.class, selector = "docsys-markdown",maturity = Maturity.Deprecated)
|
|
||||||
@Singleton
|
|
||||||
@Path("/services/docs/")
|
|
||||||
public class DocsysMarkdownEndpoint implements WebServiceObject {
|
|
||||||
private final static Logger logger = LogManager.getLogger(DocsysMarkdownEndpoint.class);
|
|
||||||
private DocsBinder docsinfo;
|
|
||||||
private DocsBinder enabled;
|
|
||||||
private DocsBinder disabled;
|
|
||||||
|
|
||||||
private final AtomicLong version = new AtomicLong(System.nanoTime());
|
|
||||||
private final Set<String> enables = new HashSet<>();
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Path("version")
|
|
||||||
public long getVersion() {
|
|
||||||
return version.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If no enable= parameter is provided, then this call simply provides a map of
|
|
||||||
* namespaces which are enabled and disabled.
|
|
||||||
*
|
|
||||||
* @param enable A set of namespaces to enable, or no provided value to enable all namespaces
|
|
||||||
* @return A view of the namespaces known to this service
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Path("namespaces")
|
|
||||||
public Map<String, Map<String, Set<java.nio.file.Path>>> getNamespaces(
|
|
||||||
@QueryParam("enable") String enable,
|
|
||||||
@QueryParam("reload") boolean reload
|
|
||||||
) {
|
|
||||||
|
|
||||||
if (enable!=null && !enable.isEmpty()) {
|
|
||||||
enables.clear();
|
|
||||||
enables.addAll(List.of(enable.split("[, ;]")));
|
|
||||||
}
|
|
||||||
|
|
||||||
init(reload);
|
|
||||||
enable(enables);
|
|
||||||
|
|
||||||
return Map.of(
|
|
||||||
"enabled",enabled.getPathMap(),
|
|
||||||
"disabled",disabled.getPathMap()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Provide a list of all files from all enabled namespaces.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
|
||||||
@Path("allfiles.csv")
|
|
||||||
public String getAllfilesList(@QueryParam("reload") boolean reload) {
|
|
||||||
|
|
||||||
init(reload);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (java.nio.file.Path path : enabled.getPaths()) {
|
|
||||||
PathWalker.findAll(path).forEach(f -> {
|
|
||||||
sb.append(path.relativize(f)).append("\n");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Provide a lit of all files from all enabled namespaces
|
|
||||||
* where the file path ends with '.md'
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
|
||||||
@Path("markdown.csv")
|
|
||||||
public String getMarkdownList(@QueryParam("reload") boolean reload) {
|
|
||||||
|
|
||||||
init(reload);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (java.nio.file.Path path : enabled.getPaths()) {
|
|
||||||
PathWalker.findAll(path).forEach(f -> {
|
|
||||||
if (f.toString().endsWith(".md")) {
|
|
||||||
sb.append(path.relativize(f)).append("\n");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Provides a list of all files from all enabled namespaces as a JSON list.
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
|
||||||
@Path("list")
|
|
||||||
public List<String> listFiles(@QueryParam("reload") boolean reload) {
|
|
||||||
init(reload);
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
for (java.nio.file.Path path : enabled.getPaths()) {
|
|
||||||
PathWalker.findAll(path).forEach(f -> {
|
|
||||||
java.nio.file.Path relative = path.relativize(f);
|
|
||||||
list.add(relative.toString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param pathspec the path as known to the manifest
|
|
||||||
* @return The contents of a file
|
|
||||||
*
|
|
||||||
* @see <A href="https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/user-guide.html#d0e7648">jersey providers</A>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path(value = "{pathspec:.*}")
|
|
||||||
public Response getFileInPath(@PathParam("pathspec") String pathspec) {
|
|
||||||
init(false);
|
|
||||||
try {
|
|
||||||
java.nio.file.Path path = findPath(pathspec);
|
|
||||||
String contentType = Files.probeContentType(path);
|
|
||||||
MediaType mediaType = MediaType.valueOf(contentType);
|
|
||||||
return Response.ok(Files.newBufferedReader(path), mediaType).build();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return Response.serverError().entity(e.getMessage()).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public java.nio.file.Path findPath(String pathspec) {
|
|
||||||
pathspec = URLDecoder.decode(pathspec, StandardCharsets.UTF_8);
|
|
||||||
for (java.nio.file.Path path : enabled.getPaths()) {
|
|
||||||
java.nio.file.Path resolved = path.resolve(pathspec);
|
|
||||||
if (Files.isDirectory(resolved)) {
|
|
||||||
throw new RuntimeException("Path is a directory: '" + pathspec + "'");
|
|
||||||
}
|
|
||||||
if (Files.exists(resolved)) {
|
|
||||||
return resolved;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new RuntimeException("Unable to find any valid file at '" + pathspec + "'");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init(boolean reload) {
|
|
||||||
if (reload) {
|
|
||||||
this.enabled = null;
|
|
||||||
this.disabled = null;
|
|
||||||
this.docsinfo = null;
|
|
||||||
}
|
|
||||||
if (this.docsinfo == null) {
|
|
||||||
this.docsinfo = DocsysPathLoader.loadDynamicPaths();
|
|
||||||
version.set(System.nanoTime());
|
|
||||||
}
|
|
||||||
if (enabled==null || disabled==null) {
|
|
||||||
enable(enables);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enable(Set<String> enabled) {
|
|
||||||
for (DocsNameSpace nsinfo : docsinfo) {
|
|
||||||
// add namespaces which are neither enabled nor disabled to the default group
|
|
||||||
if (nsinfo.isEnabledByDefault()) {
|
|
||||||
if (disabled!=null && disabled.getPathMap().containsKey(nsinfo.getName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
enables.add(nsinfo.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enabled.isEmpty()) { // Nothing is enabled or enabled by default, so enable everything
|
|
||||||
this.enabled = new Docs().merge(docsinfo);
|
|
||||||
this.disabled = new Docs().asDocsBinder();
|
|
||||||
} else { // At least one thing was enabled by default, or previously enabled specifically
|
|
||||||
this.disabled = new Docs().merge(docsinfo);
|
|
||||||
this.enabled = disabled.remove(enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 nosqlbench
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.nosqlbench.docsys.core;
|
|
||||||
|
|
||||||
import io.nosqlbench.docsys.endpoints.DocsysMarkdownEndpoint;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
public class DocsysMarkdownLoaderEndpointTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDocLoader() {
|
|
||||||
DocsysMarkdownEndpoint ep = new DocsysMarkdownEndpoint();
|
|
||||||
String markdownList = ep.getMarkdownList(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user