Skip to content

Commit a53d53a

Browse files
JoaoJandreJoão Jandre
authored andcommitted
Flexible tags for hosts and storage pools (apache#7489)
Co-authored-by: João Jandre <joao@scclouds.com.br>
1 parent 0f10ac4 commit a53d53a

63 files changed

Lines changed: 1099 additions & 216 deletions

File tree

Some content is hidden

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,9 @@ public class ApiConstants {
11371137

11381138
public static final String SHAREABLE = "shareable";
11391139
public static final String VBMC_PORT = "vbmcport";
1140+
public static final String IS_TAG_A_RULE = "istagarule";
1141+
1142+
public static final String PARAMETER_DESCRIPTION_IS_TAG_A_RULE = "Whether the informed tag is a JS interpretable rule or not.";
11401143

11411144
/**
11421145
* This enum specifies IO Drivers, each option controls specific policies on I/O.

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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public class CreateStoragePoolCmd extends BaseCmd {
9595
required = false,
9696
description = "the path of Ablestack provider")
9797
private String krbdpath;
98+
99+
@Parameter(name = ApiConstants.IS_TAG_A_RULE, type = CommandType.BOOLEAN, description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
100+
private Boolean isTagARule;
98101

99102
/////////////////////////////////////////////////////
100103
/////////////////// Accessors ///////////////////////
@@ -152,7 +155,13 @@ public String getHypervisor() {
152155
return hypervisor;
153156
}
154157

155-
public String getKrbdPath() { return krbdpath; }
158+
public String getKrbdPath() {
159+
return krbdpath;
160+
}
161+
162+
public Boolean isTagARule() {
163+
return this.isTagARule;
164+
}
156165

157166
@Override
158167
public long getEntityOwnerId() {

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
@@ -64,6 +64,9 @@ public class UpdateStoragePoolCmd extends BaseCmd {
6464
" enable it back.")
6565
private Boolean enabled;
6666

67+
@Parameter(name = ApiConstants.IS_TAG_A_RULE, type = CommandType.BOOLEAN, description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
68+
private Boolean isTagARule;
69+
6770
/////////////////////////////////////////////////////
6871
/////////////////// Accessors ///////////////////////
6972
/////////////////////////////////////////////////////
@@ -96,6 +99,10 @@ public Boolean getEnabled() {
9699
return enabled;
97100
}
98101

102+
public Boolean isTagARule() {
103+
return isTagARule;
104+
}
105+
99106
/////////////////////////////////////////////////////
100107
/////////////// API Implementation///////////////////
101108
/////////////////////////////////////////////////////

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;
@@ -737,4 +741,12 @@ public void setTpmCapabilty(Boolean hostCapability) {
737741
public void setEncryptionSupported(Boolean encryptionSupported) {
738742
this.encryptionSupported = encryptionSupported;
739743
}
744+
745+
public Boolean getIsTagARule() {
746+
return isTagARule;
747+
}
748+
749+
public void setIsTagARule(Boolean tagARule) {
750+
isTagARule = tagARule;
751+
}
740752
}

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: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class PrimaryDataStoreParameters {
4444
private Long capacityIops;
4545

4646
private String krbdPath;
47+
private Boolean isTagARule;
4748

4849
/**
4950
* @return the userInfo
@@ -280,7 +281,19 @@ public void setUsedBytes(long usedBytes) {
280281
this.usedBytes = usedBytes;
281282
}
282283

283-
public String getKrbdPath() { return krbdPath; }
284+
public String getKrbdPath() {
285+
return krbdPath;
286+
}
284287

285-
public void setKrbdPath(String krbdPath) { this.krbdPath = krbdPath; }
288+
public void setKrbdPath(String krbdPath) {
289+
this.krbdPath = krbdPath;
290+
}
291+
292+
public Boolean isTagARule() {
293+
return isTagARule;
294+
}
295+
296+
public void setIsTagARule(Boolean isTagARule) {
297+
this.isTagARule = isTagARule;
298+
}
286299
}

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)