summaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java
diff options
context:
space:
mode:
Diffstat (limited to 'configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java34
1 files changed, 22 insertions, 12 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java
index ec37f2598e0..d45764295dd 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/host/HostRegistry.java
@@ -1,12 +1,18 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.host;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import com.google.common.collect.Collections2;
+import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.config.provision.TenantName;
+
import java.util.logging.Level;
/**
@@ -15,20 +21,20 @@ import java.util.logging.Level;
*
* @author Ulf Lilleengen
*/
-public class HostRegistry<T> implements HostValidator<T> {
+public class HostRegistry implements HostValidator<ApplicationId> {
private static final Logger log = Logger.getLogger(HostRegistry.class.getName());
- private final Map<String, T> host2KeyMap = new ConcurrentHashMap<>();
+ private final Map<String, ApplicationId> host2KeyMap = new ConcurrentHashMap<>();
- public T getKeyForHost(String hostName) {
+ public ApplicationId getKeyForHost(String hostName) {
return host2KeyMap.get(hostName);
}
- public synchronized void update(T key, Collection<String> newHosts) {
+ public synchronized void update(ApplicationId key, Collection<String> newHosts) {
verifyHosts(key, newHosts);
Collection<String> currentHosts = getHostsForKey(key);
- log.log(Level.FINE, () -> "Setting hosts for key '" + key + "', " +
+ log.log(Level.INFO, () -> "Setting hosts for key '" + key + "', " +
"newHosts: " + newHosts + ", " +
"currentHosts: " + currentHosts);
Collection<String> removedHosts = getRemovedHosts(newHosts, currentHosts);
@@ -37,7 +43,7 @@ public class HostRegistry<T> implements HostValidator<T> {
}
@Override
- public synchronized void verifyHosts(T key, Collection<String> newHosts) {
+ public synchronized void verifyHosts(ApplicationId key, Collection<String> newHosts) {
for (String host : newHosts) {
if (hostAlreadyTaken(host, key)) {
throw new IllegalArgumentException("'" + key + "' tried to allocate host '" + host +
@@ -46,22 +52,26 @@ public class HostRegistry<T> implements HostValidator<T> {
}
}
- public synchronized void removeHostsForKey(T key) {
+ public synchronized void removeHostsForKey(ApplicationId key) {
host2KeyMap.entrySet().removeIf(entry -> entry.getValue().equals(key));
}
+ public synchronized void removeHostsForKey(TenantName key) {
+ host2KeyMap.entrySet().removeIf(entry -> entry.getValue().tenant().equals(key));
+ }
+
public synchronized Collection<String> getAllHosts() {
return Collections.unmodifiableCollection(new ArrayList<>(host2KeyMap.keySet()));
}
- synchronized Collection<String> getHostsForKey(T key) {
+ public synchronized Collection<String> getHostsForKey(ApplicationId key) {
return host2KeyMap.entrySet().stream()
.filter(entry -> entry.getValue().equals(key))
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}
- private boolean hostAlreadyTaken(String host, T key) {
+ private boolean hostAlreadyTaken(String host, ApplicationId key) {
return host2KeyMap.containsKey(host) && !key.equals(host2KeyMap.get(host));
}
@@ -76,7 +86,7 @@ public class HostRegistry<T> implements HostValidator<T> {
}
}
- private void addHosts(T key, Collection<String> newHosts) {
+ private void addHosts(ApplicationId key, Collection<String> newHosts) {
for (String host : newHosts) {
log.log(Level.FINE, () -> "Adding " + host);
host2KeyMap.put(host, key);