summaryrefslogtreecommitdiffstats
path: root/config-provisioning/src/main/java/com/yahoo/config/provision/Cloud.java
blob: 0899a6f100705e5dafbbaa651f1146f100672bd3 (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
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;

import java.util.Objects;

/**
 * Represents a cloud service and its supported features.
 *
 * @author mpolden
 */
public class Cloud {

    private final CloudName name;

    private final boolean dynamicProvisioning;
    private final boolean allowHostSharing;
    private final boolean reprovisionToUpgradeOs;
    private final boolean requireAccessControl;

    private Cloud(CloudName name, boolean dynamicProvisioning, boolean allowHostSharing, boolean reprovisionToUpgradeOs,
                  boolean requireAccessControl) {
        this.name = Objects.requireNonNull(name);
        this.dynamicProvisioning = dynamicProvisioning;
        this.allowHostSharing = allowHostSharing;
        this.reprovisionToUpgradeOs = reprovisionToUpgradeOs;
        this.requireAccessControl = requireAccessControl;
    }

    /** The name of this */
    public CloudName name() {
        return name;
    }

    /** Returns whether this can provision hosts dynamically */
    public boolean dynamicProvisioning() {
        return dynamicProvisioning;
    }

    /** Returns whether this allows different applications to share the same host */
    public boolean allowHostSharing() {
        return allowHostSharing;
    }

    /** Returns whether upgrading OS on hosts in this requires the host to be reprovisioned */
    public boolean reprovisionToUpgradeOs() {
        return reprovisionToUpgradeOs;
    }

    /** Returns whether to require access control for all clusters in this */
    public boolean requireAccessControl() {
        return requireAccessControl;
    }

    /** For testing purposes only */
    public static Cloud defaultCloud() {
        return new Builder().name(CloudName.defaultName()).build();
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        private CloudName name = CloudName.defaultName();
        private boolean dynamicProvisioning = false;
        private boolean allowHostSharing = true;
        private boolean reprovisionToUpgradeOs = false;
        private boolean requireAccessControl = false;

        private Builder() {}

        public Builder name(CloudName name) {
            this.name = name;
            return this;
        }

        public Builder dynamicProvisioning(boolean dynamicProvisioning) {
            this.dynamicProvisioning = dynamicProvisioning;
            return this;
        }

        public Builder allowHostSharing(boolean allowHostSharing) {
            this.allowHostSharing = allowHostSharing;
            return this;
        }

        public Builder reprovisionToUpgradeOs(boolean reprovisionToUpgradeOs) {
            this.reprovisionToUpgradeOs = reprovisionToUpgradeOs;
            return this;
        }

        public Builder requireAccessControl(boolean requireAccessControl) {
            this.requireAccessControl = requireAccessControl;
            return this;
        }

        public Cloud build() {
            return new Cloud(name, dynamicProvisioning, allowHostSharing, reprovisionToUpgradeOs, requireAccessControl);
        }

    }

    @Override
    public String toString() {
        return "cloud " + name;
    }

}