You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/05/30 14:36:44 UTC
[skywalking] 01/01: Implement the base of config API module.
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch config-API
in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit eb52169fe341b44cfab7f6a7109b58ca0a13e93b
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Thu May 30 22:36:29 2019 +0800
Implement the base of config API module.
---
.../oal/tool/output/FileGeneratorTest.java | 2 +-
.../oal/tool/parser/DeepAnalysisTest.java | 2 +-
oap-server/pom.xml | 1 +
.../server-configuration/configuration-api/pom.xml | 41 ++++++++++++
.../api/AbstractConfigurationProvider.java | 53 ++++++++++++++++
.../configuration/api/ConfigChangeWatcher.java | 61 ++++++++++++++++++
.../configuration/api/ConfigWatcherRegister.java | 72 ++++++++++++++++++++++
.../configuration/api/ConfigurationModule.java | 42 +++++++++++++
.../api/DynamicConfigurationService.java | 35 +++++++++++
...ywalking.oap.server.library.module.ModuleDefine | 19 ++++++
oap-server/server-configuration/pom.xml | 37 +++++++++++
oap-server/server-core/pom.xml | 5 ++
.../oap/server/core/CoreModuleProvider.java | 3 +-
13 files changed, 370 insertions(+), 3 deletions(-)
diff --git a/oap-server/generate-tool/src/test/java/org/apache/skywalking/oal/tool/output/FileGeneratorTest.java b/oap-server/generate-tool/src/test/java/org/apache/skywalking/oal/tool/output/FileGeneratorTest.java
index 88ce38c..201124c 100644
--- a/oap-server/generate-tool/src/test/java/org/apache/skywalking/oal/tool/output/FileGeneratorTest.java
+++ b/oap-server/generate-tool/src/test/java/org/apache/skywalking/oal/tool/output/FileGeneratorTest.java
@@ -48,7 +48,7 @@ public class FileGeneratorTest {
FilterExpression equalExpression = new FilterExpression();
equalExpression.setExpressionObject("EqualMatch");
- equalExpression.setLeft("source.getName()");
+ equalExpression.setLeft("source.getItemName()");
equalExpression.setRight("\"/service/prod/save\"");
result.addFilterExpressions(equalExpression);
diff --git a/oap-server/generate-tool/src/test/java/org/apache/skywalking/oal/tool/parser/DeepAnalysisTest.java b/oap-server/generate-tool/src/test/java/org/apache/skywalking/oal/tool/parser/DeepAnalysisTest.java
index 0334ae7..5980457 100644
--- a/oap-server/generate-tool/src/test/java/org/apache/skywalking/oal/tool/parser/DeepAnalysisTest.java
+++ b/oap-server/generate-tool/src/test/java/org/apache/skywalking/oal/tool/parser/DeepAnalysisTest.java
@@ -113,7 +113,7 @@ public class DeepAnalysisTest {
Assert.assertEquals(1, filterExpressions.size());
FilterExpression filterExpression = filterExpressions.get(0);
Assert.assertEquals("EqualMatch", filterExpression.getExpressionObject());
- Assert.assertEquals("source.getName()", filterExpression.getLeft());
+ Assert.assertEquals("source.getItemName()", filterExpression.getLeft());
Assert.assertEquals("\"/service/prod/save\"", filterExpression.getRight());
}
}
diff --git a/oap-server/pom.xml b/oap-server/pom.xml
index 6c4948c..f6e4752 100644
--- a/oap-server/pom.xml
+++ b/oap-server/pom.xml
@@ -42,6 +42,7 @@
<module>server-telemetry</module>
<module>generate-tool-grammar</module>
<module>exporter</module>
+ <module>server-configuration</module>
</modules>
<properties>
diff --git a/oap-server/server-configuration/configuration-api/pom.xml b/oap-server/server-configuration/configuration-api/pom.xml
new file mode 100644
index 0000000..e65a115
--- /dev/null
+++ b/oap-server/server-configuration/configuration-api/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ ~
+ -->
+
+<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">
+ <parent>
+ <artifactId>server-configuration</artifactId>
+ <groupId>org.apache.skywalking</groupId>
+ <version>6.2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>configuration-api</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
+ <artifactId>library-module</artifactId>
+ <version>6.2.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+
+</project>
\ No newline at end of file
diff --git a/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/AbstractConfigurationProvider.java b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/AbstractConfigurationProvider.java
new file mode 100644
index 0000000..f5c6ff6
--- /dev/null
+++ b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/AbstractConfigurationProvider.java
@@ -0,0 +1,53 @@
+/*
+ * 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.skywalking.oap.server.configuration.api;
+
+import org.apache.skywalking.oap.server.library.module.*;
+
+/**
+ * The recommendation default base implementor of Configuration module. The real implementor could extend this provider
+ * to make a new one, easily.
+ *
+ * @author wusheng
+ */
+public abstract class AbstractConfigurationProvider extends ModuleProvider {
+ private ConfigWatcherRegister configWatcherRegister;
+
+ @Override public Class<? extends ModuleDefine> module() {
+ return ConfigurationModule.class;
+ }
+
+ @Override public void prepare() throws ServiceNotProvidedException, ModuleStartException {
+ configWatcherRegister = new ConfigWatcherRegister();
+ this.registerServiceImplementation(DynamicConfigurationService.class, configWatcherRegister);
+ }
+
+ @Override public void start() throws ServiceNotProvidedException, ModuleStartException {
+
+ }
+
+ @Override public void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException {
+ configWatcherRegister.start();
+ }
+
+ @Override public String[] requiredModules() {
+ return new String[0];
+ }
+
+}
diff --git a/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigChangeWatcher.java b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigChangeWatcher.java
new file mode 100644
index 0000000..03c1809
--- /dev/null
+++ b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigChangeWatcher.java
@@ -0,0 +1,61 @@
+/*
+ * 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.skywalking.oap.server.configuration.api;
+
+import lombok.Getter;
+import org.apache.skywalking.oap.server.library.module.*;
+
+/**
+ * ConfigChangeWatcher represents a watcher implementor,
+ * it will be called when the target value changed.
+ *
+ * @author wusheng
+ */
+@Getter
+public abstract class ConfigChangeWatcher {
+ private final ModuleDefine module;
+ private final ModuleProvider provider;
+ private final String itemName;
+
+ public ConfigChangeWatcher(ModuleDefine module, ModuleProvider provider, String itemName) {
+ this.module = module;
+ this.provider = provider;
+ this.itemName = itemName;
+ }
+
+ /**
+ * Notify the watcher, the new value received.
+ *
+ * @param value of new.
+ */
+ public abstract void notify(String value);
+
+ /**
+ * @return current value of current config.
+ */
+ public abstract String value();
+
+ @Override public String toString() {
+ return "ConfigChangeWatcher{" +
+ "module=" + module +
+ ", provider=" + provider +
+ ", itemName='" + itemName + '\'' +
+ '}';
+ }
+}
diff --git a/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java
new file mode 100644
index 0000000..a39263c
--- /dev/null
+++ b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigWatcherRegister.java
@@ -0,0 +1,72 @@
+/*
+ * 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.skywalking.oap.server.configuration.api;
+
+import java.util.*;
+import java.util.concurrent.*;
+import lombok.Getter;
+import org.apache.skywalking.apm.util.RunnableWithExceptionProtection;
+import org.slf4j.*;
+
+/**
+ * The default implementor of Config Watcher register.
+ *
+ * @author wusheng
+ */
+public class ConfigWatcherRegister implements DynamicConfigurationService {
+ private static final Logger logger = LoggerFactory.getLogger(ConfigWatcherRegister.class);
+
+ private Map<String, WatcherHolder> register = new HashMap<>();
+ private volatile boolean isStarted = false;
+
+ @Override synchronized public void registerConfigChangeWatcher(ConfigChangeWatcher watcher) {
+ if (isStarted) {
+ throw new IllegalStateException("Config Register has been started. Can't register new watcher.");
+ }
+
+ WatcherHolder holder = new WatcherHolder(watcher);
+ if (register.containsKey(holder.getKey())) {
+ throw new IllegalStateException("Duplicate register, watcher=" + watcher);
+ }
+ register.put(holder.getKey(), holder);
+ }
+
+ public void start() {
+ isStarted = true;
+
+ Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(
+ new RunnableWithExceptionProtection(() -> sync(),
+ t -> logger.error("Sync config center error.", t)), 1, 60, TimeUnit.SECONDS);
+ }
+
+ private void sync() {
+
+ }
+
+ @Getter
+ private class WatcherHolder {
+ private ConfigChangeWatcher watcher;
+ private final String key;
+
+ public WatcherHolder(ConfigChangeWatcher watcher) {
+ this.watcher = watcher;
+ this.key = String.join("-", watcher.getModule().name(), watcher.getProvider().name(), watcher.getItemName());
+ }
+ }
+}
diff --git a/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigurationModule.java b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigurationModule.java
new file mode 100644
index 0000000..f0f55a4
--- /dev/null
+++ b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/ConfigurationModule.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.skywalking.oap.server.configuration.api;
+
+import org.apache.skywalking.oap.server.library.module.ModuleDefine;
+
+/**
+ * Configuration Module sync the settings from remote service, the remote service could be implemented by this module
+ * provider.
+ *
+ * Any configuration item in the whole OAP backend could register a watcher to configuration module, the item change
+ * watcher will be called, if the value changed.
+ *
+ * @author wusheng
+ */
+public class ConfigurationModule extends ModuleDefine {
+ public static final String NAME = "configuration";
+
+ public ConfigurationModule() {
+ super(NAME);
+ }
+
+ @Override public Class[] services() {
+ return new Class[] {DynamicConfigurationService.class};
+ }
+}
diff --git a/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/DynamicConfigurationService.java b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/DynamicConfigurationService.java
new file mode 100644
index 0000000..a70c270
--- /dev/null
+++ b/oap-server/server-configuration/configuration-api/src/main/java/org/apache/skywalking/oap/server/configuration/api/DynamicConfigurationService.java
@@ -0,0 +1,35 @@
+/*
+ * 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.skywalking.oap.server.configuration.api;
+
+import org.apache.skywalking.oap.server.library.module.*;
+
+/**
+ * DynamicConfigurationService provides API to register config change watcher.
+ *
+ * @author wusheng
+ */
+public interface DynamicConfigurationService extends Service {
+ /**
+ * Register a watcher to the target value
+ *
+ * @param watcher to register
+ */
+ void registerConfigChangeWatcher(ConfigChangeWatcher watcher);
+}
diff --git a/oap-server/server-configuration/configuration-api/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine b/oap-server/server-configuration/configuration-api/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine
new file mode 100644
index 0000000..0353b08
--- /dev/null
+++ b/oap-server/server-configuration/configuration-api/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+#
+
+org.apache.skywalking.oap.server.configuration.api.ConfigurationModule
\ No newline at end of file
diff --git a/oap-server/server-configuration/pom.xml b/oap-server/server-configuration/pom.xml
new file mode 100644
index 0000000..a759bf7
--- /dev/null
+++ b/oap-server/server-configuration/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ ~
+ -->
+
+<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">
+ <parent>
+ <artifactId>oap-server</artifactId>
+ <groupId>org.apache.skywalking</groupId>
+ <version>6.2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>server-configuration</artifactId>
+ <packaging>pom</packaging>
+ <modules>
+ <module>configuration-api</module>
+ </modules>
+
+
+</project>
\ No newline at end of file
diff --git a/oap-server/server-core/pom.xml b/oap-server/server-core/pom.xml
index a66eba2..047de59 100644
--- a/oap-server/server-core/pom.xml
+++ b/oap-server/server-core/pom.xml
@@ -46,6 +46,11 @@
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
+ <artifactId>configuration-api</artifactId>
+ <version>6.2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
<artifactId>library-util</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java
index 9b443d6..b4b6267 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java
@@ -19,6 +19,7 @@
package org.apache.skywalking.oap.server.core;
import java.io.IOException;
+import org.apache.skywalking.oap.server.configuration.api.ConfigurationModule;
import org.apache.skywalking.oap.server.core.analysis.*;
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
import org.apache.skywalking.oap.server.core.cache.*;
@@ -188,6 +189,6 @@ public class CoreModuleProvider extends ModuleProvider {
@Override
public String[] requiredModules() {
- return new String[] {TelemetryModule.NAME};
+ return new String[] {TelemetryModule.NAME, ConfigurationModule.NAME};
}
}