From 3ba6a9df0d1264486d575e83b404927f3eb177c1 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Sun, 12 Jul 2020 08:32:59 +0200 Subject: Do not hardcode entries and source host in mock * Use hostname of localhost if host not found and equal to localhost instead of hardcoded name for tests --- .../main/java/com/yahoo/vespa/model/HostSystem.java | 21 +++++++++++++-------- .../model/filedistribution/FileDistributor.java | 10 ++++------ 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'config-model') diff --git a/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java b/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java index 3d2918e0ee1..f7a04c36da0 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/HostSystem.java @@ -9,6 +9,7 @@ import com.yahoo.config.provision.ClusterMembership; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostSpec; import com.yahoo.config.provision.ProvisionLogger; +import com.yahoo.net.HostName; import java.net.UnknownHostException; import java.util.LinkedHashMap; @@ -31,7 +32,7 @@ import static java.util.logging.Level.FINE; */ public class HostSystem extends AbstractConfigProducer { - private static Logger log = Logger.getLogger(HostSystem.class.getName()); + private static final Logger log = Logger.getLogger(HostSystem.class.getName()); private final Map hostname2host = new LinkedHashMap<>(); private final HostProvisioner provisioner; @@ -65,15 +66,19 @@ public class HostSystem extends AbstractConfigProducer { * @return the host with the given hostname, or null if no such host */ public HostResource getHostByHostname(String name) { - // TODO: please eliminate the following ugly hack - if ("localhost.fortestingpurposesonly".equals(name)) { - String localhost = "localhost"; - if ( ! getChildren().containsKey(localhost)) { - new Host(this, localhost); + System.out.println("Getting name=" + name + " all hosts: " + hostname2host); + HostResource hostResource = hostname2host.get(name); + if (hostResource == null) { + // Create a new HostResource if this is the host this code is running on (as when running tests) + if (HostName.getLocalhost().equals(name)) { + String localhost = "localhost"; + if (! getChildren().containsKey(localhost)) { + new Host(this, localhost); + } + hostResource = new HostResource(getChildren().get(localhost)); } - return new HostResource(getChildren().get(localhost)); } - return hostname2host.get(name); + return hostResource; } @Override diff --git a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java index 5ccf86f9ba8..fb9402614f6 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributor.java @@ -11,10 +11,10 @@ import com.yahoo.vespa.model.Host; import java.util.*; /** - * Sends RPC requests to hosts (tenant hosts and config servers) to start download of files. This is used during prepare - * of an application. Services themselves will also request files, the work done in this class is done so that hosts can - * start downloading files before services gets new config that needs these files. This also tries to make sure that - * all config servers (not just the one where the application was deployed) have the files available. + * Sends RPC requests to hosts (tenant hosts and config servers) asking them to start download of files. This is used + * during prepare of an application. Services themselves will also request files, the methods in this class are used + * so that hosts can start downloading files before services gets new config that needs these files. It also tries + * to make sure that all config servers (not just the one where the application was deployed) have the files available. * * @author Tony Vaagenes */ @@ -36,7 +36,6 @@ public class FileDistributor { /** * Adds the given file to the associated application packages' registry of file and marks the file * for distribution to the given host. - * Note: This class receives ownership of the given collection. * * @return the reference to the file, created by the application package */ @@ -47,7 +46,6 @@ public class FileDistributor { /** * Adds the given file to the associated application packages' registry of file and marks the file * for distribution to the given host. - * Note: This class receives ownership of the given collection. * * @return the reference to the file, created by the application package */ -- cgit v1.2.3