Skip to content

Commit 7c4b7ca

Browse files
authored
Merge branch 'master' into github-exclusive-schema
2 parents 5713e93 + 05d75ae commit 7c4b7ca

File tree

64 files changed

+715
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+715
-82
lines changed

agent/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114
<artifactId>config</artifactId>
115115
</dependency>
116116
<dependency>
117-
<groupId>com.walmartlabs.ollie</groupId>
118-
<artifactId>ollie-config</artifactId>
117+
<groupId>com.walmartlabs.concord</groupId>
118+
<artifactId>concord-config</artifactId>
119119
</dependency>
120120

121121
<!-- Immutables -->

agent/src/assembly/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ ${JDK_SPECIFIC_OPTS} \
4141
-Djava.net.preferIPv4Stack=true \
4242
-Djava.security.egd=file:/dev/./urandom \
4343
-Dlogback.configurationFile=com/walmartlabs/concord/agent/logback.xml \
44-
-Dollie.conf=${CONCORD_CFG_FILE} \
44+
-Dconcord.conf=${CONCORD_CFG_FILE} \
4545
-cp "${BASE_DIR}/lib/*" \
4646
com.walmartlabs.concord.agent.Main

agent/src/main/java/com/walmartlabs/concord/agent/AgentModule.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
import com.walmartlabs.concord.agent.remote.ApiClientFactory;
3131
import com.walmartlabs.concord.agent.remote.QueueClientProvider;
3232
import com.walmartlabs.concord.common.ObjectMapperProvider;
33+
import com.walmartlabs.concord.config.ConfigModule;
3334
import com.walmartlabs.concord.server.queueclient.QueueClient;
34-
import com.walmartlabs.ollie.config.ConfigurationProcessor;
35-
import com.walmartlabs.ollie.config.Environment;
36-
import com.walmartlabs.ollie.config.EnvironmentSelector;
3735

3836
import javax.inject.Named;
3937

@@ -76,7 +74,6 @@ public void configure(Binder binder) {
7674
}
7775

7876
private static Config loadDefaultConfig() {
79-
Environment env = new EnvironmentSelector().select();
80-
return new ConfigurationProcessor("concord-agent", env, null, null).process();
77+
return ConfigModule.load("concord-agent");
8178
}
8279
}

