This is an automated email from the ASF dual-hosted git repository. rohit pushed a commit to branch 4.14 in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.14 by this push: new 95cd937 server: fix hahost value in listHosts (#4789) 95cd937 is described below commit 95cd937d7b32dd84c1cf62bc82539256196dbbab Author: Abhishek Kumar <abhishek.mr...@gmail.com> AuthorDate: Thu Apr 1 12:33:48 2021 +0530 server: fix hahost value in listHosts (#4789) * api/server: fix hahost value in listHosts Signed-off-by: Abhishek Kumar <abhishek.mr...@gmail.com> * fix Signed-off-by: Abhishek Kumar <abhishek.mr...@gmail.com> * Update server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java Co-authored-by: dahn <daan.hoogl...@gmail.com> * Update server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java Co-authored-by: Rohit Yadav <rohit.ya...@shapeblue.com> Co-authored-by: dahn <daan.hoogl...@gmail.com> --- .../api/response/HostForMigrationResponse.java | 7 ++- .../com/cloud/api/query/dao/HostJoinDaoImpl.java | 57 ++++++++++++---------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java index 8501f71..4ed0cdd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java @@ -18,8 +18,6 @@ package org.apache.cloudstack.api.response; import java.util.Date; -import com.google.gson.annotations.SerializedName; - import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.EntityReference; @@ -28,6 +26,7 @@ import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; @EntityReference(value = Host.class) public class HostForMigrationResponse extends BaseResponse { @@ -452,6 +451,10 @@ public class HostForMigrationResponse extends BaseResponse { this.hypervisorVersion = hypervisorVersion; } + public Boolean getHaHost() { + return haHost; + } + public void setHaHost(Boolean haHost) { this.haHost = haHost; } diff --git a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java index f7373a7..de87a0a 100644 --- a/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java +++ b/server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java @@ -26,16 +26,18 @@ import java.util.Set; import javax.inject.Inject; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - import org.apache.cloudstack.api.ApiConstants.HostDetails; import org.apache.cloudstack.api.response.GpuResponse; import org.apache.cloudstack.api.response.HostForMigrationResponse; import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.api.response.VgpuResponse; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.cloudstack.ha.HAResource; +import org.apache.cloudstack.ha.dao.HAConfigDao; import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; import com.cloud.api.ApiDBUtils; import com.cloud.api.query.vo.HostJoinVO; @@ -52,9 +54,6 @@ import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.cloudstack.ha.HAResource; -import org.apache.cloudstack.ha.dao.HAConfigDao; - @Component public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements HostJoinDao { public static final Logger s_logger = Logger.getLogger(HostJoinDaoImpl.class); @@ -178,17 +177,13 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage); String hostTags = host.getTag(); - hostResponse.setHostTags(host.getTag()); + hostResponse.setHostTags(hostTags); + hostResponse.setHaHost(false); String haTag = ApiDBUtils.getHaTag(); - if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) { - if (haTag.equalsIgnoreCase(hostTags)) { - hostResponse.setHaHost(true); - } else { - hostResponse.setHaHost(false); - } - } else { - hostResponse.setHaHost(false); + if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(hostTags) && + haTag.equalsIgnoreCase(hostTags)) { + hostResponse.setHaHost(true); } hostResponse.setHypervisorVersion(host.getHypervisorVersion()); @@ -274,12 +269,19 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements @Override public HostResponse setHostResponse(HostResponse response, HostJoinVO host) { String tag = host.getTag(); - if (tag != null) { - if (response.getHostTags() != null && response.getHostTags().length() > 0) { + if (StringUtils.isNotEmpty(tag)) { + if (StringUtils.isNotEmpty(response.getHostTags())) { response.setHostTags(response.getHostTags() + "," + tag); } else { response.setHostTags(tag); } + + if (Boolean.FALSE.equals(response.getHaHost())) { + String haTag = ApiDBUtils.getHaTag(); + if (StringUtils.isNotEmpty(haTag) && haTag.equalsIgnoreCase(tag)) { + response.setHaHost(true); + } + } } return response; } @@ -334,17 +336,13 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements hostResponse.setMemoryAllocatedBytes(mem); String hostTags = host.getTag(); - hostResponse.setHostTags(host.getTag()); + hostResponse.setHostTags(hostTags); + hostResponse.setHaHost(false); String haTag = ApiDBUtils.getHaTag(); - if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) { - if (haTag.equalsIgnoreCase(hostTags)) { - hostResponse.setHaHost(true); - } else { - hostResponse.setHaHost(false); - } - } else { - hostResponse.setHaHost(false); + if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(hostTags) && + haTag.equalsIgnoreCase(hostTags)) { + hostResponse.setHaHost(true); } hostResponse.setHypervisorVersion(host.getHypervisorVersion()); @@ -419,6 +417,13 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements } else { response.setHostTags(tag); } + + if (Boolean.FALSE.equals(response.getHaHost())) { + String haTag = ApiDBUtils.getHaTag(); + if (StringUtils.isNotEmpty(haTag) && haTag.equalsIgnoreCase(tag)) { + response.setHaHost(true); + } + } } return response; }