|
1
|
|
|
package com.hltech.judged.server.domain.environment; |
|
2
|
|
|
|
|
3
|
|
|
import com.google.common.collect.SetMultimap; |
|
4
|
|
|
import com.hltech.judged.server.domain.ServiceVersion; |
|
5
|
|
|
|
|
6
|
|
|
import java.util.HashSet; |
|
7
|
|
|
import java.util.Set; |
|
8
|
|
|
import java.util.stream.Collectors; |
|
9
|
|
|
|
|
10
|
|
|
import static com.google.common.collect.HashMultimap.create; |
|
11
|
|
|
|
|
12
|
|
|
public class Environment { |
|
13
|
|
|
|
|
14
|
|
|
public static final String DEFAULT_NAMESPACE = "default"; |
|
15
|
|
|
|
|
16
|
|
|
private final String name; |
|
17
|
|
|
private final SetMultimap<String, ServiceVersion> serviceVersions; |
|
18
|
|
|
|
|
19
|
|
|
public Environment(String name, SetMultimap<String, ServiceVersion> serviceVersions) { |
|
20
|
|
|
this.name = name; |
|
21
|
|
|
this.serviceVersions = serviceVersions; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public Environment(String name, Set<ServiceVersion> serviceVersions) { |
|
25
|
|
|
this.name = name; |
|
26
|
|
|
this.serviceVersions = create(); |
|
27
|
|
|
this.serviceVersions.putAll(DEFAULT_NAMESPACE, serviceVersions); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public String getName() { |
|
31
|
|
|
return this.name; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public Set<String> getSpaceNames() { |
|
35
|
|
|
return serviceVersions.keySet(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public Set<ServiceVersion> getServices(String space) { |
|
39
|
|
|
return serviceVersions.get(space); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public Set<ServiceVersion> getAllServices() { |
|
43
|
|
|
return serviceVersions.values().stream() |
|
44
|
|
|
.collect(Collectors.toUnmodifiableSet()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static Environment empty(String environmentName) { |
|
48
|
|
|
return new Environment(environmentName, new HashSet<>()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static EnvironmentBuilder builder(String name) { |
|
52
|
|
|
return new EnvironmentBuilder(name); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public static class EnvironmentBuilder { |
|
56
|
|
|
|
|
57
|
|
|
private final String name; |
|
58
|
|
|
// <space, serviceVersion> |
|
59
|
|
|
private final SetMultimap<String, ServiceVersion> serviceVersions = create(); |
|
60
|
|
|
|
|
61
|
|
|
private EnvironmentBuilder(String name) { |
|
62
|
|
|
this.name = name; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public EnvironmentBuilder withServiceVersion(String space, ServiceVersion serviceVersion) { |
|
66
|
|
|
this.serviceVersions.put(space, serviceVersion); |
|
67
|
|
|
return this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public EnvironmentBuilder withServiceVersions(String space, Set<ServiceVersion> serviceVersions) { |
|
71
|
|
|
this.serviceVersions.putAll(space, serviceVersions); |
|
72
|
|
|
return this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public Environment build() { |
|
76
|
|
|
return new Environment(this.name, this.serviceVersions); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|