aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/provision/ProvisionerAdapter.java
blob: 956573ecbd4245ba04469baf77638b795e3d7f10 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.provision;

import com.yahoo.config.model.api.HostProvisioner;
import com.yahoo.config.model.api.Provisioned;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Capacity;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.HostSpec;
import com.yahoo.config.provision.ProvisionLogger;
import com.yahoo.config.provision.Provisioner;

import java.util.List;


/**
 * A wrapper for {@link Provisioner} to avoid having to expose multitenant
 * behavior to the config model. Adapts interface from a {@link HostProvisioner} to a
 * {@link Provisioner}.
 *
 * @author Ulf Lilleengen
 */
public class ProvisionerAdapter implements HostProvisioner {

    private final Provisioner provisioner;
    private final ApplicationId applicationId;
    private final Provisioned provisioned;

    public ProvisionerAdapter(Provisioner provisioner, ApplicationId applicationId, Provisioned provisioned) {
        this.provisioner = provisioner;
        this.applicationId = applicationId;
        this.provisioned = provisioned;
    }

    @Override
    public HostSpec allocateHost(String alias) {
        // TODO: Remove this method since hosted/non-hosted needs different interfaces. See also ModelContextImpl.getHostProvisioner
        // Illegal argument becaiuse we end here by following a path not suitable for the environment steered
        // by the content of the nodes tag in services
        throw new IllegalArgumentException("Clusters in hosted environments must have a <nodes count='N'> tag " +
                                                "matching all zones, and having no <node> subtags, " +
                                                "see https://cloud.vespa.ai/en/reference/services");
    }

    @Override
    public List<HostSpec> prepare(ClusterSpec cluster, Capacity capacity, ProvisionLogger logger) {
        provisioned.add(cluster.id(), capacity);
        return provisioner.prepare(applicationId, cluster, capacity, logger);
    }

}