diff options
8 files changed, 62 insertions, 50 deletions
diff --git a/config/src/main/java/com/yahoo/config/subscription/ConfigInstanceUtil.java b/config/src/main/java/com/yahoo/config/subscription/ConfigInstanceUtil.java index 9710ee607eb..82d02ec89f9 100644 --- a/config/src/main/java/com/yahoo/config/subscription/ConfigInstanceUtil.java +++ b/config/src/main/java/com/yahoo/config/subscription/ConfigInstanceUtil.java @@ -22,9 +22,9 @@ public class ConfigInstanceUtil { * Values that have not been explicitly set in the source builder, will be left unchanged * in the destination. * - * @param destination The builder to copy values into. - * @param source The builder to copy values from. Unset values are not copied. - * @param <BUILDER> The builder class. + * @param destination the builder to copy values into + * @param source the builder to copy values from. Unset values are not copied + * @param <BUILDER> the builder class */ public static<BUILDER extends ConfigBuilder> void setValues(BUILDER destination, BUILDER source) { try { @@ -56,9 +56,9 @@ public class ConfigInstanceUtil { setConfigId(i, configId); } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | - NoSuchFieldException | IllegalAccessException e) { + NoSuchFieldException | IllegalAccessException e) { throw new IllegalArgumentException("Failed creating new instance of '" + type.getCanonicalName() + - "' for config id '" + configId + "': " + Exceptions.toMessageString(e), e); + "' for config id '" + configId + "'", e); } return instance; } diff --git a/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java b/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java index 814222989a1..dbe27e2933c 100644 --- a/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java +++ b/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java @@ -423,21 +423,26 @@ public class ConfigSubscriber implements AutoCloseable { * @return The handle of the config * @see #startConfigThread(Runnable) */ - public <T extends ConfigInstance> ConfigHandle<T> subscribe(final SingleSubscriber<T> singleSubscriber, Class<T> configClass, String configId) { - if (!subscriptionHandles.isEmpty()) - throw new IllegalStateException("Can not start single-subscription because subscriptions were previously opened on this."); - final ConfigHandle<T> handle = subscribe(configClass, configId); - if (!nextConfig()) - throw new ConfigurationRuntimeException("Initial config of " + configClass.getName() + " failed."); + public <T extends ConfigInstance> ConfigHandle<T> subscribe(SingleSubscriber<T> singleSubscriber, Class<T> configClass, String configId) { + if ( ! subscriptionHandles.isEmpty()) + throw new IllegalStateException("Can not start single-subscription because subscriptions were previously opened on this"); + + ConfigHandle<T> handle = subscribe(configClass, configId); + + if ( ! nextConfig()) + throw new ConfigurationRuntimeException("Initial config of " + configClass.getName() + " failed"); + singleSubscriber.configure(handle.getConfig()); startConfigThread(() -> { while (!isClosed()) { try { - if (nextConfig()) { - if (handle.isChanged()) singleSubscriber.configure(handle.getConfig()); - } - } catch (Exception e) { - log.log(SEVERE, "Exception from config system, continuing config thread: " + Exceptions.toMessageString(e)); + if (nextConfig() && handle.isChanged()) + singleSubscriber.configure(handle.getConfig()); + } + catch (Exception e) { + log.log(WARNING, "Exception on applying config " + configClass.getName() + + " for config id " + configId + ": Ignoring this change: " + + Exceptions.toMessageString(e)); } } } diff --git a/container-core/src/main/java/com/yahoo/container/handler/ClustersStatus.java b/container-core/src/main/java/com/yahoo/container/handler/ClustersStatus.java index 0ed0daa2141..f939f9e8025 100644 --- a/container-core/src/main/java/com/yahoo/container/handler/ClustersStatus.java +++ b/container-core/src/main/java/com/yahoo/container/handler/ClustersStatus.java @@ -4,8 +4,11 @@ package com.yahoo.container.handler; import com.google.inject.Inject; import com.yahoo.component.AbstractComponent; +import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Set; /** * A component which tracks the up/down status of any clusters which should influence @@ -37,11 +40,15 @@ public class ClustersStatus extends AbstractComponent { /** The status of clusters, when known. Note that clusters may exist for which there is no knowledge yet. */ private final Map<String, Boolean> clusterStatus = new HashMap<>(); - public void setContainerHasClusters(boolean containerHasClusters) { + /** Sets the current clusters of this container */ + public void setClusters(Set<String> clusters) { synchronized (mutex) { - this.containerHasClusters = containerHasClusters; - if ( ! containerHasClusters) - clusterStatus.clear(); // forget container clusters which was configured away + this.containerHasClusters = clusters.size() > 0; + for (Iterator<String> i = clusterStatus.keySet().iterator(); i.hasNext(); ) { + String existingCluster = i.next(); + if ( ! clusters.contains(existingCluster)) + i.remove(); // forget clusters which was configured away + } } } @@ -78,9 +85,11 @@ public class ClustersStatus extends AbstractComponent { public boolean containerShouldReceiveTraffic() { return containerShouldReceiveTraffic(Require.ONE); } + /** * Returns whether this container should receive traffic based on the state of this - * @param require Requirement for being up, ALL or ONE. + * + * @param require requirement for being up, ALL or ONE. */ public boolean containerShouldReceiveTraffic(Require require) { synchronized (mutex) { diff --git a/container-core/src/main/java/com/yahoo/container/handler/VipStatus.java b/container-core/src/main/java/com/yahoo/container/handler/VipStatus.java index 0bf86e8f440..e1b5b769906 100644 --- a/container-core/src/main/java/com/yahoo/container/handler/VipStatus.java +++ b/container-core/src/main/java/com/yahoo/container/handler/VipStatus.java @@ -6,6 +6,8 @@ import com.yahoo.container.QrSearchersConfig; import com.yahoo.container.core.VipStatusConfig; import com.yahoo.container.jdisc.state.StateMonitor; +import java.util.stream.Collectors; + /** * A component which keeps track of whether or not this container instance should receive traffic * and respond that it is in good health. @@ -59,8 +61,7 @@ public class VipStatus { this.clustersStatus = clustersStatus; this.healthState = healthState; initiallyInRotation = vipStatusConfig.initiallyInRotation(); - healthState.status(StateMonitor.Status.initializing); - clustersStatus.setContainerHasClusters(! dispatchers.searchcluster().isEmpty()); + clustersStatus.setClusters(dispatchers.searchcluster().stream().map(c -> c.name()).collect(Collectors.toSet())); updateCurrentlyInRotation(); } diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java index 78b65622150..0018dd22dd9 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java @@ -47,11 +47,13 @@ public class StateMonitor extends AbstractComponent { @Inject public StateMonitor(HealthMonitorConfig config, Timer timer) { - this(config, timer, runnable -> { - Thread thread = new Thread(runnable, "StateMonitor"); - thread.setDaemon(true); - return thread; - }); + this(config, + timer, + runnable -> { + Thread thread = new Thread(runnable, "StateMonitor"); + thread.setDaemon(true); + return thread; + }); } StateMonitor(HealthMonitorConfig config, Timer timer, ThreadFactory threadFactory) { @@ -59,7 +61,8 @@ public class StateMonitor extends AbstractComponent { Status.valueOf(config.initialStatus()), timer, threadFactory); } - /* For Testing */ + + /* Public for testing only */ public StateMonitor(long snapshotIntervalMS, Status status, Timer timer, ThreadFactory threadFactory) { this.timer = timer; this.snapshotIntervalMs = snapshotIntervalMS; diff --git a/container-di/src/main/java/com/yahoo/container/di/CloudSubscriberFactory.java b/container-di/src/main/java/com/yahoo/container/di/CloudSubscriberFactory.java index bd3d146cfec..1133363be8e 100644 --- a/container-di/src/main/java/com/yahoo/container/di/CloudSubscriberFactory.java +++ b/container-di/src/main/java/com/yahoo/container/di/CloudSubscriberFactory.java @@ -103,29 +103,27 @@ public class CloudSubscriberFactory implements SubscriberFactory { @Override public long waitNextGeneration() { - if (handles.isEmpty()) { + if (handles.isEmpty()) throw new IllegalStateException("No config keys registered"); - } - /* Catch and just log config exceptions due to missing config values for parameters that do - * not have a default value. These exceptions occur when the user has removed a component - * from services.xml, and the component takes a config that has parameters without a - * default value in the def-file. There is a new 'components' config underway, where the - * component is removed, so this old config generation will soon be replaced by a new one. */ + // Catch and just log config exceptions due to missing config values for parameters that do + // not have a default value. These exceptions occur when the user has removed a component + // from services.xml, and the component takes a config that has parameters without a + // default value in the def-file. There is a new 'components' config underway, where the + // component is removed, so this old config generation will soon be replaced by a new one. boolean gotNextGen = false; int numExceptions = 0; while ( ! gotNextGen) { try { - if (subscriber.nextGeneration()) { + if (subscriber.nextGeneration()) gotNextGen = true; - } - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) { numExceptions++; - log.log(Level.WARNING, "Got exception from the config system (please ignore the exception if you just removed " - + "a component from your application that used the mentioned config): ", e); - if (numExceptions >= 5) { - throw new IllegalArgumentException("Failed retrieving the next config generation.", e); - } + log.log(Level.WARNING, "Got exception from the config system (ignore if you just removed a " + + "component from your application that used the mentioned config): ", e); + if (numExceptions >= 5) + throw new IllegalArgumentException("Failed retrieving the next config generation", e); } } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java index df8a7e45917..e8639561599 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java @@ -260,7 +260,6 @@ class NodeAllocation { node = node.unretire(); } else { ++wasRetiredJustNow; - // Retire nodes which are of an unwanted flavor, retired flavor or have an overlapping parent host node = node.retire(nodeRepository.clock().instant()); } if ( ! node.allocation().get().membership().cluster().equals(cluster)) { diff --git a/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java b/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java index 52708ea6d8e..c9acd625373 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java @@ -97,11 +97,8 @@ public class Distribution { parent.addSubGroup(group); } } - if (root == null) { - throw new IllegalStateException("Got config that did not " - + "specify even a root group. Need a root group at" - + "\nminimum:\n" + config.toString()); - } + if (root == null) + throw new IllegalStateException("Config does not specify a root group"); root.calculateDistributionHashValues(); Distribution.this.config.setRelease(new Config(root, config.redundancy(), config.distributor_auto_ownership_transfer_on_whole_group_down())); } catch (ParseException e) { |