1 package org.kuali.common.devops.model; 2 3 import static com.google.common.base.Optional.absent; 4 5 import java.util.Comparator; 6 7 import org.kuali.common.core.build.ValidatingBuilder; 8 import org.kuali.common.core.validate.annotation.IdiotProofImmutable; 9 import org.kuali.common.devops.metadata.model.EC2Instance; 10 import org.kuali.common.devops.metadata.model.Memory; 11 12 import com.google.common.base.Optional; 13 14 @IdiotProofImmutable 15 public final class Environment implements Comparable<Environment> { 16 17 private static final Comparator<String> COMPARATOR = new EnvStringComparator(); 18 19 private final String name; 20 private final String fqdn; 21 private final Optional<Integer> httpStatus; 22 private final EC2Instance server; 23 private final Optional<String> java; 24 private final Optional<Tomcat> tomcat; 25 private final Optional<Application> application; 26 private final Optional<Memory> memory; 27 private final Status status; 28 29 @Override 30 public int compareTo(Environment other) { 31 return COMPARATOR.compare(name, other.getName()); 32 } 33 34 private Environment(Builder builder) { 35 this.name = builder.name; 36 this.fqdn = builder.fqdn; 37 this.server = builder.server; 38 this.tomcat = builder.tomcat; 39 this.java = builder.java; 40 this.application = builder.application; 41 this.status = builder.status; 42 this.memory = builder.memory; 43 this.httpStatus = builder.httpStatus; 44 } 45 46 public static Environment create(String name, String fqdn, EC2Instance server) { 47 return builder().name(name).fqdn(fqdn).server(server).build(); 48 } 49 50 public static Builder builder() { 51 return new Builder(); 52 } 53 54 public static class Builder extends ValidatingBuilder<Environment> implements Comparable<Environment.Builder> { 55 56 private String name; 57 private String fqdn; 58 private Optional<Integer> httpStatus; 59 private EC2Instance server; 60 private Optional<Tomcat> tomcat = absent(); 61 private Optional<String> java = absent(); 62 private Optional<Application> application = absent(); 63 private Status status = Status.UNKNOWN; 64 private Optional<Memory> memory = absent(); 65 66 @Override 67 public int compareTo(Environment.Builder other) { 68 return COMPARATOR.compare(name, other.getName()); 69 } 70 71 public Builder withHttpStatus(Optional<Integer> httpStatus) { 72 this.httpStatus = httpStatus; 73 return this; 74 } 75 76 public Builder memory(Optional<Memory> memory) { 77 this.memory = memory; 78 return this; 79 } 80 81 public Builder memory(Memory memory) { 82 return memory(Optional.of(memory)); 83 } 84 85 public Builder status(String status) { 86 this.name = status; 87 return this; 88 } 89 90 public Builder name(String name) { 91 this.name = name; 92 return this; 93 } 94 95 public Builder fqdn(String fqdn) { 96 this.fqdn = fqdn; 97 return this; 98 } 99 100 public Builder server(EC2Instance server) { 101 this.server = server; 102 return this; 103 } 104 105 public Builder tomcat(Optional<Tomcat> tomcat) { 106 this.tomcat = tomcat; 107 return this; 108 } 109 110 public Builder tomcat(Tomcat tomcat) { 111 return tomcat(Optional.of(tomcat)); 112 } 113 114 public Builder java(String java) { 115 return java(Optional.of(java)); 116 } 117 118 public Builder java(Optional<String> java) { 119 this.java = java; 120 return this; 121 } 122 123 public Builder application(Optional<Application> application) { 124 this.application = application; 125 return this; 126 } 127 128 @Override 129 public Environment build() { 130 return validate(new Environment(this)); 131 } 132 133 public String getName() { 134 return name; 135 } 136 137 public void setName(String name) { 138 this.name = name; 139 } 140 141 public String getFqdn() { 142 return fqdn; 143 } 144 145 public void setFqdn(String fqdn) { 146 this.fqdn = fqdn; 147 } 148 149 public EC2Instance getServer() { 150 return server; 151 } 152 153 public void setServer(EC2Instance server) { 154 this.server = server; 155 } 156 157 public Optional<String> getJava() { 158 return java; 159 } 160 161 public void setJava(Optional<String> java) { 162 this.java = java; 163 } 164 165 public Optional<Application> getApplication() { 166 return application; 167 } 168 169 public void setApplication(Optional<Application> application) { 170 this.application = application; 171 } 172 173 public Optional<Tomcat> getTomcat() { 174 return tomcat; 175 } 176 177 public void setTomcat(Optional<Tomcat> tomcat) { 178 this.tomcat = tomcat; 179 } 180 181 public Status getStatus() { 182 return status; 183 } 184 185 public void setStatus(Status status) { 186 this.status = status; 187 } 188 189 } 190 191 public String getName() { 192 return name; 193 } 194 195 public String getFqdn() { 196 return fqdn; 197 } 198 199 public EC2Instance getServer() { 200 return server; 201 } 202 203 public Optional<Tomcat> getTomcat() { 204 return tomcat; 205 } 206 207 public Optional<String> getJava() { 208 return java; 209 } 210 211 public Optional<Application> getApplication() { 212 return application; 213 } 214 215 public Status getStatus() { 216 return status; 217 } 218 219 public Optional<Memory> getMemory() { 220 return memory; 221 } 222 223 public Optional<Integer> getHttpStatus() { 224 return httpStatus; 225 } 226 227 }