提交 afd61643 编写于 作者: 彭勇升 pengys 提交者: wu-sheng

OAP server testing module. (#1931)

* OAP server testing module.

#1930

* #Missing delete code.
上级 e727de96
......@@ -36,6 +36,7 @@
<module>server-starter</module>
<module>server-query-plugin</module>
<module>server-alarm-plugin</module>
<module>server-testing</module>
</modules>
<properties>
......
......@@ -23,10 +23,8 @@ import org.apache.skywalking.oap.server.cluster.plugin.kubernetes.dependencies.U
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.*;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.ModuleProvider;
import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException;
/**
* Use kubernetes to manage all instances in Skywalking cluster.
......
......@@ -29,7 +29,7 @@ import org.apache.skywalking.oap.server.core.remote.client.RemoteClientManager;
import org.apache.skywalking.oap.server.core.server.*;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.core.storage.model.IModelGetter;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.*;
/**
* @author peng-yongsheng
......@@ -38,8 +38,8 @@ public class CoreModule extends ModuleDefine {
public static final String NAME = "core";
@Override public String name() {
return NAME;
public CoreModule() {
super(NAME);
}
@Override public Class[] services() {
......
......@@ -64,11 +64,8 @@ import org.apache.skywalking.oap.server.core.storage.PersistenceTimer;
import org.apache.skywalking.oap.server.core.storage.annotation.StorageAnnotationListener;
import org.apache.skywalking.oap.server.core.storage.model.IModelGetter;
import org.apache.skywalking.oap.server.core.storage.ttl.DataTTLKeeperTimer;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
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;
......@@ -190,7 +187,7 @@ public class CoreModuleProvider extends ModuleProvider {
}
RemoteInstance gRPCServerInstance = new RemoteInstance(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort(), true);
this.getManager().find(ClusterModule.NAME).getService(ClusterRegister.class).registerRemote(gRPCServerInstance);
this.getManager().find(ClusterModule.NAME).provider().getService(ClusterRegister.class).registerRemote(gRPCServerInstance);
PersistenceTimer.INSTANCE.start(getManager());
......
......@@ -71,8 +71,8 @@ public class AlarmEntrance {
initLock.lock();
try {
if (serviceInventoryCache == null) {
serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
indicatorNotify = moduleManager.find(AlarmModule.NAME).getService(IndicatorNotify.class);
serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
indicatorNotify = moduleManager.find(AlarmModule.NAME).provider().getService(IndicatorNotify.class);
indicatorNotify.init(new AlarmStandardPersistence());
}
} finally {
......
......@@ -18,7 +18,7 @@
package org.apache.skywalking.oap.server.core.alarm;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.*;
/**
* Alarm module define the main bridge entrance of the alarm implementor.
......@@ -30,8 +30,8 @@ import org.apache.skywalking.oap.server.library.module.ModuleDefine;
public class AlarmModule extends ModuleDefine {
public static final String NAME = "alarm";
@Override public String name() {
return NAME;
public AlarmModule() {
super(NAME);
}
@Override public Class[] services() {
......
......@@ -44,7 +44,7 @@ public enum IndicatorProcess {
String modelName = StorageEntityAnnotationUtils.getModelName(indicatorClass);
Class<? extends StorageBuilder> builderClass = StorageEntityAnnotationUtils.getBuilder(indicatorClass);
StorageDAO storageDAO = moduleManager.find(StorageModule.NAME).getService(StorageDAO.class);
StorageDAO storageDAO = moduleManager.find(StorageModule.NAME).provider().getService(StorageDAO.class);
IIndicatorDAO indicatorDAO;
try {
indicatorDAO = storageDAO.newIndicatorDao(builderClass.newInstance());
......
......@@ -41,7 +41,7 @@ public class IndicatorRemoteWorker extends AbstractWorker<Indicator> {
IndicatorRemoteWorker(int workerId, ModuleManager moduleManager, AbstractWorker<Indicator> nextWorker,
String modelName) {
super(workerId);
this.remoteSender = moduleManager.find(CoreModule.NAME).getService(RemoteSenderService.class);
this.remoteSender = moduleManager.find(CoreModule.NAME).provider().getService(RemoteSenderService.class);
this.nextWorker = nextWorker;
this.modelName = modelName;
}
......
......@@ -38,7 +38,7 @@ public abstract class PersistenceWorker<INPUT extends StorageData, CACHE extends
PersistenceWorker(ModuleManager moduleManager, int workerId, int batchSize) {
super(workerId);
this.batchSize = batchSize;
this.batchDAO = moduleManager.find(StorageModule.NAME).getService(IBatchDAO.class);
this.batchDAO = moduleManager.find(StorageModule.NAME).provider().getService(IBatchDAO.class);
}
void onWork(INPUT input) {
......
......@@ -45,7 +45,7 @@ public enum RecordProcess {
String modelName = StorageEntityAnnotationUtils.getModelName(recordClass);
Class<? extends StorageBuilder> builderClass = StorageEntityAnnotationUtils.getBuilder(recordClass);
StorageDAO storageDAO = moduleManager.find(StorageModule.NAME).getService(StorageDAO.class);
StorageDAO storageDAO = moduleManager.find(StorageModule.NAME).provider().getService(StorageDAO.class);
IRecordDAO recordDAO;
try {
recordDAO = storageDAO.newRecordDao(builderClass.newInstance());
......
......@@ -53,8 +53,8 @@ public enum CacheUpdateTimer {
}
private void update(ModuleManager moduleManager) {
IServiceInventoryCacheDAO serviceInventoryCacheDAO = moduleManager.find(StorageModule.NAME).getService(IServiceInventoryCacheDAO.class);
ServiceInventoryCache serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
IServiceInventoryCacheDAO serviceInventoryCacheDAO = moduleManager.find(StorageModule.NAME).provider().getService(IServiceInventoryCacheDAO.class);
ServiceInventoryCache serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
List<ServiceInventory> serviceInventories = serviceInventoryCacheDAO.loadLastMappingUpdate();
serviceInventories.forEach(serviceInventory -> {
......
......@@ -55,7 +55,7 @@ public class EndpointInventoryCache implements Service {
private IEndpointInventoryCacheDAO getCacheDAO() {
if (isNull(cacheDAO)) {
cacheDAO = moduleManager.find(StorageModule.NAME).getService(IEndpointInventoryCacheDAO.class);
cacheDAO = moduleManager.find(StorageModule.NAME).provider().getService(IEndpointInventoryCacheDAO.class);
}
return cacheDAO;
}
......
......@@ -49,7 +49,7 @@ public class NetworkAddressInventoryCache implements Service {
private INetworkAddressInventoryCacheDAO getCacheDAO() {
if (isNull(cacheDAO)) {
this.cacheDAO = moduleManager.find(StorageModule.NAME).getService(INetworkAddressInventoryCacheDAO.class);
this.cacheDAO = moduleManager.find(StorageModule.NAME).provider().getService(INetworkAddressInventoryCacheDAO.class);
}
return this.cacheDAO;
}
......
......@@ -59,7 +59,7 @@ public class ServiceInstanceInventoryCache implements Service {
private IServiceInstanceInventoryCacheDAO getCacheDAO() {
if (isNull(cacheDAO)) {
this.cacheDAO = moduleManager.find(StorageModule.NAME).getService(IServiceInstanceInventoryCacheDAO.class);
this.cacheDAO = moduleManager.find(StorageModule.NAME).provider().getService(IServiceInstanceInventoryCacheDAO.class);
}
return this.cacheDAO;
}
......
......@@ -56,7 +56,7 @@ public class ServiceInventoryCache implements Service {
private IServiceInventoryCacheDAO getCacheDAO() {
if (isNull(cacheDAO)) {
this.cacheDAO = moduleManager.find(StorageModule.NAME).getService(IServiceInventoryCacheDAO.class);
this.cacheDAO = moduleManager.find(StorageModule.NAME).provider().getService(IServiceInventoryCacheDAO.class);
}
return this.cacheDAO;
}
......
......@@ -18,7 +18,7 @@
package org.apache.skywalking.oap.server.core.cluster;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.*;
/**
* @author peng-yongsheng
......@@ -27,8 +27,8 @@ public class ClusterModule extends ModuleDefine {
public static final String NAME = "cluster";
@Override public String name() {
return NAME;
public ClusterModule() {
super(NAME);
}
@Override public Class[] services() {
......
......@@ -44,7 +44,7 @@ public class AggregationQueryService implements Service {
private IAggregationQueryDAO getAggregationQueryDAO() {
if (aggregationQueryDAO == null) {
aggregationQueryDAO = moduleManager.find(StorageModule.NAME).getService(IAggregationQueryDAO.class);
aggregationQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(IAggregationQueryDAO.class);
}
return aggregationQueryDAO;
}
......@@ -53,7 +53,7 @@ public class AggregationQueryService implements Service {
final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceTopN(indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
ServiceInventory inventory = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class).get(Integer.valueOf(entity.getId()));
ServiceInventory inventory = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class).get(Integer.valueOf(entity.getId()));
if (inventory != null) {
entity.setName(inventory.getName());
}
......@@ -65,7 +65,7 @@ public class AggregationQueryService implements Service {
final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllServiceInstanceTopN(indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
ServiceInstanceInventory inventory = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class).get(Integer.valueOf(entity.getId()));
ServiceInstanceInventory inventory = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class).get(Integer.valueOf(entity.getId()));
if (inventory != null) {
entity.setName(inventory.getName());
}
......@@ -77,7 +77,7 @@ public class AggregationQueryService implements Service {
final Step step, final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceInstanceTopN(serviceId, indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
ServiceInstanceInventory inventory = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class).get(Integer.valueOf(entity.getId()));
ServiceInstanceInventory inventory = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class).get(Integer.valueOf(entity.getId()));
if (inventory != null) {
entity.setName(inventory.getName());
}
......@@ -89,7 +89,7 @@ public class AggregationQueryService implements Service {
final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllEndpointTopN(indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
EndpointInventory inventory = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class).get(Integer.valueOf(entity.getId()));
EndpointInventory inventory = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class).get(Integer.valueOf(entity.getId()));
if (inventory != null) {
entity.setName(inventory.getName());
}
......@@ -101,7 +101,7 @@ public class AggregationQueryService implements Service {
final Step step, final long startTB, final long endTB, final Order order) throws IOException {
List<TopNEntity> topNEntities = getAggregationQueryDAO().getEndpointTopN(serviceId, indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
for (TopNEntity entity : topNEntities) {
EndpointInventory inventory = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class).get(Integer.valueOf(entity.getId()));
EndpointInventory inventory = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class).get(Integer.valueOf(entity.getId()));
if (inventory != null) {
entity.setName(inventory.getName());
}
......
......@@ -43,7 +43,7 @@ public class AlarmQueryService implements Service {
private IAlarmQueryDAO getAlarmQueryDAO() {
if (alarmQueryDAO == null) {
alarmQueryDAO = moduleManager.find(StorageModule.NAME).getService(IAlarmQueryDAO.class);
alarmQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(IAlarmQueryDAO.class);
}
return alarmQueryDAO;
}
......
......@@ -45,21 +45,21 @@ public class MetadataQueryService implements org.apache.skywalking.oap.server.li
private IMetadataQueryDAO getMetadataQueryDAO() {
if (metadataQueryDAO == null) {
metadataQueryDAO = moduleManager.find(StorageModule.NAME).getService(IMetadataQueryDAO.class);
metadataQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(IMetadataQueryDAO.class);
}
return metadataQueryDAO;
}
private ServiceInventoryCache getServiceInventoryCache() {
if (serviceInventoryCache == null) {
serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
}
return serviceInventoryCache;
}
private EndpointInventoryCache getEndpointInventoryCache() {
if (endpointInventoryCache == null) {
endpointInventoryCache = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class);
endpointInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
}
return endpointInventoryCache;
}
......
......@@ -50,7 +50,7 @@ public class MetricQueryService implements Service {
private IMetricQueryDAO getMetricQueryDAO() {
if (metricQueryDAO == null) {
metricQueryDAO = moduleManager.find(StorageModule.NAME).getService(IMetricQueryDAO.class);
metricQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(IMetricQueryDAO.class);
}
return metricQueryDAO;
}
......
......@@ -29,8 +29,8 @@ public class QueryModule extends ModuleDefine {
private static final String NAME = "query";
@Override public String name() {
return NAME;
public QueryModule() {
super(NAME);
}
@Override public Class[] services() {
......
......@@ -40,8 +40,8 @@ class TopologyBuilder {
private final IComponentLibraryCatalogService componentLibraryCatalogService;
TopologyBuilder(ModuleManager moduleManager) {
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
this.componentLibraryCatalogService = moduleManager.find(CoreModule.NAME).getService(IComponentLibraryCatalogService.class);
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
this.componentLibraryCatalogService = moduleManager.find(CoreModule.NAME).provider().getService(IComponentLibraryCatalogService.class);
}
Topology build(List<Call> serviceRelationClientCalls, List<Call> serviceRelationServerCalls) {
......
......@@ -51,28 +51,28 @@ public class TopologyQueryService implements Service {
private IMetadataQueryDAO getMetadataQueryDAO() {
if (metadataQueryDAO == null) {
metadataQueryDAO = moduleManager.find(StorageModule.NAME).getService(IMetadataQueryDAO.class);
metadataQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(IMetadataQueryDAO.class);
}
return metadataQueryDAO;
}
private ITopologyQueryDAO getTopologyQueryDAO() {
if (topologyQueryDAO == null) {
topologyQueryDAO = moduleManager.find(StorageModule.NAME).getService(ITopologyQueryDAO.class);
topologyQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(ITopologyQueryDAO.class);
}
return topologyQueryDAO;
}
private IComponentLibraryCatalogService getComponentLibraryCatalogService() {
if (componentLibraryCatalogService == null) {
componentLibraryCatalogService = moduleManager.find(CoreModule.NAME).getService(IComponentLibraryCatalogService.class);
componentLibraryCatalogService = moduleManager.find(CoreModule.NAME).provider().getService(IComponentLibraryCatalogService.class);
}
return componentLibraryCatalogService;
}
private EndpointInventoryCache getEndpointInventoryCache() {
if (endpointInventoryCache == null) {
endpointInventoryCache = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class);
endpointInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
}
return endpointInventoryCache;
}
......
......@@ -54,35 +54,35 @@ public class TraceQueryService implements Service {
private ITraceQueryDAO getTraceQueryDAO() {
if (traceQueryDAO == null) {
this.traceQueryDAO = moduleManager.find(StorageModule.NAME).getService(ITraceQueryDAO.class);
this.traceQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(ITraceQueryDAO.class);
}
return traceQueryDAO;
}
private ServiceInventoryCache getServiceInventoryCache() {
if (serviceInventoryCache == null) {
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
}
return serviceInventoryCache;
}
private EndpointInventoryCache getEndpointInventoryCache() {
if (endpointInventoryCache == null) {
this.endpointInventoryCache = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class);
this.endpointInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
}
return endpointInventoryCache;
}
private NetworkAddressInventoryCache getNetworkAddressInventoryCache() {
if (networkAddressInventoryCache == null) {
this.networkAddressInventoryCache = moduleManager.find(CoreModule.NAME).getService(NetworkAddressInventoryCache.class);
this.networkAddressInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(NetworkAddressInventoryCache.class);
}
return networkAddressInventoryCache;
}
private IComponentLibraryCatalogService getComponentLibraryCatalogService() {
if (componentLibraryCatalogService == null) {
this.componentLibraryCatalogService = moduleManager.find(CoreModule.NAME).getService(IComponentLibraryCatalogService.class);
this.componentLibraryCatalogService = moduleManager.find(CoreModule.NAME).provider().getService(IComponentLibraryCatalogService.class);
}
return componentLibraryCatalogService;
}
......
......@@ -45,7 +45,7 @@ public class EndpointInventoryRegister implements IEndpointInventoryRegister {
private EndpointInventoryCache getCacheService() {
if (isNull(cacheService)) {
cacheService = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class);
cacheService = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
}
return cacheService;
}
......
......@@ -46,21 +46,21 @@ public class NetworkAddressInventoryRegister implements INetworkAddressInventory
private NetworkAddressInventoryCache getNetworkAddressInventoryCache() {
if (isNull(networkAddressInventoryCache)) {
this.networkAddressInventoryCache = moduleManager.find(CoreModule.NAME).getService(NetworkAddressInventoryCache.class);
this.networkAddressInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(NetworkAddressInventoryCache.class);
}
return this.networkAddressInventoryCache;
}
private IServiceInventoryRegister getServiceInventoryRegister() {
if (isNull(serviceInventoryRegister)) {
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
}
return this.serviceInventoryRegister;
}
private IServiceInstanceInventoryRegister getServiceInstanceInventoryRegister() {
if (isNull(serviceInstanceInventoryRegister)) {
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
}
return this.serviceInstanceInventoryRegister;
}
......
......@@ -45,7 +45,7 @@ public class ServiceInstanceInventoryRegister implements IServiceInstanceInvento
private ServiceInstanceInventoryCache getServiceInstanceInventoryCache() {
if (isNull(serviceInstanceInventoryCache)) {
serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class);
serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
}
return serviceInstanceInventoryCache;
}
......
......@@ -45,7 +45,7 @@ public class ServiceInventoryRegister implements IServiceInventoryRegister {
private ServiceInventoryCache getServiceInventoryCache() {
if (isNull(serviceInventoryCache)) {
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
}
return serviceInventoryCache;
}
......
......@@ -52,7 +52,7 @@ public enum InventoryProcess {
Class<? extends StorageBuilder> builderClass = StorageEntityAnnotationUtils.getBuilder(inventoryClass);
StorageDAO storageDAO = moduleManager.find(StorageModule.NAME).getService(StorageDAO.class);
StorageDAO storageDAO = moduleManager.find(StorageModule.NAME).provider().getService(StorageDAO.class);
IRegisterDAO registerDAO;
try {
registerDAO = storageDAO.newRegisterDao(builderClass.newInstance());
......
......@@ -49,7 +49,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
this.modelName = modelName;
this.sources = new HashMap<>();
this.registerDAO = registerDAO;
this.registerLockDAO = moduleManager.find(StorageModule.NAME).getService(IRegisterLockDAO.class);
this.registerLockDAO = moduleManager.find(StorageModule.NAME).provider().getService(IRegisterLockDAO.class);
this.scope = scope;
this.dataCarrier = new DataCarrier<>("IndicatorPersistentWorker." + modelName, 1, 10000);
this.dataCarrier.consume(new RegisterPersistentWorker.PersistentConsumer(this), 1);
......
......@@ -38,7 +38,7 @@ public class RegisterRemoteWorker extends AbstractWorker<RegisterSource> {
RegisterRemoteWorker(int workerId, ModuleManager moduleManager, AbstractWorker<RegisterSource> nextWorker) {
super(workerId);
this.remoteSender = moduleManager.find(CoreModule.NAME).getService(RemoteSenderService.class);
this.remoteSender = moduleManager.find(CoreModule.NAME).provider().getService(RemoteSenderService.class);
this.nextWorker = nextWorker;
}
......
......@@ -42,7 +42,7 @@ public class RemoteSenderService implements Service {
}
public void send(int nextWorkId, StreamData streamData, Selector selector) {
RemoteClientManager clientManager = moduleManager.find(CoreModule.NAME).getService(RemoteClientManager.class);
RemoteClientManager clientManager = moduleManager.find(CoreModule.NAME).provider().getService(RemoteClientManager.class);
RemoteClient remoteClient;
switch (selector) {
......
......@@ -45,7 +45,7 @@ public class RemoteServiceHandler extends RemoteServiceGrpc.RemoteServiceImplBas
@Override public StreamObserver<RemoteMessage> call(StreamObserver<Empty> responseObserver) {
if (Objects.isNull(streamDataClassGetter)) {
streamDataClassGetter = moduleManager.find(CoreModule.NAME).getService(StreamDataClassGetter.class);
streamDataClassGetter = moduleManager.find(CoreModule.NAME).provider().getService(StreamDataClassGetter.class);
}
return new StreamObserver<RemoteMessage>() {
......
......@@ -48,8 +48,8 @@ public class RemoteClientManager implements Service {
}
public void start() {
this.clusterNodesQuery = moduleManager.find(ClusterModule.NAME).getService(ClusterNodesQuery.class);
this.streamDataClassGetter = moduleManager.find(CoreModule.NAME).getService(StreamDataClassGetter.class);
this.clusterNodesQuery = moduleManager.find(ClusterModule.NAME).provider().getService(ClusterNodesQuery.class);
this.streamDataClassGetter = moduleManager.find(CoreModule.NAME).provider().getService(StreamDataClassGetter.class);
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::refresh, 5, 5, TimeUnit.SECONDS);
}
......
......@@ -45,7 +45,7 @@ public enum PersistenceTimer {
//TODO timer value config
// final long timeInterval = EsConfig.Es.Persistence.Timer.VALUE * 1000;
final long timeInterval = 3;
IBatchDAO batchDAO = moduleManager.find(StorageModule.NAME).getService(IBatchDAO.class);
IBatchDAO batchDAO = moduleManager.find(StorageModule.NAME).provider().getService(IBatchDAO.class);
if (!isStarted) {
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(
......
......@@ -20,7 +20,7 @@ package org.apache.skywalking.oap.server.core.storage;
import org.apache.skywalking.oap.server.core.storage.cache.*;
import org.apache.skywalking.oap.server.core.storage.query.*;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.*;
/**
* @author peng-yongsheng
......@@ -29,8 +29,8 @@ public class StorageModule extends ModuleDefine {
public static final String NAME = "storage";
@Override public String name() {
return NAME;
public StorageModule() {
super(NAME);
}
@Override public Class[] services() {
......
......@@ -40,8 +40,8 @@ public abstract class ModelInstaller {
}
public final void install(Client client) throws StorageException {
IModelGetter modelGetter = moduleManager.find(CoreModule.NAME).getService(IModelGetter.class);
DownsamplingConfigService downsamplingConfigService = moduleManager.find(CoreModule.NAME).getService(DownsamplingConfigService.class);
IModelGetter modelGetter = moduleManager.find(CoreModule.NAME).provider().getService(IModelGetter.class);
DownsamplingConfigService downsamplingConfigService = moduleManager.find(CoreModule.NAME).provider().getService(DownsamplingConfigService.class);
List<Model> models = modelGetter.getModels();
List<Model> downsamplingModels = new ArrayList<>();
......
......@@ -58,7 +58,7 @@ public enum DataTTLKeeperTimer {
public void start(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
this.clusterNodesQuery = moduleManager.find(ClusterModule.NAME).getService(ClusterNodesQuery.class);
this.clusterNodesQuery = moduleManager.find(ClusterModule.NAME).provider().getService(ClusterNodesQuery.class);
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(
new RunnableWithExceptionProtection(this::delete,
......@@ -79,8 +79,8 @@ public enum DataTTLKeeperTimer {
logger.info("Metrics in day dimension before {}, are going to be removed.", timeBuckets.dayTimeBucketBefore);
logger.info("Metrics in month dimension before {}, are going to be removed.", timeBuckets.monthTimeBucketBefore);
IModelGetter modelGetter = moduleManager.find(CoreModule.NAME).getService(IModelGetter.class);
DownsamplingConfigService downsamplingConfigService = moduleManager.find(CoreModule.NAME).getService(DownsamplingConfigService.class);
IModelGetter modelGetter = moduleManager.find(CoreModule.NAME).provider().getService(IModelGetter.class);
DownsamplingConfigService downsamplingConfigService = moduleManager.find(CoreModule.NAME).provider().getService(DownsamplingConfigService.class);
List<Model> models = modelGetter.getModels();
models.forEach(model -> {
if (model.isIndicator()) {
......@@ -115,7 +115,7 @@ public enum DataTTLKeeperTimer {
private void execute(String modelName, long timeBucketBefore, String timeBucketColumnName) {
try {
moduleManager.find(StorageModule.NAME).getService(IHistoryDeleteDAO.class).deleteHistory(modelName, timeBucketColumnName, timeBucketBefore);
moduleManager.find(StorageModule.NAME).provider().getService(IHistoryDeleteDAO.class).deleteHistory(modelName, timeBucketColumnName, timeBucketBefore);
} catch (IOException e) {
logger.warn("History delete failure, error message: {}", e.getMessage());
}
......
......@@ -18,14 +18,9 @@
package org.apache.skywalking.oap.server.library.module;
import java.util.*;
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.slf4j.*;
/**
* @author wu-sheng, peng-yongsheng
......
......@@ -16,10 +16,9 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
public class DuplicateProviderException extends Exception {
public class DuplicateProviderException extends RuntimeException {
public DuplicateProviderException(String message) {
super(message);
}
......
......@@ -27,16 +27,24 @@ import org.slf4j.*;
*
* @author wu-sheng, peng-yongsheng
*/
public abstract class ModuleDefine {
public abstract class ModuleDefine implements ModuleProviderHolder {
private static final Logger logger = LoggerFactory.getLogger(ModuleDefine.class);
private LinkedList<ModuleProvider> loadedProviders = new LinkedList<>();
private final LinkedList<ModuleProvider> loadedProviders = new LinkedList<>();
private final String name;
public ModuleDefine(String name) {
this.name = name;
}
/**
* @return the module name
*/
public abstract String name();
public final String name() {
return name;
}
/**
* @return the {@link Service} provided by this module.
......@@ -68,7 +76,7 @@ public abstract class ModuleDefine {
throw new ProviderNotFoundException(e);
}
newProvider.setManager(moduleManager);
newProvider.setModule(this);
newProvider.setModuleDefine(this);
loadedProviders.add(newProvider);
}
}
......@@ -129,19 +137,13 @@ public abstract class ModuleDefine {
return loadedProviders;
}
public final ModuleProvider provider() throws DuplicateProviderException {
@Override public final ModuleProvider provider() throws DuplicateProviderException, ProviderNotFoundException {
if (loadedProviders.size() > 1) {
throw new DuplicateProviderException(this.name() + " module exist " + loadedProviders.size() + " providers");
} else if (loadedProviders.size() == 0) {
throw new ProviderNotFoundException("There is no module provider in " + this.name() + " module!");
}
return loadedProviders.getFirst();
}
public final <T extends Service> T getService(Class<T> serviceType) throws ServiceNotProvidedRuntimeException {
try {
return provider().getService(serviceType);
} catch (DuplicateProviderException | ServiceNotProvidedException e) {
throw new ServiceNotProvidedRuntimeException(e.getMessage());
}
}
}
/*
* 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.library.module;
/**
* @author peng-yongsheng
*/
public interface ModuleDefineHolder {
boolean has(String moduleName);
ModuleProviderHolder find(String moduleName) throws ModuleNotFoundRuntimeException;
}
......@@ -25,9 +25,10 @@ import java.util.*;
*
* @author wu-sheng, peng-yongsheng
*/
public class ModuleManager {
public class ModuleManager implements ModuleDefineHolder {
private boolean isInPrepareStage = true;
private Map<String, ModuleDefine> loadedModules = new HashMap<>();
private final Map<String, ModuleDefine> loadedModules = new HashMap<>();
/**
* Init the given modules
......@@ -65,11 +66,11 @@ public class ModuleManager {
bootstrapFlow.notifyAfterCompleted();
}
public boolean has(String moduleName) {
@Override public boolean has(String moduleName) {
return loadedModules.get(moduleName) != null;
}
public ModuleDefine find(String moduleName) throws ModuleNotFoundRuntimeException {
@Override public ModuleProviderHolder find(String moduleName) throws ModuleNotFoundRuntimeException {
assertPreparedStage();
ModuleDefine module = loadedModules.get(moduleName);
if (module != null)
......
......@@ -19,30 +19,23 @@
package org.apache.skywalking.oap.server.library.module;
import java.util.*;
import lombok.Setter;
/**
* The <code>ModuleProvider</code> is an implementation of a {@link ModuleDefine}.
*
* And each module can have one or more implementation, which depends on `application.yml`
* And each moduleDefine can have one or more implementation, which depends on `application.yml`
*
* @author wu-sheng, peng-yongsheng
*/
public abstract class ModuleProvider {
private ModuleManager manager;
private ModuleDefine module;
private Map<Class<? extends Service>, Service> services = new HashMap<>();
public abstract class ModuleProvider implements ModuleServiceHolder {
@Setter private ModuleManager manager;
@Setter private ModuleDefine moduleDefine;
private final Map<Class<? extends Service>, Service> services = new HashMap<>();
public ModuleProvider() {
}
void setManager(ModuleManager manager) {
this.manager = manager;
}
void setModule(ModuleDefine module) {
this.module = module;
}
protected final ModuleManager getManager() {
return manager;
}
......@@ -53,7 +46,7 @@ public abstract class ModuleProvider {
public abstract String name();
/**
* @return the module name
* @return the moduleDefine name
*/
public abstract Class<? extends ModuleDefine> module();
......@@ -63,12 +56,12 @@ public abstract class ModuleProvider {
public abstract ModuleConfig createConfigBeanIfAbsent();
/**
* In prepare stage, the module should initialize things which are irrelative other modules.
* In prepare stage, the moduleDefine should initialize things which are irrelative other modules.
*/
public abstract void prepare() throws ServiceNotProvidedException, ModuleStartException;
/**
* In start stage, the module has been ready for interop.
* In start stage, the moduleDefine has been ready for interop.
*/
public abstract void start() throws ServiceNotProvidedException, ModuleStartException;
......@@ -78,14 +71,14 @@ public abstract class ModuleProvider {
public abstract void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException;
/**
* @return module names which does this module require?
* @return moduleDefine names which does this moduleDefine require?
*/
public abstract String[] requiredModules();
/**
* Register a implementation for the service of this module provider.
* Register a implementation for the service of this moduleDefine provider.
*/
protected final void registerServiceImplementation(Class<? extends Service> serviceType,
@Override public final void registerServiceImplementation(Class<? extends Service> serviceType,
Service service) throws ServiceNotProvidedException {
if (serviceType.isInstance(service)) {
this.services.put(serviceType, service);
......@@ -97,7 +90,7 @@ public abstract class ModuleProvider {
/**
* Make sure all required services have been implemented.
*
* @param requiredServices must be implemented by the module.
* @param requiredServices must be implemented by the moduleDefine.
* @throws ServiceNotProvidedException when exist unimplemented service.
*/
void requiredCheck(Class<? extends Service>[] requiredServices) throws ServiceNotProvidedException {
......@@ -111,25 +104,25 @@ public abstract class ModuleProvider {
}
if (requiredServices.length != services.size()) {
throw new ServiceNotProvidedException("The " + this.name() + " provider in " + module.name() + " module provide more service implementations than ModuleDefine requirements.");
throw new ServiceNotProvidedException("The " + this.name() + " provider in " + moduleDefine.name() + " moduleDefine provide more service implementations than ModuleDefine requirements.");
}
}
public @SuppressWarnings("unchecked") <T extends Service> T getService(
@Override public @SuppressWarnings("unchecked") <T extends Service> T getService(
Class<T> serviceType) throws ServiceNotProvidedException {
Service serviceImpl = services.get(serviceType);
if (serviceImpl != null) {
return (T)serviceImpl;
}
throw new ServiceNotProvidedException("Service " + serviceType.getName() + " should not be provided, based on module define.");
throw new ServiceNotProvidedException("Service " + serviceType.getName() + " should not be provided, based on moduleDefine define.");
}
ModuleDefine getModule() {
return module;
return moduleDefine;
}
String getModuleName() {
return module.name();
return moduleDefine.name();
}
}
/*
* 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.library.module;
/**
* @author peng-yongsheng
*/
public interface ModuleProviderHolder {
ModuleServiceHolder provider() throws DuplicateProviderException, ProviderNotFoundException;
}
/*
* 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.library.module;
/**
* @author peng-yongsheng
*/
public interface ModuleServiceHolder {
void registerServiceImplementation(Class<? extends Service> serviceType,
Service service) throws ServiceNotProvidedException;
<T extends Service> T getService(Class<T> serviceType) throws ServiceNotProvidedException;
}
......@@ -18,7 +18,7 @@
package org.apache.skywalking.oap.server.library.module;
public class ProviderNotFoundException extends Exception {
public class ProviderNotFoundException extends RuntimeException {
public ProviderNotFoundException(String message) {
super(message);
}
......
......@@ -18,7 +18,7 @@
package org.apache.skywalking.oap.server.library.module;
public class ServiceNotProvidedException extends Exception {
public class ServiceNotProvidedException extends RuntimeException {
public ServiceNotProvidedException(String message) {
super(message);
}
......
......@@ -16,15 +16,15 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**
* @author wu-sheng
*/
public class BaseModuleA extends ModuleDefine {
@Override public String name() {
return "BaseA";
public BaseModuleA() {
super("BaseA");
}
@Override public Class<? extends Service>[] services() {
......@@ -36,6 +36,5 @@ public class BaseModuleA extends ModuleDefine {
}
public interface ServiceABusiness2 extends Service {
}
}
......@@ -16,15 +16,15 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**
* @author wu-sheng
*/
public class BaseModuleB extends ModuleDefine {
@Override public String name() {
return "BaseB";
public BaseModuleB() {
super("BaseB");
}
@Override public Class<? extends Service>[] services() {
......
......@@ -18,10 +18,8 @@
package org.apache.skywalking.oap.server.library.module;
import org.junit.Assert;
import org.junit.Test;
import java.util.Properties;
import org.junit.*;
/**
* @author wu-sheng
......
......@@ -16,15 +16,15 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**
* @author wu-sheng
*/
public class TestModule extends ModuleDefine {
@Override public String name() {
return "Test";
public TestModule() {
super("Test");
}
@Override public Class<? extends Service>[] services() {
......
......@@ -72,7 +72,7 @@ public class GraphQLQueryProvider extends ModuleProvider {
}
@Override public void start() throws ServiceNotProvidedException, ModuleStartException {
JettyHandlerRegister service = getManager().find(CoreModule.NAME).getService(JettyHandlerRegister.class);
JettyHandlerRegister service = getManager().find(CoreModule.NAME).provider().getService(JettyHandlerRegister.class);
service.addHandler(new GraphQLQueryHandler(config.getPath(), graphQL));
}
......
......@@ -41,7 +41,7 @@ public class AggregationQuery implements GraphQLQueryResolver {
private AggregationQueryService getQueryService() {
if (queryService == null) {
this.queryService = moduleManager.find(CoreModule.NAME).getService(AggregationQueryService.class);
this.queryService = moduleManager.find(CoreModule.NAME).provider().getService(AggregationQueryService.class);
}
return queryService;
}
......
......@@ -41,7 +41,7 @@ public class AlarmQuery implements GraphQLQueryResolver {
private AlarmQueryService getQueryService() {
if (queryService == null) {
this.queryService = moduleManager.find(CoreModule.NAME).getService(AlarmQueryService.class);
this.queryService = moduleManager.find(CoreModule.NAME).provider().getService(AlarmQueryService.class);
}
return queryService;
}
......
......@@ -42,7 +42,7 @@ public class MetadataQuery implements GraphQLQueryResolver {
private MetadataQueryService getMetadataQueryService() {
if (metadataQueryService == null) {
this.metadataQueryService = moduleManager.find(CoreModule.NAME).getService(MetadataQueryService.class);
this.metadataQueryService = moduleManager.find(CoreModule.NAME).provider().getService(MetadataQueryService.class);
}
return metadataQueryService;
}
......
......@@ -41,7 +41,7 @@ public class MetricQuery implements GraphQLQueryResolver {
private MetricQueryService getMetricQueryService() {
if (metricQueryService == null) {
this.metricQueryService = moduleManager.find(CoreModule.NAME).getService(MetricQueryService.class);
this.metricQueryService = moduleManager.find(CoreModule.NAME).provider().getService(MetricQueryService.class);
}
return metricQueryService;
}
......
......@@ -41,7 +41,7 @@ public class TopologyQuery implements GraphQLQueryResolver {
private TopologyQueryService getQueryService() {
if (queryService == null) {
this.queryService = moduleManager.find(CoreModule.NAME).getService(TopologyQueryService.class);
this.queryService = moduleManager.find(CoreModule.NAME).provider().getService(TopologyQueryService.class);
}
return queryService;
}
......
......@@ -43,7 +43,7 @@ public class TraceQuery implements GraphQLQueryResolver {
private TraceQueryService getQueryService() {
if (queryService == null) {
this.queryService = moduleManager.find(CoreModule.NAME).getService(TraceQueryService.class);
this.queryService = moduleManager.find(CoreModule.NAME).provider().getService(TraceQueryService.class);
}
return queryService;
}
......
......@@ -20,11 +20,11 @@ package org.apache.skywalking.oap.server.receiver.istio.telemetry.module;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
public class IstioTelemetryReceiverModule extends ModuleDefine {
public class IstioTelemetryReceiverModule extends ModuleDefine {
public static final String NAME = "istio-telemetry";
@Override public String name() {
return NAME;
public IstioTelemetryReceiverModule() {
super(NAME);
}
@Override public Class[] services() {
......
......@@ -21,11 +21,8 @@ package org.apache.skywalking.oap.server.receiver.istio.telemetry.provider;
import org.apache.skywalking.aop.server.receiver.mesh.MeshReceiverModule;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
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.receiver.istio.telemetry.module.IstioTelemetryReceiverModule;
public class IstioTelemetryReceiverProvider extends ModuleProvider {
......@@ -45,7 +42,7 @@ public class IstioTelemetryReceiverProvider extends ModuleProvider {
}
@Override public void start() throws ServiceNotProvidedException, ModuleStartException {
GRPCHandlerRegister service = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class);
GRPCHandlerRegister service = getManager().find(CoreModule.NAME).provider().getService(GRPCHandlerRegister.class);
service.addHandler(new IstioTelemetryGRPCHandler());
}
......
......@@ -18,15 +18,15 @@
package org.apache.skywalking.oap.server.receiver.jvm.module;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.*;
/**
* @author peng-yongsheng
*/
public class JVMModule extends ModuleDefine {
@Override public String name() {
return "receiver-jvm";
public JVMModule() {
super("receiver-jvm");
}
@Override public Class[] services() {
......
......@@ -45,7 +45,7 @@ public class JVMModuleProvider extends ModuleProvider {
}
@Override public void start() {
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class);
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).provider().getService(GRPCHandlerRegister.class);
grpcHandlerRegister.addHandler(new JVMMetricsServiceHandler(getManager()));
}
......
......@@ -39,7 +39,7 @@ public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsSe
private final SourceReceiver sourceReceiver;
public JVMMetricsServiceHandler(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).getService(SourceReceiver.class);
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
}
@Override public void collect(JVMMetrics request, StreamObserver<Downstream> responseObserver) {
......
......@@ -39,21 +39,21 @@ public class CoreRegisterLinker {
public static IServiceInventoryRegister getServiceInventoryRegister() {
if (SERVICE_INVENTORY_REGISTER == null) {
SERVICE_INVENTORY_REGISTER = MODULE_MANAGER.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
SERVICE_INVENTORY_REGISTER = MODULE_MANAGER.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
}
return SERVICE_INVENTORY_REGISTER;
}
public static IServiceInstanceInventoryRegister getServiceInstanceInventoryRegister() {
if (SERVICE_INSTANCE_INVENTORY_REGISTER == null) {
SERVICE_INSTANCE_INVENTORY_REGISTER = MODULE_MANAGER.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
SERVICE_INSTANCE_INVENTORY_REGISTER = MODULE_MANAGER.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
}
return SERVICE_INSTANCE_INVENTORY_REGISTER;
}
public static IEndpointInventoryRegister getEndpointInventoryRegister() {
if (ENDPOINT_INVENTORY_REGISTER == null) {
ENDPOINT_INVENTORY_REGISTER = MODULE_MANAGER.find(CoreModule.NAME).getService(IEndpointInventoryRegister.class);
ENDPOINT_INVENTORY_REGISTER = MODULE_MANAGER.find(CoreModule.NAME).provider().getService(IEndpointInventoryRegister.class);
}
return ENDPOINT_INVENTORY_REGISTER;
}
......
......@@ -23,8 +23,8 @@ import org.apache.skywalking.oap.server.library.module.ModuleDefine;
public class MeshReceiverModule extends ModuleDefine {
public static final String NAME = "service-mesh";
@Override public String name() {
return NAME;
public MeshReceiverModule() {
super("service-mesh");
}
@Override public Class[] services() {
......
......@@ -21,11 +21,8 @@ package org.apache.skywalking.aop.server.receiver.mesh;
import java.io.IOException;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
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;
public class MeshReceiverProvider extends ModuleProvider {
private MeshModuleConfig config;
......@@ -58,7 +55,7 @@ public class MeshReceiverProvider extends ModuleProvider {
throw new ModuleStartException(e.getMessage(), e);
}
CoreRegisterLinker.setModuleManager(getManager());
GRPCHandlerRegister service = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class);
GRPCHandlerRegister service = getManager().find(CoreModule.NAME).provider().getService(GRPCHandlerRegister.class);
service.addHandler(new MeshGRPCHandler());
}
......
......@@ -64,11 +64,11 @@ public class TelemetryDataDispatcher {
public static void setCache(MeshDataBufferFileCache cache, ModuleManager moduleManager) {
CACHE = cache;
SERVICE_CACHE = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
SERVICE_INSTANCE_CACHE = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class);
SOURCE_RECEIVER = moduleManager.find(CoreModule.NAME).getService(SourceReceiver.class);
SERVICE_INSTANCE_INVENTORY_REGISTER = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
SERVICE_INVENTORY_REGISTER = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
SERVICE_CACHE = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
SERVICE_INSTANCE_CACHE = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
SOURCE_RECEIVER = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
SERVICE_INSTANCE_INVENTORY_REGISTER = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
SERVICE_INVENTORY_REGISTER = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
}
public static void preProcess(ServiceMeshMetric data) {
......
......@@ -18,15 +18,15 @@
package org.apache.skywalking.oap.server.receiver.register.module;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.*;
/**
* @author peng-yongsheng
*/
public class RegisterModule extends ModuleDefine {
@Override public String name() {
return "receiver-register";
public RegisterModule() {
super("receiver-register");
}
@Override public Class[] services() {
......
......@@ -49,13 +49,13 @@ public class RegisterModuleProvider extends ModuleProvider {
}
@Override public void start() {
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class);
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).provider().getService(GRPCHandlerRegister.class);
grpcHandlerRegister.addHandler(new ApplicationRegisterHandler(getManager()));
grpcHandlerRegister.addHandler(new InstanceDiscoveryServiceHandler(getManager()));
grpcHandlerRegister.addHandler(new ServiceNameDiscoveryHandler(getManager()));
grpcHandlerRegister.addHandler(new NetworkAddressRegisterServiceHandler(getManager()));
JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).getService(JettyHandlerRegister.class);
JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).provider().getService(JettyHandlerRegister.class);
jettyHandlerRegister.addHandler(new ApplicationRegisterServletHandler(getManager()));
jettyHandlerRegister.addHandler(new InstanceDiscoveryServletHandler(getManager()));
jettyHandlerRegister.addHandler(new InstanceHeartBeatServletHandler(getManager()));
......
......@@ -36,7 +36,7 @@ public class ApplicationRegisterHandler extends ApplicationRegisterServiceGrpc.A
private final IServiceInventoryRegister serviceInventoryRegister;
public ApplicationRegisterHandler(ModuleManager moduleManager) {
serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
}
@Override
......
......@@ -45,10 +45,10 @@ public class InstanceDiscoveryServiceHandler extends InstanceDiscoveryServiceGrp
private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
public InstanceDiscoveryServiceHandler(ModuleManager moduleManager) {
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
}
@Override
......
......@@ -37,7 +37,7 @@ public class NetworkAddressRegisterServiceHandler extends NetworkAddressRegister
private final INetworkAddressInventoryRegister networkAddressInventoryRegister;
public NetworkAddressRegisterServiceHandler(ModuleManager moduleManager) {
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).getService(INetworkAddressInventoryRegister.class);
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(INetworkAddressInventoryRegister.class);
}
@Override
......
......@@ -38,7 +38,7 @@ public class ServiceNameDiscoveryHandler extends ServiceNameDiscoveryServiceGrpc
private final IEndpointInventoryRegister inventoryService;
public ServiceNameDiscoveryHandler(ModuleManager moduleManager) {
this.inventoryService = moduleManager.find(CoreModule.NAME).getService(IEndpointInventoryRegister.class);
this.inventoryService = moduleManager.find(CoreModule.NAME).provider().getService(IEndpointInventoryRegister.class);
}
@Override public void discovery(ServiceNameCollection request,
......
......@@ -40,7 +40,7 @@ public class ApplicationRegisterServletHandler extends JettyJsonHandler {
private static final String APPLICATION_ID = "i";
public ApplicationRegisterServletHandler(ModuleManager moduleManager) {
serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
}
@Override public String pathSpec() {
......
......@@ -49,8 +49,8 @@ public class InstanceDiscoveryServletHandler extends JettyJsonHandler {
private static final String OS_INFO = "oi";
public InstanceDiscoveryServletHandler(ModuleManager moduleManager) {
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
}
@Override public String pathSpec() {
......
......@@ -47,9 +47,9 @@ public class InstanceHeartBeatServletHandler extends JettyJsonHandler {
private static final String HEARTBEAT_TIME = "ht";
public InstanceHeartBeatServletHandler(ModuleManager moduleManager) {
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
}
@Override public String pathSpec() {
......
......@@ -40,7 +40,7 @@ public class NetworkAddressRegisterServletHandler extends JettyJsonHandler {
private static final String ADDRESS_ID = "i";
public NetworkAddressRegisterServletHandler(ModuleManager moduleManager) {
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).getService(INetworkAddressInventoryRegister.class);
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(INetworkAddressInventoryRegister.class);
}
@Override public String pathSpec() {
......
......@@ -47,7 +47,7 @@ public class ServiceNameDiscoveryServiceHandler extends JettyJsonHandler {
private static final String ELEMENT = "el";
public ServiceNameDiscoveryServiceHandler(ModuleManager moduleManager) {
this.inventoryService = moduleManager.find(CoreModule.NAME).getService(IEndpointInventoryRegister.class);
this.inventoryService = moduleManager.find(CoreModule.NAME).provider().getService(IEndpointInventoryRegister.class);
}
@Override public String pathSpec() {
......
......@@ -25,8 +25,8 @@ import org.apache.skywalking.oap.server.library.module.ModuleDefine;
*/
public class TraceModule extends ModuleDefine {
@Override public String name() {
return "receiver-trace";
public TraceModule() {
super("receiver-trace");
}
@Override public Class[] services() {
......
......@@ -63,8 +63,8 @@ public class TraceModuleProvider extends ModuleProvider {
listenerManager.add(new ServiceMappingSpanListener.Factory());
listenerManager.add(new SegmentSpanListener.Factory());
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).getService(GRPCHandlerRegister.class);
JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).getService(JettyHandlerRegister.class);
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).provider().getService(GRPCHandlerRegister.class);
JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).provider().getService(JettyHandlerRegister.class);
try {
SegmentParse.Producer segmentProducer = new SegmentParse.Producer(getManager(), listenerManager);
grpcHandlerRegister.addHandler(new TraceSegmentServiceHandler(segmentProducer));
......
......@@ -56,12 +56,12 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
private long minuteTimeBucket;
private MultiScopesSpanListener(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).getService(SourceReceiver.class);
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.entrySourceBuilders = new LinkedList<>();
this.exitSourceBuilders = new LinkedList<>();
this.instanceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class);
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
this.endpointInventoryCache = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class);
this.instanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
this.endpointInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
}
@Override public boolean containsPoint(Point point) {
......
......@@ -42,8 +42,8 @@ public class SegmentSpanListener implements FirstSpanListener, EntrySpanListener
private int firstEndpointId = 0;
private SegmentSpanListener(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).getService(SourceReceiver.class);
this.serviceNameCacheService = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class);
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.serviceNameCacheService = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
}
@Override public boolean containsPoint(Point point) {
......
......@@ -41,8 +41,8 @@ public class ServiceMappingSpanListener implements EntrySpanListener {
private List<ServiceMapping> serviceMappings = new LinkedList<>();
private ServiceMappingSpanListener(ModuleManager moduleManager) {
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
}
@Override public boolean containsPoint(Point point) {
......
......@@ -47,9 +47,9 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
}
private ReferenceIdExchanger(ModuleManager moduleManager) {
this.endpointInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IEndpointInventoryRegister.class);
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).getService(INetworkAddressInventoryRegister.class);
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class);
this.endpointInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IEndpointInventoryRegister.class);
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(INetworkAddressInventoryRegister.class);
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
}
@Override public boolean exchange(ReferenceDecorator standardBuilder, int serviceId) {
......
......@@ -47,9 +47,9 @@ public class SpanIdExchanger implements IdExchanger<SpanDecorator> {
}
private SpanIdExchanger(ModuleManager moduleManager) {
this.endpointInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IEndpointInventoryRegister.class);
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).getService(INetworkAddressInventoryRegister.class);
this.componentLibraryCatalogService = moduleManager.find(CoreModule.NAME).getService(IComponentLibraryCatalogService.class);
this.endpointInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IEndpointInventoryRegister.class);
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(INetworkAddressInventoryRegister.class);
this.componentLibraryCatalogService = moduleManager.find(CoreModule.NAME).provider().getService(IComponentLibraryCatalogService.class);
}
@Override public boolean exchange(SpanDecorator standardBuilder, int serviceId) {
......
......@@ -19,8 +19,7 @@
package org.apache.skywalking.oap.server.starter;
import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.starter.config.ApplicationConfigLoader;
import org.apache.skywalking.oap.server.starter.config.ConfigFileNotFoundException;
import org.apache.skywalking.oap.server.starter.config.*;
import org.slf4j.*;
/**
......
......@@ -37,11 +37,8 @@ import org.apache.skywalking.oap.server.core.storage.query.ITopologyQueryDAO;
import org.apache.skywalking.oap.server.core.storage.query.ITraceQueryDAO;
import org.apache.skywalking.oap.server.library.client.ClientException;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
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.storage.plugin.jdbc.h2.dao.H2AggregationQueryDAO;
import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2AlarmQueryDAO;
import org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao.H2BatchDAO;
......
<?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.0.0-beta-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>server-testing</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>library-module</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* 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.testing.module;
import org.apache.skywalking.oap.server.library.module.*;
/**
* @author peng-yongsheng
*/
public class ModuleDefineTesting implements ModuleProviderHolder {
private final ModuleProviderTesting moduleProvider;
public ModuleDefineTesting() {
this.moduleProvider = new ModuleProviderTesting();
}
@Override public ModuleServiceHolder provider() {
return moduleProvider;
}
}
/*
* 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.testing.module;
import java.util.*;
import org.apache.skywalking.oap.server.library.module.*;
/**
* @author peng-yongsheng
*/
public class ModuleManagerTesting implements ModuleDefineHolder {
private final Map<String, ModuleProviderHolder> modules = new HashMap<>();
@Override public boolean has(String moduleName) {
return false;
}
@Override public ModuleProviderHolder find(String moduleName) throws ModuleNotFoundRuntimeException {
return modules.get(moduleName);
}
public void put(String moduleName, ModuleProviderHolder moduleProviderHolder) {
modules.put(moduleName, moduleProviderHolder);
}
}
/*
* 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.testing.module;
import java.util.*;
import org.apache.skywalking.oap.server.library.module.*;
/**
* @author peng-yongsheng
*/
public class ModuleProviderTesting implements ModuleServiceHolder {
private final Map<Class<? extends Service>, Service> services = new HashMap<>();
@Override public void registerServiceImplementation(Class<? extends Service> serviceType,
Service service) throws ServiceNotProvidedException {
if (serviceType.isInstance(service)) {
this.services.put(serviceType, service);
} else {
throw new ServiceNotProvidedException(serviceType + " is not implemented by " + service);
}
}
@Override public <T extends Service> T getService(Class<T> serviceType) throws ServiceNotProvidedException {
return (T)services.get(serviceType);
}
}
/*
* 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.testing.module;
import org.apache.skywalking.oap.server.library.module.Service;
import org.junit.*;
/**
* @author peng-yongsheng
*/
public class ModuleManagerTestCase {
@Test
public void test() {
String moduleName = "test";
ModuleManagerTesting moduleManager = new ModuleManagerTesting();
ModuleDefineTesting moduleDefine = new ModuleDefineTesting();
moduleManager.put(moduleName, moduleDefine);
Assert.assertEquals(moduleDefine, moduleManager.find(moduleName));
TestServiceImpl testService = new TestServiceImpl();
moduleDefine.provider().registerServiceImplementation(TestService.class, testService);
TestService service = moduleManager.find(moduleName).provider().getService(TestService.class);
Assert.assertEquals(testService, service);
}
interface TestService extends Service {
}
class TestServiceImpl implements TestService {
}
}
<?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.
~
-->
<Configuration status="DEBUG">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout charset="UTF-8" pattern="%d - %c - %L [%t] %-5p %x - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册