1 package org.kuali.common.devops.jenkins.archive.model; 2 3 import static com.google.common.collect.Lists.newArrayList; 4 import static java.lang.Integer.parseInt; 5 6 import java.nio.file.Path; 7 import java.util.List; 8 9 import org.kuali.common.core.build.ValidatingBuilder; 10 import org.kuali.common.core.validate.annotation.ExistingDirectory; 11 import org.kuali.common.core.validate.annotation.IdiotProofImmutable; 12 13 import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 14 import com.google.common.base.StandardSystemProperty; 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 hostname; 22 @ExistingDirectory 23 private final Path home; 24 private final ImmutableList<JenkinsJob> jobs; 25 private final String archiveDir; 26 private final int threads; 27 28 private JenkinsMaster(Builder builder) { 29 this.hostname = builder.hostname; 30 this.home = builder.home; 31 this.archiveDir = builder.archiveDir; 32 this.jobs = ImmutableList.copyOf(builder.jobs); 33 this.threads = builder.threads; 34 } 35 36 public static Builder builder() { 37 return new Builder(); 38 } 39 40 public static class Builder extends ValidatingBuilder<JenkinsMaster> { 41 42 private String hostname; 43 private Path home; 44 private List<JenkinsJob> jobs = newArrayList(); 45 private String archiveDir = StandardSystemProperty.USER_HOME.value() + "/.s3/archive.kuali.org"; 46 private int threads = parseInt(System.getProperty("jenkins.threads", "5")); 47 48 public Builder withArchiveDir(String archiveDir) { 49 this.archiveDir = archiveDir; 50 return this; 51 } 52 53 public Builder withHostname(String hostname) { 54 this.hostname = hostname; 55 return this; 56 } 57 58 public Builder withHome(Path home) { 59 this.home = home; 60 return this; 61 } 62 63 public Builder withJobs(List<JenkinsJob> jobs) { 64 this.jobs = jobs; 65 return this; 66 } 67 68 @Override 69 public JenkinsMaster build() { 70 return validate(new JenkinsMaster(this)); 71 } 72 } 73 74 public String getHostname() { 75 return hostname; 76 } 77 78 public List<JenkinsJob> getJobs() { 79 return jobs; 80 } 81 82 public Path getHome() { 83 return home; 84 } 85 86 public String getArchiveDir() { 87 return archiveDir; 88 } 89 90 public int getThreads() { 91 return threads; 92 } 93 94 }