config/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Concord Config
2+
3+
Based on [ollie-config](https://github.com/takari/ollie/tree/master/ollie-config),
4+
minus the environment handling.

config/pom.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.walmartlabs.concord</groupId>
8+
<artifactId>parent</artifactId>
9+
<version>2.17.1-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>concord-config</artifactId>
14+
<packaging>jar</packaging>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.typesafe</groupId>
19+
<artifactId>config</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>javax.inject</groupId>
23+
<artifactId>javax.inject</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.google.inject</groupId>
27+
<artifactId>guice</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.reflections</groupId>
31+
<artifactId>reflections</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.junit.jupiter</groupId>
35+
<artifactId>junit-jupiter-api</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.junit.jupiter</groupId>
40+
<artifactId>junit-jupiter-engine</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.eclipse.sisu</groupId>
49+
<artifactId>sisu-maven-plugin</artifactId>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.walmartlabs.concord.config;
2+
3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2018 Takari
8+
* Copyright (C) 2017 - 2024 Walmart Inc.
9+
* -----
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
* =====
22+
*/
23+
24+
import com.google.inject.BindingAnnotation;
25+
26+
import java.lang.annotation.Retention;
27+
import java.lang.annotation.Target;
28+
29+
import static java.lang.annotation.ElementType.*;
30+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
31+
32+
@BindingAnnotation
33+
@Target({FIELD, PARAMETER, METHOD})
34+
@Retention(RUNTIME)
35+
public @interface Config {
36+
37+
String value();
38+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.walmartlabs.concord.config;
2+
3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2018 Takari
8+
* Copyright (C) 2017 - 2024 Walmart Inc.
9+
* -----
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
* =====
22+
*/
23+
24+
interface ConfigExtractor {
25+
26+
Object extractValue(com.typesafe.config.Config config, String path);
27+
28+
Class<?>[] getMatchingClasses();
29+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
package com.walmartlabs.concord.config;
2+
3+
/*-
4+
* *****
5+
* Concord
6+
* -----
7+
* Copyright (C) 2018 Takari
8+
* Copyright (C) 2017 - 2024 Walmart Inc.
9+
* -----
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
* =====
22+
*/
23+
24+
import com.typesafe.config.Config;
25+
import com.typesafe.config.*;
26+
27+
import java.nio.file.Path;
28+
import java.nio.file.Paths;
29+
import java.time.Duration;
30+
import java.util.Base64;
31+
import java.util.HashMap;
32+
import java.util.Map;
33+
import java.util.Optional;
34+
35+
enum ConfigExtractors implements ConfigExtractor {
36+
37+
BOOLEAN(boolean.class, Boolean.class) {
38+
@Override
39+
public Object extractValue(Config config, String path) {
40+
return config.getBoolean(path);
41+
}
42+
},
43+
BYTE(byte.class, Byte.class) {
44+
@Override
45+
public Object extractValue(Config config, String path) {
46+
return (byte) config.getInt(path);
47+
}
48+
},
49+
SHORT(short.class, Short.class) {
50+
@Override
51+
public Object extractValue(Config config, String path) {
52+
return (short) config.getInt(path);
53+
}
54+
},
55+
INTEGER(int.class, Integer.class) {
56+
@Override
57+
public Object extractValue(Config config, String path) {
58+
return config.getInt(path);
59+
}
60+
},
61+
LONG(long.class, Long.class) {
62+
@Override
63+
public Object extractValue(Config config, String path) {
64+
return config.getLong(path);
65+
}
66+
},
67+
FLOAT(float.class, Float.class) {
68+
@Override
69+
public Object extractValue(Config config, String path) {
70+
return (float) config.getDouble(path);
71+
}
72+
},
73+
DOUBLE(double.class, Double.class) {
74+
@Override
75+
public Object extractValue(Config config, String path) {
76+
return config.getDouble(path);
77+
}
78+
},
79+
STRING(String.class) {
80+
@Override
81+
public Object extractValue(Config config, String path) {
82+
return config.getString(path);
83+
}
84+
},
85+
PATH(Path.class) {
86+
@Override
87+
public Object extractValue(Config config, String path) {
88+
return Paths.get(config.getString(path));
89+
}
90+
},
91+
ANY_REF(Object.class) {
92+
@Override
93+
public Object extractValue(Config config, String path) {
94+
return config.getAnyRef(path);
95+
}
96+
},
97+
CONFIG(Config.class) {
98+
@Override
99+
public Object extractValue(Config config, String path) {
100+
return config.getConfig(path);
101+
}
102+
},
103+
CONFIG_OBJECT(ConfigObject.class) {
104+
@Override
105+
public Object extractValue(Config config, String path) {
106+
return config.getObject(path);
107+
}
108+
},
109+
CONFIG_VALUE(ConfigValue.class) {
110+
@Override
111+
public Object extractValue(Config config, String path) {
112+
return config.getValue(path);
113+
}
114+
},
115+
CONFIG_LIST(ConfigList.class) {
116+
@Override
117+
public Object extractValue(Config config, String path) {
118+
return config.getList(path);
119+
}
120+
},
121+
DURATION(Duration.class) {
122+
@Override
123+
public Object extractValue(Config config, String path) {
124+
return config.getDuration(path);
125+
}
126+
},
127+
MEMORY_SIZE(ConfigMemorySize.class) {
128+
@Override
129+
public Object extractValue(Config config, String path) {
130+
return config.getMemorySize(path);
131+
}
132+
},
133+
BYTE_ARRAY(byte[].class) {
134+
@Override
135+
public Object extractValue(Config config, String path) {
136+
return Base64.getDecoder().decode(config.getString(path));
137+
}
138+
};
139+
140+
private final Class<?>[] matchingClasses;
141+
private static final Map<Class<?>, ConfigExtractor> EXTRACTOR_MAP = new HashMap<>();
142+
143+
static {
144+
for (var extractor : ConfigExtractors.values()) {
145+
for (var clazz : extractor.getMatchingClasses()) {
146+
EXTRACTOR_MAP.put(clazz, extractor);
147+
}
148+
}
149+
}
150+
151+
ConfigExtractors(Class<?>... matchingClasses) {
152+
this.matchingClasses = matchingClasses;
153+
}
154+
155+
@Override
156+
public Class<?>[] getMatchingClasses() {
157+
return matchingClasses;
158+
}
159+
160+
static Optional<Object> extractConfigValue(Config config, Class<?> paramClass, String path) {
161+
if (config.hasPath(path) && EXTRACTOR_MAP.containsKey(paramClass)) {
162+
return Optional.of(EXTRACTOR_MAP.get(paramClass).extractValue(config, path));
163+
} else {
164+
return Optional.empty();
165+
}
166+
}
167+
}

0 commit comments

Comments
 (0)