|
18 | 18 |
|
19 | 19 | import java.text.DecimalFormat; |
20 | 20 | import java.util.ArrayList; |
| 21 | +import java.util.Arrays; |
21 | 22 | import java.util.Date; |
22 | 23 | import java.util.EnumSet; |
23 | 24 | import java.util.Iterator; |
|
26 | 27 |
|
27 | 28 | import javax.inject.Inject; |
28 | 29 |
|
29 | | -import org.apache.log4j.Logger; |
30 | | -import org.springframework.stereotype.Component; |
31 | | - |
32 | 30 | import org.apache.cloudstack.api.ApiConstants.HostDetails; |
33 | 31 | import org.apache.cloudstack.api.response.GpuResponse; |
34 | 32 | import org.apache.cloudstack.api.response.HostForMigrationResponse; |
35 | 33 | import org.apache.cloudstack.api.response.HostResponse; |
36 | 34 | import org.apache.cloudstack.api.response.VgpuResponse; |
37 | 35 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
| 36 | +import org.apache.cloudstack.ha.HAResource; |
| 37 | +import org.apache.cloudstack.ha.dao.HAConfigDao; |
38 | 38 | import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao; |
| 39 | +import org.apache.commons.lang3.StringUtils; |
| 40 | +import org.apache.log4j.Logger; |
| 41 | +import org.springframework.stereotype.Component; |
39 | 42 |
|
40 | 43 | import com.cloud.api.ApiDBUtils; |
41 | 44 | import com.cloud.api.query.vo.HostJoinVO; |
|
52 | 55 | import com.cloud.utils.db.SearchBuilder; |
53 | 56 | import com.cloud.utils.db.SearchCriteria; |
54 | 57 |
|
55 | | -import org.apache.cloudstack.ha.HAResource; |
56 | | -import org.apache.cloudstack.ha.dao.HAConfigDao; |
57 | | - |
58 | 58 | @Component |
59 | 59 | public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements HostJoinDao { |
60 | 60 | public static final Logger s_logger = Logger.getLogger(HostJoinDaoImpl.class); |
@@ -94,6 +94,18 @@ protected HostJoinDaoImpl() { |
94 | 94 | this._count = "select count(distinct id) from host_view WHERE "; |
95 | 95 | } |
96 | 96 |
|
| 97 | + private boolean containsHostHATag(final String tags) { |
| 98 | + boolean result = false; |
| 99 | + String haTag = ApiDBUtils.getHaTag(); |
| 100 | + if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(tags)) { |
| 101 | + List<String> tagsList = Arrays.asList(tags.split(",")); |
| 102 | + if (tagsList.contains(haTag)) { |
| 103 | + result = true; |
| 104 | + } |
| 105 | + } |
| 106 | + return result; |
| 107 | + } |
| 108 | + |
97 | 109 | @Override |
98 | 110 | public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> details) { |
99 | 111 | HostResponse hostResponse = new HostResponse(); |
@@ -178,18 +190,8 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail |
178 | 190 | hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage); |
179 | 191 |
|
180 | 192 | String hostTags = host.getTag(); |
181 | | - hostResponse.setHostTags(host.getTag()); |
182 | | - |
183 | | - String haTag = ApiDBUtils.getHaTag(); |
184 | | - if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) { |
185 | | - if (haTag.equalsIgnoreCase(hostTags)) { |
186 | | - hostResponse.setHaHost(true); |
187 | | - } else { |
188 | | - hostResponse.setHaHost(false); |
189 | | - } |
190 | | - } else { |
191 | | - hostResponse.setHaHost(false); |
192 | | - } |
| 193 | + hostResponse.setHostTags(hostTags); |
| 194 | + hostResponse.setHaHost(containsHostHATag(hostTags)); |
193 | 195 |
|
194 | 196 | hostResponse.setHypervisorVersion(host.getHypervisorVersion()); |
195 | 197 |
|
@@ -271,19 +273,6 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail |
271 | 273 | return hostResponse; |
272 | 274 | } |
273 | 275 |
|
274 | | - @Override |
275 | | - public HostResponse setHostResponse(HostResponse response, HostJoinVO host) { |
276 | | - String tag = host.getTag(); |
277 | | - if (tag != null) { |
278 | | - if (response.getHostTags() != null && response.getHostTags().length() > 0) { |
279 | | - response.setHostTags(response.getHostTags() + "," + tag); |
280 | | - } else { |
281 | | - response.setHostTags(tag); |
282 | | - } |
283 | | - } |
284 | | - return response; |
285 | | - } |
286 | | - |
287 | 276 | @Override |
288 | 277 | public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, EnumSet<HostDetails> details) { |
289 | 278 | HostForMigrationResponse hostResponse = new HostForMigrationResponse(); |
@@ -334,18 +323,8 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu |
334 | 323 | hostResponse.setMemoryAllocatedBytes(mem); |
335 | 324 |
|
336 | 325 | String hostTags = host.getTag(); |
337 | | - hostResponse.setHostTags(host.getTag()); |
338 | | - |
339 | | - String haTag = ApiDBUtils.getHaTag(); |
340 | | - if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) { |
341 | | - if (haTag.equalsIgnoreCase(hostTags)) { |
342 | | - hostResponse.setHaHost(true); |
343 | | - } else { |
344 | | - hostResponse.setHaHost(false); |
345 | | - } |
346 | | - } else { |
347 | | - hostResponse.setHaHost(false); |
348 | | - } |
| 326 | + hostResponse.setHostTags(hostTags); |
| 327 | + hostResponse.setHaHost(containsHostHATag(hostTags)); |
349 | 328 |
|
350 | 329 | hostResponse.setHypervisorVersion(host.getHypervisorVersion()); |
351 | 330 |
|
@@ -410,19 +389,6 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu |
410 | 389 | return hostResponse; |
411 | 390 | } |
412 | 391 |
|
413 | | - @Override |
414 | | - public HostForMigrationResponse setHostForMigrationResponse(HostForMigrationResponse response, HostJoinVO host) { |
415 | | - String tag = host.getTag(); |
416 | | - if (tag != null) { |
417 | | - if (response.getHostTags() != null && response.getHostTags().length() > 0) { |
418 | | - response.setHostTags(response.getHostTags() + "," + tag); |
419 | | - } else { |
420 | | - response.setHostTags(tag); |
421 | | - } |
422 | | - } |
423 | | - return response; |
424 | | - } |
425 | | - |
426 | 392 | @Override |
427 | 393 | public List<HostJoinVO> newHostView(Host host) { |
428 | 394 | SearchCriteria<HostJoinVO> sc = hostIdSearch.create(); |
|
0 commit comments