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 2018/04/20 03:30:23 UTC
[incubator-servicecomb-java-chassis] 02/02: SCB-474 fix pr comment
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/incubator-servicecomb-java-chassis.git
commit 94f034ac5de9c64993b25db119be3aa8e69d435f
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Fri Apr 20 10:02:56 2018 +0800
SCB-474 fix pr comment
Signed-off-by: zhengyangyong <ya...@huawei.com>
---
.../spring-boot-starter-discovery/pom.xml | 2 +-
.../CseRibbonEndpointDiscoveryFilter.java | 19 ++++++++++--
.../starter/discovery/ServiceCombServerList.java | 11 +------
.../discovery/TestServiceCombServerList.java | 36 +---------------------
4 files changed, 20 insertions(+), 48 deletions(-)
diff --git a/spring-boot-starter/spring-boot-starter-discovery/pom.xml b/spring-boot-starter/spring-boot-starter-discovery/pom.xml
index 8453465..96d535a 100644
--- a/spring-boot-starter/spring-boot-starter-discovery/pom.xml
+++ b/spring-boot-starter/spring-boot-starter-discovery/pom.xml
@@ -73,7 +73,7 @@
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>java-chassis-core</artifactId>
+ <artifactId>service-registry</artifactId>
</dependency>
</dependencies>
</project>
diff --git a/spring-boot-starter/spring-boot-starter-discovery/src/main/java/org/apache/servicecomb/springboot/starter/discovery/CseRibbonEndpointDiscoveryFilter.java b/spring-boot-starter/spring-boot-starter-discovery/src/main/java/org/apache/servicecomb/springboot/starter/discovery/CseRibbonEndpointDiscoveryFilter.java
index 741dd0a..65f72d7 100644
--- a/spring-boot-starter/spring-boot-starter-discovery/src/main/java/org/apache/servicecomb/springboot/starter/discovery/CseRibbonEndpointDiscoveryFilter.java
+++ b/spring-boot-starter/spring-boot-starter-discovery/src/main/java/org/apache/servicecomb/springboot/starter/discovery/CseRibbonEndpointDiscoveryFilter.java
@@ -17,14 +17,29 @@
package org.apache.servicecomb.springboot.starter.discovery;
-import org.apache.servicecomb.core.filter.EndpointDiscoveryFilter;
+import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.serviceregistry.discovery.AbstractEndpointDiscoveryFilter;
import org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext;
import org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode;
-public class CseRibbonEndpointDiscoveryFilter extends EndpointDiscoveryFilter {
+import com.netflix.loadbalancer.Server;
+
+public class CseRibbonEndpointDiscoveryFilter extends AbstractEndpointDiscoveryFilter {
@Override
protected String findTransportName(DiscoveryContext context, DiscoveryTreeNode parent) {
//only need rest endpoints
return "rest";
}
+
+ @Override
+ protected Object createEndpoint(String transportName, String endpoint, MicroserviceInstance instance) {
+ URIEndpointObject uri = new URIEndpointObject(endpoint);
+ return new Server(uri.getHostOrIp(), uri.getPort());
+ }
+
+ @Override
+ public int getOrder() {
+ return (int) Short.MAX_VALUE - 1;
+ }
}
diff --git a/spring-boot-starter/spring-boot-starter-discovery/src/main/java/org/apache/servicecomb/springboot/starter/discovery/ServiceCombServerList.java b/spring-boot-starter/spring-boot-starter-discovery/src/main/java/org/apache/servicecomb/springboot/starter/discovery/ServiceCombServerList.java
index 6393dbc..13f092b 100644
--- a/spring-boot-starter/spring-boot-starter-discovery/src/main/java/org/apache/servicecomb/springboot/starter/discovery/ServiceCombServerList.java
+++ b/spring-boot-starter/spring-boot-starter-discovery/src/main/java/org/apache/servicecomb/springboot/starter/discovery/ServiceCombServerList.java
@@ -16,12 +16,9 @@
*/
package org.apache.servicecomb.springboot.starter.discovery;
-import java.util.ArrayList;
import java.util.List;
-import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.foundation.common.cache.VersionedCache;
-import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
import org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext;
@@ -49,13 +46,7 @@ public class ServiceCombServerList extends AbstractServerList<Server> {
RegistryUtils.getAppId(),
serviceId,
DefinitionConst.VERSION_RULE_ALL);
- ArrayList<Endpoint> endpoints = serversVersionedCache.data();
- List<Server> instances = new ArrayList<>(endpoints.size());
- for (Endpoint endpoint : endpoints) {
- URIEndpointObject uri = new URIEndpointObject(endpoint.getEndpoint());
- instances.add(new Server(uri.getHostOrIp(), uri.getPort()));
- }
- return instances;
+ return serversVersionedCache.data();
}
@Override
diff --git a/spring-boot-starter/spring-boot-starter-discovery/src/test/java/org/apache/servicecomb/springboot/starter/discovery/TestServiceCombServerList.java b/spring-boot-starter/spring-boot-starter-discovery/src/test/java/org/apache/servicecomb/springboot/starter/discovery/TestServiceCombServerList.java
index 5f76c4b..8201641 100644
--- a/spring-boot-starter/spring-boot-starter-discovery/src/test/java/org/apache/servicecomb/springboot/starter/discovery/TestServiceCombServerList.java
+++ b/spring-boot-starter/spring-boot-starter-discovery/src/test/java/org/apache/servicecomb/springboot/starter/discovery/TestServiceCombServerList.java
@@ -19,15 +19,11 @@ package org.apache.servicecomb.springboot.starter.discovery;
import java.util.ArrayList;
import java.util.List;
-import org.apache.servicecomb.core.Endpoint;
-import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.Transport;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext;
import org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree;
import org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.junit.Assert;
import org.junit.Test;
@@ -63,37 +59,7 @@ public class TestServiceCombServerList {
discoveryTree.discovery((DiscoveryContext) any, anyString, anyString, anyString);
result = versionedCache;
versionedCache.data();
- result = Lists.newArrayList(new Endpoint(new Transport() {
- @Override
- public String getName() {
- return null;
- }
-
- @Override
- public boolean init() {
- return false;
- }
-
- @Override
- public Object parseAddress(String endpoint) {
- return null;
- }
-
- @Override
- public Endpoint getEndpoint() {
- return null;
- }
-
- @Override
- public Endpoint getPublishEndpoint() {
- return null;
- }
-
- @Override
- public void send(Invocation invocation, AsyncResponse asyncResp) {
-
- }
- }, "rest://localhost:3333"));
+ result = Lists.newArrayList(new Server("localhost", 3333));
}
};
--
To stop receiving notification emails like this one, please contact
liubao@apache.org.