summaryrefslogtreecommitdiffstats
path: root/container-search/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-04-05 22:31:40 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2018-04-05 22:47:25 +0200
commit97874347c52fafaf81f5c51f23816fdd99c7436c (patch)
tree66682cfcb4fdac7a08da1b00ca4caf58a4027a42 /container-search/src
parentfcbe9060eb975ac488c665f097d516dec4226811 (diff)
Clean out some unknown debug code.
Diffstat (limited to 'container-search/src')
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/BackendStatistics.java60
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/DebugMethodHandler.java13
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/DebugRpcAdaptor.java42
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/IndentStringBuilder.java102
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/JrtMethodSignature.java17
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/OutputSearchChain.java59
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/SearchChainTextRepresentation.java88
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/SearcherUtils.java67
-rw-r--r--container-search/src/main/java/com/yahoo/search/debug/TracePackets.java44
-rw-r--r--container-search/src/test/java/com/yahoo/search/debug/test/SearchChainTextRepresentationTestCase.java51
10 files changed, 0 insertions, 543 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/debug/BackendStatistics.java b/container-search/src/main/java/com/yahoo/search/debug/BackendStatistics.java
deleted file mode 100644
index f8d46ec6851..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/BackendStatistics.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-import static com.yahoo.search.debug.SearcherUtils.clusterSearchers;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang.ArrayUtils;
-
-import com.yahoo.fs4.mplex.Backend;
-import com.yahoo.jrt.Int32Array;
-import com.yahoo.jrt.Request;
-import com.yahoo.jrt.StringArray;
-import com.yahoo.jrt.Value;
-import com.yahoo.jrt.Values;
-import com.yahoo.prelude.cluster.ClusterSearcher;
-import com.yahoo.yolean.Exceptions;
-
-/**
- * @author tonytv
- */
-public class BackendStatistics implements DebugMethodHandler {
- public JrtMethodSignature getSignature() {
- String returnTypes = "" + (char)Value.STRING_ARRAY + (char)Value.INT32_ARRAY + (char)Value.INT32_ARRAY;
- String parametersTypes = "" + (char)Value.STRING;
-
- return new JrtMethodSignature(returnTypes, parametersTypes);
- }
-
- public void invoke(Request request) {
- try {
- Collection<ClusterSearcher> searchers = clusterSearchers(request);
- List<String> backendIdentificators = new ArrayList<>();
- List<Integer> activeConnections = new ArrayList<>();
- List<Integer> totalConnections = new ArrayList<>();
-
- for (ClusterSearcher searcher : searchers) {
- for (Map.Entry<String,Backend.BackendStatistics> statistics : searcher.getBackendStatistics().entrySet()) {
- backendIdentificators.add(statistics.getKey());
- activeConnections.add(statistics.getValue().activeConnections);
- totalConnections.add(statistics.getValue().totalConnections());
- }
- }
- Values returnValues = request.returnValues();
- returnValues.add(new StringArray(backendIdentificators.toArray(new String[0])));
- addInt32Array(returnValues, activeConnections);
- addInt32Array(returnValues, totalConnections);
-
- } catch (Exception e) {
- request.setError(1000, Exceptions.toMessageString(e));
- }
- }
-
- private void addInt32Array(Values returnValues, List<Integer> ints) {
- returnValues.add(new Int32Array(ArrayUtils.toPrimitive(ints.toArray(new Integer[0]))));
- }
-}
diff --git a/container-search/src/main/java/com/yahoo/search/debug/DebugMethodHandler.java b/container-search/src/main/java/com/yahoo/search/debug/DebugMethodHandler.java
deleted file mode 100644
index 08dc98dd20a..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/DebugMethodHandler.java
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-import com.yahoo.jrt.MethodHandler;
-
-/**
- * A method handler that can describe its signature.
- *
- * @author tonytv
- */
-interface DebugMethodHandler extends MethodHandler {
- JrtMethodSignature getSignature();
-}
diff --git a/container-search/src/main/java/com/yahoo/search/debug/DebugRpcAdaptor.java b/container-search/src/main/java/com/yahoo/search/debug/DebugRpcAdaptor.java
deleted file mode 100644
index e196c11e31d..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/DebugRpcAdaptor.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-import com.yahoo.container.osgi.AbstractRpcAdaptor;
-import com.yahoo.jrt.Method;
-import com.yahoo.jrt.Supervisor;
-import com.yahoo.fs4.PacketDumper.PacketType;
-
-/**
- * Handles rpc calls for retrieving debug information.
- *
- * @author tonytv
- */
-public final class DebugRpcAdaptor extends AbstractRpcAdaptor {
- private static final String debugPrefix = "debug.";
-
- public void bindCommands(Supervisor supervisor) {
- addTraceMethod(supervisor, "query", PacketType.query);
- addTraceMethod(supervisor, "result", PacketType.result);
- addMethod(supervisor, "output-search-chain", new OutputSearchChain());
- addMethod(supervisor, "backend-statistics", new BackendStatistics());
- }
-
- private void addTraceMethod(Supervisor supervisor, String name, PacketType packetType) {
- addMethod(supervisor, constructTraceMethodName(name), new TracePackets(packetType));
- }
-
- private void addMethod(Supervisor supervisor, String name, DebugMethodHandler handler) {
- JrtMethodSignature typeStrings = handler.getSignature();
- supervisor.addMethod(
- new Method(debugPrefix + name,
- typeStrings.parametersTypes,
- typeStrings.returnTypes,
- handler));
-
- }
-
- //example: debug.dump-query-packets
- private String constructTraceMethodName(String name) {
- return debugPrefix + "dump-" + name + "-packets";
- }
-}
diff --git a/container-search/src/main/java/com/yahoo/search/debug/IndentStringBuilder.java b/container-search/src/main/java/com/yahoo/search/debug/IndentStringBuilder.java
deleted file mode 100644
index 24a3ec3ea81..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/IndentStringBuilder.java
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-import java.io.Serializable;
-
-/**
- * A StringBuilder that also handles indentation for append operations.
- * @author tonytv
- */
-@SuppressWarnings("serial")
-final class IndentStringBuilder implements Serializable, Appendable, CharSequence {
- private final StringBuilder builder = new StringBuilder();
- private final String singleIndentation;
-
- private int level = 0;
- private boolean newline = true;
-
- private void appendIndentation() {
- if (newline) {
- for (int i=0; i<level; i++) {
- builder.append(singleIndentation);
- }
- }
- newline = false;
- }
-
- public IndentStringBuilder(String singleIndentation) {
- this.singleIndentation = singleIndentation;
- }
-
- public IndentStringBuilder() {
- this(" ");
- }
-
- public void resetIndentLevel(int level) {
- this.level = level;
- }
-
- //returns the indent level before indenting.
- public int newlineAndIndent() {
- newline();
- return indent();
- }
-
- //returns the indent level before indenting.
- public int indent() {
- return level++;
- }
-
- public IndentStringBuilder newline() {
- newline = true;
- builder.append('\n');
- return this;
- }
-
- public IndentStringBuilder append(Object o) {
- appendIndentation();
- builder.append(o);
- return this;
- }
-
- public IndentStringBuilder append(String s) {
- appendIndentation();
- builder.append(s);
- return this;
- }
-
- public IndentStringBuilder append(CharSequence charSequence) {
- appendIndentation();
- builder.append(charSequence);
- return this;
- }
-
- public IndentStringBuilder append(CharSequence charSequence, int i, int i1) {
- appendIndentation();
- builder.append(charSequence, i, i1);
- return this;
- }
-
- public IndentStringBuilder append(char c) {
- appendIndentation();
- builder.append(c);
- return this;
- }
-
- public String toString() {
- return builder.toString();
- }
-
- public int length() {
- return builder.length();
- }
-
- public char charAt(int i) {
- return builder.charAt(i);
- }
-
- public CharSequence subSequence(int i, int i1) {
- return builder.subSequence(i, i1);
- }
-
-}
diff --git a/container-search/src/main/java/com/yahoo/search/debug/JrtMethodSignature.java b/container-search/src/main/java/com/yahoo/search/debug/JrtMethodSignature.java
deleted file mode 100644
index 160a861f352..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/JrtMethodSignature.java
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-/**
- * Represents the signatures of a jrt method.
- *
- * @author tonytv
- */
-final class JrtMethodSignature {
- final String returnTypes;
- final String parametersTypes;
-
- JrtMethodSignature(String returnTypes, String parametersTypes) {
- this.returnTypes = returnTypes;
- this.parametersTypes = parametersTypes;
- }
-}
diff --git a/container-search/src/main/java/com/yahoo/search/debug/OutputSearchChain.java b/container-search/src/main/java/com/yahoo/search/debug/OutputSearchChain.java
deleted file mode 100644
index 8656c811590..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/OutputSearchChain.java
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-import static com.yahoo.protect.Validator.ensureNotNull;
-
-import com.yahoo.jrt.Request;
-import com.yahoo.jrt.StringValue;
-import com.yahoo.jrt.Value;
-import com.yahoo.yolean.Exceptions;
-import com.yahoo.search.handler.SearchHandler;
-import com.yahoo.search.searchchain.SearchChain;
-import com.yahoo.search.searchchain.SearchChainRegistry;
-
-/**
- * Outputs a human readable representation of a given search chain.
- *
- * @author tonytv
- */
-final class OutputSearchChain implements DebugMethodHandler {
- private String getSearchChainName(Request request) {
- final int numParameters = request.parameters().size();
-
- if (numParameters == 0)
- return SearchHandler.defaultSearchChainName;
- else if (numParameters == 1)
- return request.parameters().get(0).asString();
- else
- throw new RuntimeException("Too many parameters given.");
- }
-
- private SearchChain getSearchChain(SearchChainRegistry registry, String searchChainName) {
- SearchChain searchChain = registry.getComponent(searchChainName);
- ensureNotNull("There is no search chain named '" + searchChainName + "'", searchChain);
- return searchChain;
- }
-
- public JrtMethodSignature getSignature() {
- String returnTypes = "" + (char)Value.STRING;
- String parametersTypes = "*"; //optional string
- return new JrtMethodSignature(returnTypes, parametersTypes);
- }
-
- public void invoke(Request request) {
- try {
- SearchHandler searchHandler = SearcherUtils.getSearchHandler();
- SearchChainRegistry searchChainRegistry = searchHandler.getSearchChainRegistry();
- SearchChain searchChain = getSearchChain(searchChainRegistry,
- getSearchChainName(request));
-
- SearchChainTextRepresentation textRepresentation = new SearchChainTextRepresentation(searchChain, searchChainRegistry);
- request.returnValues().add(new StringValue(textRepresentation.toString()));
- } catch (Exception e) {
- request.setError(1000, Exceptions.toMessageString(e));
- }
- }
-
-
-}
-
diff --git a/container-search/src/main/java/com/yahoo/search/debug/SearchChainTextRepresentation.java b/container-search/src/main/java/com/yahoo/search/debug/SearchChainTextRepresentation.java
deleted file mode 100644
index 2515281ca96..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/SearchChainTextRepresentation.java
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-import com.yahoo.component.chain.Chain;
-import com.yahoo.search.Searcher;
-import com.yahoo.search.searchchain.ForkingSearcher;
-import com.yahoo.search.searchchain.SearchChain;
-import com.yahoo.search.searchchain.SearchChainRegistry;
-
-import java.util.Collection;
-
-/**
- * Text representation of a given search chain intended for debugging purposes.
- *
- * @author tonytv
- */
-public class SearchChainTextRepresentation {
-
- private final SearchChainRegistry searchChainRegistry;
-
- private static class Block {
- private static final String openBlock = " {";
- private static final char closeBlock = '}';
- private final IndentStringBuilder str;
- private final int level;
-
- Block(IndentStringBuilder str) {
- this.str = str;
- level = str.append(openBlock).newlineAndIndent();
- }
-
- void close() {
- str.resetIndentLevel(level);
- str.append(closeBlock).newline();
- }
- }
-
- private final String textRepresentation;
-
- private void outputChain(IndentStringBuilder str, Chain<Searcher> chain) {
- if (chain == null) {
- str.append(" [Unresolved Searchchain]");
- } else {
- str.append(chain.getId()).append(" [Searchchain] ");
- Block block = new Block(str);
-
- for (Searcher searcher : chain.components())
- outputSearcher(str, searcher);
-
- block.close();
- }
- }
-
- private void outputSearcher(IndentStringBuilder str, Searcher searcher) {
- str.append(searcher.getId()).append(" [Searcher]");
- if ( ! (searcher instanceof ForkingSearcher) ) {
- str.newline();
- return;
- }
- Collection<ForkingSearcher.CommentedSearchChain> chains =
- ((ForkingSearcher)searcher).getSearchChainsForwarded(searchChainRegistry);
- if (chains.isEmpty()) {
- str.newline();
- return;
- }
- Block block = new Block(str);
- for (ForkingSearcher.CommentedSearchChain chain : chains) {
- if (chain.comment != null)
- str.append(chain.comment).newline();
- outputChain(str, chain.searchChain);
- }
- block.close();
- }
-
- @Override
- public String toString() {
- return textRepresentation;
- }
-
- public SearchChainTextRepresentation(SearchChain searchChain, SearchChainRegistry searchChainRegistry) {
- this.searchChainRegistry = searchChainRegistry;
-
- IndentStringBuilder stringBuilder = new IndentStringBuilder();
- outputChain(stringBuilder, searchChain);
- textRepresentation = stringBuilder.toString();
- }
-
-}
diff --git a/container-search/src/main/java/com/yahoo/search/debug/SearcherUtils.java b/container-search/src/main/java/com/yahoo/search/debug/SearcherUtils.java
deleted file mode 100644
index d0ac466622b..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/SearcherUtils.java
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-import static com.yahoo.protect.Validator.ensureNotNull;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import com.yahoo.component.provider.ComponentRegistry;
-import org.apache.commons.collections.CollectionUtils;
-
-import com.yahoo.container.Container;
-import com.yahoo.jrt.Request;
-import com.yahoo.prelude.cluster.ClusterSearcher;
-import com.yahoo.search.Searcher;
-import com.yahoo.search.handler.SearchHandler;
-import com.yahoo.search.searchchain.SearchChainRegistry;
-
-/**
- * Utility functions for searchers and search chains.
- *
- * @author tonytv
- */
-final class SearcherUtils {
- private static Collection<Searcher> allSearchers() {
- SearchChainRegistry searchChainRegistry = getSearchHandler().getSearchChainRegistry();
- ComponentRegistry<Searcher> searcherRegistry = searchChainRegistry.getSearcherRegistry();
- return searcherRegistry.allComponents();
- }
-
- private static Collection<ClusterSearcher> allClusterSearchers() {
- return filter(allSearchers(), ClusterSearcher.class);
- }
-
- private static <T> Collection<T> filter(Collection<?> collection, Class<T> classToMatch) {
- List<T> filtered = new ArrayList<>();
- for (Object candidate : collection) {
- if (classToMatch.isInstance(candidate))
- filtered.add(classToMatch.cast(candidate));
- }
- return filtered;
- }
-
- public static Collection<ClusterSearcher> clusterSearchers(final String clusterName) {
- Collection<ClusterSearcher> searchers = allClusterSearchers();
- CollectionUtils.filter(searchers,
- o -> clusterName.equalsIgnoreCase(((ClusterSearcher)o).getClusterModelName()));
- return searchers;
- }
-
- //Return value is never null
- static SearchHandler getSearchHandler() {
- SearchHandler searchHandler = (SearchHandler) Container.get().getRequestHandlerRegistry().getComponent("com.yahoo.search.handler.SearchHandler");
- ensureNotNull("The standard search handler is not available.", searchHandler);
- return searchHandler;
- }
-
- //Retrieve all the cluster searchers as specified by the first parameter of the request.
- static Collection<ClusterSearcher> clusterSearchers(Request request) {
- String clusterName = request.parameters().get(0).asString();
- Collection<ClusterSearcher> searchers = clusterSearchers(clusterName);
- if (searchers.isEmpty())
- throw new RuntimeException("No cluster named " + clusterName);
- return searchers;
- }
-}
diff --git a/container-search/src/main/java/com/yahoo/search/debug/TracePackets.java b/container-search/src/main/java/com/yahoo/search/debug/TracePackets.java
deleted file mode 100644
index b0a7543716d..00000000000
--- a/container-search/src/main/java/com/yahoo/search/debug/TracePackets.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug;
-
-import static com.yahoo.search.debug.SearcherUtils.clusterSearchers;
-
-import java.util.Collection;
-
-import com.yahoo.jrt.Request;
-import com.yahoo.jrt.Value;
-import com.yahoo.prelude.cluster.ClusterSearcher;
-import com.yahoo.fs4.PacketDumper;
-import com.yahoo.yolean.Exceptions;
-
-/**
- * Rpc method for enabling packet dumping for a specific packet type.
- *
- * @author tonytv
- */
-final class TracePackets implements DebugMethodHandler {
- private final PacketDumper.PacketType packetType;
-
- public void invoke(Request request) {
- try {
- Collection<ClusterSearcher> searchers = clusterSearchers(request);
- boolean on = request.parameters().get(1).asInt8() != 0;
-
- for (ClusterSearcher searcher : searchers)
- searcher.dumpPackets(packetType, on);
-
- } catch (Exception e) {
- request.setError(1000, Exceptions.toMessageString(e));
- }
- }
-
- TracePackets(PacketDumper.PacketType packetType) {
- this.packetType = packetType;
- }
-
- public JrtMethodSignature getSignature() {
- String returnTypes = "";
- String parametersTypes = "" + (char)Value.STRING + (char)Value.INT8;
- return new JrtMethodSignature(returnTypes, parametersTypes);
- }
-}
diff --git a/container-search/src/test/java/com/yahoo/search/debug/test/SearchChainTextRepresentationTestCase.java b/container-search/src/test/java/com/yahoo/search/debug/test/SearchChainTextRepresentationTestCase.java
deleted file mode 100644
index faa9fba033b..00000000000
--- a/container-search/src/test/java/com/yahoo/search/debug/test/SearchChainTextRepresentationTestCase.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.debug.test;
-
-import junit.framework.TestCase;
-
-import com.yahoo.search.debug.SearchChainTextRepresentation;
-import com.yahoo.search.searchchain.SearchChainRegistry;
-import com.yahoo.search.searchchain.test.SimpleSearchChain;
-
-/**
- * Test of SearchChainTextRepresentation.
- * @author tonytv
- */
-public class SearchChainTextRepresentationTestCase extends TestCase {
-
- public void testTextRepresentation() {
- SearchChainTextRepresentation textRepresentation =
- new SearchChainTextRepresentation(SimpleSearchChain.orderedChain, new SearchChainRegistry());
-
- String[] expected = {
- "test [Searchchain] {",
- " one [Searcher] {",
- " Reason for forwarding to this search chain.",
- " child-chain [Searchchain] {",
- " child-searcher [Searcher]",
- " }",
- " child-chain [Searchchain] {",
- " child-searcher [Searcher]",
- " }",
- " }",
- " two [Searcher] {",
- " Reason for forwarding to this search chain.",
- " child-chain [Searchchain] {",
- " child-searcher [Searcher]",
- " }",
- " child-chain [Searchchain] {",
- " child-searcher [Searcher]",
- " }",
- " }",
- "}"
- };
-
- String[] result = textRepresentation.toString().split("\n");
- assertEquals(expected.length, result.length);
-
- int i = 0;
- for (String line : textRepresentation.toString().split("\n"))
- assertEquals(expected[i++], line);
- }
-
-}