001package org.kuali.common.devops.ci.model;
002
003import org.kuali.common.core.build.ValidatingBuilder;
004import org.kuali.common.core.validate.annotation.IdiotProofImmutable;
005import org.kuali.common.devops.aws.Tags;
006
007import com.amazonaws.regions.Region;
008import com.amazonaws.regions.Regions;
009
010@IdiotProofImmutable
011public final class JenkinsContext {
012
013        private final String dnsPrefix;
014        private final Tags.Name name;
015        private final Tags.Stack stack;
016        private final Region region;
017        private final BackupMode backupMode;
018        private final String availabilityZone;
019
020        private JenkinsContext(Builder builder) {
021                this.dnsPrefix = builder.dnsPrefix;
022                this.name = builder.name;
023                this.stack = builder.stack;
024                this.region = builder.region;
025                this.backupMode = builder.backupMode;
026                this.availabilityZone = builder.availabilityZone;
027        }
028
029        public static Builder builder() {
030                return new Builder();
031        }
032
033        public static class Builder extends ValidatingBuilder<JenkinsContext> {
034
035                private String dnsPrefix;
036                private Tags.Name name;
037                private Tags.Stack stack;
038                private Region region = Region.getRegion(Regions.DEFAULT_REGION);
039                private String availabilityZone;
040                private BackupMode backupMode = BackupMode.THIN;
041
042                public Builder withAvailabilityZone(String availabilityZone) {
043                        this.availabilityZone = availabilityZone;
044                        return this;
045                }
046
047                public Builder withBackupMode(BackupMode backupMode) {
048                        this.backupMode = backupMode;
049                        return this;
050                }
051
052                public Builder withRegion(String region) {
053                        return withRegion(Regions.fromName(region));
054                }
055
056                public Builder withRegion(Region region) {
057                        this.region = region;
058                        return this;
059                }
060
061                public Builder withRegion(Regions region) {
062                        return withRegion(Region.getRegion(region));
063                }
064
065                public Builder withDnsPrefix(String dnsPrefix) {
066                        this.dnsPrefix = dnsPrefix;
067                        return this;
068                }
069
070                public Builder withName(Tags.Name name) {
071                        this.name = name;
072                        return this;
073                }
074
075                public Builder withStack(Tags.Stack stack) {
076                        this.stack = stack;
077                        return this;
078                }
079
080                @Override
081                public JenkinsContext build() {
082                        return validate(new JenkinsContext(this));
083                }
084
085                public String getDnsPrefix() {
086                        return dnsPrefix;
087                }
088
089                public void setDnsPrefix(String dnsPrefix) {
090                        this.dnsPrefix = dnsPrefix;
091                }
092
093                public Tags.Name getName() {
094                        return name;
095                }
096
097                public void setName(Tags.Name name) {
098                        this.name = name;
099                }
100
101                public Tags.Stack getStack() {
102                        return stack;
103                }
104
105                public void setStack(Tags.Stack stack) {
106                        this.stack = stack;
107                }
108
109                public Region getRegion() {
110                        return region;
111                }
112
113                public void setRegion(Region region) {
114                        this.region = region;
115                }
116
117                public BackupMode getBackupMode() {
118                        return backupMode;
119                }
120
121                public void setBackupMode(BackupMode backupMode) {
122                        this.backupMode = backupMode;
123                }
124        }
125
126        public String getDnsPrefix() {
127                return dnsPrefix;
128        }
129
130        public Tags.Name getName() {
131                return name;
132        }
133
134        public Tags.Stack getStack() {
135                return stack;
136        }
137
138        public Region getRegion() {
139                return region;
140        }
141
142        public BackupMode getBackupMode() {
143                return backupMode;
144        }
145
146        public String getAvailabilityZone() {
147                return availabilityZone;
148        }
149
150}