Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ public void preInstantiateVmResource(VmInstanceSpec spec, Completion completion)
} else if (image.getInventory() != null && ImageMediaType.RootVolumeTemplate.toString().equals(image.getInventory().getMediaType())) {
InstantiateVolumeMsg rmsg = fillMsg(new InstantiateRootVolumeMsg(), spec.getDestRootVolume(), spec);
((InstantiateRootVolumeMsg) rmsg).setTemplateSpec(image);
rmsg.setSystemTags(spec.getRootVolumeSystemTags());
msgs.add(rmsg);
} else {
msgs.add(fillMsg(new InstantiateVolumeMsg(), spec.getDestRootVolume(), spec));
InstantiateVolumeMsg rmsg = fillMsg(new InstantiateVolumeMsg(), spec.getDestRootVolume(), spec);
rmsg.setSystemTags(spec.getRootVolumeSystemTags());
msgs.add(rmsg);
}

if (spec.getDataVolumeTemplateUuids() != null) {
Expand Down
13 changes: 13 additions & 0 deletions tag/src/main/java/org/zstack/tag/EphemeralPatternSystemTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.zstack.tag;

import org.zstack.header.tag.TagConstant;

public class EphemeralPatternSystemTag extends PatternedSystemTag {
public EphemeralPatternSystemTag(String tagFormat, Class resourceClass) {
super(String.format("%s::%s", TagConstant.EPHEMERAL_TAG_PREFIX, tagFormat), resourceClass);
}
Comment on lines +5 to +8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

应实现 EphemeralTag 标记接口,否则不会被判定为“短暂标签”

根据以往结论,实例方法 isEphemeralTag 通过 EphemeralTag 接口识别短暂标签。当前类未实现该接口,可能导致被误当作可持久化标签参与校验/持久化。

-public class EphemeralPatternSystemTag extends PatternedSystemTag {
+public class EphemeralPatternSystemTag extends PatternedSystemTag implements EphemeralTag {

(请补充正确的 EphemeralTag 导入路径)

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public class EphemeralPatternSystemTag extends PatternedSystemTag {
public EphemeralPatternSystemTag(String tagFormat, Class resourceClass) {
super(String.format("%s::%s", TagConstant.EPHEMERAL_TAG_PREFIX, tagFormat), resourceClass);
}
public class EphemeralPatternSystemTag extends PatternedSystemTag implements EphemeralTag {
public EphemeralPatternSystemTag(String tagFormat, Class resourceClass) {
super(String.format("%s::%s", TagConstant.EPHEMERAL_TAG_PREFIX, tagFormat), resourceClass);
}
}
🤖 Prompt for AI Agents
In tag/src/main/java/org/zstack/tag/EphemeralPatternSystemTag.java around lines
5 to 8, the class EphemeralPatternSystemTag must implement the EphemeralTag
marker interface so it is recognized as an ephemeral (short-lived) tag; update
the class declaration to implement org.zstack.tag.EphemeralTag and add the
corresponding import (import org.zstack.tag.EphemeralTag;) so the type system
marks instances as ephemeral and they won’t be treated as persistent during
validation/persistence.


public String getTagFormatWithoutEphemeralPrefix() {
return tagFormat.substring(String.format("%s::", TagConstant.EPHEMERAL_TAG_PREFIX).length());
}
}
8 changes: 7 additions & 1 deletion tag/src/main/java/org/zstack/tag/TagManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ private void initSystemTags() throws IllegalAccessException {
f.getDeclaringClass(), f.getName()));
}

if (PatternedSystemTag.class.isAssignableFrom(f.getType())) {
if (EphemeralPatternSystemTag.class.isAssignableFrom(f.getType())) {
EphemeralPatternSystemTag ptag = new EphemeralPatternSystemTag(((EphemeralPatternSystemTag) stag).getTagFormatWithoutEphemeralPrefix(), stag.getResourceClass());
ptag.setValidators(stag.getValidators());
f.set(null, ptag);
systemTags.add(ptag);
stag = ptag;
} else if (PatternedSystemTag.class.isAssignableFrom(f.getType())) {
PatternedSystemTag ptag = new PatternedSystemTag(stag.getTagFormat(), stag.getResourceClass());
ptag.setValidators(stag.getValidators());
f.set(null, ptag);
Expand Down