-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hanbingleixue <[email protected]>
- Loading branch information
1 parent
d7a054d
commit e2cc6cd
Showing
13 changed files
with
623 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...rmant-agentcore-core/src/main/java/io/sermant/core/service/xds/XdsFlowControlService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.XdsCircuitBreakers; | ||
import io.sermant.core.service.xds.entity.XdsHttpFault; | ||
import io.sermant.core.service.xds.entity.XdsOutlierDetection; | ||
import io.sermant.core.service.xds.entity.XdsRateLimit; | ||
import io.sermant.core.service.xds.entity.XdsRetryPolicy; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* xDS FlowControl service | ||
* | ||
* @author zhp | ||
* @since 2024-11-27 | ||
**/ | ||
public interface XdsFlowControlService { | ||
/** | ||
* get circuit breaker information of cluster | ||
* | ||
* @param serviceName service name | ||
* @param clusterName cluster name | ||
* @return circuit breaker rules | ||
*/ | ||
Optional<XdsCircuitBreakers> getCircuitBreakers(String serviceName, String clusterName); | ||
|
||
/** | ||
* get Outlier Detection of cluster | ||
* | ||
* @param serviceName service name | ||
* @param clusterName cluster name | ||
* @return Outlier Detection rules | ||
*/ | ||
Optional<XdsOutlierDetection> getOutlierDetection(String serviceName, String clusterName); | ||
|
||
/** | ||
* get retry policy of route name | ||
* | ||
* @param serviceName service name | ||
* @param routeName route name | ||
* @return retry policy | ||
*/ | ||
Optional<XdsRetryPolicy> getRetryPolicy(String serviceName, String routeName); | ||
|
||
/** | ||
* get rate limit of route name | ||
* | ||
* @param serviceName service name | ||
* @param routeName route name | ||
* @return rate limit rule | ||
*/ | ||
Optional<XdsRateLimit> getRateLimit(String serviceName, String routeName); | ||
|
||
/** | ||
* get http fault of route name | ||
* | ||
* @param serviceName service name | ||
* @param routeName route name | ||
* @return http fault rule | ||
*/ | ||
Optional<XdsHttpFault> getHttpFault(String serviceName, String routeName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...src/main/java/io/sermant/implement/service/xds/flowcontrol/XdsFlowControlServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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.implement.service.xds.flowcontrol; | ||
|
||
import io.sermant.core.service.xds.XdsFlowControlService; | ||
import io.sermant.core.service.xds.entity.XdsCircuitBreakers; | ||
import io.sermant.core.service.xds.entity.XdsHttpFault; | ||
import io.sermant.core.service.xds.entity.XdsOutlierDetection; | ||
import io.sermant.core.service.xds.entity.XdsRateLimit; | ||
import io.sermant.core.service.xds.entity.XdsRetryPolicy; | ||
import io.sermant.core.service.xds.entity.XdsRoute; | ||
import io.sermant.core.service.xds.entity.XdsRouteAction; | ||
import io.sermant.core.service.xds.entity.XdsServiceCluster; | ||
import io.sermant.core.utils.StringUtils; | ||
import io.sermant.implement.service.xds.cache.XdsDataCache; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* The implementation class of XdsFlowControlService | ||
* | ||
* @author zhp | ||
* @since 2024-11-27 | ||
**/ | ||
public class XdsFlowControlServiceImpl implements XdsFlowControlService { | ||
/** | ||
* constructor | ||
*/ | ||
public XdsFlowControlServiceImpl() { | ||
} | ||
|
||
@Override | ||
public Optional<XdsCircuitBreakers> getCircuitBreakers(String serviceName, String clusterName) { | ||
Map<String, XdsServiceCluster> serviceClusterMap = XdsDataCache.getServiceClusterMap(); | ||
XdsServiceCluster serviceCluster = serviceClusterMap.get(serviceName); | ||
if (serviceCluster == null) { | ||
return Optional.empty(); | ||
} | ||
return serviceCluster.getCircuitBreakersOfCluster(clusterName); | ||
} | ||
|
||
@Override | ||
public Optional<XdsOutlierDetection> getOutlierDetection(String serviceName, String clusterName) { | ||
Map<String, XdsServiceCluster> serviceClusterMap = XdsDataCache.getServiceClusterMap(); | ||
XdsServiceCluster serviceCluster = serviceClusterMap.get(serviceName); | ||
if (serviceCluster == null) { | ||
return Optional.empty(); | ||
} | ||
return serviceCluster.getOutlierDetectionOfCluster(clusterName); | ||
} | ||
|
||
@Override | ||
public Optional<XdsRetryPolicy> getRetryPolicy(String serviceName, String routeName) { | ||
List<XdsRoute> xdsRoutes = XdsDataCache.getServiceRoute(serviceName); | ||
for (XdsRoute xdsRoute : xdsRoutes) { | ||
if (StringUtils.equals(xdsRoute.getName(), routeName)) { | ||
XdsRouteAction routeAction = xdsRoute.getRouteAction(); | ||
return routeAction == null ? Optional.empty() : Optional.ofNullable(routeAction.getRetryPolicy()); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<XdsRateLimit> getRateLimit(String serviceName, String routeName) { | ||
List<XdsRoute> xdsRoutes = XdsDataCache.getServiceRoute(serviceName); | ||
for (XdsRoute xdsRoute : xdsRoutes) { | ||
if (StringUtils.equals(xdsRoute.getName(), routeName)) { | ||
return Optional.ofNullable(xdsRoute.getRateLimit()); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<XdsHttpFault> getHttpFault(String serviceName, String routeName) { | ||
List<XdsRoute> xdsRoutes = XdsDataCache.getServiceRoute(serviceName); | ||
for (XdsRoute xdsRoute : xdsRoutes) { | ||
if (StringUtils.equals(xdsRoute.getName(), routeName)) { | ||
return Optional.ofNullable(xdsRoute.getHttpFault()); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
Oops, something went wrong.