Skip to content

Commit f4b9cf5

Browse files
authored
594: Structure Domain Model config.Config as proposed in section "New Modeling Propose" (#614)
* testing * tesing * adjusting test * config object new model * config object new model * config object new model * config object new model * config object new model * config object new model * config object new model * config object new model * config object new model * release notes * refactoring * refactoring object structure * fixing bug * fixing test * fixing test * solver docker changes * adapting solver docker and fixing compiling errors * fixing tests * fixing tests * fixing tests * fixing tests * fixing tests * fixing tests * fixing tests * fixing tests * fixing tests * missing obj * fixing tests * mapping new objects * migrating log object * refactoring log object * refactoring local solver * --amend * fixing solver local mapping * fixing remote server mapping * fixing test * fixing bug * clean code * release notes * [Gradle Release Plugin] - new version commit: '3.32.5-snapshot'.
1 parent 9c26699 commit f4b9cf5

40 files changed

+864
-175
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ examples/tmp
7070
issues
7171
/files
7272
tmp/
73-
Poc.java
73+
Poc.*
74+
7475

7576
src/stress-test/docker/dps-stress-test-instance/files

RELEASE-NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.32.5
2+
* Structuring Domain Model config.Config as proposed in section "New Modeling Propose". #594
3+
14
## 3.32.4
25
* Migrating aarch docker image as the previous one is not available. #612
36

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=3.32.4-snapshot
1+
version=3.32.5-snapshot

src/main/java/com/mageddo/dnsproxyserver/config/Config.java

Lines changed: 192 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import lombok.Value;
1111
import org.apache.commons.lang3.Validate;
1212

13+
import javax.annotation.Nonnull;
1314
import java.io.IOException;
1415
import java.io.UncheckedIOException;
1516
import java.net.URI;
@@ -29,54 +30,207 @@
2930
* @see com.mageddo.dnsproxyserver.config.application.ConfigService
3031
*/
3132
@Value
32-
@Builder(toBuilder = true)
33+
@Builder(toBuilder = true, builderClassName = "ConfigBuilder")
3334
public class Config {
3435

3536
private String version;
3637

37-
@Builder.Default
38-
private List<IpAddr> remoteDnsServers = new ArrayList<>();
38+
private Server server;
3939

40-
private Integer webServerPort;
40+
private DefaultDns defaultDns;
4141

42-
private Integer dnsServerPort;
42+
private Log log;
4343

44-
private Boolean defaultDns;
44+
private Path configPath;
4545

46-
private LogLevel logLevel;
46+
private SolverStub solverStub;
4747

48-
private String logFile;
48+
private SolverRemote solverRemote;
4949

50-
private Boolean registerContainerNames;
50+
private SolverDocker solverDocker;
5151

52-
private String hostMachineHostname;
52+
private SolverSystem solverSystem;
5353

54-
private String domain;
54+
private SolverLocal solverLocal;
5555

56-
private Boolean mustConfigureDpsNetwork;
56+
@NonNull
57+
private Source source;
5758

58-
private Boolean dpsNetworkAutoConnect;
59+
@JsonIgnore
60+
public Boolean isDefaultDnsActive() {
61+
if (this.defaultDns == null) {
62+
return null;
63+
}
64+
return this.defaultDns.active;
65+
}
5966

60-
private Path configPath;
67+
@JsonIgnore
68+
public String getDefaultDnsResolvConfPaths() {
69+
if (this.getDefaultDnsResolvConf() == null) {
70+
return null;
71+
}
72+
return this.getDefaultDnsResolvConf().paths;
73+
}
6174

62-
private String resolvConfPaths;
75+
@JsonIgnore
76+
public Boolean isResolvConfOverrideNameServersActive() {
77+
if (this.getDefaultDnsResolvConf() == null) {
78+
return null;
79+
}
80+
return this.getDefaultDnsResolvConf().overrideNameServers;
81+
}
6382

64-
private SimpleServer.Protocol serverProtocol;
83+
@JsonIgnore
84+
private DefaultDns.ResolvConf getDefaultDnsResolvConf() {
85+
if (this.defaultDns == null) {
86+
return null;
87+
}
88+
return this.defaultDns.resolvConf;
89+
}
6590

66-
private URI dockerHost;
91+
@Nonnull
92+
@JsonIgnore
93+
public List<IpAddr> getRemoteDnsServers() {
94+
if (this.solverRemote == null) {
95+
return Collections.emptyList();
96+
}
97+
return this.solverRemote.getDnsServers();
98+
}
6799

68-
private Boolean resolvConfOverrideNameServers;
100+
@JsonIgnore
101+
public Boolean getRegisterContainerNames() {
102+
if (this.solverDocker == null) {
103+
return null;
104+
}
105+
return this.solverDocker.getRegisterContainerNames();
106+
}
69107

70-
private Integer noEntriesResponseCode;
108+
@JsonIgnore
109+
public String getDockerDomain() {
110+
if (this.solverDocker == null) {
111+
return null;
112+
}
113+
return this.solverDocker.getDomain();
114+
}
71115

72-
private Boolean dockerSolverHostMachineFallbackActive;
116+
@JsonIgnore
117+
public Boolean getDockerSolverMustConfigureDpsNetwork() {
118+
if (this.solverDocker == null) {
119+
return null;
120+
}
121+
return this.solverDocker.shouldAutoCreateDpsNetwork();
122+
}
73123

74-
private SolverStub solverStub;
124+
@JsonIgnore
125+
public Boolean getDpsNetworkAutoConnect() {
126+
if (this.solverDocker == null) {
127+
return null;
128+
}
129+
return this.solverDocker.shouldAutoConnect();
130+
}
75131

76-
private SolverRemote solverRemote;
132+
@JsonIgnore
133+
public URI getDockerDaemonUri() {
134+
if (this.solverDocker == null) {
135+
return null;
136+
}
137+
return this.solverDocker.getDockerDaemonUri();
138+
}
77139

78-
@NonNull
79-
private Source source;
140+
@JsonIgnore
141+
public SolverDocker.DpsNetwork getDockerSolverDpsNetwork() {
142+
return this.solverDocker.getDpsNetwork();
143+
}
144+
145+
@JsonIgnore
146+
public Boolean getDockerSolverHostMachineFallbackActive() {
147+
if (this.solverDocker == null) {
148+
return null;
149+
}
150+
return this.solverDocker.shouldUseHostMachineFallback();
151+
}
152+
153+
public String getHostMachineHostname() {
154+
if (this.solverSystem == null) {
155+
return null;
156+
}
157+
return this.solverSystem.getHostMachineHostname();
158+
}
159+
160+
public Integer getNoEntriesResponseCode() {
161+
if (this.server == null) {
162+
return null;
163+
}
164+
return this.server.getDnsServerNoEntriesResponseCode();
165+
}
166+
167+
public Integer getDnsServerPort() {
168+
if (this.server == null) {
169+
return null;
170+
}
171+
return this.server.getDnsServerPort();
172+
}
173+
174+
public Integer getWebServerPort() {
175+
if (this.server == null) {
176+
return null;
177+
}
178+
return this.server.getWebServerPort();
179+
}
180+
181+
public SimpleServer.Protocol getServerProtocol() {
182+
if (this.server == null) {
183+
return null;
184+
}
185+
return this.server.getServerProtocol();
186+
}
187+
188+
@JsonIgnore
189+
public LogLevel getLogLevel() {
190+
if (this.log == null) {
191+
return null;
192+
}
193+
return this.log.getLevel();
194+
}
195+
196+
@JsonIgnore
197+
public String getLogFile() {
198+
if (this.log == null) {
199+
return null;
200+
}
201+
return this.log.getFile();
202+
}
203+
204+
@JsonIgnore
205+
public List<Env> getEnvs() {
206+
if (this.solverLocal == null) {
207+
return null;
208+
}
209+
return this.solverLocal.getEnvs();
210+
}
211+
212+
@JsonIgnore
213+
public String getActiveEnv() {
214+
if (this.solverLocal == null) {
215+
return null;
216+
}
217+
return this.solverLocal.getActiveEnv();
218+
}
219+
220+
@Value
221+
@Builder(toBuilder = true)
222+
public static class DefaultDns {
223+
224+
private Boolean active;
225+
private ResolvConf resolvConf;
226+
227+
@Value
228+
@Builder(toBuilder = true)
229+
public static class ResolvConf {
230+
private String paths;
231+
private Boolean overrideNameServers;
232+
}
233+
}
80234

81235
@JsonIgnore
82236
public Boolean isSolverRemoteActive() {
@@ -87,6 +241,9 @@ public Boolean isSolverRemoteActive() {
87241
}
88242

89243
public void resetConfigFile() {
244+
if (this.getConfigPath() == null) {
245+
throw new IllegalStateException("config file is null");
246+
}
90247
try {
91248
Files.deleteIfExists(this.getConfigPath());
92249
} catch (IOException e) {
@@ -150,6 +307,12 @@ public static Env theDefault() {
150307
return new Env(DEFAULT_ENV, new ArrayList<>());
151308
}
152309

310+
public Entry getFirstEntry() {
311+
if (this.entries == null || this.entries.isEmpty()) {
312+
return null;
313+
}
314+
return this.entries.getFirst();
315+
}
153316
}
154317

155318
@Value
@@ -247,4 +410,9 @@ public boolean isAddressSolving() {
247410
}
248411
}
249412
}
413+
414+
public static class ConfigBuilder {
415+
416+
417+
}
250418
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.mageddo.dnsproxyserver.config;
2+
3+
import lombok.Builder;
4+
import lombok.Value;
5+
6+
@Value
7+
@Builder
8+
public class Log {
9+
LogLevel level;
10+
String file;
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.mageddo.dnsproxyserver.config;
2+
3+
import com.mageddo.dnsserver.SimpleServer;
4+
import lombok.Builder;
5+
import lombok.Value;
6+
7+
@Value
8+
@Builder
9+
public class Server {
10+
11+
private Integer webServerPort;
12+
13+
private Integer dnsServerPort;
14+
private Integer dnsServerNoEntriesResponseCode;
15+
16+
private SimpleServer.Protocol serverProtocol;
17+
18+
19+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.mageddo.dnsproxyserver.config;
2+
3+
4+
import lombok.Builder;
5+
import lombok.Value;
6+
import org.apache.commons.lang3.BooleanUtils;
7+
8+
import java.net.URI;
9+
10+
@Value
11+
@Builder(toBuilder = true)
12+
public class SolverDocker {
13+
14+
private URI dockerDaemonUri;
15+
private Boolean registerContainerNames;
16+
private String domain;
17+
private DpsNetwork dpsNetwork;
18+
private Boolean hostMachineFallback;
19+
20+
public boolean shouldUseHostMachineFallback() {
21+
return BooleanUtils.toBoolean(hostMachineFallback);
22+
}
23+
24+
public boolean shouldAutoCreateDpsNetwork() {
25+
if (this.dpsNetwork == null) {
26+
return false;
27+
}
28+
return this.dpsNetwork.shouldAutoCreate();
29+
}
30+
31+
public boolean shouldAutoConnect() {
32+
if (this.dpsNetwork == null) {
33+
return false;
34+
}
35+
return this.dpsNetwork.shouldAutoConnect();
36+
}
37+
38+
@Value
39+
@Builder
40+
public static class DpsNetwork {
41+
42+
private Boolean autoCreate;
43+
private Boolean autoConnect;
44+
45+
public boolean shouldAutoConnect() {
46+
return BooleanUtils.isTrue(this.autoConnect);
47+
}
48+
49+
public boolean shouldAutoCreate() {
50+
return BooleanUtils.isTrue(this.autoCreate);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)