aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java
blob: 4502cc7e223806647796a092fbfa1ea58e019b08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.deploy;

import com.yahoo.component.Version;
import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.config.application.api.FileRegistry;
import com.yahoo.config.model.api.ConfigDefinitionRepo;
import com.yahoo.config.model.api.ConfigServerSpec;
import com.yahoo.config.model.api.HostProvisioner;
import com.yahoo.config.model.api.Model;
import com.yahoo.config.model.api.ModelContext;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.Rotation;
import com.yahoo.config.provision.Zone;

import java.io.File;
import java.util.List;
import java.util.Optional;
import java.util.Set;

/**
 * Implementation of {@link ModelContext} for configserver.
 *
 * @author Ulf Lilleengen
 */
public class ModelContextImpl implements ModelContext {

    private final ApplicationPackage applicationPackage;
    private final Optional<Model> previousModel;
    private final Optional<ApplicationPackage> permanentApplicationPackage;
    private final DeployLogger deployLogger;
    private final ConfigDefinitionRepo configDefinitionRepo;
    private final FileRegistry fileRegistry;
    private final Optional<HostProvisioner> hostProvisioner;
    private final ModelContext.Properties properties;
    private final Optional<File> appDir;
    
    /** The version of Vespa we are building a model for */
    private final Version modelVespaVersion;

    /**
     * The Version of Vespa this model should specify that nodes should use. Note that this
     * is separate from the version of this model, as upgrades are not immediate.
     * We may build a config model of Vespa version "a" which specifies that nodes should
     * use Vespa version "b". The "a" model will then be used by nodes who have not yet
     * upgraded to version "b".
     */
    private final Version wantedNodeVespaVersion;

    public ModelContextImpl(ApplicationPackage applicationPackage,
                            Optional<Model> previousModel,
                            Optional<ApplicationPackage> permanentApplicationPackage,
                            DeployLogger deployLogger,
                            ConfigDefinitionRepo configDefinitionRepo,
                            FileRegistry fileRegistry,
                            Optional<HostProvisioner> hostProvisioner,
                            ModelContext.Properties properties,
                            Optional<File> appDir,
                            Version modelVespaVersion,
                            Version wantedNodeVespaVersion) {
        this.applicationPackage = applicationPackage;
        this.previousModel = previousModel;
        this.permanentApplicationPackage = permanentApplicationPackage;
        this.deployLogger = deployLogger;
        this.configDefinitionRepo = configDefinitionRepo;
        this.fileRegistry = fileRegistry;
        this.hostProvisioner = hostProvisioner;
        this.properties = properties;
        this.appDir = appDir;
        this.modelVespaVersion = modelVespaVersion;
        this.wantedNodeVespaVersion = wantedNodeVespaVersion;
    }

    @Override
    public ApplicationPackage applicationPackage() {
        return applicationPackage;
    }

    @Override
    public Optional<Model> previousModel() {
        return previousModel;
    }

    @Override
    public Optional<ApplicationPackage> permanentApplicationPackage() {
        return permanentApplicationPackage;
    }

    /** 
     * Returns the host provisioner to use, or empty to use the default provisioner, 
     * creating hosts from the application package defined hosts 
     */
    // TODO: Don't allow empty here but create the right provisioner when this is set up instead
    @Override
    public Optional<HostProvisioner> hostProvisioner() {
        return hostProvisioner;
    }

    @Override
    public DeployLogger deployLogger() {
        return deployLogger;
    }

    @Override
    public ConfigDefinitionRepo configDefinitionRepo() {
        return configDefinitionRepo;
    }

    @Override
    public FileRegistry getFileRegistry() {
        return fileRegistry;
    }

    @Override
    public ModelContext.Properties properties() {
        return properties;
    }

    @Override
    public Optional<File> appDir() {
        return appDir;
    }

    @Override
    public Version modelVespaVersion() { return modelVespaVersion; }

    @Override
    public Version wantedNodeVespaVersion() { return wantedNodeVespaVersion; }

    /**
     * @author Ulf Lilleengen
     */
    public static class Properties implements ModelContext.Properties {

        private final ApplicationId applicationId;
        private final boolean multitenant;
        private final List<ConfigServerSpec> configServerSpecs;
        private final HostName loadBalancerName;
        private final boolean hostedVespa;
        private final Zone zone;
        private final Set<Rotation> rotations;
        private final boolean disableFileDistributor;

        public Properties(ApplicationId applicationId,
                          boolean multitenant,
                          List<ConfigServerSpec> configServerSpecs,
                          HostName loadBalancerName,
                          boolean hostedVespa,
                          Zone zone,
                          Set<Rotation> rotations,
                          boolean disableFileDistributor) {
            this.applicationId = applicationId;
            this.multitenant = multitenant;
            this.configServerSpecs = configServerSpecs;
            this.loadBalancerName = loadBalancerName;
            this.hostedVespa = hostedVespa;
            this.zone = zone;
            this.rotations = rotations;
            this.disableFileDistributor = disableFileDistributor;
        }

        @Override
        public boolean multitenant() {
            return multitenant;
        }

        @Override
        public ApplicationId applicationId() {
            return applicationId;
        }

        @Override
        public List<ConfigServerSpec> configServerSpecs() {
            return configServerSpecs;
        }

        @Override
        public HostName loadBalancerName() {
            return loadBalancerName;
        }

        @Override
        public boolean hostedVespa() {
            return hostedVespa;
        }

        @Override
        public Zone zone() {
            return zone;
        }

        @Override
        public Set<Rotation> rotations() { return rotations; }

        @Override
        public boolean disableFileDistributor() { return disableFileDistributor; }
    }

}