You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2020/05/14 08:00:24 UTC
[servicecomb-java-chassis] 02/09: [SCB-1876] part-2: extract
interface Registration and Discovery
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 437a63c4e5ff58aa9f64b664ebb6777f37be6e50
Author: liubao <bi...@qq.com>
AuthorDate: Wed Apr 29 12:08:06 2020 +0800
[SCB-1876] part-2: extract interface Registration and Discovery
---
core/pom.xml | 4 +
.../org/apache/servicecomb/core/SCBEngine.java | 44 +++-----
.../core/endpoint/AbstractEndpointsCache.java | 119 ---------------------
.../consumer/MicroserviceReferenceConfig.java | 4 +-
.../provider/producer/ProducerBootListener.java | 27 +++--
.../provider/producer/ProducerProviderManager.java | 9 +-
.../FindInstancesResponse.java => Discovery.java} | 26 +++--
.../serviceregistry/DiscoveryManager.java | 77 +++++++++++++
.../servicecomb/serviceregistry/LifeCycle.java | 10 +-
...indInstancesResponse.java => Registration.java} | 27 ++---
.../serviceregistry/RegistrationManager.java | 74 +++++++++++++
.../api/response/FindInstancesResponse.java | 11 +-
.../cache/InstanceCacheManager.java | 0
.../cache/MicroserviceInstanceCache.java | 0
.../client/http/MicroserviceInstances.java | 39 ++++++-
.../config/ServiceRegistryCommonConfig.java} | 22 ++--
.../consumer/MicroserviceVersions.java | 12 +--
.../definition/DefinitionConst.java | 4 +
.../definition/MicroserviceDefinition.java | 0
.../definition/MicroserviceNameParser.java | 0
.../event/MicroserviceInstanceRegisteredEvent.java | 10 +-
.../serviceregistry/swagger/SwaggerLoader.java | 0
.../org/apache/servicecomb/core/TestTransport.java | 47 --------
.../servicecomb/serviceregistry/RegistryUtils.java | 14 +--
.../servicecomb/serviceregistry/api/Const.java | 2 -
.../config/ServiceRegistryConfig.java | 11 --
.../config/ServiceRegistryConfigBuilder.java | 9 --
.../cache/RefreshableMicroserviceCache.java | 4 +-
28 files changed, 290 insertions(+), 316 deletions(-)
diff --git a/core/pom.xml b/core/pom.xml
index c1dcef8..326efc9 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -30,6 +30,10 @@
<dependencies>
<dependency>
<groupId>org.apache.servicecomb</groupId>
+ <artifactId>foundation-vertx</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
<artifactId>swagger-invocation-core</artifactId>
</dependency>
<dependency>
diff --git a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
index 0c13f85..0ba04c8 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
@@ -38,7 +38,6 @@ import org.apache.servicecomb.core.definition.CoreMetaUtils;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.MicroserviceVersionsMeta;
import org.apache.servicecomb.core.definition.ServiceRegistryListener;
-import org.apache.servicecomb.core.endpoint.AbstractEndpointsCache;
import org.apache.servicecomb.core.event.InvocationFinishEvent;
import org.apache.servicecomb.core.event.InvocationStartEvent;
import org.apache.servicecomb.core.executor.ExecutorManager;
@@ -50,18 +49,18 @@ import org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig
import org.apache.servicecomb.core.provider.producer.ProducerProviderManager;
import org.apache.servicecomb.core.transport.TransportManager;
import org.apache.servicecomb.foundation.common.VendorExtensions;
-import org.apache.servicecomb.foundation.common.concurrency.SuppressedRunnableWrapper;
import org.apache.servicecomb.foundation.common.event.EnableExceptionPropagation;
import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.vertx.VertxUtils;
import org.apache.servicecomb.foundation.vertx.client.http.HttpClients;
+import org.apache.servicecomb.serviceregistry.DiscoveryManager;
+import org.apache.servicecomb.serviceregistry.RegistrationManager;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
-import org.apache.servicecomb.serviceregistry.ServiceRegistry;
-import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions;
import org.apache.servicecomb.serviceregistry.definition.MicroserviceNameParser;
+import org.apache.servicecomb.serviceregistry.event.MicroserviceInstanceRegisteredEvent;
import org.apache.servicecomb.serviceregistry.swagger.SwaggerLoader;
import org.apache.servicecomb.serviceregistry.task.MicroserviceInstanceRegisterTask;
import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
@@ -161,7 +160,7 @@ public class SCBEngine {
}
public String getAppId() {
- return RegistryUtils.getAppId();
+ return DiscoveryManager.INSTANCE.getApplicationId();
}
public void setStatus(SCBStatus status) {
@@ -183,12 +182,8 @@ public class SCBEngine {
return INSTANCE;
}
- public ServiceRegistry getServiceRegistry() {
- return RegistryUtils.getServiceRegistry();
- }
-
public SwaggerLoader getSwaggerLoader() {
- return RegistryUtils.getSwaggerLoader();
+ return RegistrationManager.INSTANCE.getSwaggerLoader();
}
@@ -362,8 +357,6 @@ public class SCBEngine {
bootListeners.sort(Comparator.comparingInt(BootListener::getOrder));
- AbstractEndpointsCache.init(RegistryUtils.getInstanceCacheManager(), transportManager);
-
triggerEvent(EventType.BEFORE_HANDLER);
HandlerConfigUtils.init(consumerHandlerManager, producerHandlerManager);
triggerEvent(EventType.AFTER_HANDLER);
@@ -386,14 +379,15 @@ public class SCBEngine {
triggerAfterRegistryEvent();
- RegistryUtils.run();
+ RegistrationManager.INSTANCE.run();
+ DiscoveryManager.INSTANCE.run();
shutdownHook = new Thread(this::destroyForShutdownHook);
Runtime.getRuntime().addShutdownHook(shutdownHook);
}
private void createProducerMicroserviceMeta() {
- String microserviceName = RegistryUtils.getMicroservice().getServiceName();
+ String microserviceName = RegistrationManager.INSTANCE.getMicroservice().getServiceName();
List<Handler> consumerHandlerChain = consumerHandlerManager.getOrCreate(microserviceName);
List<Handler> producerHandlerChain = producerHandlerManager.getOrCreate(microserviceName);
@@ -437,7 +431,9 @@ public class SCBEngine {
//Step 3: Unregister microservice instance from Service Center and close vertx
// Forbidden other consumers find me
- RegistryUtils.destroy();
+ RegistrationManager.INSTANCE.destroy();
+ DiscoveryManager.INSTANCE.destroy();
+
serviceRegistryListener.destroy();
//Step 4: wait all invocation finished
@@ -452,7 +448,7 @@ public class SCBEngine {
priorityPropertyManager.close();
//Step 6: Stop vertx to prevent blocking exit
- // delete the following one line when every refactor is done.
+ // delete the following one line when every refactor is done.
VertxUtils.blockCloseVertxByName("transport");
HttpClients.destroy();
@@ -462,13 +458,7 @@ public class SCBEngine {
}
private void turnDownInstanceStatus() {
- RegistryUtils.executeOnEachServiceRegistry(sr -> new SuppressedRunnableWrapper(() -> {
- MicroserviceInstance selfInstance = sr.getMicroserviceInstance();
- sr.getServiceRegistryClient().updateMicroserviceInstanceStatus(
- selfInstance.getServiceId(),
- selfInstance.getInstanceId(),
- MicroserviceInstanceStatus.DOWN);
- }).run());
+ RegistrationManager.INSTANCE.updateMicroserviceInstanceStatus(MicroserviceInstanceStatus.DOWN);
}
private void blockShutDownOperationForConsumerRefresh() {
@@ -527,7 +517,7 @@ public class SCBEngine {
* @return
*/
public MicroserviceReferenceConfig createMicroserviceReferenceConfig(String microserviceName, String versionRule) {
- MicroserviceVersions microserviceVersions = RegistryUtils.getAppManager()
+ MicroserviceVersions microserviceVersions = DiscoveryManager.INSTANCE
.getOrCreateMicroserviceVersions(parseAppId(microserviceName), microserviceName);
ConsumerMicroserviceVersionsMeta microserviceVersionsMeta = CoreMetaUtils
.getMicroserviceVersionsMeta(microserviceVersions);
@@ -603,10 +593,10 @@ public class SCBEngine {
@Subscribe
@EnableExceptionPropagation
- public void afterRegistryInstance(MicroserviceInstanceRegisterTask microserviceInstanceRegisterTask) {
- LOGGER.info("receive MicroserviceInstanceRegisterTask event, check instance Id...");
+ public void afterRegistryInstance(MicroserviceInstanceRegisteredEvent microserviceInstanceRegisteredEvent) {
+ LOGGER.info("receive MicroserviceInstanceRegisteredEvent event, check instance Id...");
- if (!StringUtils.isEmpty(RegistryUtils.getMicroserviceInstance().getInstanceId())) {
+ if (!StringUtils.isEmpty(RegistrationManager.INSTANCE.getMicroserviceInstance().getInstanceId())) {
LOGGER.info("instance registry succeeds for the first time, will send AFTER_REGISTRY event.");
engine.setStatus(SCBStatus.UP);
engine.triggerEvent(EventType.AFTER_REGISTRY);
diff --git a/core/src/main/java/org/apache/servicecomb/core/endpoint/AbstractEndpointsCache.java b/core/src/main/java/org/apache/servicecomb/core/endpoint/AbstractEndpointsCache.java
deleted file mode 100644
index 8501013..0000000
--- a/core/src/main/java/org/apache/servicecomb/core/endpoint/AbstractEndpointsCache.java
+++ /dev/null
@@ -1,119 +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.servicecomb.core.endpoint;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.serviceregistry.cache.CacheEndpoint;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCache;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
-import org.springframework.util.StringUtils;
-
-/**
- * registry模块不理解core中的概念
- * 所以要将字符串的各种信息转义一下,方便运行时使用
- */
-public abstract class AbstractEndpointsCache<ENDPOINT> {
- protected static InstanceCacheManager instanceCacheManager;
-
- protected static TransportManager transportManager;
-
- protected List<ENDPOINT> endpoints = new ArrayList<>();
-
- protected String transportName;
-
- protected InstanceCache instanceCache = null;
-
- public static void init(InstanceCacheManager instanceCacheManager, TransportManager transportManager) {
- AbstractEndpointsCache.instanceCacheManager = instanceCacheManager;
- AbstractEndpointsCache.transportManager = transportManager;
- }
-
- /*
- * transportName 可能为"",表示走任意健康的地址即可
- */
- public AbstractEndpointsCache(String appId, String microserviceName, String microserviceVersionRule,
- String transportName) {
- this.transportName = transportName;
- this.instanceCache = new InstanceCache(appId, microserviceName, microserviceVersionRule, null);
- }
-
- public List<ENDPOINT> getLatestEndpoints() {
- InstanceCache newCache = instanceCacheManager.getOrCreate(instanceCache.getAppId(),
- instanceCache.getMicroserviceName(),
- instanceCache.getMicroserviceVersionRule());
- if (!instanceCache.cacheChanged(newCache)) {
- return endpoints;
- }
-
- // 走到这里,肯定已经是存在"有效"地址了(可能是个空列表,表示没有存活的实例)
- // 先创建,成功了,再走下面的更新逻辑
- List<ENDPOINT> tmpEndpoints = createEndpoints(newCache);
-
- this.instanceCache = newCache;
- this.endpoints = tmpEndpoints;
- return endpoints;
- }
-
- protected List<ENDPOINT> createEndpoints(InstanceCache newCache) {
- Map<String, List<CacheEndpoint>> transportMap = getOrCreateTransportMap(newCache);
-
- return createEndpoints(transportMap);
- }
-
- protected List<ENDPOINT> createEndpoints(Map<String, List<CacheEndpoint>> transportMap) {
- List<ENDPOINT> tmpEndpoints = new ArrayList<>();
- for (Entry<String, List<CacheEndpoint>> entry : transportMap.entrySet()) {
- Transport transport = transportManager.findTransport(entry.getKey());
- if (transport == null) {
- continue;
- }
-
- List<CacheEndpoint> endpointList = entry.getValue();
- if (endpointList == null) {
- continue;
- }
-
- for (CacheEndpoint cacheEndpoint : endpointList) {
- ENDPOINT endpoint = createEndpoint(transport, cacheEndpoint);
- tmpEndpoints.add(endpoint);
- }
- }
- return tmpEndpoints;
- }
-
- private Map<String, List<CacheEndpoint>> getOrCreateTransportMap(InstanceCache newCache) {
- Map<String, List<CacheEndpoint>> allTransportMap = newCache.getOrCreateTransportMap();
- if (StringUtils.isEmpty(transportName)) {
- // 未指定transport,将所有transport全取出来
- return allTransportMap;
- }
-
- Map<String, List<CacheEndpoint>> transportMap = new HashMap<>();
- transportMap.put(transportName, allTransportMap.get(transportName));
- return transportMap;
- }
-
- protected abstract ENDPOINT createEndpoint(Transport transport, CacheEndpoint cacheEndpoint);
-}
diff --git a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/MicroserviceReferenceConfig.java b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/MicroserviceReferenceConfig.java
index feaf882..82af266 100644
--- a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/MicroserviceReferenceConfig.java
+++ b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/MicroserviceReferenceConfig.java
@@ -23,7 +23,7 @@ import org.apache.servicecomb.core.definition.ConsumerMicroserviceVersionsMeta;
import org.apache.servicecomb.core.definition.CoreMetaUtils;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
-import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.DiscoveryManager;
import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersion;
import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule;
import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions;
@@ -100,7 +100,7 @@ public class MicroserviceReferenceConfig {
}
private void mark3rdPartyService(OperationMeta operationMeta, ReferenceConfig referenceConfig) {
- final MicroserviceVersions microserviceVersions = RegistryUtils.getAppManager()
+ final MicroserviceVersions microserviceVersions = DiscoveryManager.INSTANCE
.getOrCreateMicroserviceVersions(
operationMeta.getMicroserviceMeta().getAppId(),
operationMeta.getMicroserviceName());
diff --git a/core/src/main/java/org/apache/servicecomb/core/provider/producer/ProducerBootListener.java b/core/src/main/java/org/apache/servicecomb/core/provider/producer/ProducerBootListener.java
index 542783a..0aac744 100644
--- a/core/src/main/java/org/apache/servicecomb/core/provider/producer/ProducerBootListener.java
+++ b/core/src/main/java/org/apache/servicecomb/core/provider/producer/ProducerBootListener.java
@@ -24,15 +24,15 @@ import java.util.concurrent.ExecutorService;
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.core.BootListener;
+import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
-import org.apache.servicecomb.deployment.Deployment;
import org.apache.servicecomb.foundation.common.utils.IOUtils;
-import org.apache.servicecomb.serviceregistry.RegistryUtils;
-import org.apache.servicecomb.serviceregistry.api.Const;
+import org.apache.servicecomb.serviceregistry.RegistrationManager;
import org.apache.servicecomb.serviceregistry.api.registry.BasePath;
import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
import org.apache.servicecomb.swagger.SwaggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,7 +48,7 @@ public class ProducerBootListener implements BootListener {
@Override
public void onAfterTransport(BootEvent event) {
// register schema to microservice;
- Microservice microservice = event.getScbEngine().getServiceRegistry().getMicroservice();
+ Microservice microservice = RegistrationManager.INSTANCE.getMicroservice();
String swaggerSchema = "http";
for (String endpoint : microservice.getInstance().getEndpoints()) {
@@ -67,23 +67,21 @@ public class ProducerBootListener implements BootListener {
microserviceMeta.getMicroserviceName(),
schemaMeta.getSchemaId(),
content);
- RegistryUtils.executeOnEachServiceRegistry(sr -> {
- sr.getMicroservice().addSchema(schemaMeta.getSchemaId(), content);
- });
+ // TODO: don't forget to implement this in registry
+ RegistrationManager.INSTANCE.addSchema(schemaMeta.getSchemaId(), content);
}
- RegistryUtils.executeOnEachServiceRegistry(sr -> {
- saveBasePaths(microserviceMeta, sr.getMicroservice());
- });
+ // TODO: don't forget to implement this in registry
+ saveBasePaths(microserviceMeta);
}
// just compatible to old 3rd components, servicecomb not use it......
- private void saveBasePaths(MicroserviceMeta microserviceMeta, Microservice microservice) {
- if (!DynamicPropertyFactory.getInstance().getBooleanProperty(Const.REGISTER_SERVICE_PATH, false).get()) {
+ private void saveBasePaths(MicroserviceMeta microserviceMeta) {
+ if (!DynamicPropertyFactory.getInstance().getBooleanProperty(DefinitionConst.REGISTER_SERVICE_PATH, false).get()) {
return;
}
- String urlPrefix = Deployment.getClassLoaderScopeProperty(Const.URL_PREFIX);
+ String urlPrefix = SCBEngine.getClassLoaderScopeProperty(DefinitionConst.URL_PREFIX);
Map<String, BasePath> basePaths = new LinkedHashMap<>();
for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas().values()) {
Swagger swagger = schemaMeta.getSwagger();
@@ -98,7 +96,8 @@ public class ProducerBootListener implements BootListener {
basePaths.put(basePath, basePathObj);
}
}
- microservice.getPaths().addAll(basePaths.values());
+
+ RegistrationManager.INSTANCE.addBasePath(basePaths.values());
}
// bug: can not close all thread for edge
diff --git a/core/src/main/java/org/apache/servicecomb/core/provider/producer/ProducerProviderManager.java b/core/src/main/java/org/apache/servicecomb/core/provider/producer/ProducerProviderManager.java
index d7694d8..56db136 100644
--- a/core/src/main/java/org/apache/servicecomb/core/provider/producer/ProducerProviderManager.java
+++ b/core/src/main/java/org/apache/servicecomb/core/provider/producer/ProducerProviderManager.java
@@ -30,9 +30,8 @@ import org.apache.servicecomb.core.definition.MicroserviceMeta;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.definition.SchemaMeta;
import org.apache.servicecomb.core.executor.ExecutorManager;
-import org.apache.servicecomb.deployment.Deployment;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
-import org.apache.servicecomb.serviceregistry.api.Const;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
import org.apache.servicecomb.swagger.engine.SwaggerProducer;
import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
import org.slf4j.Logger;
@@ -117,11 +116,11 @@ public class ProducerProviderManager {
// This is special requirement by users: When service deployed in tomcat,user want to use RestTemplate to
// call REST service by the full url. e.g. restTemplate.getForObejct("cse://serviceName/root/prefix/health")
// By default, user's do not need context prefix, e.g. restTemplate.getForObejct("cse://serviceName/health")
- private void registerUrlPrefixToSwagger( Swagger swagger) {
- String urlPrefix = Deployment.getClassLoaderScopeProperty(Const.URL_PREFIX);
+ private void registerUrlPrefixToSwagger(Swagger swagger) {
+ String urlPrefix = SCBEngine.getClassLoaderScopeProperty(DefinitionConst.URL_PREFIX);
if (!StringUtils.isEmpty(urlPrefix) && !swagger.getBasePath().startsWith(urlPrefix)
&& DynamicPropertyFactory.getInstance()
- .getBooleanProperty(Const.REGISTER_URL_PREFIX, false).get()) {
+ .getBooleanProperty(DefinitionConst.REGISTER_URL_PREFIX, false).get()) {
LOGGER.info("Add swagger base path prefix for {} with {}", swagger.getBasePath(), urlPrefix);
swagger.setBasePath(urlPrefix + swagger.getBasePath());
}
diff --git a/core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/Discovery.java
similarity index 57%
copy from core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java
copy to core/src/main/java/org/apache/servicecomb/serviceregistry/Discovery.java
index b4a2e8a..30ea1e9 100644
--- a/core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/Discovery.java
@@ -15,23 +15,21 @@
* limitations under the License.
*/
-package org.apache.servicecomb.serviceregistry.api.response;
+package org.apache.servicecomb.serviceregistry;
-import java.util.List;
+import org.apache.servicecomb.foundation.common.utils.SPIOrder;
+import org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
+import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions;
-import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+public interface Discovery extends SPIOrder, LifeCycle {
+ MicroserviceInstances findServiceInstances(String appId, String serviceName,
+ String versionRule);
-/**
- * Created by on 2016/12/8.
- */
-public class FindInstancesResponse {
- private List<MicroserviceInstance> instances;
+ MicroserviceVersions getOrCreateMicroserviceVersions(String appId, String microserviceName);
+
+ String getRevision();
- public List<MicroserviceInstance> getInstances() {
- return instances;
- }
+ void setRevision(String revision);
- public void setInstances(List<MicroserviceInstance> instances) {
- this.instances = instances;
- }
+ String name();
}
diff --git a/core/src/main/java/org/apache/servicecomb/serviceregistry/DiscoveryManager.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/DiscoveryManager.java
new file mode 100644
index 0000000..ff2975a
--- /dev/null
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/DiscoveryManager.java
@@ -0,0 +1,77 @@
+/*
+ * 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.servicecomb.serviceregistry;
+
+import java.util.List;
+
+import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader;
+import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
+import org.apache.servicecomb.serviceregistry.consumer.AppManager;
+import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions;
+import org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition;
+
+public class DiscoveryManager {
+ public static DiscoveryManager INSTANCE = new DiscoveryManager();
+
+ private List<Discovery> discoveryList = SPIServiceUtils.getOrLoadSortedService(Discovery.class);
+
+ private final AppManager appManager = new AppManager();
+
+ private final MicroserviceDefinition microserviceDefinition;
+
+ public DiscoveryManager() {
+ MicroserviceConfigLoader loader = ConfigUtil.getMicroserviceConfigLoader();
+ microserviceDefinition = new MicroserviceDefinition(loader.getConfigModels());
+ }
+
+ public MicroserviceInstances findServiceInstances(String appId, String serviceName,
+ String versionRule, String revision) {
+ MicroserviceInstances result = new MicroserviceInstances();
+
+ discoveryList
+ .forEach(discovery -> {
+ MicroserviceInstances microserviceInstances = discovery.findServiceInstances(appId, serviceName, versionRule);
+ result.mergeMicroserviceInstances(microserviceInstances);
+ discovery.setRevision(microserviceInstances.getRevision());
+ });
+
+ return result;
+ }
+
+ public AppManager getAppManager() {
+ return this.appManager;
+ }
+
+ public MicroserviceVersions getOrCreateMicroserviceVersions(String appId, String microserviceName) {
+ return appManager.getOrCreateMicroserviceVersions(appId, microserviceName);
+ }
+
+ public String getApplicationId() {
+ return microserviceDefinition.getApplicationId();
+ }
+
+ public void destroy() {
+ discoveryList.forEach(discovery -> discovery.destroy());
+ }
+
+ public void run() {
+ discoveryList.forEach(discovery -> discovery.run());
+ }
+}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/LifeCycle.java
similarity index 67%
copy from service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
copy to core/src/main/java/org/apache/servicecomb/serviceregistry/LifeCycle.java
index 43a7377..70bbccb 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/LifeCycle.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.servicecomb.serviceregistry.cache;
+package org.apache.servicecomb.serviceregistry;
-import org.apache.servicecomb.foundation.common.cache.VersionedCache;
+public interface LifeCycle {
+ void run();
-public interface InstanceCacheManager {
- InstanceCache getOrCreate(String appId, String microserviceName, String microserviceVersionRule);
-
- VersionedCache getOrCreateVersionedCache(String appId, String microserviceName, String microserviceVersionRule);
+ void destroy();
}
diff --git a/core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/Registration.java
similarity index 56%
copy from core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java
copy to core/src/main/java/org/apache/servicecomb/serviceregistry/Registration.java
index b4a2e8a..1262733 100644
--- a/core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/Registration.java
@@ -15,23 +15,24 @@
* limitations under the License.
*/
-package org.apache.servicecomb.serviceregistry.api.response;
+package org.apache.servicecomb.serviceregistry;
-import java.util.List;
+import java.util.Collection;
+import org.apache.servicecomb.foundation.common.utils.SPIOrder;
+import org.apache.servicecomb.serviceregistry.api.registry.BasePath;
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
-/**
- * Created by on 2016/12/8.
- */
-public class FindInstancesResponse {
- private List<MicroserviceInstance> instances;
+public interface Registration extends SPIOrder, LifeCycle {
+ MicroserviceInstance getMicroserviceInstance();
+
+ Microservice getMicroservice();
+
+ boolean updateMicroserviceInstanceStatus(MicroserviceInstanceStatus status);
- public List<MicroserviceInstance> getInstances() {
- return instances;
- }
+ void addSchema(String schemaId, String content);
- public void setInstances(List<MicroserviceInstance> instances) {
- this.instances = instances;
- }
+ void addBasePath(Collection<BasePath> basePaths);
}
diff --git a/core/src/main/java/org/apache/servicecomb/serviceregistry/RegistrationManager.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/RegistrationManager.java
new file mode 100644
index 0000000..da0bb9e
--- /dev/null
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/RegistrationManager.java
@@ -0,0 +1,74 @@
+/*
+ * 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.servicecomb.serviceregistry;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.serviceregistry.api.registry.BasePath;
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
+import org.apache.servicecomb.serviceregistry.swagger.SwaggerLoader;
+
+public class RegistrationManager {
+ public static RegistrationManager INSTANCE = new RegistrationManager();
+
+ private List<Registration> registrationList = SPIServiceUtils.getOrLoadSortedService(Registration.class);
+
+ private Registration primary = SPIServiceUtils.getPriorityHighestService(Registration.class);
+
+ private static SwaggerLoader swaggerLoader = new SwaggerLoader();
+
+ public MicroserviceInstance getMicroserviceInstance() {
+ return primary.getMicroserviceInstance();
+ }
+
+ public Microservice getMicroservice() {
+ return primary.getMicroservice();
+ }
+
+ public SwaggerLoader getSwaggerLoader() {
+ return swaggerLoader;
+ }
+
+ public void updateMicroserviceInstanceStatus(
+ MicroserviceInstanceStatus status) {
+ registrationList
+ .forEach(registration -> registration.updateMicroserviceInstanceStatus(status));
+ }
+
+ public void addSchema(String schemaId, String content) {
+ registrationList
+ .forEach(registration -> registration.addSchema(schemaId, content));
+ }
+
+ public void addBasePath(Collection<BasePath> basePaths) {
+ registrationList
+ .forEach(registration -> registration.addBasePath(basePaths));
+ }
+
+ public void destroy() {
+ registrationList.forEach(registration -> registration.destroy());
+ }
+
+ public void run() {
+ registrationList.forEach(registration -> registration.run());
+ }
+}
diff --git a/core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java
index b4a2e8a..4376967 100644
--- a/core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/api/response/FindInstancesResponse.java
@@ -21,9 +21,6 @@ import java.util.List;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
-/**
- * Created by on 2016/12/8.
- */
public class FindInstancesResponse {
private List<MicroserviceInstance> instances;
@@ -34,4 +31,12 @@ public class FindInstancesResponse {
public void setInstances(List<MicroserviceInstance> instances) {
this.instances = instances;
}
+
+ public void mergeInstances(List<MicroserviceInstance> instances) {
+ if (this.instances == null) {
+ this.instances = instances;
+ } else {
+ this.instances.addAll(instances);
+ }
+ }
}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
similarity index 100%
copy from service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
copy to core/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/MicroserviceInstanceCache.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/cache/MicroserviceInstanceCache.java
similarity index 100%
rename from service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/MicroserviceInstanceCache.java
rename to core/src/main/java/org/apache/servicecomb/serviceregistry/cache/MicroserviceInstanceCache.java
diff --git a/core/src/main/java/org/apache/servicecomb/serviceregistry/client/http/MicroserviceInstances.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/client/http/MicroserviceInstances.java
index 8a51e50..218d555 100644
--- a/core/src/main/java/org/apache/servicecomb/serviceregistry/client/http/MicroserviceInstances.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/client/http/MicroserviceInstances.java
@@ -19,9 +19,6 @@ package org.apache.servicecomb.serviceregistry.client.http;
import org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse;
-/**
- * Created by on 2017/12/28.
- */
public class MicroserviceInstances {
private boolean microserviceNotExist;
@@ -62,4 +59,40 @@ public class MicroserviceInstances {
public void setInstancesResponse(FindInstancesResponse instancesResponse) {
this.instancesResponse = instancesResponse;
}
+
+ public void mergeMicroserviceInstances(MicroserviceInstances other) {
+ mergeNeedRefresh(other.needRefresh);
+ mergeMicroserviceNotExist(other.microserviceNotExist);
+ mergeRevision(other.revision);
+ mergeInstanceResponse(other.getInstancesResponse());
+ mergeRevision(other.getRevision());
+ }
+
+ private void mergeRevision(String revision) {
+ if (this.revision == null || this.revision.compareTo(revision) < 0) {
+ this.revision = revision;
+ }
+ }
+
+ private void mergeMicroserviceNotExist(boolean microserviceNotExist) {
+ // if one of discovery not exist, all mark not exist
+ if (microserviceNotExist) {
+ this.microserviceNotExist = microserviceNotExist;
+ }
+ }
+
+ private void mergeNeedRefresh(boolean needRefresh) {
+ // if one of discovery need refresh, all need refresh
+ if (needRefresh) {
+ this.needRefresh = needRefresh;
+ }
+ }
+
+ private void mergeInstanceResponse(FindInstancesResponse instancesResponse) {
+ if (this.instancesResponse == null) {
+ this.instancesResponse = instancesResponse;
+ } else {
+ this.instancesResponse.mergeInstances(instancesResponse.getInstances());
+ }
+ }
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/endpoint/EndpointsCache.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryCommonConfig.java
similarity index 54%
rename from core/src/main/java/org/apache/servicecomb/core/endpoint/EndpointsCache.java
rename to core/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryCommonConfig.java
index 9fe5266..12c51a2 100644
--- a/core/src/main/java/org/apache/servicecomb/core/endpoint/EndpointsCache.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryCommonConfig.java
@@ -15,21 +15,17 @@
* limitations under the License.
*/
-package org.apache.servicecomb.core.endpoint;
+package org.apache.servicecomb.serviceregistry.config;
-import org.apache.servicecomb.core.Endpoint;
-import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.serviceregistry.cache.CacheEndpoint;
+import com.netflix.config.DynamicPropertyFactory;
-public class EndpointsCache extends AbstractEndpointsCache<Endpoint> {
+public class ServiceRegistryCommonConfig {
+ private static final String REGISTRY_EMPTY_PROTECTION = "servicecomb.service.registry.instance.empty.protection";
- public EndpointsCache(String appId, String microserviceName, String microserviceVersionRule,
- String transportName) {
- super(appId, microserviceName, microserviceVersionRule, transportName);
- }
-
- @Override
- protected Endpoint createEndpoint(Transport transport, CacheEndpoint cacheEndpoint) {
- return new Endpoint(transport, cacheEndpoint.getEndpoint(), cacheEndpoint.getInstance());
+ public static boolean isEmptyInstanceProtectionEnabled() {
+ return
+ DynamicPropertyFactory.getInstance()
+ .getBooleanProperty(REGISTRY_EMPTY_PROTECTION,
+ true).get();
}
}
diff --git a/core/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
index dd34169..b254838 100644
--- a/core/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
@@ -28,12 +28,11 @@ import java.util.Map.Entry;
import org.apache.servicecomb.foundation.common.VendorExtensions;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
-import org.apache.servicecomb.serviceregistry.RegistryUtils;
-import org.apache.servicecomb.serviceregistry.api.Const;
+import org.apache.servicecomb.serviceregistry.DiscoveryManager;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
import org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
-import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
+import org.apache.servicecomb.serviceregistry.config.ServiceRegistryCommonConfig;
import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
import org.apache.servicecomb.serviceregistry.definition.MicroserviceNameParser;
import org.apache.servicecomb.serviceregistry.event.CreateMicroserviceEvent;
@@ -178,7 +177,7 @@ public class MicroserviceVersions {
}
protected MicroserviceInstances findServiceInstances() {
- return RegistryUtils.findServiceInstances(appId,
+ return DiscoveryManager.INSTANCE.findServiceInstances(appId,
microserviceName,
DefinitionConst.VERSION_RULE_ALL,
revision);
@@ -250,7 +249,7 @@ public class MicroserviceVersions {
return mergedInstances;
}
- if (pulledInstances.isEmpty() && inUseInstances != null && ServiceRegistryConfig.INSTANCE
+ if (pulledInstances.isEmpty() && inUseInstances != null && ServiceRegistryCommonConfig
.isEmptyInstanceProtectionEnabled()) {
MicroserviceInstancePing ping = SPIServiceUtils.getPriorityHighestService(MicroserviceInstancePing.class);
inUseInstances.stream().forEach(instance -> {
@@ -315,7 +314,8 @@ public class MicroserviceVersions {
return (appId.equals(changedEvent.getKey().getAppId()) &&
microserviceName.equals(changedEvent.getKey().getServiceName())) ||
microserviceName.equals(
- changedEvent.getKey().getAppId() + DefinitionConst.APP_SERVICE_SEPARATOR + changedEvent.getKey().getServiceName());
+ changedEvent.getKey().getAppId() + DefinitionConst.APP_SERVICE_SEPARATOR + changedEvent.getKey()
+ .getServiceName());
}
public void destroy() {
diff --git a/core/src/main/java/org/apache/servicecomb/serviceregistry/definition/DefinitionConst.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/definition/DefinitionConst.java
index 53a61aa..9bb145e 100644
--- a/core/src/main/java/org/apache/servicecomb/serviceregistry/definition/DefinitionConst.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/definition/DefinitionConst.java
@@ -44,4 +44,8 @@ public interface DefinitionConst {
String APP_SERVICE_SEPARATOR = ":";
String URL_PREFIX = "urlPrefix";
+
+ public static final String REGISTER_URL_PREFIX = "servicecomb.service.registry.registerUrlPrefix";
+
+ public static final String REGISTER_SERVICE_PATH = "servicecomb.service.registry.registerPath";
}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/definition/MicroserviceDefinition.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/definition/MicroserviceDefinition.java
similarity index 100%
rename from service-registry/src/main/java/org/apache/servicecomb/serviceregistry/definition/MicroserviceDefinition.java
rename to core/src/main/java/org/apache/servicecomb/serviceregistry/definition/MicroserviceDefinition.java
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/definition/MicroserviceNameParser.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/definition/MicroserviceNameParser.java
similarity index 100%
rename from service-registry/src/main/java/org/apache/servicecomb/serviceregistry/definition/MicroserviceNameParser.java
rename to core/src/main/java/org/apache/servicecomb/serviceregistry/definition/MicroserviceNameParser.java
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/event/MicroserviceInstanceRegisteredEvent.java
similarity index 67%
rename from service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
rename to core/src/main/java/org/apache/servicecomb/serviceregistry/event/MicroserviceInstanceRegisteredEvent.java
index 43a7377..8149a76 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
+++ b/core/src/main/java/org/apache/servicecomb/serviceregistry/event/MicroserviceInstanceRegisteredEvent.java
@@ -15,12 +15,8 @@
* limitations under the License.
*/
-package org.apache.servicecomb.serviceregistry.cache;
+package org.apache.servicecomb.serviceregistry.event;
-import org.apache.servicecomb.foundation.common.cache.VersionedCache;
-
-public interface InstanceCacheManager {
- InstanceCache getOrCreate(String appId, String microserviceName, String microserviceVersionRule);
-
- VersionedCache getOrCreateVersionedCache(String appId, String microserviceName, String microserviceVersionRule);
+public class MicroserviceInstanceRegisteredEvent {
+ // TODO: registry need publish this event instead of MicroserviceInstanceRegisterTask
}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/swagger/SwaggerLoader.java b/core/src/main/java/org/apache/servicecomb/serviceregistry/swagger/SwaggerLoader.java
similarity index 100%
rename from service-registry/src/main/java/org/apache/servicecomb/serviceregistry/swagger/SwaggerLoader.java
rename to core/src/main/java/org/apache/servicecomb/serviceregistry/swagger/SwaggerLoader.java
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestTransport.java b/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
index f588df9..7f51cba 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
@@ -17,29 +17,13 @@
package org.apache.servicecomb.core;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
-import org.apache.servicecomb.core.endpoint.EndpointsCache;
-import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
-import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
-import org.apache.servicecomb.serviceregistry.cache.CacheEndpoint;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCache;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import mockit.Expectations;
-import mockit.Injectable;
-import mockit.Mocked;
-
public class TestTransport {
@BeforeClass
public static void classSetup() {
@@ -89,35 +73,4 @@ public class TestTransport {
Assert.assertEquals("test", oEndpoint.getTransport().getName());
Assert.assertEquals("rest://127.0.0.1:8080", oEndpoint.getEndpoint());
}
-
- @Test
- public void testAbstractTransport(@Mocked Microservice microservice,
- @Injectable InstanceCacheManager instanceCacheManager, @Injectable TransportManager transportManager,
- @Mocked InstanceCache instanceCache, @Injectable MicroserviceInstance instance) {
- EndpointsCache.init(instanceCacheManager, transportManager);
- EndpointsCache oEndpointsCache = new EndpointsCache("app", "testname", "test", "rest");
-
- List<Endpoint> endpoionts = oEndpointsCache.getLatestEndpoints();
- Assert.assertEquals(endpoionts.size(), 0);
-
- Map<String, List<CacheEndpoint>> allTransportMap = new HashMap<>();
- CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://127.0.0.1:9999", instance);
- List<CacheEndpoint> restEndpoints = new ArrayList<>();
- restEndpoints.add(cacheEndpoint);
- allTransportMap.put("rest", restEndpoints);
-
- new Expectations() {
- {
- instanceCacheManager.getOrCreate(anyString, anyString, anyString);
- result = instanceCache;
- instanceCache.cacheChanged((InstanceCache) any);
- result = true;
- instanceCache.getOrCreateTransportMap();
- result = allTransportMap;
- }
- };
-
- endpoionts = oEndpointsCache.getLatestEndpoints();
- Assert.assertEquals(endpoionts.size(), 1);
- }
}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
index 28e881d..9e02945 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/RegistryUtils.java
@@ -76,11 +76,7 @@ public final class RegistryUtils {
private static final String PUBLISH_PORT = "servicecomb.{transport_name}.publishPort";
- private static SwaggerLoader swaggerLoader = new SwaggerLoader();
-
- private static AppManager appManager = new AppManager();
-
- private static InstanceCacheManager instanceCacheManager = new InstanceCacheManagerNew(appManager);
+ private static InstanceCacheManager instanceCacheManager = new InstanceCacheManagerNew(DiscoveryManager.INSTANCE.getAppManager());
private static final Map<String, ServiceRegistryConfig> EXTRA_SERVICE_REGISTRY_CONFIGS = new LinkedHashMap<>();
@@ -160,14 +156,6 @@ public final class RegistryUtils {
return instanceCacheManager;
}
- public static SwaggerLoader getSwaggerLoader() {
- return swaggerLoader;
- }
-
- public static AppManager getAppManager() {
- return appManager;
- }
-
public static String getAppId() {
return serviceRegistry.getAppId();
}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
index 606b0b2..697f16a 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/api/Const.java
@@ -193,7 +193,5 @@ public final class Const {
public static final String SERVICECENTER_FRAMEWORK_VERSION = "1.0.0";
- public static final String REGISTER_SERVICE_PATH = "servicecomb.service.registry.registerPath";
- public static final String REGISTER_URL_PREFIX = "servicecomb.service.registry.registerUrlPrefix";
}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
index a926b27..407d712 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
@@ -102,8 +102,6 @@ public final class ServiceRegistryConfig {
private int resendHeartBeatTimes;
- private boolean emptyInstanceProtectionEnabled;
-
private boolean alwaysOverrideSchema;
private boolean preferIpAddress;
@@ -283,15 +281,6 @@ public final class ServiceRegistryConfig {
return this;
}
- public boolean isEmptyInstanceProtectionEnabled() {
- return emptyInstanceProtectionEnabled;
- }
-
- public ServiceRegistryConfig setEmptyInstanceProtectionEnabled(boolean emptyInstanceProtectionEnabled) {
- this.emptyInstanceProtectionEnabled = emptyInstanceProtectionEnabled;
- return this;
- }
-
public boolean isAlwaysOverrideSchema() {
return alwaysOverrideSchema;
}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfigBuilder.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfigBuilder.java
index f00d356..69a55eb 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfigBuilder.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfigBuilder.java
@@ -59,7 +59,6 @@ class ServiceRegistryConfigBuilder {
.setInstancePullInterval(getInstancePullInterval())
.setRegistryAutoDiscovery(isRegistryAutoDiscovery())
.setResendHeartBeatTimes(getResendHeartBeatTimes())
- .setEmptyInstanceProtectionEnabled(isEmptyInstanceProtectionEnabled())
.setAlwaysOverrideSchema(isAlwaysOverrideSchema())
.setPreferIpAddress(isPreferIpAddress())
.setWatch(isWatch())
@@ -211,14 +210,6 @@ class ServiceRegistryConfigBuilder {
return times < 0 ? ServiceRegistryConfig.DEFAULT_CHECK_TIMES : times;
}
- public boolean isEmptyInstanceProtectionEnabled() {
- DynamicBooleanProperty property =
- DynamicPropertyFactory.getInstance()
- .getBooleanProperty("servicecomb.service.registry.instance.empty.protection",
- true);
- return property.get();
- }
-
public boolean isAlwaysOverrideSchema() {
DynamicBooleanProperty property =
DynamicPropertyFactory.getInstance()
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/cache/RefreshableMicroserviceCache.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/cache/RefreshableMicroserviceCache.java
index 9a74cf0..6038dba 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/cache/RefreshableMicroserviceCache.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/cache/RefreshableMicroserviceCache.java
@@ -24,13 +24,13 @@ import java.util.List;
import java.util.Set;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
-import org.apache.servicecomb.serviceregistry.api.Const;
import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
import org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
import org.apache.servicecomb.serviceregistry.consumer.MicroserviceInstancePing;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
import org.apache.servicecomb.serviceregistry.task.event.SafeModeChangeEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -242,7 +242,7 @@ public class RefreshableMicroserviceCache implements MicroserviceCache {
&& ( // microserviceName matched
key.getServiceName().equals(event.getKey().getServiceName())
|| key.getServiceName().equals(
- event.getKey().getAppId() + Const.APP_SERVICE_SEPARATOR + event.getKey().getServiceName()
+ event.getKey().getAppId() + DefinitionConst.APP_SERVICE_SEPARATOR + event.getKey().getServiceName()
));
}
}