From 62ca37bc8f9f80140d1efa01fcd794495866ea99 Mon Sep 17 00:00:00 2001 From: Wu Sheng Date: Fri, 20 Jul 2018 11:40:00 +0800 Subject: [PATCH] Refactor codebases for v6, restore modulization back --- .../ClusterModuleStandaloneProvider.java | 20 +++--- .../plugin/standalone/StandaloneManager.java | 52 +++++++++++++++ .../standalone/StandaloneModuleRegister.java | 38 ----------- .../plugin/standalone/StandaloneRegister.java | 32 --------- .../standalone/StandaloneServiceManager.java | 42 ------------ .../standalone/StandaloneManagerTest.java} | 30 ++++----- .../ClusterModuleZookeeperProvider.java | 50 +++++++++----- .../zookeeper/SWInstanceSerializer.java | 10 +-- .../plugin/zookeeper/ServiceCacheManager.java | 44 ------------- .../zookeeper/ZookeeperModuleQuery.java | 21 +++--- .../zookeeper/ZookeeperModuleRegister.java | 66 ------------------- .../zookeeper/ZookeeperNodeRegister.java | 60 +++++++++++++++++ ...lusterModuleZookeeperProviderTestCase.java | 42 ++++++++---- .../oap/server/core/CoreModuleProvider.java | 38 ++++++----- .../server/core/cluster/ClusterModule.java | 2 +- ...oduleQuery.java => ClusterNodesQuery.java} | 4 +- ...duleRegister.java => ClusterRegister.java} | 5 +- ...stanceDetails.java => RemoteInstance.java} | 11 +--- ...ing.oap.server.library.module.ModuleDefine | 21 ++++++ .../server/library/module/BootstrapFlow.java | 2 +- .../server/library/module/ModuleDefine.java | 2 +- .../server/library/module/ModuleProvider.java | 4 +- .../config/ApplicationConfigLoader.java | 26 -------- .../src/main/resources/application.yml | 17 ++--- 24 files changed, 274 insertions(+), 365 deletions(-) create mode 100644 oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneManager.java delete mode 100644 oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneModuleRegister.java delete mode 100644 oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneRegister.java delete mode 100644 oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneServiceManager.java rename oap-server/server-cluster-plugin/cluster-standalone-plugin/src/{main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneModuleQuery.java => test/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneManagerTest.java} (58%) delete mode 100644 oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ServiceCacheManager.java delete mode 100644 oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperModuleRegister.java create mode 100644 oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperNodeRegister.java rename oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/{ModuleQuery.java => ClusterNodesQuery.java} (86%) rename oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/{ModuleRegister.java => ClusterRegister.java} (84%) rename oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/{InstanceDetails.java => RemoteInstance.java} (83%) create mode 100644 oap-server/server-core/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine diff --git a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/ClusterModuleStandaloneProvider.java b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/ClusterModuleStandaloneProvider.java index a6f4bef338..a861e3efa5 100644 --- a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/ClusterModuleStandaloneProvider.java +++ b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/ClusterModuleStandaloneProvider.java @@ -18,9 +18,15 @@ package org.apache.skywalking.oap.server.cluster.plugin.standalone; -import org.apache.skywalking.oap.server.core.cluster.*; -import org.apache.skywalking.oap.server.library.module.*; -import org.slf4j.*; +import org.apache.skywalking.oap.server.core.cluster.ClusterModule; +import org.apache.skywalking.oap.server.core.cluster.ClusterNodesQuery; +import org.apache.skywalking.oap.server.core.cluster.ClusterRegister; +import org.apache.skywalking.oap.server.library.module.ModuleConfig; +import org.apache.skywalking.oap.server.library.module.ModuleProvider; +import org.apache.skywalking.oap.server.library.module.ModuleStartException; +import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author peng-yongsheng @@ -29,11 +35,8 @@ public class ClusterModuleStandaloneProvider extends ModuleProvider { private static final Logger logger = LoggerFactory.getLogger(ClusterModuleStandaloneProvider.class); - private final StandaloneServiceManager serviceManager; - public ClusterModuleStandaloneProvider() { super(); - this.serviceManager = new StandaloneServiceManager(); } @Override public String name() { @@ -49,8 +52,9 @@ public class ClusterModuleStandaloneProvider extends ModuleProvider { } @Override public void prepare() throws ServiceNotProvidedException { - this.registerServiceImplementation(ModuleRegister.class, new StandaloneModuleRegister(serviceManager)); - this.registerServiceImplementation(ModuleQuery.class, new StandaloneModuleQuery(serviceManager)); + StandaloneManager standaloneManager = new StandaloneManager(); + this.registerServiceImplementation(ClusterRegister.class, standaloneManager); + this.registerServiceImplementation(ClusterNodesQuery.class, standaloneManager); } @Override public void start() throws ModuleStartException { diff --git a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneManager.java b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneManager.java new file mode 100644 index 0000000000..c266eb4e5c --- /dev/null +++ b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneManager.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.skywalking.oap.server.cluster.plugin.standalone; + +import org.apache.skywalking.oap.server.core.cluster.ClusterNodesQuery; +import org.apache.skywalking.oap.server.core.cluster.ClusterRegister; +import org.apache.skywalking.oap.server.core.cluster.RemoteInstance; + +import java.util.ArrayList; +import java.util.List; + +/** + * A cluster manager simulator. Work in memory only. + * Also return the current instance. + * + * @author peng-yongsheng, Wu Sheng + */ +public class StandaloneManager implements ClusterNodesQuery, ClusterRegister { + + private volatile RemoteInstance remoteInstance; + + + @Override public void registerRemote(RemoteInstance remoteInstance) { + this.remoteInstance = remoteInstance; + } + + @Override + public List queryRemoteNodes() { + if(remoteInstance == null){ + return new ArrayList(0); + } + ArrayList remoteList = new ArrayList(1); + remoteList.add(remoteInstance); + return remoteList; + } +} diff --git a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneModuleRegister.java b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneModuleRegister.java deleted file mode 100644 index bb9241d4e9..0000000000 --- a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneModuleRegister.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.cluster.plugin.standalone; - -import org.apache.skywalking.oap.server.core.cluster.*; - -/** - * @author peng-yongsheng - */ -public class StandaloneModuleRegister implements ModuleRegister { - - private final StandaloneServiceManager serviceManager; - - StandaloneModuleRegister(StandaloneServiceManager serviceManager) { - this.serviceManager = serviceManager; - } - - @Override public void register(String moduleName, String providerName, - InstanceDetails instanceDetails) { - serviceManager.put(moduleName, providerName, instanceDetails); - } -} diff --git a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneRegister.java b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneRegister.java deleted file mode 100644 index 7f923fa997..0000000000 --- a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneRegister.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.cluster.plugin.standalone; - -import org.apache.skywalking.oap.server.core.cluster.*; - -/** - * @author peng-yongsheng - */ -public class StandaloneRegister implements ModuleRegister { - - @Override public void register(String moduleName, String providerName, - InstanceDetails instanceDetails) throws ServiceRegisterException { - - } -} diff --git a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneServiceManager.java b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneServiceManager.java deleted file mode 100644 index fe5fe1d89d..0000000000 --- a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneServiceManager.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.cluster.plugin.standalone; - -import java.util.*; -import org.apache.skywalking.oap.server.core.cluster.InstanceDetails; - -/** - * @author peng-yongsheng - */ -public class StandaloneServiceManager { - - private final Map instanceDetailsMap; - - public StandaloneServiceManager() { - this.instanceDetailsMap = new HashMap<>(); - } - - public void put(String moduleName, String providerName, InstanceDetails instanceDetails) { - instanceDetailsMap.put(moduleName + "/" + providerName, instanceDetails); - } - - public InstanceDetails get(String moduleName, String providerName) { - return instanceDetailsMap.get(moduleName + "/" + providerName); - } -} diff --git a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneModuleQuery.java b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneManagerTest.java similarity index 58% rename from oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneModuleQuery.java rename to oap-server/server-cluster-plugin/cluster-standalone-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneManagerTest.java index cc0b326f96..2679492901 100644 --- a/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneModuleQuery.java +++ b/oap-server/server-cluster-plugin/cluster-standalone-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/standalone/StandaloneManagerTest.java @@ -18,24 +18,20 @@ package org.apache.skywalking.oap.server.cluster.plugin.standalone; -import java.util.*; -import org.apache.skywalking.oap.server.core.cluster.*; +import org.apache.skywalking.oap.server.core.cluster.RemoteInstance; +import org.junit.Assert; +import org.junit.Test; -/** - * @author peng-yongsheng - */ -public class StandaloneModuleQuery implements ModuleQuery { - - private final StandaloneServiceManager serviceManager; - - StandaloneModuleQuery(StandaloneServiceManager serviceManager) { - this.serviceManager = serviceManager; - } +public class StandaloneManagerTest { + @Test + public void test(){ + StandaloneManager standaloneManager = new StandaloneManager(); + RemoteInstance remote1 = new RemoteInstance(); + RemoteInstance remote2 = new RemoteInstance(); - @Override - public List query(String moduleName, String providerName) { - List instanceDetails = new ArrayList<>(1); - instanceDetails.add(serviceManager.get(moduleName, providerName)); - return instanceDetails; + standaloneManager.registerRemote(remote1); + Assert.assertEquals(remote1, standaloneManager.queryRemoteNodes().get(0)); + standaloneManager.registerRemote(remote2); + Assert.assertEquals(remote2, standaloneManager.queryRemoteNodes().get(0)); } } diff --git a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperProvider.java b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperProvider.java index 0c52a81be5..0cfa3d5b34 100644 --- a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperProvider.java +++ b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperProvider.java @@ -19,15 +19,27 @@ package org.apache.skywalking.oap.server.cluster.plugin.zookeeper; import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.*; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.curator.x.discovery.*; -import org.apache.skywalking.oap.server.core.cluster.*; -import org.apache.skywalking.oap.server.library.module.*; -import org.slf4j.*; +import org.apache.curator.x.discovery.ServiceCache; +import org.apache.curator.x.discovery.ServiceDiscovery; +import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; +import org.apache.skywalking.oap.server.core.cluster.ClusterModule; +import org.apache.skywalking.oap.server.core.cluster.ClusterNodesQuery; +import org.apache.skywalking.oap.server.core.cluster.ClusterRegister; +import org.apache.skywalking.oap.server.core.cluster.RemoteInstance; +import org.apache.skywalking.oap.server.library.module.ModuleConfig; +import org.apache.skywalking.oap.server.library.module.ModuleProvider; +import org.apache.skywalking.oap.server.library.module.ModuleStartException; +import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * @author peng-yongsheng + * Use Zookeeper to manage all instances in SkyWalking cluster. + * + * @author peng-yongsheng, Wu Sheng */ public class ClusterModuleZookeeperProvider extends ModuleProvider { @@ -35,15 +47,13 @@ public class ClusterModuleZookeeperProvider extends ModuleProvider { private static final String BASE_PATH = "/skywalking"; - private final ServiceCacheManager cacheManager; private final ClusterModuleZookeeperConfig config; private CuratorFramework client; - private ServiceDiscovery serviceDiscovery; + private ServiceDiscovery serviceDiscovery; public ClusterModuleZookeeperProvider() { super(); this.config = new ClusterModuleZookeeperConfig(); - this.cacheManager = new ServiceCacheManager(); } @Override public String name() { @@ -58,27 +68,35 @@ public class ClusterModuleZookeeperProvider extends ModuleProvider { return config; } - @Override public void prepare() throws ServiceNotProvidedException { + @Override public void prepare() throws ServiceNotProvidedException, ModuleStartException { RetryPolicy retryPolicy = new ExponentialBackoffRetry(config.getBaseSleepTimeMs(), config.getMaxRetries()); client = CuratorFrameworkFactory.newClient(config.getHostPort(), retryPolicy); - serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class).client(client) + serviceDiscovery = ServiceDiscoveryBuilder.builder(RemoteInstance.class).client(client) .basePath(BASE_PATH) .watchInstances(true) .serializer(new SWInstanceSerializer()).build(); - this.registerServiceImplementation(ModuleRegister.class, new ZookeeperModuleRegister(serviceDiscovery, cacheManager)); - this.registerServiceImplementation(ModuleQuery.class, new ZookeeperModuleQuery(cacheManager)); - } - - @Override public void start() throws ModuleStartException { + String remoteName = "remote"; + ServiceCache serviceCache = serviceDiscovery.serviceCacheBuilder() + .name(remoteName) + .build(); try { client.start(); client.blockUntilConnected(); serviceDiscovery.start(); + + serviceCache.start(); } catch (Exception e) { + logger.error(e.getMessage(), e); throw new ModuleStartException(e.getMessage(), e); } + + this.registerServiceImplementation(ClusterRegister.class, new ZookeeperNodeRegister(serviceDiscovery, remoteName)); + this.registerServiceImplementation(ClusterNodesQuery.class, new ZookeeperModuleQuery(serviceCache)); + } + + @Override public void start() { } @Override public void notifyAfterCompleted() { diff --git a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/SWInstanceSerializer.java b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/SWInstanceSerializer.java index 76b59b52fb..3b86f9de3c 100644 --- a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/SWInstanceSerializer.java +++ b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/SWInstanceSerializer.java @@ -22,21 +22,21 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import org.apache.curator.x.discovery.ServiceInstance; import org.apache.curator.x.discovery.details.InstanceSerializer; -import org.apache.skywalking.oap.server.core.cluster.InstanceDetails; +import org.apache.skywalking.oap.server.core.cluster.RemoteInstance; /** * @author peng-yongsheng */ -public class SWInstanceSerializer implements InstanceSerializer { +public class SWInstanceSerializer implements InstanceSerializer { private final Gson gson = new Gson(); - @Override public byte[] serialize(ServiceInstance instance) throws Exception { + @Override public byte[] serialize(ServiceInstance instance) throws Exception { return gson.toJson(instance).getBytes(); } - @Override public ServiceInstance deserialize(byte[] bytes) throws Exception { - return gson.fromJson(new String(bytes), new TypeToken>() { + @Override public ServiceInstance deserialize(byte[] bytes) throws Exception { + return gson.fromJson(new String(bytes), new TypeToken>() { }.getType()); } } diff --git a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ServiceCacheManager.java b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ServiceCacheManager.java deleted file mode 100644 index e08a01bbd1..0000000000 --- a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ServiceCacheManager.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.cluster.plugin.zookeeper; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import org.apache.curator.x.discovery.ServiceCache; -import org.apache.skywalking.oap.server.core.cluster.InstanceDetails; - -/** - * @author peng-yongsheng - */ -public class ServiceCacheManager { - - private final Map> serviceCacheMap; - - public ServiceCacheManager() { - this.serviceCacheMap = new ConcurrentHashMap<>(); - } - - public void put(String name, ServiceCache cache) { - serviceCacheMap.put(name, cache); - } - - public ServiceCache get(String name) { - return serviceCacheMap.get(name); - } -} diff --git a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperModuleQuery.java b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperModuleQuery.java index 7dd93e86ca..7a41531a18 100644 --- a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperModuleQuery.java +++ b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperModuleQuery.java @@ -19,26 +19,27 @@ package org.apache.skywalking.oap.server.cluster.plugin.zookeeper; import java.util.*; +import org.apache.curator.x.discovery.ServiceCache; import org.apache.curator.x.discovery.ServiceInstance; import org.apache.skywalking.oap.server.core.cluster.*; /** - * @author peng-yongsheng + * @author peng-yongsheng, Wu Sheng */ -public class ZookeeperModuleQuery implements ModuleQuery { +public class ZookeeperModuleQuery implements ClusterNodesQuery { - private final ServiceCacheManager cacheManager; + private final ServiceCache serviceCache; - ZookeeperModuleQuery(ServiceCacheManager cacheManager) { - this.cacheManager = cacheManager; + ZookeeperModuleQuery(ServiceCache serviceCache) { + this.serviceCache = serviceCache; } @Override - public List query(String moduleName, String providerName) throws ServiceRegisterException { - List> serviceInstances = cacheManager.get(NodeNameBuilder.build(moduleName, providerName)).getInstances(); + public List queryRemoteNodes() throws ServiceRegisterException { + List> serviceInstances = serviceCache.getInstances(); - List instanceDetails = new ArrayList<>(serviceInstances.size()); - serviceInstances.forEach(serviceInstance -> instanceDetails.add(serviceInstance.getPayload())); - return instanceDetails; + List remoteInstanceDetails = new ArrayList<>(serviceInstances.size()); + serviceInstances.forEach(serviceInstance -> remoteInstanceDetails.add(serviceInstance.getPayload())); + return remoteInstanceDetails; } } diff --git a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperModuleRegister.java b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperModuleRegister.java deleted file mode 100644 index ede5fbdaac..0000000000 --- a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperModuleRegister.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.cluster.plugin.zookeeper; - -import java.util.UUID; -import org.apache.curator.x.discovery.*; -import org.apache.skywalking.oap.server.core.cluster.*; - -/** - * @author peng-yongsheng - */ -public class ZookeeperModuleRegister implements ModuleRegister { - - private final ServiceDiscovery serviceDiscovery; - private final ServiceCacheManager cacheManager; - - ZookeeperModuleRegister(ServiceDiscovery serviceDiscovery, - ServiceCacheManager cacheManager) { - this.serviceDiscovery = serviceDiscovery; - this.cacheManager = cacheManager; - } - - @Override public synchronized void register(String moduleName, String providerName, - InstanceDetails instanceDetails) throws ServiceRegisterException { - try { - String name = NodeNameBuilder.build(moduleName, providerName); - - ServiceInstance thisInstance = ServiceInstance.builder() - .name(NodeNameBuilder.build(moduleName, providerName)) - .id(UUID.randomUUID().toString()) - .address(instanceDetails.getHost()) - .port(instanceDetails.getPort()) -// .uriSpec(new UriSpec(StringUtils.isEmpty(instanceDetails.getContextPath()) ? StringUtils.EMPTY_STRING : instanceDetails.getContextPath())) - .payload(instanceDetails) - .build(); - - serviceDiscovery.registerService(thisInstance); - - ServiceCache serviceCache = serviceDiscovery.serviceCacheBuilder() - .name(name) - .build(); - serviceCache.start(); - - cacheManager.put(name, serviceCache); - } catch (Exception e) { - e.printStackTrace(); - throw new ServiceRegisterException(e.getMessage()); - } - } -} diff --git a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperNodeRegister.java b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperNodeRegister.java new file mode 100644 index 0000000000..ba6b518130 --- /dev/null +++ b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/main/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ZookeeperNodeRegister.java @@ -0,0 +1,60 @@ +/* + * 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.cluster.plugin.zookeeper; + +import java.util.UUID; +import org.apache.curator.x.discovery.ServiceDiscovery; +import org.apache.curator.x.discovery.ServiceInstance; +import org.apache.skywalking.oap.server.core.cluster.ClusterRegister; +import org.apache.skywalking.oap.server.core.cluster.RemoteInstance; +import org.apache.skywalking.oap.server.core.cluster.ServiceRegisterException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ZookeeperNodeRegister implements ClusterRegister { + private static final Logger logger = LoggerFactory.getLogger(ZookeeperNodeRegister.class); + + private final ServiceDiscovery serviceDiscovery; + private final String nodeName; + + ZookeeperNodeRegister(ServiceDiscovery serviceDiscovery, String nodeName) { + this.serviceDiscovery = serviceDiscovery; + this.nodeName = nodeName; + } + + @Override public synchronized void registerRemote(RemoteInstance remoteInstance) throws ServiceRegisterException { + try { + ServiceInstance thisInstance = ServiceInstance.builder() + .name(nodeName) + .id(UUID.randomUUID().toString()) + .address(remoteInstance.getHost()) + .port(remoteInstance.getPort()) + .payload(remoteInstance) + .build(); + + serviceDiscovery.registerService(thisInstance); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new ServiceRegisterException(e.getMessage()); + } + } +} diff --git a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperProviderTestCase.java b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperProviderTestCase.java index 218ecccd23..fafd1275eb 100644 --- a/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperProviderTestCase.java +++ b/oap-server/server-cluster-plugin/cluster-zookeeper-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper/ClusterModuleZookeeperProviderTestCase.java @@ -21,9 +21,16 @@ package org.apache.skywalking.oap.server.cluster.plugin.zookeeper; import java.io.IOException; import java.util.List; import org.apache.curator.test.TestingServer; -import org.apache.skywalking.oap.server.core.cluster.*; -import org.apache.skywalking.oap.server.library.module.*; -import org.junit.*; +import org.apache.skywalking.oap.server.core.cluster.ClusterNodesQuery; +import org.apache.skywalking.oap.server.core.cluster.ClusterRegister; +import org.apache.skywalking.oap.server.core.cluster.RemoteInstance; +import org.apache.skywalking.oap.server.core.cluster.ServiceRegisterException; +import org.apache.skywalking.oap.server.library.module.ModuleStartException; +import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; /** * @author peng-yongsheng @@ -39,7 +46,7 @@ public class ClusterModuleZookeeperProviderTestCase { } @Test - public void testStart() throws ServiceNotProvidedException, ModuleStartException, ServiceRegisterException { + public void testStart() throws ServiceNotProvidedException, ModuleStartException, ServiceRegisterException, InterruptedException { ClusterModuleZookeeperProvider provider = new ClusterModuleZookeeperProvider(); ClusterModuleZookeeperConfig moduleConfig = (ClusterModuleZookeeperConfig)provider.createConfigBeanIfAbsent(); moduleConfig.setHostPort(server.getConnectString()); @@ -49,19 +56,26 @@ public class ClusterModuleZookeeperProviderTestCase { provider.prepare(); provider.start(); - ModuleRegister moduleRegister = provider.getService(ModuleRegister.class); - ModuleQuery moduleQuery = provider.getService(ModuleQuery.class); + ClusterRegister moduleRegister = provider.getService(ClusterRegister.class); + ClusterNodesQuery clusterNodesQuery = provider.getService(ClusterNodesQuery.class); - InstanceDetails instanceDetails = new InstanceDetails(); - instanceDetails.setHost("ProviderAHost"); - instanceDetails.setPort(1000); + RemoteInstance remoteInstance = new RemoteInstance(); + remoteInstance.setHost("ProviderAHost"); + remoteInstance.setPort(1000); - moduleRegister.register("ModuleA", "ProviderA", instanceDetails); + moduleRegister.registerRemote(remoteInstance); + + for (int i = 0; i < 20; i++) { + List detailsList = clusterNodesQuery.queryRemoteNodes(); + if(detailsList.size() == 0){ + Thread.sleep(500); + continue; + } + Assert.assertEquals(1, detailsList.size()); + Assert.assertEquals("ProviderAHost", detailsList.get(0).getHost()); + Assert.assertEquals(1000, detailsList.get(0).getPort()); + } - List detailsList = moduleQuery.query("ModuleA", "ProviderA"); - Assert.assertEquals(1, detailsList.size()); - Assert.assertEquals("ProviderAHost", detailsList.get(0).getHost()); - Assert.assertEquals(1000, detailsList.get(0).getPort()); } @After 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 6a8ca4f5ef..f58f2073e7 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 @@ -18,14 +18,24 @@ package org.apache.skywalking.oap.server.core; -import org.apache.skywalking.oap.server.core.cluster.*; -import org.apache.skywalking.oap.server.core.receiver.*; -import org.apache.skywalking.oap.server.core.server.*; -import org.apache.skywalking.oap.server.library.module.*; +import org.apache.skywalking.oap.server.core.cluster.ClusterModule; +import org.apache.skywalking.oap.server.core.cluster.ClusterRegister; +import org.apache.skywalking.oap.server.core.cluster.RemoteInstance; +import org.apache.skywalking.oap.server.core.receiver.SourceReceiver; +import org.apache.skywalking.oap.server.core.receiver.SourceReceiverImpl; +import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister; +import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegisterImpl; +import org.apache.skywalking.oap.server.core.server.JettyHandlerRegister; +import org.apache.skywalking.oap.server.core.server.JettyHandlerRegisterImpl; +import org.apache.skywalking.oap.server.library.module.ModuleConfig; +import org.apache.skywalking.oap.server.library.module.ModuleProvider; +import org.apache.skywalking.oap.server.library.module.ModuleStartException; +import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; import org.apache.skywalking.oap.server.library.server.ServerException; import org.apache.skywalking.oap.server.library.server.grpc.GRPCServer; import org.apache.skywalking.oap.server.library.server.jetty.JettyServer; -import org.slf4j.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author peng-yongsheng @@ -68,26 +78,22 @@ public class CoreModuleProvider extends ModuleProvider { this.registerServiceImplementation(SourceReceiver.class, new SourceReceiverImpl()); } - @Override public void start() throws ModuleStartException { + @Override public void start() { + + } + + @Override public void notifyAfterCompleted() throws ModuleStartException{ try { grpcServer.start(); jettyServer.start(); } catch (ServerException e) { throw new ModuleStartException(e.getMessage(), e); } - } - @Override public void notifyAfterCompleted() { - InstanceDetails gRPCServerInstance = new InstanceDetails(); + RemoteInstance gRPCServerInstance = new RemoteInstance(); gRPCServerInstance.setHost(moduleConfig.getGRPCHost()); gRPCServerInstance.setPort(moduleConfig.getGRPCPort()); - this.getManager().find(ClusterModule.NAME).getService(ModuleRegister.class).register(CoreModule.NAME, "gRPC", gRPCServerInstance); - - InstanceDetails restServerInstance = new InstanceDetails(); - restServerInstance.setHost(moduleConfig.getRestHost()); - restServerInstance.setPort(moduleConfig.getRestPort()); - restServerInstance.setContextPath(moduleConfig.getRestContextPath()); - this.getManager().find(ClusterModule.NAME).getService(ModuleRegister.class).register(CoreModule.NAME, "rest", restServerInstance); + this.getManager().find(ClusterModule.NAME).getService(ClusterRegister.class).registerRemote(gRPCServerInstance); } @Override diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterModule.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterModule.java index 992ed10d49..a4499dcbdb 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterModule.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterModule.java @@ -32,6 +32,6 @@ public class ClusterModule extends ModuleDefine { } @Override public Class[] services() { - return new Class[] {ModuleRegister.class, ModuleQuery.class}; + return new Class[] {ClusterRegister.class, ClusterNodesQuery.class}; } } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ModuleQuery.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterNodesQuery.java similarity index 86% rename from oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ModuleQuery.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterNodesQuery.java index d44532adf2..a7c0d82d0a 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ModuleQuery.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterNodesQuery.java @@ -25,7 +25,7 @@ import java.util.List; /** * @author peng-yongsheng */ -public interface ModuleQuery extends Service { +public interface ClusterNodesQuery extends Service { - List query(String moduleName, String providerName) throws ServiceRegisterException; + List queryRemoteNodes(); } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ModuleRegister.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterRegister.java similarity index 84% rename from oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ModuleRegister.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterRegister.java index e3cdb0e6eb..3e5a8c2d05 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ModuleRegister.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/ClusterRegister.java @@ -23,8 +23,7 @@ import org.apache.skywalking.oap.server.library.module.Service; /** * @author peng-yongsheng */ -public interface ModuleRegister extends Service { +public interface ClusterRegister extends Service { - void register(String moduleName, String providerName, - InstanceDetails instanceDetails) throws ServiceRegisterException; + void registerRemote(RemoteInstance remoteInstance) throws ServiceRegisterException; } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/InstanceDetails.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/RemoteInstance.java similarity index 83% rename from oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/InstanceDetails.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/RemoteInstance.java index a4f8dc260b..14018e197b 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/InstanceDetails.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cluster/RemoteInstance.java @@ -21,11 +21,10 @@ package org.apache.skywalking.oap.server.core.cluster; /** * @author peng-yongsheng */ -public class InstanceDetails { +public class RemoteInstance { private String host; private int port; - private String contextPath; public String getHost() { return host; @@ -42,12 +41,4 @@ public class InstanceDetails { public void setPort(int port) { this.port = port; } - - public String getContextPath() { - return contextPath; - } - - public void setContextPath(String contextPath) { - this.contextPath = contextPath; - } } diff --git a/oap-server/server-core/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine b/oap-server/server-core/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine new file mode 100644 index 0000000000..d0a876f7cf --- /dev/null +++ b/oap-server/server-core/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine @@ -0,0 +1,21 @@ +# +# 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.core.storage.StorageModule +org.apache.skywalking.oap.server.core.cluster.ClusterModule +org.apache.skywalking.oap.server.core.CoreModule \ No newline at end of file diff --git a/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/BootstrapFlow.java b/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/BootstrapFlow.java index 187575f486..e41e2bea85 100644 --- a/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/BootstrapFlow.java +++ b/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/BootstrapFlow.java @@ -63,7 +63,7 @@ class BootstrapFlow { } } - void notifyAfterCompleted() throws ServiceNotProvidedException { + void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException { for (ModuleProvider provider : startupSequence) { provider.notifyAfterCompleted(); } diff --git a/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/ModuleDefine.java b/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/ModuleDefine.java index 3f6a80c9e6..74c908d2b1 100644 --- a/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/ModuleDefine.java +++ b/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/ModuleDefine.java @@ -53,7 +53,7 @@ public abstract class ModuleDefine { * @throws ProviderNotFoundException when even don't find a single one providers. */ void prepare(ModuleManager moduleManager, - ApplicationConfiguration.ModuleConfiguration configuration) throws ProviderNotFoundException, ServiceNotProvidedException, ModuleConfigException { + ApplicationConfiguration.ModuleConfiguration configuration) throws ProviderNotFoundException, ServiceNotProvidedException, ModuleConfigException, ModuleStartException { ServiceLoader moduleProviderLoader = ServiceLoader.load(ModuleProvider.class); boolean providerExist = false; for (ModuleProvider provider : moduleProviderLoader) { diff --git a/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/ModuleProvider.java b/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/ModuleProvider.java index 78597ea5bb..7596fb60b9 100644 --- a/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/ModuleProvider.java +++ b/oap-server/server-library/library-module/src/main/java/org/apache/skywalking/oap/server/library/module/ModuleProvider.java @@ -66,7 +66,7 @@ public abstract class ModuleProvider { /** * In prepare stage, the module should initialize things which are irrelative other modules. */ - public abstract void prepare() throws ServiceNotProvidedException; + public abstract void prepare() throws ServiceNotProvidedException, ModuleStartException; /** * In start stage, the module has been ready for interop. @@ -76,7 +76,7 @@ public abstract class ModuleProvider { /** * This callback executes after all modules start up successfully. */ - public abstract void notifyAfterCompleted() throws ServiceNotProvidedException; + public abstract void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException; /** * @return module names which does this module require? diff --git a/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoader.java b/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoader.java index ea4cafff43..dbedbf6a4f 100644 --- a/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoader.java +++ b/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoader.java @@ -48,7 +48,6 @@ public class ApplicationConfigLoader implements ConfigLoader>> moduleConfig = yaml.loadAs(applicationReader, Map.class); - if (CollectionUtils.isNotEmpty(moduleConfig)) { - moduleConfig.forEach((moduleName, providerConfig) -> { - if (!configuration.has(moduleName)) { - logger.warn("The {} module did't define in application.yml, use default", moduleName); - ApplicationConfiguration.ModuleConfiguration moduleConfiguration = configuration.addModule(moduleName); - providerConfig.forEach((name, propertiesConfig) -> { - Properties properties = new Properties(); - if (propertiesConfig != null) { - propertiesConfig.forEach(properties::put); - } - moduleConfiguration.addProviderConfiguration(name, properties); - }); - } - }); - } - } catch (FileNotFoundException e) { - throw new ConfigFileNotFoundException(e.getMessage(), e); - } - } - private void overrideConfigBySystemEnv(ApplicationConfiguration configuration) { for (Map.Entry prop : System.getProperties().entrySet()) { overrideModuleSettings(configuration, prop.getKey().toString(), prop.getValue().toString()); diff --git a/oap-server/server-starter/src/main/resources/application.yml b/oap-server/server-starter/src/main/resources/application.yml index 5bdaa05e2e..1faf0e2d8d 100644 --- a/oap-server/server-starter/src/main/resources/application.yml +++ b/oap-server/server-starter/src/main/resources/application.yml @@ -15,17 +15,12 @@ # limitations under the License. cluster: - zookeeper: - hostPort: localhost:2181 - # Retry Policy - baseSleepTimeMs: 1000 # initial amount of time to wait between retries - maxRetries: 3 # max number of times to retry -#naming: -# jetty: -# #OS real network IP(binding required), for agent to find collector cluster -# host: localhost -# port: 10800 -# contextPath: / + standalone: +# zookeeper: +# hostPort: localhost:2181 +# # Retry Policy +# baseSleepTimeMs: 1000 # initial amount of time to wait between retries +# maxRetries: 3 # max number of times to retry core: default: restHost: localhost -- GitLab