Skip to content

Commit 26b01f6

Browse files
JoaoJandreJoão Jandre
andauthored
Flexible tags for hosts and storage pools (#7489)
Co-authored-by: João Jandre <joao@scclouds.com.br>
1 parent a31f211 commit 26b01f6

File tree

63 files changed

+1092
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1092
-213
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,10 @@ public class ApiConstants {
10661066
public static final String CLIENT_ID = "clientid";
10671067
public static final String REDIRECT_URI = "redirecturi";
10681068

1069+
public static final String IS_TAG_A_RULE = "istagarule";
1070+
1071+
public static final String PARAMETER_DESCRIPTION_IS_TAG_A_RULE = "Whether the informed tag is a JS interpretable rule or not.";
1072+
10691073
/**
10701074
* This enum specifies IO Drivers, each option controls specific policies on I/O.
10711075
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).

api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class UpdateHostCmd extends BaseCmd {
6060
@Parameter(name = ApiConstants.HOST_TAGS, type = CommandType.LIST, collectionType = CommandType.STRING, description = "list of tags to be added to the host")
6161
private List<String> hostTags;
6262

63+
@Parameter(name = ApiConstants.IS_TAG_A_RULE, type = CommandType.BOOLEAN, description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
64+
private Boolean isTagARule;
65+
6366
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, description = "the new uri for the secondary storage: nfs://host/path")
6467
private String url;
6568

@@ -90,6 +93,10 @@ public List<String> getHostTags() {
9093
return hostTags;
9194
}
9295

96+
public Boolean getIsTagARule() {
97+
return isTagARule;
98+
}
99+
93100
public String getUrl() {
94101
return url;
95102
}

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public class CreateStoragePoolCmd extends BaseCmd {
9090
description = "hypervisor type of the hosts in zone that will be attached to this storage pool. KVM, VMware supported as of now.")
9191
private String hypervisor;
9292

93+
@Parameter(name = ApiConstants.IS_TAG_A_RULE, type = CommandType.BOOLEAN, description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
94+
private Boolean isTagARule;
95+
9396
/////////////////////////////////////////////////////
9497
/////////////////// Accessors ///////////////////////
9598
/////////////////////////////////////////////////////
@@ -146,6 +149,10 @@ public String getHypervisor() {
146149
return hypervisor;
147150
}
148151

152+
public Boolean isTagARule() {
153+
return this.isTagARule;
154+
}
155+
149156
@Override
150157
public long getEntityOwnerId() {
151158
return Account.ACCOUNT_ID_SYSTEM;

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public class UpdateStoragePoolCmd extends BaseCmd {
6161
" enable it back.")
6262
private Boolean enabled;
6363

64+
@Parameter(name = ApiConstants.IS_TAG_A_RULE, type = CommandType.BOOLEAN, description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
65+
private Boolean isTagARule;
66+
6467
/////////////////////////////////////////////////////
6568
/////////////////// Accessors ///////////////////////
6669
/////////////////////////////////////////////////////
@@ -89,6 +92,10 @@ public Boolean getEnabled() {
8992
return enabled;
9093
}
9194

95+
public Boolean isTagARule() {
96+
return isTagARule;
97+
}
98+
9299
/////////////////////////////////////////////////////
93100
/////////////// API Implementation///////////////////
94101
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ public class HostResponse extends BaseResponseWithAnnotations {
221221
@Param(description = "comma-separated list of tags for the host")
222222
private String hostTags;
223223

224+
@SerializedName(ApiConstants.IS_TAG_A_RULE)
225+
@Param(description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
226+
private Boolean isTagARule;
227+
224228
@SerializedName("hasenoughcapacity")
225229
@Param(description = "true if this host has enough CPU and RAM capacity to migrate a VM to it, false otherwise")
226230
private Boolean hasEnoughCapacity;
@@ -732,4 +736,12 @@ public void setUefiCapabilty(Boolean hostCapability) {
732736
public void setEncryptionSupported(Boolean encryptionSupported) {
733737
this.encryptionSupported = encryptionSupported;
734738
}
739+
740+
public Boolean getIsTagARule() {
741+
return isTagARule;
742+
}
743+
744+
public void setIsTagARule(Boolean tagARule) {
745+
isTagARule = tagARule;
746+
}
735747
}

api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public class StoragePoolResponse extends BaseResponseWithAnnotations {
101101
@Param(description = "the tags for the storage pool")
102102
private String tags;
103103

104+
@SerializedName(ApiConstants.IS_TAG_A_RULE)
105+
@Param(description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
106+
private Boolean isTagARule;
107+
104108
@SerializedName(ApiConstants.STATE)
105109
@Param(description = "the state of the storage pool")
106110
private StoragePoolStatus state;
@@ -304,6 +308,14 @@ public void setTags(String tags) {
304308
this.tags = tags;
305309
}
306310

311+
public Boolean getIsTagARule() {
312+
return isTagARule;
313+
}
314+
315+
public void setIsTagARule(Boolean tagARule) {
316+
isTagARule = tagARule;
317+
}
318+
307319
public StoragePoolStatus getState() {
308320
return state;
309321
}

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreParameters.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class PrimaryDataStoreParameters {
4343
private boolean managed;
4444
private Long capacityIops;
4545

46+
private Boolean isTagARule;
47+
4648
/**
4749
* @return the userInfo
4850
*/
@@ -277,4 +279,12 @@ public long getUsedBytes() {
277279
public void setUsedBytes(long usedBytes) {
278280
this.usedBytes = usedBytes;
279281
}
282+
283+
public Boolean isTagARule() {
284+
return isTagARule;
285+
}
286+
287+
public void setIsTagARule(Boolean isTagARule) {
288+
this.isTagARule = isTagARule;
289+
}
280290
}

engine/schema/src/main/java/com/cloud/host/HostTagVO.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.persistence.Table;
2525

2626
import org.apache.cloudstack.api.InternalIdentity;
27+
import org.apache.commons.lang3.BooleanUtils;
2728

2829
@Entity
2930
@Table(name = "host_tags")
@@ -39,12 +40,22 @@ public class HostTagVO implements InternalIdentity {
3940
@Column(name = "tag")
4041
private String tag;
4142

43+
@Column(name = "is_tag_a_rule")
44+
private boolean isTagARule;
45+
4246
protected HostTagVO() {
4347
}
4448

4549
public HostTagVO(long hostId, String tag) {
4650
this.hostId = hostId;
4751
this.tag = tag;
52+
this.isTagARule = false;
53+
}
54+
55+
public HostTagVO(long hostId, String tag, Boolean isTagARule) {
56+
this.hostId = hostId;
57+
this.tag = tag;
58+
this.isTagARule = BooleanUtils.toBooleanDefaultIfNull(isTagARule, false);
4859
}
4960

5061
public long getHostId() {
@@ -59,6 +70,11 @@ public void setTag(String tag) {
5970
this.tag = tag;
6071
}
6172

73+
public boolean getIsTagARule() {
74+
return isTagARule;
75+
}
76+
77+
6278
@Override
6379
public long getId() {
6480
return id;

engine/schema/src/main/java/com/cloud/host/HostVO.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@
3939
import javax.persistence.Transient;
4040

4141
import com.cloud.agent.api.VgpuTypesInfo;
42+
import com.cloud.host.dao.HostTagsDao;
4243
import com.cloud.hypervisor.Hypervisor.HypervisorType;
4344
import com.cloud.offering.ServiceOffering;
4445
import com.cloud.resource.ResourceState;
4546
import com.cloud.storage.Storage.StoragePoolType;
4647
import com.cloud.utils.NumbersUtil;
4748
import com.cloud.utils.db.GenericDao;
4849
import java.util.Arrays;
50+
51+
import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper;
4952
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
53+
import org.apache.commons.lang.BooleanUtils;
5054
import org.apache.commons.lang3.StringUtils;
5155

5256
@Entity
@@ -159,6 +163,14 @@ public class HostVO implements Host {
159163
@Transient
160164
List<String> hostTags;
161165

166+
/**
167+
* This is a delayed load value.
168+
* If the value is null, then this field has not been loaded yet.
169+
* Call host dao to load it.
170+
*/
171+
@Transient
172+
Boolean isTagARule;
173+
162174
// This value is only for saving and current cannot be loaded.
163175
@Transient
164176
HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
@@ -322,8 +334,13 @@ public List<String> getHostTags() {
322334
return hostTags;
323335
}
324336

325-
public void setHostTags(List<String> hostTags) {
337+
public void setHostTags(List<String> hostTags, Boolean isTagARule) {
326338
this.hostTags = hostTags;
339+
this.isTagARule = isTagARule;
340+
}
341+
342+
public Boolean getIsTagARule() {
343+
return isTagARule;
327344
}
328345

329346
public HashMap<String, HashMap<String, VgpuTypesInfo>> getGpuGroupDetails() {
@@ -748,6 +765,11 @@ public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering){
748765
if (serviceOffering == null) {
749766
return false;
750767
}
768+
769+
if (BooleanUtils.isTrue(this.getIsTagARule())) {
770+
return TagAsRuleHelper.interpretTagAsRule(this.getHostTags().get(0), serviceOffering.getHostTag(), HostTagsDao.hostTagRuleExecutionTimeout.value());
771+
}
772+
751773
if (StringUtils.isEmpty(serviceOffering.getHostTag())) {
752774
return true;
753775
}

engine/schema/src/main/java/com/cloud/host/dao/HostDao.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
108108

109109
List<HostVO> listAllHostsByZoneAndHypervisorType(long zoneId, HypervisorType hypervisorType);
110110

111+
List<HostVO> listAllHostsThatHaveNoRuleTag(Host.Type type, Long clusterId, Long podId, Long dcId);
112+
111113
List<HostVO> listAllHostsByType(Host.Type type);
112114

113115
HostVO findByPublicIp(String publicIp);
@@ -161,4 +163,8 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
161163
* @return ordered list of hypervisor versions
162164
*/
163165
List<String> listOrderedHostsHypervisorVersionsInDatacenter(long datacenterId, HypervisorType hypervisorType);
166+
167+
List<HostVO> findHostsWithTagRuleThatMatchComputeOferringTags(String computeOfferingTags);
168+
169+
List<Long> findClustersThatMatchHostTagRule(String computeOfferingTags);
164170
}

0 commit comments

Comments
 (0)