001package org.kuali.common.devops.model; 002 003import static com.google.common.base.Optional.absent; 004 005import java.util.Comparator; 006 007import org.kuali.common.core.build.ValidatingBuilder; 008import org.kuali.common.core.validate.annotation.IdiotProofImmutable; 009import org.kuali.common.devops.metadata.model.EC2Instance; 010import org.kuali.common.devops.metadata.model.Memory; 011 012import com.google.common.base.Optional; 013 014@IdiotProofImmutable 015public final class Environment implements Comparable<Environment> { 016 017 private static final Comparator<String> COMPARATOR = new EnvStringComparator(); 018 019 private final String name; 020 private final String fqdn; 021 private final Optional<Integer> httpStatus; 022 private final EC2Instance server; 023 private final Optional<String> java; 024 private final Optional<Tomcat> tomcat; 025 private final Optional<Application> application; 026 private final Optional<Memory> memory; 027 private final Status status; 028 029 @Override 030 public int compareTo(Environment other) { 031 return COMPARATOR.compare(name, other.getName()); 032 } 033 034 private Environment(Builder builder) { 035 this.name = builder.name; 036 this.fqdn = builder.fqdn; 037 this.server = builder.server; 038 this.tomcat = builder.tomcat; 039 this.java = builder.java; 040 this.application = builder.application; 041 this.status = builder.status; 042 this.memory = builder.memory; 043 this.httpStatus = builder.httpStatus; 044 } 045 046 public static Environment create(String name, String fqdn, EC2Instance server) { 047 return builder().name(name).fqdn(fqdn).server(server).build(); 048 } 049 050 public static Builder builder() { 051 return new Builder(); 052 } 053 054 public static class Builder extends ValidatingBuilder<Environment> implements Comparable<Environment.Builder> { 055 056 private String name; 057 private String fqdn; 058 private Optional<Integer> httpStatus; 059 private EC2Instance server; 060 private Optional<Tomcat> tomcat = absent(); 061 private Optional<String> java = absent(); 062 private Optional<Application> application = absent(); 063 private Status status = Status.UNKNOWN; 064 private Optional<Memory> memory = absent(); 065 066 @Override 067 public int compareTo(Environment.Builder other) { 068 return COMPARATOR.compare(name, other.getName()); 069 } 070 071 public Builder withHttpStatus(Optional<Integer> httpStatus) { 072 this.httpStatus = httpStatus; 073 return this; 074 } 075 076 public Builder memory(Optional<Memory> memory) { 077 this.memory = memory; 078 return this; 079 } 080 081 public Builder memory(Memory memory) { 082 return memory(Optional.of(memory)); 083 } 084 085 public Builder status(String status) { 086 this.name = status; 087 return this; 088 } 089 090 public Builder name(String name) { 091 this.name = name; 092 return this; 093 } 094 095 public Builder fqdn(String fqdn) { 096 this.fqdn = fqdn; 097 return this; 098 } 099 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}