View Javadoc
1   package org.kuali.common.devops.logic;
2   
3   import static com.google.common.base.Stopwatch.createStarted;
4   import static java.util.concurrent.TimeUnit.MILLISECONDS;
5   import static org.kuali.common.util.log.Loggers.newLogger;
6   
7   import java.util.List;
8   import java.util.Set;
9   import java.util.concurrent.Callable;
10  
11  import javax.validation.ConstraintViolation;
12  
13  import org.kuali.common.core.build.ViolationsBuilder;
14  import org.kuali.common.core.validate.annotation.IdiotProofImmutable;
15  import org.kuali.common.devops.metadata.logic.EnvironmentMetadataService;
16  import org.kuali.common.devops.model.Environment;
17  import org.kuali.common.util.inform.PercentCompleteInformer;
18  import org.slf4j.Logger;
19  
20  import com.google.common.base.Stopwatch;
21  import com.google.common.collect.ImmutableList;
22  
23  @IdiotProofImmutable
24  public final class BuilderFillerCallable implements Callable<Long> {
25  
26  	private final ImmutableList<Environment.Builder> builders;
27  	private final EnvironmentMetadataService service;
28  	private final PercentCompleteInformer informer;
29  
30  	private static final Logger logger = newLogger();
31  
32  	@Override
33  	public Long call() {
34  		Stopwatch sw = createStarted();
35  		for (Environment.Builder builder : builders) {
36  			logger.debug(builder.getFqdn());
37  			Environments2.fillIn(builder, service);
38  			informer.incrementProgress();
39  		}
40  		return sw.elapsed(MILLISECONDS);
41  	}
42  
43  	private BuilderFillerCallable(Builder builder) {
44  		this.builders = ImmutableList.copyOf(builder.builders);
45  		this.service = builder.service;
46  		this.informer = builder.informer;
47  	}
48  
49  	public static Builder builder() {
50  		return new Builder();
51  	}
52  
53  	public static class Builder extends ViolationsBuilder<BuilderFillerCallable> {
54  
55  		private List<Environment.Builder> builders;
56  		private EnvironmentMetadataService service;
57  		private PercentCompleteInformer informer;
58  
59  		public Builder informer(PercentCompleteInformer informer) {
60  			this.informer = informer;
61  			return this;
62  		}
63  
64  		public Builder builders(List<Environment.Builder> builders) {
65  			this.builders = builders;
66  			return this;
67  		}
68  
69  		public Builder service(EnvironmentMetadataService service) {
70  			this.service = service;
71  			return this;
72  		}
73  
74  		@Override
75  		public BuilderFillerCallable build() {
76  			return validate(make());
77  		}
78  
79  		@Override
80  		public Set<ConstraintViolation<BuilderFillerCallable>> violations() {
81  			return violations(make());
82  		}
83  
84  		private BuilderFillerCallable make() {
85  			return new BuilderFillerCallable(this);
86  		}
87  
88  		public List<Environment.Builder> getBuilders() {
89  			return builders;
90  		}
91  
92  		public void setBuilders(List<Environment.Builder> builders) {
93  			this.builders = builders;
94  		}
95  
96  		public EnvironmentMetadataService getService() {
97  			return service;
98  		}
99  
100 		public void setService(EnvironmentMetadataService service) {
101 			this.service = service;
102 		}
103 
104 		public PercentCompleteInformer getInformer() {
105 			return informer;
106 		}
107 
108 		public void setInformer(PercentCompleteInformer informer) {
109 			this.informer = informer;
110 		}
111 
112 	}
113 
114 	public List<Environment.Builder> getBuilders() {
115 		return builders;
116 	}
117 
118 	public EnvironmentMetadataService getService() {
119 		return service;
120 	}
121 
122 	public PercentCompleteInformer getInformer() {
123 		return informer;
124 	}
125 
126 }