diff options
Diffstat (limited to 'service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java')
-rw-r--r-- | service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java | 99 |
1 files changed, 63 insertions, 36 deletions
diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java index 89aabbfe2b0..8c74fe0396e 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/InfraApplication.java @@ -1,6 +1,7 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.duper; +import com.yahoo.component.Version; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.model.api.PortInfo; @@ -11,34 +12,34 @@ import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.NodeType; import com.yahoo.config.provision.TenantName; -import com.yahoo.component.Version; +import com.yahoo.vespa.applicationmodel.ApplicationInstanceId; +import com.yahoo.vespa.applicationmodel.ClusterId; import com.yahoo.vespa.applicationmodel.ConfigId; import com.yahoo.vespa.applicationmodel.ServiceType; -import com.yahoo.vespa.service.monitor.InfraApplicationApi; -import com.yahoo.vespa.service.model.ModelGenerator; +import com.yahoo.vespa.applicationmodel.TenantId; import com.yahoo.vespa.service.health.ApplicationHealthMonitor; +import com.yahoo.vespa.service.model.ModelGenerator; +import com.yahoo.vespa.service.monitor.InfraApplicationApi; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; /** * @author freva */ public abstract class InfraApplication implements InfraApplicationApi { - static final int HEALTH_PORT = 8080; - private static final TenantName TENANT_NAME = TenantName.from("hosted-vespa"); - private static final String CONFIG_ID_PREFIX = "configid."; private final ApplicationId applicationId; private final Capacity capacity; - private final ClusterSpec.Type clusterType; - private final ClusterSpec.Id clusterId; + private final ClusterSpec.Type clusterSpecType; + private final ClusterSpec.Id clusterSpecId; private final ServiceType serviceType; + private final int healthPort; public static ApplicationId createHostedVespaApplicationId(String applicationName) { return new ApplicationId.Builder() @@ -49,14 +50,16 @@ public abstract class InfraApplication implements InfraApplicationApi { protected InfraApplication(String applicationName, NodeType nodeType, - ClusterSpec.Type clusterType, - ClusterSpec.Id clusterId, - ServiceType serviceType) { + ClusterSpec.Type clusterSpecType, + ClusterSpec.Id clusterSpecId, + ServiceType serviceType, + int healthPort) { this.applicationId = createHostedVespaApplicationId(applicationName); this.capacity = Capacity.fromRequiredNodeType(nodeType); - this.clusterType = clusterType; - this.clusterId = clusterId; + this.clusterSpecType = clusterSpecType; + this.clusterSpecId = clusterSpecId; this.serviceType = serviceType; + this.healthPort = healthPort; } @Override @@ -71,31 +74,43 @@ public abstract class InfraApplication implements InfraApplicationApi { @Override public ClusterSpec getClusterSpecWithVersion(Version version) { - return ClusterSpec.request(clusterType, clusterId, version, true); + return ClusterSpec.request(clusterSpecType, clusterSpecId, version, true); } - public ClusterSpec.Type getClusterType() { - return clusterType; + public ClusterSpec.Type getClusterSpecType() { + return clusterSpecType; } - public ClusterSpec.Id getClusterId() { - return clusterId; + public ClusterSpec.Id getClusterSpecId() { + return clusterSpecId; } - public ApplicationInfo makeApplicationInfo(List<HostName> hostnames) { - List<HostInfo> hostInfos = new ArrayList<>(); - for (int index = 0; index < hostnames.size(); ++index) { - hostInfos.add(makeHostInfo(hostnames.get(index), HEALTH_PORT, index, serviceType, clusterId)); - } + public ClusterId getClusterId() { + return new ClusterId(clusterSpecId.value()); + } + public ServiceType getServiceType() { + return serviceType; + } + + public ApplicationInstanceId getApplicationInstanceId() { + return new ApplicationInstanceId(applicationId.application().value()); + } + + public TenantId getTenantId() { + return new TenantId(applicationId.tenant().value()); + } + + public ApplicationInfo makeApplicationInfo(List<HostName> hostnames) { + List<HostInfo> hostInfos = hostnames.stream().map(this::makeHostInfo).collect(Collectors.toList()); return new ApplicationInfo(applicationId, 0, new HostsModel(hostInfos)); } - private static HostInfo makeHostInfo(HostName hostname, int port, int configIndex, ServiceType serviceType, ClusterSpec.Id clusterId) { - PortInfo portInfo = new PortInfo(port, ApplicationHealthMonitor.PORT_TAGS_HEALTH); + private HostInfo makeHostInfo(HostName hostname) { + PortInfo portInfo = new PortInfo(healthPort, ApplicationHealthMonitor.PORT_TAGS_HEALTH); Map<String, String> properties = new HashMap<>(); - properties.put(ModelGenerator.CLUSTER_ID_PROPERTY_NAME, clusterId.value()); + properties.put(ModelGenerator.CLUSTER_ID_PROPERTY_NAME, getClusterId().s()); ServiceInfo serviceInfo = new ServiceInfo( // service name == service type for the first service of each type on each host @@ -103,14 +118,24 @@ public abstract class InfraApplication implements InfraApplicationApi { serviceType.s(), Collections.singletonList(portInfo), properties, - configIdFrom(configIndex).s(), + configIdFor(hostname).s(), hostname.value()); return new HostInfo(hostname.value(), Collections.singletonList(serviceInfo)); } - private static ConfigId configIdFrom(int index) { - return new ConfigId(CONFIG_ID_PREFIX + index); + public ConfigId configIdFor(HostName hostname) { + // Not necessarily unique, but service monitor doesn't require it to be unique. + return new ConfigId(String.format("%s/%s", clusterSpecId.value(), prefixTo(hostname.value(), '.'))); + } + + private static String prefixTo(String string, char sentinel) { + int offset = string.indexOf(sentinel); + if (offset == -1) { + return string; + } else { + return string.substring(0, offset); + } } @Override @@ -118,16 +143,17 @@ public abstract class InfraApplication implements InfraApplicationApi { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; InfraApplication that = (InfraApplication) o; - return Objects.equals(applicationId, that.applicationId) && + return healthPort == that.healthPort && + Objects.equals(applicationId, that.applicationId) && Objects.equals(capacity, that.capacity) && - clusterType == that.clusterType && - Objects.equals(clusterId, that.clusterId) && + clusterSpecType == that.clusterSpecType && + Objects.equals(clusterSpecId, that.clusterSpecId) && Objects.equals(serviceType, that.serviceType); } @Override public int hashCode() { - return Objects.hash(applicationId, capacity, clusterType, clusterId, serviceType); + return Objects.hash(applicationId, capacity, clusterSpecType, clusterSpecId, serviceType, healthPort); } @Override @@ -135,9 +161,10 @@ public abstract class InfraApplication implements InfraApplicationApi { return "InfraApplication{" + "applicationId=" + applicationId + ", capacity=" + capacity + - ", clusterType=" + clusterType + - ", clusterId=" + clusterId + + ", clusterSpecType=" + clusterSpecType + + ", clusterSpecId=" + clusterSpecId + ", serviceType=" + serviceType + + ", healthPort=" + healthPort + '}'; } } |