diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-10-14 15:21:24 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-10-14 15:21:24 +0200 |
commit | b6835afcbd43195b363c9e578ad151030ce7f9fe (patch) | |
tree | 7e5893b29a35dc22e73be92fbe2786300d0e0889 | |
parent | cb943c079ba1cd53f9e70e92e9c03343e85ec780 (diff) |
Minor fixes
17 files changed, 76 insertions, 78 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/rpc/RPCCommunicator.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/rpc/RPCCommunicator.java index bad32f87a8c..9089da68e10 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/rpc/RPCCommunicator.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/rpc/RPCCommunicator.java @@ -1,25 +1,35 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** - * @class Communicator - * - * Responsible for doing RPC requests to VDS nodes. - */ - package com.yahoo.vespa.clustercontroller.core.rpc; -import com.yahoo.jrt.*; +import com.yahoo.jrt.DataValue; +import com.yahoo.jrt.Int32Value; +import com.yahoo.jrt.Int8Value; +import com.yahoo.jrt.Request; +import com.yahoo.jrt.Spec; +import com.yahoo.jrt.StringValue; +import com.yahoo.jrt.Supervisor; +import com.yahoo.jrt.Target; +import com.yahoo.jrt.Transport; +import com.yahoo.jrt.Values; import com.yahoo.vdslib.state.NodeState; import com.yahoo.vdslib.state.ClusterState; import com.yahoo.vdslib.state.State; import com.yahoo.log.LogLevel; -import com.yahoo.vespa.clustercontroller.core.*; +import com.yahoo.vespa.clustercontroller.core.ClusterStateBundle; +import com.yahoo.vespa.clustercontroller.core.Communicator; +import com.yahoo.vespa.clustercontroller.core.FleetControllerOptions; +import com.yahoo.vespa.clustercontroller.core.GetNodeStateRequest; +import com.yahoo.vespa.clustercontroller.core.NodeInfo; +import com.yahoo.vespa.clustercontroller.core.SetClusterStateRequest; +import com.yahoo.vespa.clustercontroller.core.Timer; import java.util.logging.Logger; import static com.google.common.base.Preconditions.checkArgument; /** - * This class is not thread-safe. + * Responsible for doing RPC requests to VDS nodes. + This class is not thread-safe. */ public class RPCCommunicator implements Communicator { @@ -43,14 +53,13 @@ public class RPCCommunicator implements Communicator { return new Supervisor(new Transport()); } - public RPCCommunicator( - final Supervisor supervisor, - final Timer t, - final int index, - final int nodeStateRequestTimeoutIntervalMaxMs, - final int nodeStateRequestTimeoutIntervalStartPercentage, - final int nodeStateRequestTimeoutIntervalStopPercentage, - final int nodeStateRequestRoundTripTimeMaxSeconds) { + public RPCCommunicator(Supervisor supervisor, + Timer t, + int index, + int nodeStateRequestTimeoutIntervalMaxMs, + int nodeStateRequestTimeoutIntervalStartPercentage, + int nodeStateRequestTimeoutIntervalStopPercentage, + int nodeStateRequestRoundTripTimeMaxSeconds) { this.timer = t; this.fleetControllerIndex = index; checkArgument(nodeStateRequestTimeoutIntervalMaxMs > 0); @@ -73,14 +82,13 @@ public class RPCCommunicator implements Communicator { public Target getConnection(final NodeInfo node) { Target t = node.getConnection(); if (t == null || !t.isValid()) { - t = node.setConnection( - supervisor.connect(new Spec(node.getRpcAddress()))); + t = node.setConnection(supervisor.connect(new Spec(node.getRpcAddress()))); } return t; } @Override - public void propagateOptions(final FleetControllerOptions options) { + public void propagateOptions(FleetControllerOptions options) { checkArgument(options.nodeStateRequestTimeoutMS > 0); checkArgument(options.nodeStateRequestTimeoutEarliestPercentage >= 0); checkArgument(options.nodeStateRequestTimeoutEarliestPercentage <= 100); @@ -121,15 +129,15 @@ public class RPCCommunicator implements Communicator { @Override public void setSystemState(ClusterStateBundle stateBundle, NodeInfo node, Waiter<SetClusterStateRequest> externalWaiter) { - final RPCSetClusterStateWaiter waiter = new RPCSetClusterStateWaiter(externalWaiter, timer); - final ClusterState baselineState = stateBundle.getBaselineClusterState(); + RPCSetClusterStateWaiter waiter = new RPCSetClusterStateWaiter(externalWaiter, timer); + ClusterState baselineState = stateBundle.getBaselineClusterState(); Target connection = getConnection(node); - if (!connection.isValid()) { + if ( ! connection.isValid()) { log.log(LogLevel.DEBUG, "Connection to " + node.getRpcAddress() + " could not be created."); return; } - final int nodeVersion = node.getVersion(); + int nodeVersion = node.getVersion(); Request req; if (nodeVersion <= 2) { req = new Request(LEGACY_SET_SYSTEM_STATE2_RPC_METHOD_NAME); @@ -155,13 +163,13 @@ public class RPCCommunicator implements Communicator { // protected for testing. protected int generateNodeStateRequestTimeoutMs() { - final double intervalFraction = Math.random(); - final double earliestTimeoutSeconds = + double intervalFraction = Math.random(); + double earliestTimeoutSeconds = nodeStateRequestTimeoutIntervalMaxSeconds * nodeStateRequestTimeoutIntervalStartPercentage / 100.0; - final double latestTimeoutSeconds = + double latestTimeoutSeconds = nodeStateRequestTimeoutIntervalMaxSeconds * nodeStateRequestTimeoutIntervalStopPercentage / 100.0; - final double interval = latestTimeoutSeconds - earliestTimeoutSeconds; - final double timeoutSeconds = earliestTimeoutSeconds + intervalFraction * interval; + double interval = latestTimeoutSeconds - earliestTimeoutSeconds; + double timeoutSeconds = earliestTimeoutSeconds + intervalFraction * interval; return (int) (timeoutSeconds * 1000); } diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/statuspage/StatusPageServer.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/statuspage/StatusPageServer.java index ed4192941b4..52cd0a27933 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/statuspage/StatusPageServer.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/status/statuspage/StatusPageServer.java @@ -143,11 +143,9 @@ public class StatusPageServer implements Runnable, StatusPageServerInterface { if (connection == null) continue; log.log(LogLevel.DEBUG, "Got a status page request."); String requestString = ""; - BufferedReader br = null; OutputStream output = null; - try{ + try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { StringBuilder sb = new StringBuilder(); - br = new BufferedReader(new InputStreamReader(connection.getInputStream())); while (true) { String s = br.readLine(); if (s == null) throw new java.io.IOException("No data in HTTP request on socket " + connection.toString()); @@ -235,17 +233,12 @@ public class StatusPageServer implements Runnable, StatusPageServerInterface { log.log(LogLevel.WARNING, "Caught exception in HTTP server thread: " + e.getClass().getName() + ": " + e.getMessage()); } finally { - if (output != null) try{ + if (output != null) try { output.close(); } catch (IOException e) { log.log(e.getMessage().indexOf("Broken pipe") >= 0 ? LogLevel.DEBUG : LogLevel.INFO, "Failed to close output stream on socket " + connection + ": " + e.getMessage()); } - if (br != null) try { - br.close(); - } catch (IOException e) { - log.log(LogLevel.INFO, "Failed to close input stream on socket " + connection + ": " + e.getMessage()); - } if (connection != null) try{ connection.close(); } catch (IOException e) { diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java index d3cab74c66f..c38f7aec8c6 100644 --- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java +++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandler.java @@ -34,6 +34,7 @@ import java.util.logging.Level; import java.util.logging.Logger; public class RestApiHandler implements HttpRequestHandler { + public static final Duration MAX_TIMEOUT = Duration.ofHours(1); private final static Logger log = Logger.getLogger(RestApiHandler.class.getName()); @@ -56,8 +57,7 @@ public class RestApiHandler implements HttpRequestHandler { private static void logRequestException(HttpRequest request, Exception exception, Level level) { String exceptionString = Exceptions.toMessageString(exception); - log.log(level, "Failed to process request with URI path " + - request.getPath() + ": " + exceptionString); + log.log(level, "Failed to process request with URI path " + request.getPath() + ": " + exceptionString); } @Override diff --git a/configgen/src/main/java/com/yahoo/config/codegen/CppClassBuilder.java b/configgen/src/main/java/com/yahoo/config/codegen/CppClassBuilder.java index f891d0c0a0a..44180b3f863 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/CppClassBuilder.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/CppClassBuilder.java @@ -72,13 +72,14 @@ public class CppClassBuilder implements ClassBuilder { String readFile(File f) throws IOException { if (!f.isFile()) return null; StringBuilder sb = new StringBuilder(); - BufferedReader sr = new BufferedReader(new FileReader(f)); - while (true) { - String line = sr.readLine(); - if (line == null) break; - sb.append(line).append("\n"); + try (BufferedReader sr = new BufferedReader(new FileReader(f))) { + while (true) { + String line = sr.readLine(); + if (line == null) break; + sb.append(line).append("\n"); + } + return sb.toString(); } - return sb.toString(); } void writeFile(File f, String content) throws IOException { diff --git a/configgen/src/main/java/com/yahoo/config/codegen/NormalizedDefinition.java b/configgen/src/main/java/com/yahoo/config/codegen/NormalizedDefinition.java index 849b4f34914..3250fc69ae8 100644 --- a/configgen/src/main/java/com/yahoo/config/codegen/NormalizedDefinition.java +++ b/configgen/src/main/java/com/yahoo/config/codegen/NormalizedDefinition.java @@ -19,7 +19,8 @@ import java.nio.charset.Charset; * @author hmusum */ public class NormalizedDefinition { - /* Patterns used for finding ranges in config definitions */ + + // Patterns used for finding ranges in config definitions private static final Pattern intPattern = Pattern.compile(".*int.*range.*"); private static final Pattern doublePattern = Pattern.compile(".*double.*range.*"); private MessageDigest md5; diff --git a/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java b/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java index 8bb072b5a64..1f56523bce6 100644 --- a/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java +++ b/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java @@ -226,7 +226,7 @@ public class LogFileHandler extends StreamHandler { } // Throw InterruptedException upwards rather than relying on isInterrupted to stop the thread as - // isInterrupted() returns false after inerruption in p.waitFor + // isInterrupted() returns false after interruption in p.waitFor private void internalRotateNow() throws InterruptedException { // figure out new file name, then // use super.setOutputStream to switch to a new file @@ -295,7 +295,7 @@ public class LogFileHandler extends StreamHandler { } /** Name files by date - create a symlink with a constant name to the newest file */ - private void createSymlinkToCurrentFile() throws InterruptedException { + private void createSymlinkToCurrentFile() { if (symlinkName == null) return; File f = new File(fileName); File f2 = new File(f.getParent(), symlinkName); diff --git a/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFormatter.java b/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFormatter.java index 0cedfc0f693..adb4583d405 100644 --- a/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFormatter.java +++ b/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFormatter.java @@ -101,7 +101,7 @@ public class LogFormatter extends Formatter { * <li>%% % * </ul> */ - public static final String insertDate (String pattern, long time) { + public static String insertDate(String pattern, long time) { DateFormat df = new SimpleDateFormat("yyyy.MM.dd:HH:mm:ss.SSS Z"); df.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = new Date(time); diff --git a/fsa/src/main/java/com/yahoo/fsa/FSA.java b/fsa/src/main/java/com/yahoo/fsa/FSA.java index a4ec93286c4..a0ca7ebee36 100644 --- a/fsa/src/main/java/com/yahoo/fsa/FSA.java +++ b/fsa/src/main/java/com/yahoo/fsa/FSA.java @@ -17,7 +17,7 @@ import java.util.NoSuchElementException; /** * Finite-State Automaton. * - * @author <a href="mailto:boros@yahoo-inc.com">Peter Boros</a> + * @author Peter Boros */ public class FSA { @@ -158,6 +158,7 @@ public class FSA { * Class used to iterate over all accepted strings in the fsa. */ public static class Iterator implements java.util.Iterator<Iterator.Item> { + /** * Internally, this class stores the state information for the iterator. * Externally, it is used for accessing the data associated with the iterator position. @@ -171,6 +172,7 @@ public class FSA { /** * Constructor + * * @param fsa the FSA object the iterator is associated with. * @param state the state used as start state. */ @@ -216,6 +218,7 @@ public class FSA { return fsa.dataString(state); } + @Override public String toString() { return "string: " + string + "(" + getString() + "), symbol: " + symbol + ", state: " + state; } @@ -382,25 +385,19 @@ public class FSA { private void init(FileInputStream file, String charsetname) { try { _charset = Charset.forName(charsetname); - _header = file.getChannel().map(MapMode.READ_ONLY,0,256); _header.order(ByteOrder.LITTLE_ENDIAN); if (h_magic()!=2038637673) { throw new IOException("Stream does not contain an FSA: Wrong file magic number " + h_magic()); } - _symbol_tab = file.getChannel().map(MapMode.READ_ONLY, - 256,h_size()); + _symbol_tab = file.getChannel().map(MapMode.READ_ONLY, 256, h_size()); _symbol_tab.order(ByteOrder.LITTLE_ENDIAN); - _state_tab = file.getChannel().map(MapMode.READ_ONLY, - 256+h_size(),4*h_size()); + _state_tab = file.getChannel().map(MapMode.READ_ONLY, 256+h_size(), 4*h_size()); _state_tab.order(ByteOrder.LITTLE_ENDIAN); - _data = file.getChannel().map(MapMode.READ_ONLY, - 256+5*h_size(),h_data_size()); + _data = file.getChannel().map(MapMode.READ_ONLY, 256+5*h_size(), h_data_size()); _data.order(ByteOrder.LITTLE_ENDIAN); if(h_has_phash()>0){ - _phash = file.getChannel().map(MapMode.READ_ONLY, - 256+5*h_size()+h_data_size(), - 4*h_size()); + _phash = file.getChannel().map(MapMode.READ_ONLY, 256+5*h_size()+h_data_size(), 4*h_size()); _phash.order(ByteOrder.LITTLE_ENDIAN); } _ok=true; diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ApplicationLoader.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ApplicationLoader.java index 68be5bb5d94..f28731a47c7 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ApplicationLoader.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ApplicationLoader.java @@ -101,7 +101,7 @@ public class ApplicationLoader implements BootstrapLoader, ContainerActivator, C return; // application class bound by another module } try { - final Class<Application> appClass = ContainerBuilder.safeClassCast(Application.class, Class.forName(appLocation)); + Class<Application> appClass = ContainerBuilder.safeClassCast(Application.class, Class.forName(appLocation)); guiceModules.install(new AbstractModule() { @Override public void configure() { diff --git a/jrt/src/com/yahoo/jrt/XorCryptoSocket.java b/jrt/src/com/yahoo/jrt/XorCryptoSocket.java index 90be58bb700..fa784f62b12 100644 --- a/jrt/src/com/yahoo/jrt/XorCryptoSocket.java +++ b/jrt/src/com/yahoo/jrt/XorCryptoSocket.java @@ -1,20 +1,21 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jrt; - import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; +import java.security.SecureRandom; import java.util.ArrayDeque; import java.util.Queue; import java.util.Random; - /** * A very simple CryptoSocket that performs connection handshaking and * data transformation. Used to test encryption integration separate * from TLS. - **/ + * + * @author havardpe + */ public class XorCryptoSocket implements CryptoSocket { private static final int CHUNK_SIZE = 4096; @@ -28,7 +29,7 @@ public class XorCryptoSocket implements CryptoSocket { private SocketChannel channel; private static byte genKey() { - return (byte) new Random().nextInt(256); + return (byte) new SecureRandom().nextInt(256); } private HandshakeResult readKey() throws IOException { diff --git a/libmlr/src/main/java/com/yahoo/yst/libmlr/converter/DecisionTreeXmlToCpp.java b/libmlr/src/main/java/com/yahoo/yst/libmlr/converter/DecisionTreeXmlToCpp.java index 98eef506194..fce71fe27a6 100644 --- a/libmlr/src/main/java/com/yahoo/yst/libmlr/converter/DecisionTreeXmlToCpp.java +++ b/libmlr/src/main/java/com/yahoo/yst/libmlr/converter/DecisionTreeXmlToCpp.java @@ -31,7 +31,6 @@ import com.yahoo.yst.libmlr.converter.parser.MlrXmlParser; * This class generates C++ from an MLR Decision Tree File * * @author allenwei - * */ public class DecisionTreeXmlToCpp { diff --git a/logserver/src/main/java/com/yahoo/logserver/AbstractPluginLoader.java b/logserver/src/main/java/com/yahoo/logserver/AbstractPluginLoader.java index db2ed6b0b83..f2393edeff3 100644 --- a/logserver/src/main/java/com/yahoo/logserver/AbstractPluginLoader.java +++ b/logserver/src/main/java/com/yahoo/logserver/AbstractPluginLoader.java @@ -14,6 +14,7 @@ import java.util.logging.Logger; * @author Stig Bakken */ public abstract class AbstractPluginLoader implements PluginLoader { + private static final Logger log = Logger.getLogger(AbstractPluginLoader.class.getName()); public abstract void loadPlugins(); diff --git a/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java b/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java index 5c6569d9b9b..22453528777 100644 --- a/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java +++ b/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java @@ -14,6 +14,7 @@ import com.yahoo.logserver.handlers.replicator.ReplicatorPlugin; * @author Stig Bakken */ public class BuiltinPluginLoader extends AbstractPluginLoader { + private static final Logger log = Logger.getLogger(BuiltinPluginLoader.class.getName()); public void loadPlugins() { diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java index a62e5c525b1..f1e1665a7d1 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java @@ -231,9 +231,7 @@ public class ArchiverHandler extends AbstractLogHandler { private void setRootDir(String rootDir) { // roundabout way of setting things, but this way we can - // get around Java's ineptitude for file handling. (relative - // paths in File are broken) - // + // get around Java's ineptitude for file handling (relative paths in File are broken) absoluteRootDir = new File(rootDir).getAbsolutePath(); root = new File(absoluteRootDir); @@ -242,8 +240,7 @@ public class ArchiverHandler extends AbstractLogHandler { log.log(LogLevel.DEBUG, "Using " + absoluteRootDir + " as root"); } else { if (! root.mkdirs()) { - log.log(LogLevel.ERROR, - "Unable to create directory " + absoluteRootDir); + log.log(LogLevel.ERROR, "Unable to create directory " + absoluteRootDir); } else { log.log(LogLevel.DEBUG, "Created root at " + absoluteRootDir); } diff --git a/messagebus/src/main/java/com/yahoo/messagebus/network/rpc/RPCService.java b/messagebus/src/main/java/com/yahoo/messagebus/network/rpc/RPCService.java index 58fcfe88465..e3989a22c66 100644 --- a/messagebus/src/main/java/com/yahoo/messagebus/network/rpc/RPCService.java +++ b/messagebus/src/main/java/com/yahoo/messagebus/network/rpc/RPCService.java @@ -10,7 +10,7 @@ import java.util.Random; * An RPCService represents a set of remote sessions matching a service pattern. The sessions are monitored using the * slobrok. If multiple sessions are available, round robin is used to balance load between them. * - * @author <a href="mailto:havardpe@yahoo-inc.com">Haavard Pettersen</a> + * @author havardpe */ public class RPCService { diff --git a/metrics/src/main/java/com/yahoo/metrics/Metric.java b/metrics/src/main/java/com/yahoo/metrics/Metric.java index ff86662247a..f1f389a4dfe 100644 --- a/metrics/src/main/java/com/yahoo/metrics/Metric.java +++ b/metrics/src/main/java/com/yahoo/metrics/Metric.java @@ -8,8 +8,8 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.List; -public abstract class Metric -{ +public abstract class Metric { + private String name; private String tags; private String description; @@ -146,7 +146,7 @@ public abstract class Metric writer.openTag(getXMLTag()); - if (getXMLTag() != getName()) { + if ( ! getXMLTag().equals(getName())) { writer.attribute(TAG_NAME, getName()); } diff --git a/statistics/src/main/java/com/yahoo/statistics/Value.java b/statistics/src/main/java/com/yahoo/statistics/Value.java index d60bad36d47..b1e08300d69 100644 --- a/statistics/src/main/java/com/yahoo/statistics/Value.java +++ b/statistics/src/main/java/com/yahoo/statistics/Value.java @@ -361,8 +361,7 @@ public class Value extends Handle { throw new IllegalStateException("The Limits instance must be frozen."); } if (parameters.histogramId != HistogramType.REGULAR) { - log.log(LogLevel.WARNING, HISTOGRAM_TYPE_WARNING - + " '" + name + "'"); + log.log(LogLevel.WARNING, HISTOGRAM_TYPE_WARNING + " '" + name + "'"); } this.histogramId = HistogramType.REGULAR; this.histogram = parameters.limits; |