-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
【enhancement】add policy event, report to backend
- Loading branch information
Showing
7 changed files
with
246 additions
and
8 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
61 changes: 61 additions & 0 deletions
61
.../router-common/src/main/java/com/huaweicloud/sermant/router/common/event/PolicyEvent.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,61 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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 com.huaweicloud.sermant.router.common.event; | ||
|
||
/** | ||
* Policy事件包含三件: | ||
* 1 相同tag规则匹配生效: 全部可用实例数小于全部实例最小可用阈值,则同TAG优先 | ||
* 2 相同tag规则匹配生效: | ||
* 未设置全部实例最小可用阈值,超过同TAG比例阈值,则同TAG优先; | ||
* 设置了全部实例最小可用阈值,但其小于全部TAG可用实例,超过同TAG比例阈值,则同TAG优先 | ||
* 3. 相同tag规则匹配不生效 | ||
* | ||
* @author robotLJW | ||
* @since 2023-04-03 | ||
* | ||
*/ | ||
public enum PolicyEvent { | ||
/** | ||
* 符合相同Tag规则匹配:全部可用实例数小于全部实例最小可用阈值,则同TAG优先 | ||
*/ | ||
SAME_TAG_MATCH_LESS_MIN_ALL_INSTANCES("According to the policy in the rule, same tag rule match that less" | ||
+ " than the minimum available threshold for all instances"), | ||
|
||
/** | ||
* 符合相同Tag规则匹配:超过同TAG比例阈值,则同TAG优先 | ||
*/ | ||
SAME_TAG_MATCH_EXCEEDED_TRIGGER_THRESHOLD("According to the policy in the rule, same tag rule match that" | ||
+ " exceeded trigger threshold"), | ||
|
||
/** | ||
* 相同Tag规则匹配没匹配上 | ||
*/ | ||
SAME_TAG_MISMATCH("According to the policy in the rule, same tag rule mismatch"); | ||
|
||
/** | ||
* 事件描述 | ||
*/ | ||
private String desc; | ||
|
||
PolicyEvent(String desc) { | ||
this.desc = desc; | ||
} | ||
|
||
public String getDesc() { | ||
return this.desc; | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
...er-common/src/main/java/com/huaweicloud/sermant/router/common/utils/PolicyEventUtils.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,66 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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 com.huaweicloud.sermant.router.common.utils; | ||
|
||
import com.huaweicloud.sermant.router.common.event.PolicyEvent; | ||
import com.huaweicloud.sermant.router.common.event.RouterEventCollector; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* | ||
* Policy事件工具类 | ||
* | ||
* @author robotLJW | ||
* @since 2023-04-06 | ||
*/ | ||
public class PolicyEventUtils { | ||
|
||
private static final ConcurrentHashMap<String, PolicyEvent> MAP = new ConcurrentHashMap<>(); | ||
|
||
private PolicyEventUtils() { | ||
} | ||
|
||
/** | ||
* | ||
* @param newState 新匹配状态 | ||
* @param tagMsg tag信息 | ||
* @param serviceName 服务名 | ||
*/ | ||
public static void notifySameTagMatchedEvent(PolicyEvent newState, String tagMsg, String serviceName) { | ||
PolicyEvent previousState = MAP.get(serviceName); | ||
if (!newState.equals(previousState)) { | ||
MAP.put(serviceName, newState); | ||
RouterEventCollector.getInstance().collectSameTagMatchedEvent(tagMsg, serviceName, newState.getDesc()); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param newState 新匹配状态 | ||
* @param tagMsg tag信息 | ||
* @param serviceName 服务名 | ||
*/ | ||
public static void notifySameTagMisMatchedEvent(PolicyEvent newState, String tagMsg, String serviceName) { | ||
PolicyEvent previousState = MAP.get(serviceName); | ||
if (!newState.equals(previousState)) { | ||
MAP.put(serviceName, newState); | ||
RouterEventCollector.getInstance().collectSameTagMisMatchedEvent(tagMsg, serviceName, newState.getDesc()); | ||
} | ||
} | ||
|
||
} |
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