Skip to content

Commit

Permalink
xds framework route and load balance config
Browse files Browse the repository at this point in the history
Signed-off-by: daizhenyu <[email protected]>
  • Loading branch information
daizhenyu committed Aug 26, 2024
1 parent 71acc27 commit 06c7e71
Show file tree
Hide file tree
Showing 42 changed files with 2,357 additions and 3 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
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* Licensed 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 io.sermant.core.service.xds;

import io.sermant.core.service.xds.entity.XdsLbPolicy;

/**
* xDS load balance service
*
* @author daizhenyu
* @since 2024-07-30
**/
public interface XdsLoadBalanceService {
/**
* get lb policy of cluster
*
* @param clusterName cluster name
* @return route rules
*/
XdsLbPolicy getClusterLbPolicy(String clusterName);

/**
* get lb policy of service (base cluster)
*
* @param serviceName service name
* @return route rules
*/
XdsLbPolicy getServiceLbPolicy(String serviceName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* Licensed 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 io.sermant.core.service.xds;

import io.sermant.core.service.xds.entity.XdsLbPolicy;

Check failure on line 19 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/XdsRouteService.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 Unused import - io.sermant.core.service.xds.entity.XdsLbPolicy. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/XdsRouteService.java:19:8: error: Unused import - io.sermant.core.service.xds.entity.XdsLbPolicy. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import io.sermant.core.service.xds.entity.XdsRoute;

import java.util.List;

/**
* xDS route service
*
* @author daizhenyu
* @since 2024-07-30
**/
public interface XdsRouteService {
/**
* get route rules of service
*
* @param serviceName service name
* @return route rules
*/
List<XdsRoute> getServiceRoute(String serviceName);

/**
* get lb policy of cluster
*
* @param clusterName cluster name
* @return route rules
*/
boolean isLocalityRoute(String clusterName);
}
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.XdsClusterInstance;
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 without tag by service name
*
* @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<XdsClusterInstance> getClusterInstance(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
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* Licensed 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 io.sermant.core.service.xds.entity;

/**
* XdsCluster
*
* @author daizhenyu
* @since 2024-08-06
**/
public class XdsCluster {
private String clusterName;

private String serviceName;

private XdsLbPolicy lbPolicy;

private boolean isLocalityLb;

public String getClusterName() {
return clusterName;
}

public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}

public String getServiceName() {
return serviceName;
}

public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public XdsLbPolicy getLbPolicy() {
return lbPolicy;
}

public void setLbPolicy(XdsLbPolicy lbPolicy) {
this.lbPolicy = lbPolicy;
}

public boolean isLocalityLb() {
return isLocalityLb;
}

public void setLocalityLb(boolean localityLb) {
isLocalityLb = localityLb;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* Licensed 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 io.sermant.core.service.xds.entity;

import java.util.HashMap;

Check failure on line 19 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsClusterInstance.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 Unused import - java.util.HashMap. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/xds/entity/XdsClusterInstance.java:19:8: error: Unused import - java.util.HashMap. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import java.util.Map;
import java.util.Set;

/**
* xDS ClusterInstance
*
* @author daizhenyu
* @since 2024-08-15
**/
public class XdsClusterInstance {
private String serviceName;

private String clusterName;

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

public String getServiceName() {
return serviceName;
}

public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public String getClusterName() {
return clusterName;
}

public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}

public Map<XdsLocality, Set<ServiceInstance>> getLocalityInstances() {
return localityInstances;
}

public void setLocalityInstances(
Map<XdsLocality, Set<ServiceInstance>> localityInstances) {
this.localityInstances = localityInstances;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* Licensed 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 io.sermant.core.service.xds.entity;

import io.sermant.core.service.xds.entity.match.MatchStrategy;

import java.util.Map;

/**
* xDS HeaderMatcher
*
* @author daizhenyu
* @since 2024-08-15
**/
public class XdsHeaderMatcher {
private final String name;

private final MatchStrategy matchStrategy;

/**
* parameterized constructor
*
* @param name header name
* @param matchStrategy match strategy
*/
public XdsHeaderMatcher(String name, MatchStrategy matchStrategy) {
this.name = name;
this.matchStrategy = matchStrategy;
}

/**
* the request header matches the route configuration header or not.
*
* @param headers request headers
* @return isMatch
*/
public boolean isMatch(Map<String, String> headers) {
if (headers.containsKey(name)) {
return matchStrategy.isMatch(headers.get(name));
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* Licensed 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 io.sermant.core.service.xds.entity;

/**
* xDS HttpConnectionManager
*
* @author daizhenyu
* @since 2024-08-15
**/
public class XdsHttpConnectionManager {
private String routeConfigName;

public String getRouteConfigName() {
return routeConfigName;
}

public void setRouteConfigName(String routeConfigName) {
this.routeConfigName = routeConfigName;
}
}
Loading

0 comments on commit 06c7e71

Please sign in to comment.