diff options
author | Harald Musum <musum@yahoo-inc.com> | 2017-06-14 09:36:10 +0200 |
---|---|---|
committer | Harald Musum <musum@yahoo-inc.com> | 2017-06-14 09:36:10 +0200 |
commit | 918c1f833d3aaa1093f20df2a0b066abd56f63bb (patch) | |
tree | 23243bc634249f1000811a7440499e5a09e44370 /config-model/src | |
parent | 0d0e6ca025d9e0e3420fe3852406ff29f38d0a57 (diff) |
Minor cleanup
Reindentation, added a toString(), removed unused methods, style fixes
Diffstat (limited to 'config-model/src')
8 files changed, 53 insertions, 69 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java index bda79ee2356..dd6556f81d2 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java @@ -102,7 +102,7 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon Map<HostResource, List<SERVICE>> affinityMap = new HashMap<>(); for (SERVICE service : services) { if (!affinityMap.containsKey(service.getHostResource())) { - affinityMap.put(service.getHostResource(), new ArrayList<SERVICE>()); + affinityMap.put(service.getHostResource(), new ArrayList<>()); } int cpuSocket = affinityMap.get(service.getHostResource()).size(); affinityMap.get(service.getHostResource()).add(service); @@ -548,4 +548,9 @@ public abstract class AbstractService extends AbstractConfigProducer<AbstractCon public void setAffinity(Affinity affinity) { this.affinity = Optional.ofNullable(affinity); } + + @Override + public String toString() { + return getServiceName() + " on " + getHost().toString(); + } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/HostResource.java b/config-model/src/main/java/com/yahoo/vespa/model/HostResource.java index d54dc912da6..46dc287bb10 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/HostResource.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/HostResource.java @@ -3,13 +3,11 @@ package com.yahoo.vespa.model; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.provision.ClusterMembership; -import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.Flavor; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -30,7 +28,7 @@ import java.util.stream.Collectors; public class HostResource implements Comparable<HostResource> { public final static int BASE_PORT = 19100; - public final static int MAX_PORTS = 799; + final static int MAX_PORTS = 799; private final Host host; // Map from "sentinel name" to service @@ -81,18 +79,6 @@ public class HostResource implements Comparable<HostResource> { 0; } - boolean isPortRangeAvailable(int start, int numPorts) { - int range = 0; - int port = start; - for (; port < BASE_PORT + MAX_PORTS && (range < numPorts); port++) { - if (portDB.containsKey(port)) { - return false; - } - range++; - } - return range == numPorts; - } - /** * Adds service and allocates resources for it. * @@ -179,7 +165,8 @@ public class HostResource implements Comparable<HostResource> { return port >= BASE_PORT && port < BASE_PORT + MAX_PORTS; } - private void portAlreadyReserved(AbstractService service, int port) { + + private void portAlreadyReserved(AbstractService service, int port) { AbstractService otherService = (AbstractService)portDB.get(port); int nextAvailablePort = nextAvailableBaseport(service.getPortCount()); if (nextAvailablePort == 0) { @@ -190,10 +177,9 @@ public class HostResource implements Comparable<HostResource> { : ""; throw new RuntimeException(service.getServiceName() + " cannot reserve port " + port + " on " + this + ": Already reserved for " + otherService.getServiceName() + - ". " + msg + "Next available port is: " + nextAvailablePort); + ". " + msg + "Next available port is: " + nextAvailablePort + " ports used: " + portDB); } - private void noMoreAvailablePorts() { throw new RuntimeException ("Too many ports are reserved in Vespa's port range (" + @@ -201,7 +187,6 @@ public class HostResource implements Comparable<HostResource> { ". Move one or more services to another host, or outside this port range."); } - /** * Returns the service with the given "sentinel name" on this Host, * or null if the name does not match any service. diff --git a/config-model/src/main/java/com/yahoo/vespa/model/PortsMeta.java b/config-model/src/main/java/com/yahoo/vespa/model/PortsMeta.java index a0b3cc7294b..e8f2bf42807 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/PortsMeta.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/PortsMeta.java @@ -20,7 +20,7 @@ public class PortsMeta implements Serializable { private Integer rpcAdminOffset = null; /** Remember the rpc status port offset. */ private Integer rpcStatusOffset = null; - /** Remember the https admin port offset. */ + /** Remember the http admin port offset. */ private Integer httpAdminOffset = null; /** Remember the http status port offset. */ private Integer httpStatusOffset = null; @@ -64,7 +64,7 @@ public class PortsMeta implements Serializable { private PortsMeta register(int offset, String meta) { // Allocate new LinkedLists on each element up-to-and-including offset for (int i = ports.size(); i <= offset; i++) { - ports.add(i, new LinkedList<String>()); + ports.add(i, new LinkedList<>()); } ports.get(offset).addFirst(meta); @@ -88,6 +88,7 @@ public class PortsMeta implements Serializable { public int getNumPorts() { return ports.size(); } + /** * Get an iterator of the Strings registered at the specific point. * @param offset The relative offset to inquire about tags. diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/Configserver.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/Configserver.java index b2c2510ce22..cd06ae67776 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/Configserver.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/Configserver.java @@ -42,16 +42,16 @@ public class Configserver extends AbstractService { * Returns the desired base port for this service. */ public int getWantedPort() { - try { - // TODO: Provide configserver port as argument when creating this service instead - Process process = new ProcessBuilder(getDefaults().underVespaHome("bin/vespa-print-default"), "configserver_rpc_port").start(); - InputStream in = process.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - return Integer.parseInt(reader.readLine().trim()); - } catch (Exception exception) { - log.log(LogLevel.DEBUG, "Error reading port from script, using " + defaultPort); - return defaultPort; - } + try { + // TODO: Provide configserver port as argument when creating this service instead + Process process = new ProcessBuilder(getDefaults().underVespaHome("bin/vespa-print-default"), "configserver_rpc_port").start(); + InputStream in = process.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + return Integer.parseInt(reader.readLine().trim()); + } catch (Exception exception) { + log.log(LogLevel.DEBUG, "Error reading port from script, using " + defaultPort); + return defaultPort; + } } /** diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/Slobrok.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/Slobrok.java index a2b7c7a5532..912809178ee 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/Slobrok.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/Slobrok.java @@ -13,8 +13,8 @@ public class Slobrok extends AbstractService { private static final long serialVersionUID = 1L; /** - * @param parent The parent ConfigProducer. - * @param index unique index for all slobroks + * @param parent The parent ConfigProducer. + * @param index unique index for all slobroks */ public Slobrok(AbstractConfigProducer parent, int index) { super(parent, "slobrok." + index); @@ -42,8 +42,8 @@ public class Slobrok extends AbstractService { public String getStartupCommand() { return "exec $ROOT/bin/slobrok -p " + getPort() + - " -s " + getStatePort() + - " -c " + getConfigId(); + " -s " + getStatePort() + + " -c " + getConfigId(); } /** diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java b/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java index 56fa3d01abc..baf4b8d41e4 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java @@ -48,18 +48,7 @@ public class Container extends AbstractService implements ComponentsConfig.Producer, JdiscBindingsConfig.Producer, ContainerHttpConfig.Producer, - ContainerMbusConfig.Producer -{ - public static final class PortOverride { - public final ComponentSpecification serverId; - public final int port; - - public PortOverride(ComponentSpecification serverId, int port) { - this.serverId = serverId; - this.port = port; - } - } - + ContainerMbusConfig.Producer { public static final int BASEPORT = Defaults.getDefaults().vespaWebServicePort(); public static final String SINGLENODE_CONTAINER_SERVICESPEC = "default_singlenode_container"; @@ -80,15 +69,15 @@ public class Container extends AbstractService implements private final int index; private final ComponentGroup<Handler<?>> handlers = new ComponentGroup<>(this, "handler"); - private final ComponentGroup<Component<?, ?>> components = new ComponentGroup(this, "components"); + private final ComponentGroup<Component<?, ?>> components = new ComponentGroup<>(this, "components"); private final JettyHttpServer defaultHttpServer = new JettyHttpServer(new ComponentId("DefaultHttpServer")); private final List<PortOverride> portOverrides; private final int numHttpServerPorts; - private final int numRpcServerPorts = 2; - private static String defaultHostedJVMArgs = "-XX:+UseOSErrorReporting -XX:+SuppressFatalErrorMessage"; + private static final int numRpcServerPorts = 2; + private static final String defaultHostedJVMArgs = "-XX:+UseOSErrorReporting -XX:+SuppressFatalErrorMessage"; public Container(AbstractConfigProducer parent, String name, int index) { this(parent, name, Collections.<PortOverride>emptyList(), index); @@ -218,7 +207,7 @@ public class Container extends AbstractService implements return (parent instanceof ContainerCluster) && (((ContainerCluster)parent).getDocproc() != null); } - // TODO: hack to retain old service names, e.g. in ymon config, vespa.log etc. + // TODO: hack to retain old service names, e.g. in monitoring config, vespa.log etc. @Override public String getServiceType() { if (parent instanceof ContainerCluster) { @@ -404,4 +393,14 @@ public class Container extends AbstractService implements this.httpServerEnabled = httpServerEnabled; } + public static final class PortOverride { + public final ComponentSpecification serverId; + public final int port; + + public PortOverride(ComponentSpecification serverId, int port) { + this.serverId = serverId; + this.port = port; + } + } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java index dbae6851977..fdb0f08f631 100755 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java @@ -154,7 +154,7 @@ public final class ContainerCluster public static final String ROOT_HANDLER_BINDING = "*://*/"; - private String name; + private final String name; private List<Container> containers = new ArrayList<>(); @@ -243,9 +243,9 @@ public final class ContainerCluster Handler<AbstractConfigProducer<?>> stateHandler = new Handler<>( new ComponentModel(STATE_HANDLER_CLASS, null, null, null)); stateHandler.addServerBindings("http://*" + StateHandler.STATE_API_ROOT, - "https://*" + StateHandler.STATE_API_ROOT, - "http://*" + StateHandler.STATE_API_ROOT + "/*", - "https://*" + StateHandler.STATE_API_ROOT + "/*"); + "https://*" + StateHandler.STATE_API_ROOT, + "http://*" + StateHandler.STATE_API_ROOT + "/*", + "https://*" + StateHandler.STATE_API_ROOT + "/*"); addComponent(stateHandler); } @@ -308,12 +308,6 @@ public final class ContainerCluster } } - public final void addComponents(Collection<Component<?, ?>> components) { - for (Component<?, ?> component : components) { - addComponent(component); - } - } - public final void addSimpleComponent(String idSpec, String classSpec, String bundleSpec) { addComponent(new SimpleComponent(new ComponentModel(idSpec, classSpec, bundleSpec))); } @@ -847,14 +841,14 @@ public final class ContainerCluster } public static class MbusParams { - //the amount of the maxpendingbytes to process concurrently, typically 0.2 (20%) - public final Double maxConcurrentFactor; + // the amount of the maxpendingbytes to process concurrently, typically 0.2 (20%) + final Double maxConcurrentFactor; - //the amount that documents expand temporarily when processing them - public final Double documentExpansionFactor; + // the amount that documents expand temporarily when processing them + final Double documentExpansionFactor; - //the space to reserve for container, docproc stuff (memory that cannot be used for processing documents), in MB - public final Integer containerCoreMemory; + // the space to reserve for container, docproc stuff (memory that cannot be used for processing documents), in MB + final Integer containerCoreMemory; public MbusParams(Double maxConcurrentFactor, Double documentExpansionFactor, Integer containerCoreMemory) { this.maxConcurrentFactor = maxConcurrentFactor; diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/ContainerClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/ContainerClusterTest.java index 859dd15e040..9b0e02d580b 100755 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/ContainerClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/ContainerClusterTest.java @@ -207,7 +207,7 @@ public class ContainerClusterTest { addContainer(cluster, "c2", "host-c2"); assertTrue(false); } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().startsWith("Cluster container1 does not accept container com.yahoo.vespa.model.container.Container")); + assertEquals("Cluster container1 does not accept container qrserver on host 'host-c2'", e.getMessage()); } } |