1 package org.kuali.common.devops.jenkins.monitor.model; 2 3 import static com.google.common.collect.Lists.newArrayList; 4 import static org.kuali.common.util.base.Precondition.checkMax; 5 6 import java.util.List; 7 8 import javax.validation.constraints.Min; 9 10 import org.kuali.common.core.build.ValidatingBuilder; 11 import org.kuali.common.core.validate.annotation.IdiotProofImmutable; 12 13 import com.fasterxml.jackson.annotation.JsonProperty; 14 import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 15 import com.google.common.collect.ImmutableList; 16 17 @IdiotProofImmutable 18 @JsonDeserialize(builder = JenkinsMaster.Builder.class) 19 public final class JenkinsMaster { 20 21 private final String displayName; 22 23 @Min(0) 24 private final int busyExecutors; 25 26 @Min(0) 27 private final int totalExecutors; 28 29 @JsonProperty("computer") 30 private final ImmutableList<JenkinsNode> nodes; 31 32 public static Builder builder() { 33 return new Builder(); 34 } 35 36 private JenkinsMaster(Builder builder) { 37 this.displayName = builder.displayName; 38 this.busyExecutors = builder.busyExecutors; 39 this.totalExecutors = builder.totalExecutors; 40 this.nodes = ImmutableList.copyOf(builder.nodes); 41 } 42 43 public static class Builder extends ValidatingBuilder<JenkinsMaster> { 44 45 private String displayName; 46 private int busyExecutors; 47 private int totalExecutors; 48 @JsonProperty("computer") 49 private List<JenkinsNode> nodes = newArrayList(); 50 51 public Builder withNodes(List<JenkinsNode> nodes) { 52 this.nodes = nodes; 53 return this; 54 } 55 56 public Builder withDisplayName(String displayName) { 57 this.displayName = displayName; 58 return this; 59 } 60 61 public Builder withBusyExecutors(int busyExecutors) { 62 this.busyExecutors = busyExecutors; 63 return this; 64 } 65 66 public Builder withTotalExecutors(int totalExecutors) { 67 this.totalExecutors = totalExecutors; 68 return this; 69 } 70 71 @Override 72 public JenkinsMaster build() { 73 return checkInstance(validate(new JenkinsMaster(this))); 74 } 75 76 private static JenkinsMaster checkInstance(JenkinsMaster instance) { 77 checkMax(instance.getBusyExecutors(), instance.getTotalExecutors(), "busyExecutors"); 78 return instance; 79 } 80 } 81 82 public String getDisplayName() { 83 return displayName; 84 } 85 86 public int getBusyExecutors() { 87 return busyExecutors; 88 } 89 90 public int getTotalExecutors() { 91 return totalExecutors; 92 } 93 94 public List<JenkinsNode> getNodes() { 95 return nodes; 96 } 97 98 }