Refactor codebases for v6, restore modulization back
This commit is contained in:
parent
42072d8583
commit
62ca37bc8f
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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<RemoteInstance> queryRemoteNodes() {
|
||||
if(remoteInstance == null){
|
||||
return new ArrayList(0);
|
||||
}
|
||||
ArrayList remoteList = new ArrayList(1);
|
||||
remoteList.add(remoteInstance);
|
||||
return remoteList;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String, InstanceDetails> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
public class StandaloneManagerTest {
|
||||
@Test
|
||||
public void test(){
|
||||
StandaloneManager standaloneManager = new StandaloneManager();
|
||||
RemoteInstance remote1 = new RemoteInstance();
|
||||
RemoteInstance remote2 = new RemoteInstance();
|
||||
|
||||
private final StandaloneServiceManager serviceManager;
|
||||
|
||||
StandaloneModuleQuery(StandaloneServiceManager serviceManager) {
|
||||
this.serviceManager = serviceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InstanceDetails> query(String moduleName, String providerName) {
|
||||
List<InstanceDetails> 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));
|
||||
}
|
||||
}
|
||||
|
|
@ -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<InstanceDetails> serviceDiscovery;
|
||||
private ServiceDiscovery<RemoteInstance> 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<RemoteInstance> 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() {
|
||||
|
|
|
|||
|
|
@ -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<InstanceDetails> {
|
||||
public class SWInstanceSerializer implements InstanceSerializer<RemoteInstance> {
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
@Override public byte[] serialize(ServiceInstance<InstanceDetails> instance) throws Exception {
|
||||
@Override public byte[] serialize(ServiceInstance<RemoteInstance> instance) throws Exception {
|
||||
return gson.toJson(instance).getBytes();
|
||||
}
|
||||
|
||||
@Override public ServiceInstance<InstanceDetails> deserialize(byte[] bytes) throws Exception {
|
||||
return gson.fromJson(new String(bytes), new TypeToken<ServiceInstance<InstanceDetails>>() {
|
||||
@Override public ServiceInstance<RemoteInstance> deserialize(byte[] bytes) throws Exception {
|
||||
return gson.fromJson(new String(bytes), new TypeToken<ServiceInstance<RemoteInstance>>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String, ServiceCache<InstanceDetails>> serviceCacheMap;
|
||||
|
||||
public ServiceCacheManager() {
|
||||
this.serviceCacheMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public void put(String name, ServiceCache<InstanceDetails> cache) {
|
||||
serviceCacheMap.put(name, cache);
|
||||
}
|
||||
|
||||
public ServiceCache<InstanceDetails> get(String name) {
|
||||
return serviceCacheMap.get(name);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<RemoteInstance> serviceCache;
|
||||
|
||||
ZookeeperModuleQuery(ServiceCacheManager cacheManager) {
|
||||
this.cacheManager = cacheManager;
|
||||
ZookeeperModuleQuery(ServiceCache<RemoteInstance> serviceCache) {
|
||||
this.serviceCache = serviceCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InstanceDetails> query(String moduleName, String providerName) throws ServiceRegisterException {
|
||||
List<ServiceInstance<InstanceDetails>> serviceInstances = cacheManager.get(NodeNameBuilder.build(moduleName, providerName)).getInstances();
|
||||
public List<RemoteInstance> queryRemoteNodes() throws ServiceRegisterException {
|
||||
List<ServiceInstance<RemoteInstance>> serviceInstances = serviceCache.getInstances();
|
||||
|
||||
List<InstanceDetails> instanceDetails = new ArrayList<>(serviceInstances.size());
|
||||
serviceInstances.forEach(serviceInstance -> instanceDetails.add(serviceInstance.getPayload()));
|
||||
return instanceDetails;
|
||||
List<RemoteInstance> remoteInstanceDetails = new ArrayList<>(serviceInstances.size());
|
||||
serviceInstances.forEach(serviceInstance -> remoteInstanceDetails.add(serviceInstance.getPayload()));
|
||||
return remoteInstanceDetails;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<InstanceDetails> serviceDiscovery;
|
||||
private final ServiceCacheManager cacheManager;
|
||||
|
||||
ZookeeperModuleRegister(ServiceDiscovery<InstanceDetails> 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<InstanceDetails> thisInstance = ServiceInstance.<InstanceDetails>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<InstanceDetails> serviceCache = serviceDiscovery.serviceCacheBuilder()
|
||||
.name(name)
|
||||
.build();
|
||||
serviceCache.start();
|
||||
|
||||
cacheManager.put(name, serviceCache);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceRegisterException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<RemoteInstance> serviceDiscovery;
|
||||
private final String nodeName;
|
||||
|
||||
ZookeeperNodeRegister(ServiceDiscovery<RemoteInstance> serviceDiscovery, String nodeName) {
|
||||
this.serviceDiscovery = serviceDiscovery;
|
||||
this.nodeName = nodeName;
|
||||
}
|
||||
|
||||
@Override public synchronized void registerRemote(RemoteInstance remoteInstance) throws ServiceRegisterException {
|
||||
try {
|
||||
ServiceInstance<RemoteInstance> thisInstance = ServiceInstance.<RemoteInstance>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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<RemoteInstance> 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<InstanceDetails> 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface ModuleQuery extends Service {
|
||||
public interface ClusterNodesQuery extends Service {
|
||||
|
||||
List<InstanceDetails> query(String moduleName, String providerName) throws ServiceRegisterException;
|
||||
List<RemoteInstance> queryRemoteNodes();
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -63,7 +63,7 @@ class BootstrapFlow {
|
|||
}
|
||||
}
|
||||
|
||||
void notifyAfterCompleted() throws ServiceNotProvidedException {
|
||||
void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException {
|
||||
for (ModuleProvider provider : startupSequence) {
|
||||
provider.notifyAfterCompleted();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ModuleProvider> moduleProviderLoader = ServiceLoader.load(ModuleProvider.class);
|
||||
boolean providerExist = false;
|
||||
for (ModuleProvider provider : moduleProviderLoader) {
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ public class ApplicationConfigLoader implements ConfigLoader<ApplicationConfigur
|
|||
@Override public ApplicationConfiguration load() throws ConfigFileNotFoundException {
|
||||
ApplicationConfiguration configuration = new ApplicationConfiguration();
|
||||
this.loadConfig(configuration);
|
||||
this.loadDefaultConfig(configuration);
|
||||
this.overrideConfigBySystemEnv(configuration);
|
||||
return configuration;
|
||||
}
|
||||
|
|
@ -84,31 +83,6 @@ public class ApplicationConfigLoader implements ConfigLoader<ApplicationConfigur
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void loadDefaultConfig(ApplicationConfiguration configuration) throws ConfigFileNotFoundException {
|
||||
try {
|
||||
Reader applicationReader = ResourceUtils.read("application-default.yml");
|
||||
Map<String, Map<String, Map<String, ?>>> 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<Object, Object> prop : System.getProperties().entrySet()) {
|
||||
overrideModuleSettings(configuration, prop.getKey().toString(), prop.getValue().toString());
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue