You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/12/15 07:50:19 UTC
[shardingsphere-elasticjob] branch master updated: Refactor
TracingConfiguration with YamlConfiguration (#1775)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new 73713af Refactor TracingConfiguration with YamlConfiguration (#1775)
73713af is described below
commit 73713af3c4666d82f8cc0f9b49c3e679d4ebd7a6
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Tue Dec 15 15:50:03 2020 +0800
Refactor TracingConfiguration with YamlConfiguration (#1775)
* Extract YAML from infra-common and revise Tracing API
* Complete testcases
* Revert extracting infra-yaml
* Remove unused file
---
.../elasticjob-tracing-api/pom.xml | 5 +++
.../tracing/api/TracingConfiguration.java | 12 ++---
.../tracing/yaml/YamlTracingConfiguration.java | 26 ++++++++---
.../yaml/YamlTracingConfigurationConverter.java | 52 ++++++++++++++++++++++
.../yaml/YamlTracingStorageConfiguration.java} | 18 +++-----
...ob.infra.yaml.config.YamlConfigurationConverter | 9 +---
...ation.java => JobEventCallerConfiguration.java} | 2 +-
...Converter.java => JobEventCallerConverter.java} | 4 +-
.../listener/TracingListenerFactoryTest.java | 4 +-
.../YamlJobEventCallerConfiguration.java} | 22 +++++----
.../YamlJobEventCallerConfigurationConverter.java | 42 +++++++++++++++++
.../YamlTracingConfigurationConverterTest.java | 44 ++++++++++++++++++
...b.infra.yaml.config.YamlConfigurationConverter} | 2 +-
...sticjob.tracing.storage.TracingStorageConverter | 2 +-
.../rdb/datasource/DataSourceConfiguration.java | 14 ++----
.../rdb/yaml/YamlDataSourceConfiguration.java | 49 ++++++++++++++++++++
.../yaml/YamlDataSourceConfigurationConverter.java | 46 +++++++++++++++++++
...b.infra.yaml.config.YamlConfigurationConverter} | 2 +-
.../YamlDataSourceConfigurationConverterTest.java | 44 ++++++++++++++++++
.../infra/pojo/JobConfigurationPOJO.java | 11 +++--
.../elasticjob/infra/yaml/YamlEngine.java | 39 +---------------
.../infra/yaml/config/YamlConfiguration.java} | 27 ++++++-----
.../yaml/config/YamlConfigurationConverter.java | 31 ++++++++-----
.../config/YamlConfigurationConverterFactory.java | 52 ++++++++++++++++++++++
...mlConfigurationConverterNotFoundException.java} | 22 +++++----
.../DefaultYamlTupleProcessor.java | 4 +-
.../ElasticJobYamlRepresenter.java | 4 +-
.../elasticjob/infra/yaml/YamlEngineTest.java | 20 +--------
.../YamlConfigurationConverterFactoryTest.java} | 22 ++++-----
.../infra/yaml/fixture/FooYamlConfiguration.java | 2 +-
30 files changed, 463 insertions(+), 170 deletions(-)
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/pom.xml b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/pom.xml
index 5b90874..a4f1313 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/pom.xml
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/pom.xml
@@ -32,6 +32,11 @@
<artifactId>elasticjob-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-infra-common</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/api/TracingConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/api/TracingConfiguration.java
index 6a8cf76..1c504a7 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/api/TracingConfiguration.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/api/TracingConfiguration.java
@@ -17,10 +17,8 @@
package org.apache.shardingsphere.elasticjob.tracing.api;
-import lombok.AllArgsConstructor;
import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
+import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.elasticjob.api.JobExtraConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.exception.TracingStorageConverterNotFoundException;
import org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverterFactory;
@@ -31,14 +29,12 @@ import org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConver
* @param <T> type of tracing storage
*/
@Getter
-@Setter
-@NoArgsConstructor
-@AllArgsConstructor
+@RequiredArgsConstructor
public final class TracingConfiguration<T> implements JobExtraConfiguration {
- private String type;
+ private final String type;
- private TracingStorageConfiguration<T> tracingStorageConfiguration;
+ private final TracingStorageConfiguration<T> tracingStorageConfiguration;
@SuppressWarnings("unchecked")
public TracingConfiguration(final String type, final T storage) {
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfiguration.java
similarity index 50%
copy from elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
copy to elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfiguration.java
index 685bdfe..fa4e81f 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfiguration.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,18 +15,32 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.infra.yaml.fixture;
+package org.apache.shardingsphere.elasticjob.tracing.yaml;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
+/**
+ * YAML configuration for {@link org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration}.
+ *
+ * @param <T> type of storage
+ */
@Getter
@Setter
-public final class FooYamlConfiguration {
+@NoArgsConstructor
+public final class YamlTracingConfiguration<T> implements YamlConfiguration<TracingConfiguration<T>> {
+
+ private static final long serialVersionUID = -6625535892000287729L;
- private String foo;
+ private String type;
- private String bar;
+ private YamlTracingStorageConfiguration<T> tracingStorageConfiguration;
- private FooYamlConfiguration nest;
+ @Override
+ public TracingConfiguration<T> toConfiguration() {
+ return new TracingConfiguration<>(type, tracingStorageConfiguration.toConfiguration());
+ }
}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfigurationConverter.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfigurationConverter.java
new file mode 100644
index 0000000..5d7bf34
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfigurationConverter.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.tracing.yaml;
+
+import org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter;
+import org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverterFactory;
+import org.apache.shardingsphere.elasticjob.infra.yaml.exception.YamlConfigurationConverterNotFoundException;
+import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
+
+/**
+ * Converter to convert {@link TracingConfiguration} to {@link YamlTracingConfiguration}.
+ *
+ * @param <T> type of storage
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public final class YamlTracingConfigurationConverter<T> implements YamlConfigurationConverter<TracingConfiguration<T>, YamlTracingConfiguration<T>> {
+
+ @Override
+ public YamlTracingConfiguration<T> convertToYamlConfiguration(final TracingConfiguration<T> tracingConfiguration) {
+ YamlTracingConfiguration<T> result = new YamlTracingConfiguration<>();
+ result.setType(tracingConfiguration.getType());
+ result.setTracingStorageConfiguration(convertTracingStorageConfiguration(tracingConfiguration.getTracingStorageConfiguration()));
+ return result;
+ }
+
+ private YamlTracingStorageConfiguration<T> convertTracingStorageConfiguration(final TracingStorageConfiguration<T> tracingStorageConfiguration) {
+ return YamlConfigurationConverterFactory
+ .<TracingStorageConfiguration<T>, YamlTracingStorageConfiguration<T>>findConverter((Class<TracingStorageConfiguration<T>>) tracingStorageConfiguration.getClass())
+ .orElseThrow(() -> new YamlConfigurationConverterNotFoundException(tracingStorageConfiguration.getClass())).convertToYamlConfiguration(tracingStorageConfiguration);
+ }
+
+ @Override
+ public Class configurationType() {
+ return TracingConfiguration.class;
+ }
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingStorageConfiguration.java
similarity index 66%
copy from elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java
copy to elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingStorageConfiguration.java
index 2042bc0..1e50d9e 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingStorageConfiguration.java
@@ -15,21 +15,15 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.tracing.fixture;
+package org.apache.shardingsphere.elasticjob.tracing.yaml;
-import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
/**
- * {@link TracingStorageConfiguration} for {@link JobEventCaller}.
+ * YAML configuration for {@link org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration}.
+ *
+ * @param <T> type of storage
*/
-@RequiredArgsConstructor
-public final class JobEventCallerTracingStorageConfiguration implements TracingStorageConfiguration<JobEventCaller> {
-
- private final JobEventCaller jobEventCaller;
-
- @Override
- public JobEventCaller getStorage() {
- return jobEventCaller;
- }
+public interface YamlTracingStorageConfiguration<T> extends YamlConfiguration<TracingStorageConfiguration<T>> {
}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/resources/yaml-test.yaml b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
similarity index 88%
rename from elasticjob-infra/elasticjob-infra-common/src/test/resources/yaml-test.yaml
rename to elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
index 02cb163..e353bc0 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/test/resources/yaml-test.yaml
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
@@ -15,11 +15,4 @@
# limitations under the License.
#
-bar: bar
-foo: foo
-nest:
- bar: nest_bar
- foo: nest_foo
- nest:
- bar: nest_bar2
- foo: nest_foo2
+org.apache.shardingsphere.elasticjob.tracing.yaml.YamlTracingConfigurationConverter
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerConfiguration.java
similarity index 91%
copy from elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java
copy to elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerConfiguration.java
index 2042bc0..1a9d01c 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerConfiguration.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfigurat
* {@link TracingStorageConfiguration} for {@link JobEventCaller}.
*/
@RequiredArgsConstructor
-public final class JobEventCallerTracingStorageConfiguration implements TracingStorageConfiguration<JobEventCaller> {
+public final class JobEventCallerConfiguration implements TracingStorageConfiguration<JobEventCaller> {
private final JobEventCaller jobEventCaller;
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConverter.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerConverter.java
similarity index 88%
rename from elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConverter.java
rename to elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerConverter.java
index b094230..d46ed55 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConverter.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerConverter.java
@@ -23,11 +23,11 @@ import org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConver
/**
* {@link TracingStorageConverter} for {@link JobEventCaller}.
*/
-public final class JobEventCallerTracingStorageConverter implements TracingStorageConverter<JobEventCaller> {
+public final class JobEventCallerConverter implements TracingStorageConverter<JobEventCaller> {
@Override
public TracingStorageConfiguration<JobEventCaller> convertObjectToConfiguration(final JobEventCaller storage) {
- return new JobEventCallerTracingStorageConfiguration(storage);
+ return new JobEventCallerConfiguration(storage);
}
@Override
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/listener/TracingListenerFactoryTest.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/listener/TracingListenerFactoryTest.java
index 0d5bd3b..bc6c0fe 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/listener/TracingListenerFactoryTest.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/listener/TracingListenerFactoryTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.elasticjob.tracing.listener;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.exception.TracingConfigurationException;
-import org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCallerTracingStorageConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCallerConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.fixture.TestTracingListener;
import org.junit.Test;
@@ -40,7 +40,7 @@ public final class TracingListenerFactoryTest {
@Test
public void assertGetListener() throws TracingConfigurationException {
- assertThat(TracingListenerFactory.getListener(new TracingConfiguration<>("TEST", new JobEventCallerTracingStorageConfiguration(() -> {
+ assertThat(TracingListenerFactory.getListener(new TracingConfiguration<>("TEST", new JobEventCallerConfiguration(() -> {
}))), instanceOf(TestTracingListener.class));
}
}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlJobEventCallerConfiguration.java
similarity index 57%
copy from elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java
copy to elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlJobEventCallerConfiguration.java
index 2042bc0..d1a0fda 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlJobEventCallerConfiguration.java
@@ -15,21 +15,27 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.tracing.fixture;
+package org.apache.shardingsphere.elasticjob.tracing.yaml;
-import lombok.RequiredArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCaller;
+import org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCallerConfiguration;
/**
- * {@link TracingStorageConfiguration} for {@link JobEventCaller}.
+ * YAML JobEventCaller configuration.
*/
-@RequiredArgsConstructor
-public final class JobEventCallerTracingStorageConfiguration implements TracingStorageConfiguration<JobEventCaller> {
+@Getter
+@Setter
+public final class YamlJobEventCallerConfiguration implements YamlTracingStorageConfiguration<JobEventCaller> {
- private final JobEventCaller jobEventCaller;
+ private static final long serialVersionUID = -3152825887223378472L;
+
+ private JobEventCaller jobEventCaller;
@Override
- public JobEventCaller getStorage() {
- return jobEventCaller;
+ public TracingStorageConfiguration<JobEventCaller> toConfiguration() {
+ return new JobEventCallerConfiguration(jobEventCaller);
}
}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlJobEventCallerConfigurationConverter.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlJobEventCallerConfigurationConverter.java
new file mode 100644
index 0000000..22d282c
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlJobEventCallerConfigurationConverter.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.tracing.yaml;
+
+import org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter;
+import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCaller;
+import org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCallerConfiguration;
+
+/**
+ * YAML JobEventCaller configuration converter.
+ */
+@SuppressWarnings({"unchecked", "rawtypes"})
+public final class YamlJobEventCallerConfigurationConverter implements YamlConfigurationConverter<TracingStorageConfiguration<JobEventCaller>, YamlTracingStorageConfiguration<JobEventCaller>> {
+
+ @Override
+ public YamlTracingStorageConfiguration<JobEventCaller> convertToYamlConfiguration(final TracingStorageConfiguration<JobEventCaller> data) {
+ YamlJobEventCallerConfiguration result = new YamlJobEventCallerConfiguration();
+ result.setJobEventCaller(data.getStorage());
+ return result;
+ }
+
+ @Override
+ public Class configurationType() {
+ return JobEventCallerConfiguration.class;
+ }
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfigurationConverterTest.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfigurationConverterTest.java
new file mode 100644
index 0000000..7f2993e
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/yaml/YamlTracingConfigurationConverterTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.tracing.yaml;
+
+import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCaller;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class YamlTracingConfigurationConverterTest {
+
+ @Test
+ public void assertConvertTracingConfiguration() {
+ JobEventCaller expectedStorage = () -> {
+ };
+ TracingConfiguration<JobEventCaller> tracingConfiguration = new TracingConfiguration<>("TEST", expectedStorage);
+ YamlTracingConfigurationConverter<JobEventCaller> converter = new YamlTracingConfigurationConverter<>();
+ YamlTracingConfiguration<JobEventCaller> actual = converter.convertToYamlConfiguration(tracingConfiguration);
+ assertThat(actual.getType(), is("TEST"));
+ assertNotNull(actual.getTracingStorageConfiguration());
+ assertTrue(actual.getTracingStorageConfiguration() instanceof YamlJobEventCallerConfiguration);
+ YamlJobEventCallerConfiguration result = (YamlJobEventCallerConfiguration) actual.getTracingStorageConfiguration();
+ assertThat(result.getJobEventCaller(), is(expectedStorage));
+ }
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
similarity index 89%
copy from elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter
copy to elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
index f0c91c1..19d25e6 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCallerTracingStorageConverter
+org.apache.shardingsphere.elasticjob.tracing.yaml.YamlJobEventCallerConfigurationConverter
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter
index f0c91c1..73f32b3 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCallerTracingStorageConverter
+org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCallerConverter
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/datasource/DataSourceConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/datasource/DataSourceConfiguration.java
index dd934d1..3b9bc86 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/datasource/DataSourceConfiguration.java
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/datasource/DataSourceConfiguration.java
@@ -22,8 +22,7 @@ import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.collect.Sets;
import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
+import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
@@ -41,9 +40,8 @@ import java.util.ServiceLoader;
/**
* Data source configuration.
*/
-@Setter
@Getter
-@NoArgsConstructor
+@RequiredArgsConstructor
public final class DataSourceConfiguration implements TracingStorageConfiguration<DataSource> {
private static final String GETTER_PREFIX = "get";
@@ -59,13 +57,9 @@ public final class DataSourceConfiguration implements TracingStorageConfiguratio
SKIPPED_PROPERTY_NAMES = Sets.newHashSet("loginTimeout");
}
- private String dataSourceClassName;
+ private final String dataSourceClassName;
- private Map<String, Object> props = new LinkedHashMap<>();
-
- public DataSourceConfiguration(final String dataSourceClassName) {
- this.dataSourceClassName = dataSourceClassName;
- }
+ private final Map<String, Object> props = new LinkedHashMap<>();
/**
* Get data source configuration.
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfiguration.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfiguration.java
new file mode 100644
index 0000000..0db44a0
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfiguration.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.tracing.rdb.yaml;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.yaml.YamlTracingStorageConfiguration;
+
+import javax.sql.DataSource;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * YAML DataSourceConfiguration.
+ */
+@Setter
+@Getter
+public final class YamlDataSourceConfiguration implements YamlTracingStorageConfiguration<DataSource> {
+
+ private static final long serialVersionUID = -8013707594458676772L;
+
+ private String dataSourceClassName;
+
+ private Map<String, Object> props = new LinkedHashMap<>();
+
+ @Override
+ public TracingStorageConfiguration<DataSource> toConfiguration() {
+ DataSourceConfiguration result = new DataSourceConfiguration(dataSourceClassName);
+ result.getProps().putAll(props);
+ return result;
+ }
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfigurationConverter.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfigurationConverter.java
new file mode 100644
index 0000000..15ca4c5
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfigurationConverter.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.tracing.rdb.yaml;
+
+import org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter;
+import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.yaml.YamlTracingStorageConfiguration;
+
+import javax.sql.DataSource;
+
+/**
+ * {@link YamlConfigurationConverter} for {@link YamlDataSourceConfiguration}.
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public final class YamlDataSourceConfigurationConverter implements YamlConfigurationConverter<TracingStorageConfiguration<DataSource>, YamlTracingStorageConfiguration<DataSource>> {
+
+ @Override
+ public YamlTracingStorageConfiguration<DataSource> convertToYamlConfiguration(final TracingStorageConfiguration<DataSource> data) {
+ DataSourceConfiguration dataSourceConfiguration = (DataSourceConfiguration) data;
+ YamlDataSourceConfiguration result = new YamlDataSourceConfiguration();
+ result.setDataSourceClassName(dataSourceConfiguration.getDataSourceClassName());
+ result.setProps(dataSourceConfiguration.getProps());
+ return result;
+ }
+
+ @Override
+ public Class configurationType() {
+ return DataSourceConfiguration.class;
+ }
+}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
similarity index 89%
copy from elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter
copy to elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
index f0c91c1..95e5ba8 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverter
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.elasticjob.tracing.fixture.JobEventCallerTracingStorageConverter
+org.apache.shardingsphere.elasticjob.tracing.rdb.yaml.YamlDataSourceConfigurationConverter
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfigurationConverterTest.java b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfigurationConverterTest.java
new file mode 100644
index 0000000..896509b
--- /dev/null
+++ b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/yaml/YamlDataSourceConfigurationConverterTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.tracing.rdb.yaml;
+
+import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration;
+import org.apache.shardingsphere.elasticjob.tracing.yaml.YamlTracingStorageConfiguration;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class YamlDataSourceConfigurationConverterTest {
+
+ @Test
+ public void assertConvertDataSourceConfiguration() {
+ DataSourceConfiguration dataSourceConfiguration = new DataSourceConfiguration("org.h2.Driver");
+ dataSourceConfiguration.getProps().put("foo", "bar");
+ YamlDataSourceConfigurationConverter converter = new YamlDataSourceConfigurationConverter();
+ YamlTracingStorageConfiguration<DataSource> actual = converter.convertToYamlConfiguration(dataSourceConfiguration);
+ assertTrue(actual instanceof YamlDataSourceConfiguration);
+ YamlDataSourceConfiguration result = (YamlDataSourceConfiguration) actual;
+ assertThat(result.getDataSourceClassName(), is("org.h2.Driver"));
+ assertThat(result.getProps(), is(Collections.singletonMap("foo", "bar")));
+ }
+}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/pojo/JobConfigurationPOJO.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/pojo/JobConfigurationPOJO.java
index 6050e4e..61e7341 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/pojo/JobConfigurationPOJO.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/pojo/JobConfigurationPOJO.java
@@ -21,6 +21,9 @@ import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.api.JobExtraConfiguration;
+import org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfiguration;
+import org.apache.shardingsphere.elasticjob.infra.yaml.config.YamlConfigurationConverterFactory;
+import org.apache.shardingsphere.elasticjob.infra.yaml.exception.YamlConfigurationConverterNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
@@ -62,7 +65,7 @@ public final class JobConfigurationPOJO {
private Collection<String> jobListenerTypes = new ArrayList<>();
- private Collection<JobExtraConfiguration> jobExtraConfigurations = new LinkedList<>();
+ private Collection<YamlConfiguration<JobExtraConfiguration>> jobExtraConfigurations = new LinkedList<>();
private String description;
@@ -84,7 +87,7 @@ public final class JobConfigurationPOJO {
.maxTimeDiffSeconds(maxTimeDiffSeconds).reconcileIntervalMinutes(reconcileIntervalMinutes)
.jobShardingStrategyType(jobShardingStrategyType).jobExecutorServiceHandlerType(jobExecutorServiceHandlerType).jobErrorHandlerType(jobErrorHandlerType)
.jobListenerTypes(jobListenerTypes.toArray(new String[]{})).description(description).disabled(disabled).overwrite(overwrite).build();
- result.getExtraConfigurations().addAll(jobExtraConfigurations);
+ jobExtraConfigurations.stream().map(YamlConfiguration::toConfiguration).forEach(result.getExtraConfigurations()::add);
for (Object each : props.keySet()) {
result.getProps().setProperty(each.toString(), props.get(each.toString()).toString());
}
@@ -97,6 +100,7 @@ public final class JobConfigurationPOJO {
* @param jobConfiguration job configuration
* @return job configuration POJO
*/
+ @SuppressWarnings("unchecked")
public static JobConfigurationPOJO fromJobConfiguration(final JobConfiguration jobConfiguration) {
JobConfigurationPOJO result = new JobConfigurationPOJO();
result.setJobName(jobConfiguration.getJobName());
@@ -113,7 +117,8 @@ public final class JobConfigurationPOJO {
result.setJobExecutorServiceHandlerType(jobConfiguration.getJobExecutorServiceHandlerType());
result.setJobErrorHandlerType(jobConfiguration.getJobErrorHandlerType());
result.setJobListenerTypes(jobConfiguration.getJobListenerTypes());
- result.setJobExtraConfigurations(jobConfiguration.getExtraConfigurations());
+ jobConfiguration.getExtraConfigurations().stream().map(each -> YamlConfigurationConverterFactory.findConverter((Class<JobExtraConfiguration>) each.getClass())
+ .orElseThrow(() -> new YamlConfigurationConverterNotFoundException(each.getClass())).convertToYamlConfiguration(each)).forEach(result.getJobExtraConfigurations()::add);
result.setDescription(jobConfiguration.getDescription());
result.setProps(jobConfiguration.getProps());
result.setDisabled(jobConfiguration.isDisabled());
diff --git a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/YamlEngine.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/YamlEngine.java
index 3f0e92b..d0d264c 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/YamlEngine.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/YamlEngine.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,15 +17,10 @@
package org.apache.shardingsphere.elasticjob.infra.yaml;
-import com.google.common.base.Splitter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
+import org.apache.shardingsphere.elasticjob.infra.yaml.representer.ElasticJobYamlRepresenter;
import org.yaml.snakeyaml.Yaml;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
/**
* YAML engine.
@@ -54,34 +49,4 @@ public final class YamlEngine {
public static <T> T unmarshal(final String yamlContent, final Class<T> classType) {
return new Yaml().loadAs(yamlContent, classType);
}
-
- /**
- * Unmarshal YAML.
- *
- * @param prefix config prefix name
- * @param configFileInput YAML file input stream
- * @param classType class type
- * @param <T> type of class
- * @return object from YAML
- */
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static <T> T unmarshal(final String prefix, final InputStream configFileInput, final Class<T> classType) {
- Map<String, Object> configDataMap = new Yaml().loadAs(configFileInput, Map.class);
- if (null != configDataMap && StringUtils.isNotBlank(prefix)) {
- List<String> prefixStrList = Splitter.on(".").trimResults().omitEmptyStrings().splitToList(prefix);
- for (String prefixStr : prefixStrList) {
- Object configData = configDataMap.get(prefixStr);
- if (configData instanceof Map) {
- configDataMap = (Map) configData;
- } else {
- configDataMap = null;
- break;
- }
- }
- }
- if (null != configDataMap) {
- return GsonFactory.getGson().fromJson(GsonFactory.getGson().toJson(configDataMap), classType);
- }
- return null;
- }
}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfiguration.java
similarity index 70%
copy from elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
copy to elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfiguration.java
index 685bdfe..0b2d8bf 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfiguration.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,18 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.infra.yaml.fixture;
+package org.apache.shardingsphere.elasticjob.infra.yaml.config;
-import lombok.Getter;
-import lombok.Setter;
+import java.io.Serializable;
-@Getter
-@Setter
-public final class FooYamlConfiguration {
-
- private String foo;
-
- private String bar;
+/**
+ * YAML configuration.
+ *
+ * @param <T> type of configuration
+ */
+public interface YamlConfiguration<T> extends Serializable {
- private FooYamlConfiguration nest;
+ /**
+ * Convert to original configuration.
+ *
+ * @return configuration
+ */
+ T toConfiguration();
}
diff --git a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverter.java
similarity index 58%
rename from elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java
rename to elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverter.java
index 2042bc0..c15f208 100644
--- a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/tracing/fixture/JobEventCallerTracingStorageConfiguration.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverter.java
@@ -15,21 +15,28 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.tracing.fixture;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
+package org.apache.shardingsphere.elasticjob.infra.yaml.config;
/**
- * {@link TracingStorageConfiguration} for {@link JobEventCaller}.
+ * YAML configuration converter.
+ *
+ * @param <T> type of original configuration object
+ * @param <Y> type of YAML configuration
*/
-@RequiredArgsConstructor
-public final class JobEventCallerTracingStorageConfiguration implements TracingStorageConfiguration<JobEventCaller> {
+public interface YamlConfigurationConverter<T, Y extends YamlConfiguration<T>> {
- private final JobEventCaller jobEventCaller;
+ /**
+ * Convert to YAML configuration.
+ *
+ * @param data data to be converted
+ * @return YAML configuration
+ */
+ Y convertToYamlConfiguration(T data);
- @Override
- public JobEventCaller getStorage() {
- return jobEventCaller;
- }
+ /**
+ * Get type of Configuration.
+ *
+ * @return configuration type
+ */
+ Class<T> configurationType();
}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverterFactory.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverterFactory.java
new file mode 100644
index 0000000..7303894
--- /dev/null
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverterFactory.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.infra.yaml.config;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceLoader;
+
+/**
+ * Factory for {@link YamlConfigurationConverter}.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class YamlConfigurationConverterFactory {
+
+ private static final Map<Class<?>, YamlConfigurationConverter<?, ?>> CONVERTERS = new LinkedHashMap<>();
+
+ static {
+ ServiceLoader.load(YamlConfigurationConverter.class).forEach(each -> CONVERTERS.put(each.configurationType(), each));
+ }
+
+ /**
+ * Find {@link YamlConfigurationConverter} for specific configuration type.
+ *
+ * @param configurationType type of configuration
+ * @param <T> type of configuration
+ * @param <Y> type of YAML configuration
+ * @return converter for specific configuration type
+ */
+ @SuppressWarnings("unchecked")
+ public static <T, Y extends YamlConfiguration<T>> Optional<YamlConfigurationConverter<T, Y>> findConverter(final Class<T> configurationType) {
+ return Optional.ofNullable((YamlConfigurationConverter<T, Y>) CONVERTERS.get(configurationType));
+ }
+}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/exception/YamlConfigurationConverterNotFoundException.java
similarity index 63%
copy from elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
copy to elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/exception/YamlConfigurationConverterNotFoundException.java
index 685bdfe..af2a25d 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/exception/YamlConfigurationConverterNotFoundException.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,18 +15,16 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.infra.yaml.fixture;
-
-import lombok.Getter;
-import lombok.Setter;
+package org.apache.shardingsphere.elasticjob.infra.yaml.exception;
-@Getter
-@Setter
-public final class FooYamlConfiguration {
-
- private String foo;
+/**
+ * Yaml configuration converter not found exception.
+ */
+public final class YamlConfigurationConverterNotFoundException extends RuntimeException {
- private String bar;
+ private static final long serialVersionUID = 664042135874000182L;
- private FooYamlConfiguration nest;
+ public YamlConfigurationConverterNotFoundException(final Class<?> type) {
+ super(String.format("No YamlConfigurationConverter found for class [%s]", type.getName()));
+ }
}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/DefaultYamlTupleProcessor.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/representer/DefaultYamlTupleProcessor.java
similarity index 96%
rename from elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/DefaultYamlTupleProcessor.java
rename to elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/representer/DefaultYamlTupleProcessor.java
index d9d8106..480b5d8 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/DefaultYamlTupleProcessor.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/representer/DefaultYamlTupleProcessor.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.infra.yaml;
+package org.apache.shardingsphere.elasticjob.infra.yaml.representer;
import org.yaml.snakeyaml.nodes.CollectionNode;
import org.yaml.snakeyaml.nodes.MappingNode;
diff --git a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/ElasticJobYamlRepresenter.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/representer/ElasticJobYamlRepresenter.java
similarity index 95%
rename from elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/ElasticJobYamlRepresenter.java
rename to elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/representer/ElasticJobYamlRepresenter.java
index 4c486c8..2cede6b 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/ElasticJobYamlRepresenter.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/yaml/representer/ElasticJobYamlRepresenter.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.infra.yaml;
+package org.apache.shardingsphere.elasticjob.infra.yaml.representer;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.NodeTuple;
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/YamlEngineTest.java b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/YamlEngineTest.java
index 3a3c2f5..53aaff6 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/YamlEngineTest.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/YamlEngineTest.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.elasticjob.infra.yaml;
import org.apache.shardingsphere.elasticjob.infra.yaml.fixture.FooYamlConfiguration;
import org.junit.Test;
-import java.io.InputStream;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
@@ -74,21 +73,4 @@ public final class YamlEngineTest {
assertNull(actual.getBar());
assertNull(actual.getNest());
}
-
- @Test
- public void assertUnmarshalWithPrefix() {
- InputStream configFileInput = Thread.currentThread().getContextClassLoader().getResourceAsStream("yaml-test.yaml");
- FooYamlConfiguration actual = YamlEngine.unmarshal(PREFIX, configFileInput, FooYamlConfiguration.class);
- assertThat(actual.getFoo(), is("nest_foo"));
- assertThat(actual.getBar(), is("nest_bar"));
- assertThat(actual.getNest().getFoo(), is("nest_foo2"));
- assertThat(actual.getNest().getBar(), is("nest_bar2"));
- }
-
- @Test
- public void assertUnmarshalWithPrefixAndNullValue() {
- InputStream configFileInput = Thread.currentThread().getContextClassLoader().getResourceAsStream("yaml-test.yaml");
- FooYamlConfiguration actual = YamlEngine.unmarshal(PREFIX2, configFileInput, FooYamlConfiguration.class);
- assertNull(actual);
- }
}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverterFactoryTest.java
similarity index 64%
copy from elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
copy to elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverterFactoryTest.java
index 685bdfe..e6f4de1 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/config/YamlConfigurationConverterFactoryTest.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,18 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.infra.yaml.fixture;
+package org.apache.shardingsphere.elasticjob.infra.yaml.config;
+
+import org.junit.Test;
-import lombok.Getter;
-import lombok.Setter;
+import static org.junit.Assert.assertFalse;
-@Getter
-@Setter
-public final class FooYamlConfiguration {
+public final class YamlConfigurationConverterFactoryTest {
- private String foo;
+ @Test
+ public void assertConverterNotFound() {
+ assertFalse(YamlConfigurationConverterFactory.findConverter(AClassWithoutCorrespondingConverter.class).isPresent());
+ }
- private String bar;
+ private static class AClassWithoutCorrespondingConverter {
- private FooYamlConfiguration nest;
+ }
}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
index 685bdfe..b158498 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/yaml/fixture/FooYamlConfiguration.java
@@ -7,7 +7,7 @@
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.