diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2021-07-28 12:19:25 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2021-07-28 12:56:02 +0200 |
commit | d24031c95eb561edcac408e3f6f676a1960cd3ee (patch) | |
tree | 9336abe36e4e6c5f6d9a5a63fa68a0d49646be70 /orchestrator | |
parent | 8a450d4b8d7553c37a6361711b424df01a876637 (diff) |
OrchestrationParams
Diffstat (limited to 'orchestrator')
4 files changed, 280 insertions, 0 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ApplicationParams.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ApplicationParams.java new file mode 100644 index 00000000000..caadadcad21 --- /dev/null +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ApplicationParams.java @@ -0,0 +1,63 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.orchestrator.policy; + +import com.yahoo.vespa.applicationmodel.ClusterId; +import com.yahoo.vespa.applicationmodel.ServiceClusterKey; +import com.yahoo.vespa.applicationmodel.ServiceType; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Per-application parameters controlling the orchestration. + * + * @author hakonhall + */ +public class ApplicationParams { + + private static final ApplicationParams DEFAULT = new ApplicationParams.Builder().build(); + + private final Map<ServiceClusterKey, ClusterParams> clusterParams; + + public static class Builder { + private final Map<ServiceClusterKey, ClusterParams> clusterParams = new HashMap<>(); + + public Builder() {} + + public Builder add(ClusterId clusterId, ServiceType serviceType, ClusterParams clusterParams) { + this.clusterParams.put(new ServiceClusterKey(clusterId, serviceType), clusterParams); + return this; + } + + public ApplicationParams build() { + return new ApplicationParams(clusterParams); + } + } + + public static ApplicationParams getDefault() { + return DEFAULT; + } + + private ApplicationParams(Map<ServiceClusterKey, ClusterParams> clusterParams) { + this.clusterParams = Map.copyOf(clusterParams); + } + + public ClusterParams clusterParamsFor(ClusterId clusterId, ServiceType serviceType) { + var key = new ServiceClusterKey(clusterId, serviceType); + return clusterParams.getOrDefault(key, ClusterParams.getDefault()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ApplicationParams that = (ApplicationParams) o; + return clusterParams.equals(that.clusterParams); + } + + @Override + public int hashCode() { + return Objects.hash(clusterParams); + } +} diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ClusterParams.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ClusterParams.java new file mode 100644 index 00000000000..b6f90ab7302 --- /dev/null +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ClusterParams.java @@ -0,0 +1,61 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.orchestrator.policy; + +import java.util.Objects; +import java.util.OptionalInt; + +/** + * Parameters controlling orchestration of a particular service cluster of an implied application. + * + * @author hakonhall + */ +public class ClusterParams { + + private static final ClusterParams DEFAULT = new ClusterParams.Builder().build(); + + private final int size; + + public static class Builder { + private int size = 0; + + public Builder() {} + + public Builder setSize(int size) { + this.size = size; + return this; + } + + public ClusterParams build() { + return new ClusterParams(size); + } + } + + public static ClusterParams getDefault() { + return DEFAULT; + } + + private ClusterParams(int size) { + this.size = size; + } + + /** + * The expected and ideal number of members of the cluster: Count missing services as down, + * and expected to be added to the application soon. + */ + public OptionalInt size() { + return size > 0 ? OptionalInt.of(size) : OptionalInt.empty(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ClusterParams that = (ClusterParams) o; + return size == that.size; + } + + @Override + public int hashCode() { + return Objects.hash(size); + } +} diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaOrchestration.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaOrchestration.java new file mode 100644 index 00000000000..311bbb5ea8b --- /dev/null +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaOrchestration.java @@ -0,0 +1,103 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.orchestrator.policy; + +import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.vespa.applicationmodel.ClusterId; +import com.yahoo.vespa.applicationmodel.ServiceType; +import com.yahoo.vespa.service.duper.ConfigServerApplication; +import com.yahoo.vespa.service.duper.ConfigServerHostApplication; +import com.yahoo.vespa.service.duper.ControllerApplication; +import com.yahoo.vespa.service.duper.ControllerHostApplication; +import com.yahoo.vespa.service.duper.ProxyApplication; +import com.yahoo.vespa.service.duper.ProxyHostApplication; + +/** + * Creates orchestration parameters for hosted Vespa. + * + * @author hakonhall + */ +public class HostedVespaOrchestration { + public static OrchestrationParams create(ConfigserverConfig configserverConfig) { + // We'll create parameters for both the controller and config server applications, even though + // only one of them is present, as (a) no harm is done by having the extra parameters, and + // (b) it leads to simpler code below. + + return new OrchestrationParams.Builder() + + // Controller host + .addApplicationParams(new ControllerHostApplication().getApplicationId(), + new ApplicationParams + .Builder() + .add(ClusterId.CONTROLLER, + ServiceType.HOST_ADMIN, + new ClusterParams + .Builder() + .setSize(configserverConfig.zookeeperserver().size()) + .build()) + .build()) + + // Controller + .addApplicationParams(new ControllerApplication().getApplicationId(), + new ApplicationParams + .Builder() + .add(ClusterId.CONTROLLER, + ServiceType.CONTROLLER, + new ClusterParams + .Builder() + .setSize(configserverConfig.zookeeperserver().size()) + .build()) + .build()) + + // Config server host + .addApplicationParams(new ConfigServerHostApplication().getApplicationId(), + new ApplicationParams + .Builder() + .add(ClusterId.CONFIG_SERVER_HOST, + ServiceType.HOST_ADMIN, + new ClusterParams + .Builder() + .setSize(configserverConfig.zookeeperserver().size()) + .build()) + .build()) + + // Config server + .addApplicationParams(new ConfigServerApplication().getApplicationId(), + new ApplicationParams + .Builder() + .add(ClusterId.CONFIG_SERVER, + ServiceType.CONFIG_SERVER, + new ClusterParams + .Builder() + .setSize(configserverConfig.zookeeperserver().size()) + .build()) + .build()) + + // Proxy host + .addApplicationParams(new ProxyHostApplication().getApplicationId(), + new ApplicationParams + .Builder() + .add(ClusterId.PROXY_HOST, + ServiceType.HOST_ADMIN, + new ClusterParams + .Builder() + // todo: get the number of proxy nodes + .setSize(0) + .build()) + .build()) + + // Proxy + .addApplicationParams(new ProxyApplication().getApplicationId(), + new ApplicationParams + .Builder() + .add(ClusterId.ROUTING, + ServiceType.CONTAINER, + new ClusterParams + .Builder() + // todo: get the number of proxy nodes + .setSize(0) + .build()) + .build()) + + .build(); + } +} diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/OrchestrationParams.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/OrchestrationParams.java new file mode 100644 index 00000000000..7519564b080 --- /dev/null +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/OrchestrationParams.java @@ -0,0 +1,53 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.orchestrator.policy; + +import com.yahoo.config.provision.ApplicationId; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Parameters controlling orchestration. + * + * @author hakonhall + */ +public class OrchestrationParams { + private final Map<ApplicationId, ApplicationParams> applicationParams; + + public static class Builder { + private final Map<ApplicationId, ApplicationParams> applicationParams = new HashMap<>(); + + public Builder() {} + + public Builder addApplicationParams(ApplicationId applicationId, ApplicationParams params) { + this.applicationParams.put(applicationId, params); + return this; + } + + public OrchestrationParams build() { + return new OrchestrationParams(applicationParams); + } + } + + private OrchestrationParams(Map<ApplicationId, ApplicationParams> applicationParams) { + this.applicationParams = Map.copyOf(applicationParams); + } + + public ApplicationParams getApplicationParams(ApplicationId applicationId) { + return applicationParams.getOrDefault(applicationId, ApplicationParams.getDefault()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + OrchestrationParams that = (OrchestrationParams) o; + return applicationParams.equals(that.applicationParams); + } + + @Override + public int hashCode() { + return Objects.hash(applicationParams); + } +} |