Skip to content

Commit

Permalink
Fix the issue that ClassCastException error is reported when the Rest…
Browse files Browse the repository at this point in the history
…Template uses xDS routing

Signed-off-by: daizhenyu <[email protected]>
  • Loading branch information
daizhenyu committed Sep 27, 2024
1 parent 2246c98 commit 014e85f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private boolean handleXdsRouterAndUpdateServiceInstance(String serviceName, Requ
return false;
}
context.skip(Collections.unmodifiableList(SpringRouterUtils
.getSpringCloudServiceInstanceByXds(serviceInstanceByXdsRoute)));
.getSpringCloudServerByXds(serviceInstanceByXdsRoute)));
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.sermant.router.spring.utils;

import com.netflix.loadbalancer.Server;

import io.sermant.core.plugin.config.PluginConfigManager;
import io.sermant.core.service.xds.entity.ServiceInstance;
import io.sermant.core.utils.StringUtils;
Expand Down Expand Up @@ -61,6 +63,19 @@ public static List<org.springframework.cloud.client.ServiceInstance> getSpringCl
.collect(Collectors.toList());
}

/**
* get SpringCloud ServiceInstance By XdsServiceInstance
*
* @param xdsServiceInstances
* @return spring cloud service instance
*/
public static List<Server> getSpringCloudServerByXds(
Set<ServiceInstance> xdsServiceInstances) {
return xdsServiceInstances.stream()
.map(SpringRouterUtils::convertServiceInstance2Server)
.collect(Collectors.toList());
}

/**
* Get metadata
*
Expand Down Expand Up @@ -94,7 +109,7 @@ public static void putMetaData(Map<String, String> metadata, RouterConfig config
}

private static org.springframework.cloud.client.ServiceInstance convertServiceInstance(
io.sermant.core.service.xds.entity.ServiceInstance xdsServiceInstance) {
ServiceInstance xdsServiceInstance) {
StringBuilder instanceIdBuilder = new StringBuilder();
instanceIdBuilder.append(xdsServiceInstance.getHost())
.append(":")
Expand All @@ -103,4 +118,9 @@ private static org.springframework.cloud.client.ServiceInstance convertServiceIn
instanceIdBuilder.toString(), xdsServiceInstance.getServiceName(), xdsServiceInstance.getHost(),
xdsServiceInstance.getPort(), routerConfig.isEnabledSpringCloudXdsRouteSecure());
}

private static Server convertServiceInstance2Server(ServiceInstance xdsServiceInstance) {
String scheme = routerConfig.isEnabledSpringCloudXdsRouteSecure() ? "https" : "http";
return new Server(scheme, xdsServiceInstance.getHost(), xdsServiceInstance.getPort());
}
}

0 comments on commit 014e85f

Please sign in to comment.