Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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 numberDiff line numberDiff line change
Expand Up@@ -1066,6 +1066,10 @@ public class ApiConstants {
public static final String CLIENT_ID = "clientid";
public static final String REDIRECT_URI = "redirecturi";

public static final String IS_TAG_A_RULE = "istagarule";

public static final String PARAMETER_DESCRIPTION_IS_TAG_A_RULE = "Whether the informed tag is a JS interpretable rule or not.";

/**
* This enum specifies IO Drivers, each option controls specific policies on I/O.
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,6 +60,9 @@ public class UpdateHostCmd extends BaseCmd {
@Parameter(name = ApiConstants.HOST_TAGS, type = CommandType.LIST, collectionType = CommandType.STRING, description = "list of tags to be added to the host")
private List<String> hostTags;

@Parameter(name = ApiConstants.IS_TAG_A_RULE, type = CommandType.BOOLEAN, description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
private Boolean isTagARule;

@Parameter(name = ApiConstants.URL, type = CommandType.STRING, description = "the new uri for the secondary storage: nfs://host/path")
private String url;

Expand DownExpand Up@@ -90,6 +93,10 @@ public List<String> getHostTags() {
return hostTags;
}

public Boolean getIsTagARule() {
return isTagARule;
}

public String getUrl() {
return url;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,6 +90,9 @@ public class CreateStoragePoolCmd extends BaseCmd {
description = "hypervisor type of the hosts in zone that will be attached to this storage pool. KVM, VMware supported as of now.")
private String hypervisor;

@Parameter(name = ApiConstants.IS_TAG_A_RULE, type = CommandType.BOOLEAN, description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
private Boolean isTagARule;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand DownExpand Up@@ -146,6 +149,10 @@ public String getHypervisor() {
return hypervisor;
}

public Boolean isTagARule() {
return this.isTagARule;
}

@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,6 +61,9 @@ public class UpdateStoragePoolCmd extends BaseCmd {
" enable it back.")
private Boolean enabled;

@Parameter(name = ApiConstants.IS_TAG_A_RULE, type = CommandType.BOOLEAN, description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
private Boolean isTagARule;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand DownExpand Up@@ -89,6 +92,10 @@ public Boolean getEnabled() {
return enabled;
}

public Boolean isTagARule() {
return isTagARule;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -221,6 +221,10 @@ public class HostResponse extends BaseResponseWithAnnotations {
@Param(description = "comma-separated list of tags for the host")
private String hostTags;

@SerializedName(ApiConstants.IS_TAG_A_RULE)
@Param(description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
private Boolean isTagARule;

@SerializedName("hasenoughcapacity")
@Param(description = "true if this host has enough CPU and RAM capacity to migrate a VM to it, false otherwise")
private Boolean hasEnoughCapacity;
Expand DownExpand Up@@ -732,4 +736,12 @@ public void setUefiCapabilty(Boolean hostCapability) {
public void setEncryptionSupported(Boolean encryptionSupported) {
this.encryptionSupported = encryptionSupported;
}

public Boolean getIsTagARule() {
return isTagARule;
}

public void setIsTagARule(Boolean tagARule) {
isTagARule = tagARule;
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -101,6 +101,10 @@ public class StoragePoolResponse extends BaseResponseWithAnnotations {
@Param(description = "the tags for the storage pool")
private String tags;

@SerializedName(ApiConstants.IS_TAG_A_RULE)
@Param(description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE)
private Boolean isTagARule;

@SerializedName(ApiConstants.STATE)
@Param(description = "the state of the storage pool")
private StoragePoolStatus state;
Expand DownExpand Up@@ -304,6 +308,14 @@ public void setTags(String tags) {
this.tags = tags;
}

public Boolean getIsTagARule() {
return isTagARule;
}

public void setIsTagARule(Boolean tagARule) {
isTagARule = tagARule;
}

public StoragePoolStatus getState() {
return state;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,8 @@ public class PrimaryDataStoreParameters {
private boolean managed;
private Long capacityIops;

private Boolean isTagARule;

/**
* @return the userInfo
*/
Expand DownExpand Up@@ -277,4 +279,12 @@ public long getUsedBytes() {
public void setUsedBytes(long usedBytes) {
this.usedBytes = usedBytes;
}

public Boolean isTagARule() {
return isTagARule;
}

public void setIsTagARule(Boolean isTagARule) {
this.isTagARule = isTagARule;
}
}
16 changes: 16 additions & 0 deletions engine/schema/src/main/java/com/cloud/host/HostTagVO.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@
import javax.persistence.Table;

import org.apache.cloudstack.api.InternalIdentity;
import org.apache.commons.lang3.BooleanUtils;

@Entity
@Table(name = "host_tags")
Expand All@@ -39,12 +40,22 @@ public class HostTagVO implements InternalIdentity {
@Column(name = "tag")
private String tag;

@Column(name = "is_tag_a_rule")
private boolean isTagARule;

protected HostTagVO() {
}

public HostTagVO(long hostId, String tag) {
this.hostId = hostId;
this.tag = tag;
this.isTagARule = false;
}

public HostTagVO(long hostId, String tag, Boolean isTagARule) {
this.hostId = hostId;
this.tag = tag;
this.isTagARule = BooleanUtils.toBooleanDefaultIfNull(isTagARule, false);
}

public long getHostId() {
Expand All@@ -59,6 +70,11 @@ public void setTag(String tag) {
this.tag = tag;
}

public boolean getIsTagARule() {
return isTagARule;
}


@Override
public long getId() {
return id;
Expand Down
24 changes: 23 additions & 1 deletion engine/schema/src/main/java/com/cloud/host/HostVO.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,14 +39,18 @@
import javax.persistence.Transient;

import com.cloud.agent.api.VgpuTypesInfo;
import com.cloud.host.dao.HostTagsDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.ServiceOffering;
import com.cloud.resource.ResourceState;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.GenericDao;
import java.util.Arrays;

import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang3.StringUtils;

@Entity
Expand DownExpand Up@@ -159,6 +163,14 @@ public class HostVO implements Host {
@Transient
List<String> hostTags;

/**
* This is a delayed load value.
* If the value is null, then this field has not been loaded yet.
* Call host dao to load it.
*/
@Transient
Boolean isTagARule;

// This value is only for saving and current cannot be loaded.
@Transient
HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
Expand DownExpand Up@@ -322,8 +334,13 @@ public List<String> getHostTags() {
return hostTags;
}

public void setHostTags(List<String> hostTags) {
public void setHostTags(List<String> hostTags, Boolean isTagARule) {
this.hostTags = hostTags;
this.isTagARule = isTagARule;
}

public Boolean getIsTagARule() {
return isTagARule;
}

public HashMap<String, HashMap<String, VgpuTypesInfo>> getGpuGroupDetails() {
Expand DownExpand Up@@ -748,6 +765,11 @@ public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering){
if (serviceOffering == null) {
return false;
}

if (BooleanUtils.isTrue(this.getIsTagARule())) {
return TagAsRuleHelper.interpretTagAsRule(this.getHostTags().get(0), serviceOffering.getHostTag(), HostTagsDao.hostTagRuleExecutionTimeout.value());
}

if (StringUtils.isEmpty(serviceOffering.getHostTag())) {
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions engine/schema/src/main/java/com/cloud/host/dao/HostDao.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,8 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat

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

List<HostVO> listAllHostsThatHaveNoRuleTag(Host.Type type, Long clusterId, Long podId, Long dcId);

List<HostVO> listAllHostsByType(Host.Type type);

HostVO findByPublicIp(String publicIp);
Expand DownExpand Up@@ -161,4 +163,8 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
* @return ordered list of hypervisor versions
*/
List<String> listOrderedHostsHypervisorVersionsInDatacenter(long datacenterId, HypervisorType hypervisorType);

List<HostVO> findHostsWithTagRuleThatMatchComputeOferringTags(String computeOfferingTags);

List<Long> findClustersThatMatchHostTagRule(String computeOfferingTags);
}
Loading