-
Notifications
You must be signed in to change notification settings - Fork 0
fix(ai): add clusterId column to ModelServiceInstanceVO #3358
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
Changes from all commits
6b4521b
3b5bda3
80df074
24d4f3b
42ff614
ba18569
76490a5
461e8a2
32e1e94
addec8c
343bceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/bin/bash | ||
| # Pre-push hook: validate remote, branch name, and commit before pushing | ||
| # Prevents common mistakes: | ||
| # - Pushing to fork instead of upstream (or vice versa) | ||
| # - Branch name not matching ZSTAC-XXXXX pattern for fix branches | ||
| # - Pushing wrong commits | ||
|
|
||
| RED='\033[0;31m' | ||
| YELLOW='\033[1;33m' | ||
| GREEN='\033[0;32m' | ||
| NC='\033[0m' | ||
|
|
||
| REMOTE="$1" | ||
| URL="$2" | ||
|
|
||
| BRANCH=$(git branch --show-current) | ||
|
|
||
| # Skip validation for non-fix branches (master, release branches, etc.) | ||
| if [[ ! "$BRANCH" =~ ^fix/ ]] && [[ ! "$BRANCH" =~ ^feature/ ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| ERRORS=0 | ||
|
|
||
| # --- Check 1: Branch name format --- | ||
| if [[ "$BRANCH" =~ ^fix/ ]]; then | ||
| if [[ ! "$BRANCH" =~ ^fix/ZSTAC-[0-9]+ ]]; then | ||
| echo -e "${RED}[pre-push] Branch name '$BRANCH' does not match fix/ZSTAC-XXXXX pattern${NC}" | ||
| echo -e "${YELLOW} Hint: Use 'ZSTAC' not 'ZSTACK'. Example: fix/ZSTAC-82099${NC}" | ||
| ERRORS=$((ERRORS + 1)) | ||
| fi | ||
| fi | ||
|
|
||
| # --- Check 2: Remote URL sanity --- | ||
| REMOTE_URL=$(git remote get-url "$REMOTE" 2>/dev/null) | ||
| if [ -z "$REMOTE_URL" ]; then | ||
| echo -e "${RED}[pre-push] Cannot resolve remote '$REMOTE'${NC}" | ||
| ERRORS=$((ERRORS + 1)) | ||
| fi | ||
|
|
||
| # Warn if pushing to upstream (zstackio) directly — usually want to push to fork (origin) | ||
| if echo "$REMOTE_URL" | grep -q "zstackio/" && [ "$REMOTE" = "upstream" ]; then | ||
| echo -e "${YELLOW}[pre-push] WARNING: Pushing directly to upstream (zstackio). Are you sure?${NC}" | ||
| echo -e "${YELLOW} Remote URL: $REMOTE_URL${NC}" | ||
| echo -e "${YELLOW} Usually you want to push to 'origin' (your fork) instead.${NC}" | ||
| # Warning only, don't block | ||
| fi | ||
|
|
||
| # --- Check 3: Verify latest commit has a Change-Id --- | ||
| LAST_COMMIT_MSG=$(git log -1 --format=%B) | ||
| if ! echo "$LAST_COMMIT_MSG" | grep -q "^Change-Id: I[0-9a-f]\{40\}"; then | ||
| echo -e "${RED}[pre-push] Latest commit is missing Change-Id${NC}" | ||
| echo -e "${YELLOW} Use 'source scripts/zcommit.sh && zcommit ...' to create commits with Change-Id${NC}" | ||
| ERRORS=$((ERRORS + 1)) | ||
| fi | ||
|
|
||
| # --- Check 4: Verify latest commit references a Jira ticket (for fix branches) --- | ||
| if [[ "$BRANCH" =~ ^fix/ ]]; then | ||
| if ! echo "$LAST_COMMIT_MSG" | grep -qi "ZSTAC-[0-9]\+"; then | ||
| echo -e "${RED}[pre-push] Latest commit does not reference a ZSTAC ticket${NC}" | ||
| ERRORS=$((ERRORS + 1)) | ||
| fi | ||
| fi | ||
|
|
||
| # --- Check 5: Confirm repo identity (main vs premium) --- | ||
| TOPLEVEL=$(git rev-parse --show-toplevel 2>/dev/null) | ||
| REPO_NAME=$(basename "$TOPLEVEL") | ||
| if [[ "$BRANCH" =~ premium ]] && [[ "$REPO_NAME" != "premium" ]]; then | ||
| echo -e "${RED}[pre-push] Branch name suggests premium but you're in repo '$REPO_NAME'${NC}" | ||
| ERRORS=$((ERRORS + 1)) | ||
| fi | ||
|
|
||
| # --- Summary --- | ||
| if [ $ERRORS -gt 0 ]; then | ||
| echo "" | ||
| echo -e "${RED}[pre-push] $ERRORS error(s) found. Push blocked.${NC}" | ||
| echo -e "${YELLOW} To bypass: git push --no-verify${NC}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo -e "${GREEN}[pre-push] All checks passed: branch=$BRANCH remote=$REMOTE${NC}" | ||
| exit 0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -847,7 +847,9 @@ public void setBootMode(String bootMode) { | |
|
|
||
| public long getRootDiskAllocateSize() { | ||
| if (rootDiskOffering == null) { | ||
| return this.getImageSpec().getInventory().getSize(); | ||
| long virtualSize = this.getImageSpec().getInventory().getSize(); | ||
| long actualSize = this.getImageSpec().getInventory().getActualSize(); | ||
| return Math.max(virtualSize, actualSize); | ||
|
Comment on lines
+850
to
+852
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Read the VmInstanceSpec.java file, focusing on the getRootDiskAllocateSize method around line 850
head -860 header/src/main/java/org/zstack/header/vm/VmInstanceSpec.java | tail -100Repository: MatheMatrix/zstack Length of output: 3379 🏁 Script executed: # Find the ImageSpec class definition
fd -n "ImageSpec.java" --type fRepository: MatheMatrix/zstack Length of output: 292 🏁 Script executed: # Search for getInventory() definition and usage
rg -n "getInventory|setInventory" header/src/main/java/org/zstack/header/vm/VmInstanceSpec.java -A 2 -B 2Repository: MatheMatrix/zstack Length of output: 1141 🏁 Script executed: # Check ImageInventory class
fd -n "ImageInventory.java" --type fRepository: MatheMatrix/zstack Length of output: 292 🏁 Script executed: # Find ImageInventory class
rg -l "class ImageInventory" --type javaRepository: MatheMatrix/zstack Length of output: 179 🏁 Script executed: # Check the ImageInventory class for getActualSize method
rg -A 5 "getActualSize" --type java | head -50Repository: MatheMatrix/zstack Length of output: 5300 🏁 Script executed: # Look for where getRootDiskAllocateSize is called
rg -B 3 -A 3 "getRootDiskAllocateSize\(\)" --type java | head -80Repository: MatheMatrix/zstack Length of output: 4161 🏁 Script executed: # Check if ImageInventory can be null in ImageSpec
rg -B 5 -A 5 "private ImageInventory inventory" header/src/main/java/org/zstack/header/vm/VmInstanceSpec.javaRepository: MatheMatrix/zstack Length of output: 457 🏁 Script executed: # Check the ImageInventory class definition to see getActualSize method
head -150 header/src/main/java/org/zstack/header/image/ImageInventory.java | tail -100Repository: MatheMatrix/zstack Length of output: 3377 🏁 Script executed: # Look for where ImageSpec is instantiated and how inventory is set
rg "new ImageSpec\(\)" --type java -A 10 | head -100Repository: MatheMatrix/zstack Length of output: 13363 🏁 Script executed: # Check if there's any null check pattern used before calling getInventory in the codebase
rg "getInventory\(\)" --type java -B 2 -A 2 | head -150Repository: MatheMatrix/zstack Length of output: 12197 🏁 Script executed: # Look for test cases that use getRootDiskAllocateSize to see expected behavior
rg "getRootDiskAllocateSize" --type java -B 5 -A 5Repository: MatheMatrix/zstack Length of output: 6207 🏁 Script executed: # Check if there are any unit tests for getRootDiskAllocateSize
find . -name "*Test.java" -type f -exec rg -l "getRootDiskAllocateSize" {} \;Repository: MatheMatrix/zstack Length of output: 44 🏁 Script executed: # Look at the full initialization context of VmInstanceSpec.imageSpec
sed -n '320,330p' header/src/main/java/org/zstack/header/vm/VmInstanceSpec.javaRepository: MatheMatrix/zstack Length of output: 534 🏁 Script executed: # Check if ImageInventory fields can be null - look at the type of actualSize field
sed -n '1,200p' header/src/main/java/org/zstack/header/image/ImageInventory.java | grep -A 2 "private.*actualSize"Repository: MatheMatrix/zstack Length of output: 141 🏁 Script executed: # Check the return type of getSize() in ImageInventory
rg "public.*getSize\(\)" header/src/main/java/org/zstack/header/image/ImageInventory.java -A 1Repository: MatheMatrix/zstack Length of output: 110 🏁 Script executed: # Check if there are any defensive null checks before calling getActualSize on actualSize fields
rg "actualSize.*null|null.*actualSize" --type java | head -30Repository: MatheMatrix/zstack Length of output: 3319 🏁 Script executed: # Verify Math.max behavior with auto-unboxing of null Long
cat > /tmp/test_autobox.java << 'EOF'
public class Test {
public static void main(String[] args) {
Long actualSize = null;
long virtualSize = 100L;
// This will throw NPE on auto-unboxing
long result = Math.max(virtualSize, actualSize);
}
}
EOF
javac /tmp/test_autobox.java 2>&1 | head -20Repository: MatheMatrix/zstack Length of output: 106 存在多处空指针异常风险 第 850-852 行代码存在以下空指针异常隐患:
建议添加完整的空值检查,同时考虑 🛡️ 建议的修复方案 public long getRootDiskAllocateSize() {
if (rootDiskOffering == null) {
+ ImageInventory inventory = this.getImageSpec().getInventory();
+ if (inventory == null) {
+ return 0;
+ }
- long virtualSize = this.getImageSpec().getInventory().getSize();
- long actualSize = this.getImageSpec().getInventory().getActualSize();
+ long virtualSize = inventory.getSize();
+ Long actualSizeWrapper = inventory.getActualSize();
+ long actualSize = actualSizeWrapper != null ? actualSizeWrapper : virtualSize;
return Math.max(virtualSize, actualSize);
}
return rootDiskOffering.getDiskSize();
}🤖 Prompt for AI Agents |
||
| } | ||
| return rootDiskOffering.getDiskSize(); | ||
| } | ||
|
|
||
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.
premium匹配规则过于宽松,可能导致误报当前检查
[[ "$BRANCH" =~ premium ]]会匹配分支名中任意位置出现的 "premium"。例如,在主仓库中创建的fix/ZSTAC-12345-premium-bugfix分支会被误判为 premium 仓库的分支而报错。建议使用更精确的匹配模式:
🐛 建议的修复方案
📝 Committable suggestion
🤖 Prompt for AI Agents