Skip to content

Commit

Permalink
xds route and lb service
Browse files Browse the repository at this point in the history
Signed-off-by: daizhenyu <[email protected]>
  • Loading branch information
daizhenyu committed Sep 10, 2024
1 parent 88f8654 commit 570d039
Show file tree
Hide file tree
Showing 29 changed files with 1,452 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ public interface XdsCoreService extends BaseService {
* @return XdsServiceDiscovery
*/
XdsServiceDiscovery getXdsServiceDiscovery();

/**
* get xDS route service
*
* @return XdsRoute
*/
XdsRouteService getXdsRouteService();

/**
* get xDS lb service
*
* @return XdsRoute
*/
XdsLoadBalanceService getLoadBalanceService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public interface XdsLoadBalanceService {
* @param clusterName cluster name
* @return route rules
*/
XdsLbPolicy getClusterLbPolicy(String clusterName);
XdsLbPolicy getLbPolicyOfCluster(String clusterName);

/**
* get lb policy of service (base cluster)
*
* @param serviceName service name
* @return route rules
*/
XdsLbPolicy getServiceLbPolicy(String serviceName);
XdsLbPolicy getBaseLbPolicyOfService(String serviceName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package io.sermant.core.service.xds;

import io.sermant.core.service.xds.entity.ServiceInstance;
import io.sermant.core.service.xds.entity.XdsClusterLoadAssigment;
import io.sermant.core.service.xds.listener.XdsServiceDiscoveryListener;

import java.util.Optional;
import java.util.Set;

/**
Expand All @@ -29,15 +31,24 @@
**/
public interface XdsServiceDiscovery {
/**
* get service instance by service name
* get all the service instance by service name with base cluster
*
* @param serviceName service name
* @return service instances
*/
Set<ServiceInstance> getServiceInstance(String serviceName);

/**
* subscribe service instance by service name, the listener will be triggered when the service instance changes
* get service instance of service cluster
*
* @param clusterName cluster name
* @return XdsClusterInstance
*/
Optional<XdsClusterLoadAssigment> getClusterServiceInstance(String clusterName);

/**
* subscribe service instance without tag by service name, the listener will be triggered when the service instance
* changes
*
* @param serviceName service name
* @param listener listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ public class XdsClusterLoadAssigment {

private Map<XdsLocality, Set<ServiceInstance>> localityInstances;

/**
* constructor
*/
public XdsClusterLoadAssigment() {
}

/**
* parameterized constructor
*
* @param serviceName service name
* @param clusterName cluster name
* @param localityInstances service instances sorted by locality
*/
public XdsClusterLoadAssigment(String serviceName, String clusterName,
Map<XdsLocality, Set<ServiceInstance>> localityInstances) {
this.serviceName = serviceName;
this.clusterName = clusterName;
this.localityInstances = localityInstances;
}

public String getServiceName() {
return serviceName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ public class XdsLocality {

private int localityPriority;

/**
* constructor
*/
public XdsLocality() {
}

/**
* parameterized constructor
*
* @param region region
* @param zone zone
* @param subZone sub zone
* @param loadBalanceWeight load balance weigh
* @param localityPriority locality priority
*/
public XdsLocality(String region, String zone, String subZone, int loadBalanceWeight, int localityPriority) {
this.region = region;
this.zone = zone;
this.subZone = subZone;
this.loadBalanceWeight = loadBalanceWeight;
this.localityPriority = localityPriority;
}

public String getRegion() {
return region;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public class XdsServiceClusterLoadAssigment {

private String baseClusterName;

/**
* constructor
*/
public XdsServiceClusterLoadAssigment() {
}

/**
* parameterized constructor
*
* @param clusterLoadAssigments cluster load assigments
* @param baseClusterName base cluster name
*/
public XdsServiceClusterLoadAssigment(
Map<String, XdsClusterLoadAssigment> clusterLoadAssigments, String baseClusterName) {
this.clusterLoadAssigments = clusterLoadAssigments;
this.baseClusterName = baseClusterName;
}

public Map<String, XdsClusterLoadAssigment> getClusterLoadAssigments() {
return clusterLoadAssigments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@

import io.sermant.core.common.LoggerFactory;
import io.sermant.core.service.xds.XdsCoreService;
import io.sermant.core.service.xds.XdsLoadBalanceService;
import io.sermant.core.service.xds.XdsRouteService;
import io.sermant.core.service.xds.XdsServiceDiscovery;
import io.sermant.implement.service.xds.client.XdsClient;
import io.sermant.implement.service.xds.discovery.XdsServiceDiscoveryImpl;
import io.sermant.implement.service.xds.env.XdsConstant;
import io.sermant.implement.service.xds.handler.CdsHandler;
import io.sermant.implement.service.xds.handler.EdsHandler;
import io.sermant.implement.service.xds.handler.LdsHandler;
import io.sermant.implement.service.xds.handler.RdsHandler;
import io.sermant.implement.service.xds.loadbalance.XdsLoadBalanceServiceImpl;
import io.sermant.implement.service.xds.route.XdsRouteServiceImpl;

import java.io.IOException;
import java.util.logging.Level;
Expand All @@ -37,12 +46,31 @@ public class XdsCoreServiceImpl implements XdsCoreService {

private XdsServiceDiscovery xdsServiceDiscovery;

private XdsRouteService xdsRouteService;

private XdsLoadBalanceService xdsLoadBalanceService;

private XdsClient client;

@Override
public void start() {
client = new XdsClient();
xdsServiceDiscovery = new XdsServiceDiscoveryImpl(client);

// create xdsHandler
RdsHandler rdsHandler = new RdsHandler(client);
LdsHandler ldsHandler = new LdsHandler(client);
CdsHandler cdsHandler = new CdsHandler(client);

// start to subscribe lds、rds、cds
rdsHandler.subscribe(XdsConstant.RDS_ALL_RESOURCE);
ldsHandler.subscribe(XdsConstant.LDS_ALL_RESOURCE);
cdsHandler.subscribe(XdsConstant.CDS_ALL_RESOURCE);

// create xds service
EdsHandler edsHandler = new EdsHandler(client);
xdsServiceDiscovery = new XdsServiceDiscoveryImpl(edsHandler);
xdsRouteService = new XdsRouteServiceImpl();
xdsLoadBalanceService = new XdsLoadBalanceServiceImpl();
}

@Override
Expand All @@ -58,4 +86,14 @@ public void stop() {
public XdsServiceDiscovery getXdsServiceDiscovery() {
return xdsServiceDiscovery;
}

@Override
public XdsRouteService getXdsRouteService() {
return xdsRouteService;
}

@Override
public XdsLoadBalanceService getLoadBalanceService() {
return xdsLoadBalanceService;
}
}
Loading

0 comments on commit 570d039

Please sign in to comment.