1 package org.kuali.common.devops.jenkins.monitor.model; 2 3 import static com.google.common.base.Optional.absent; 4 import static com.google.common.collect.Lists.newArrayList; 5 6 import java.util.List; 7 8 import org.kuali.common.core.build.ValidatingBuilder; 9 import org.kuali.common.core.validate.annotation.IdiotProofImmutable; 10 import org.kuali.common.core.validate.annotation.IgnoreBlanks; 11 12 import com.fasterxml.jackson.annotation.JsonIgnore; 13 import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 14 import com.google.common.base.Optional; 15 import com.google.common.collect.ImmutableList; 16 17 @IdiotProofImmutable 18 @JsonDeserialize(builder = JenkinsNode.Builder.class) 19 public final class JenkinsNode { 20 21 private final String displayName; 22 private final String icon; 23 private final boolean idle; 24 private final boolean jnlpAgent; 25 private final boolean launchSupported; 26 private final boolean manualLaunchAllowed; 27 private final int numExecutors; 28 private final boolean offline; 29 @JsonIgnore 30 private final ImmutableList<String> offlineCause; 31 @IgnoreBlanks 32 private final Optional<String> offlineCauseReason; 33 private final boolean temporarilyOffline; 34 35 private JenkinsNode(Builder builder) { 36 this.displayName = builder.displayName; 37 this.icon = builder.icon; 38 this.idle = builder.idle; 39 this.jnlpAgent = builder.jnlpAgent; 40 this.launchSupported = builder.launchSupported; 41 this.manualLaunchAllowed = builder.manualLaunchAllowed; 42 this.numExecutors = builder.numExecutors; 43 this.offline = builder.offline; 44 this.offlineCause = ImmutableList.copyOf(builder.offlineCause); 45 this.offlineCauseReason = builder.offlineCauseReason; 46 this.temporarilyOffline = builder.temporarilyOffline; 47 } 48 49 public static Builder builder() { 50 return new Builder(); 51 } 52 53 public static class Builder extends ValidatingBuilder<JenkinsNode> { 54 55 private String displayName; 56 private String icon; 57 private boolean idle; 58 private boolean jnlpAgent; 59 private boolean launchSupported; 60 private boolean manualLaunchAllowed; 61 private int numExecutors; 62 private boolean offline; 63 @JsonIgnore 64 private List<String> offlineCause = newArrayList(); 65 private Optional<String> offlineCauseReason = absent(); 66 private boolean temporarilyOffline; 67 68 public Builder withDisplayName(String displayName) { 69 this.displayName = displayName; 70 return this; 71 } 72 73 public Builder withIcon(String icon) { 74 this.icon = icon; 75 return this; 76 } 77 78 public Builder withIdle(boolean idle) { 79 this.idle = idle; 80 return this; 81 } 82 83 public Builder withJnlpAgent(boolean jnlpAgent) { 84 this.jnlpAgent = jnlpAgent; 85 return this; 86 } 87 88 public Builder withLaunchSupported(boolean launchSupported) { 89 this.launchSupported = launchSupported; 90 return this; 91 } 92 93 public Builder withManualLaunchAllowed(boolean manualLaunchAllowed) { 94 this.manualLaunchAllowed = manualLaunchAllowed; 95 return this; 96 } 97 98 public Builder withNumExecutors(int numExecutors) { 99 this.numExecutors = numExecutors; 100 return this; 101 } 102 103 public Builder withOffline(boolean offline) { 104 this.offline = offline; 105 return this; 106 } 107 108 public Builder withOfflineCause(List<String> offlineCause) { 109 this.offlineCause = offlineCause; 110 return this; 111 } 112 113 public Builder withOfflineCauseReason(Optional<String> offlineCauseReason) { 114 this.offlineCauseReason = offlineCauseReason; 115 return this; 116 } 117 118 public Builder withTemporarilyOffline(boolean temporarilyOffline) { 119 this.temporarilyOffline = temporarilyOffline; 120 return this; 121 } 122 123 @Override 124 public JenkinsNode build() { 125 return validate(new JenkinsNode(this)); 126 } 127 } 128 129 public String getDisplayName() { 130 return displayName; 131 } 132 133 public String getIcon() { 134 return icon; 135 } 136 137 public boolean isIdle() { 138 return idle; 139 } 140 141 public boolean isJnlpAgent() { 142 return jnlpAgent; 143 } 144 145 public boolean isLaunchSupported() { 146 return launchSupported; 147 } 148 149 public boolean isManualLaunchAllowed() { 150 return manualLaunchAllowed; 151 } 152 153 public int getNumExecutors() { 154 return numExecutors; 155 } 156 157 public boolean isOffline() { 158 return offline; 159 } 160 161 public List<String> getOfflineCause() { 162 return offlineCause; 163 } 164 165 public Optional<String> getOfflineCauseReason() { 166 return offlineCauseReason; 167 } 168 169 public boolean isTemporarilyOffline() { 170 return temporarilyOffline; 171 } 172 173 }