-
Notifications
You must be signed in to change notification settings - Fork 32
fix 模块 pod 替换导致 JVM 进程内模块实例消失 #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1bdc7ea
feat(biz-ops): implement BizOpsPodCoordinator for managing biz identi…
Aiden2014 afdd6ff
feat(logging): add logging for access control in UninstallBizHandler
Aiden2014 a74e808
feat(BizOpsPodCoordinator): enhance canAccess method with detailed logic
Aiden2014 e6aee62
fix(pom): update revision to 1.4.3
Aiden2014 b2b3508
fix(BizOpsPodCoordinator): add null checks for save and remove methods
Aiden2014 55f2fb7
style: format code for better readability in InstallBizHandler and
Aiden2014 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
.../java/com/alipay/sofa/koupleless/arklet/core/command/coordinate/BizOpsPodCoordinator.java
This file contains hidden or 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,102 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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.alipay.sofa.koupleless.arklet.core.command.coordinate; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| import com.alipay.sofa.ark.common.util.StringUtils; | ||
|
|
||
| /** | ||
| * <p> | ||
| * BizOpsPodCoordinator class. | ||
| * </p> | ||
| * | ||
| * @author liuzhuoheng | ||
| * @since 2025/7/15 | ||
| * @version 1.0.0 | ||
| */ | ||
| public class BizOpsPodCoordinator { | ||
|
|
||
| /** | ||
| * bizIdentityLockMap | ||
| * key: bizIdentity, value: bizModelVersion | ||
| */ | ||
| private static final Map<String, String> bizIdentityLockMap = new ConcurrentHashMap<>(); | ||
|
|
||
| /** | ||
| * <p> | ||
| * save. | ||
| * </p> | ||
| * | ||
| * @param bizIdentity a {@link java.lang.String} object | ||
| * @param bizModelVersion a {@link java.lang.String} object | ||
| * @return | ||
| */ | ||
| public static void save(String bizIdentity, String bizModelVersion) { | ||
| if (StringUtils.isEmpty(bizIdentity)) { | ||
| return; | ||
| } | ||
| if (StringUtils.isEmpty(bizModelVersion)) { | ||
| bizModelVersion = StringUtils.EMPTY_STRING; | ||
| } | ||
| bizIdentityLockMap.put(bizIdentity, bizModelVersion); | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * remove. | ||
| * </p> | ||
| * | ||
| * @param bizIdentity a {@link java.lang.String} object | ||
| * @param bizModelVersion a {@link java.lang.String} object | ||
| * @return | ||
| */ | ||
| public static void remove(String bizIdentity, String bizModelVersion) { | ||
| if (StringUtils.isEmpty(bizIdentity)) { | ||
| return; | ||
| } | ||
| if (StringUtils.isEmpty(bizModelVersion)) { | ||
| bizIdentityLockMap.remove(bizIdentity); | ||
| return; | ||
| } | ||
| bizIdentityLockMap.remove(bizIdentity, bizModelVersion); | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * canAccess. | ||
| * </p> | ||
| * 判断是否可以访问指定的业务模块,基于业务模块版本的协调机制 | ||
| * | ||
| * @param bizIdentity 业务模块标识 (bizName:bizVersion) | ||
| * @param bizModelVersion 业务模块模型版本,用于命令协调和防止过期命令执行 | ||
| * @return 是否允许访问该业务模块 | ||
| */ | ||
| public static boolean canAccess(String bizIdentity, String bizModelVersion) { | ||
| // 判断逻辑说明: | ||
| // Case 1: bizModelVersion 为空 - 兼容性处理,允许访问(兼容旧版本 module-controller,arktcl, | ||
| // pod-not-exist 和 pod 紧急删除场景) | ||
| // Case 2: bizIdentityLockMap 中没有该 bizIdentity 的记录,允许访问(安装时不带 | ||
| // BizModelVersion,卸载时带上 BizModelVersion) | ||
| // Case 3: bizIdentityLockMap 中的版本与当前请求的版本匹配 - 版本一致,确认卸载的是该 Biz,允许访问 | ||
| // 只有当 bizModelVersion 不为空且存在 bizModelVersion 且不匹配时,才拒绝访问(防止旧的卸载命令执行) | ||
| return StringUtils.isEmpty(bizModelVersion) | ||
| || StringUtils.isEmpty(bizIdentityLockMap.get(bizIdentity)) | ||
| || bizIdentityLockMap.get(bizIdentity).equals(bizModelVersion); | ||
| } | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible NPE on remove when bizModelVersion is null (ConcurrentHashMap disallows null value).
BizOpsPodCoordinator.remove(bizIdentity, bizModelVersion)will throw ifbizModelVersion == null(legacy clients). Fix in coordinator by normalizing null/empty before callingMap.remove.Apply coordinator fix shown in that file’s comment; alternatively, add a local guard: