forked from sermant-io/Sermant
-
Notifications
You must be signed in to change notification settings - Fork 0
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
91e61f3
commit 1e080c7
Showing
14 changed files
with
266 additions
and
68 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
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
97 changes: 97 additions & 0 deletions
97
...on/src/main/java/io/sermant/flowcontrol/common/xds/retry/ExceptionRetryConditionType.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,97 @@ | ||
/* | ||
* 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.flowcontrol.common.xds.retry; | ||
|
||
import io.sermant.core.utils.StringUtils; | ||
import io.sermant.flowcontrol.common.xds.retry.condition.ConnectErrorRetryCondition; | ||
import io.sermant.flowcontrol.common.xds.retry.condition.ResetBeforeRequestErrorCondition; | ||
import io.sermant.flowcontrol.common.xds.retry.condition.ResetErrorCondition; | ||
import io.sermant.flowcontrol.common.xds.retry.condition.ServerExceptionCondition; | ||
import io.sermant.flowcontrol.common.xds.retry.condition.SpecificHeaderNameErrorRetryCondition; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Retry Condition Manager | ||
* | ||
* @author zhp | ||
* @since 2024-11-29 | ||
*/ | ||
public enum ExceptionRetryConditionType { | ||
/** | ||
* The type of conditional judgment for server errors | ||
*/ | ||
SERVER_ERROR("5xx", new ServerExceptionCondition()), | ||
|
||
/** | ||
* The type of conditional judgment for reset errors | ||
*/ | ||
RESET_ERROR("reset", new ResetErrorCondition()), | ||
|
||
/** | ||
* The type of conditional judgment for resetting errors before request | ||
*/ | ||
RESET_BEFORE_REQUEST_ERROR("reset-before-request", new ResetBeforeRequestErrorCondition()), | ||
|
||
/** | ||
* The type of conditional judgment for connect errors | ||
*/ | ||
CONNECT_ERROR("connect-failure", new ConnectErrorRetryCondition()), | ||
|
||
/** | ||
* The type of conditional judgment for Specify response headers | ||
*/ | ||
SPECIFIC_HEADER_NAME_ERROR("retriable-headers", new SpecificHeaderNameErrorRetryCondition()); | ||
|
||
/** | ||
* the name of retry condition | ||
*/ | ||
private final String conditionName; | ||
|
||
/** | ||
* the instance of implements class for retry condition | ||
*/ | ||
private final RetryCondition retryCondition; | ||
|
||
ExceptionRetryConditionType(String conditionName, RetryCondition retryCondition) { | ||
this.conditionName = conditionName; | ||
this.retryCondition = retryCondition; | ||
} | ||
|
||
public String getConditionName() { | ||
return conditionName; | ||
} | ||
|
||
public RetryCondition getRetryCondition() { | ||
return retryCondition; | ||
} | ||
|
||
/** | ||
* get the instance of implements class by condition name | ||
* | ||
* @param conditionName condition name | ||
* @return instance of implements class for retry condition | ||
*/ | ||
public static Optional<RetryCondition> getRetryConditionByName(String conditionName) { | ||
for (ExceptionRetryConditionType retryConditionType : ExceptionRetryConditionType.values()) { | ||
if (StringUtils.equals(retryConditionType.getConditionName(), conditionName)) { | ||
return Optional.of(retryConditionType.getRetryCondition()); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
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
Oops, something went wrong.