|
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; |
@@ -93,6 +94,18 @@ protected HostJoinDaoImpl() { |
93 | 94 | this._count = "select count(distinct id) from host_view WHERE "; |
94 | 95 | } |
95 | 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 | + |
96 | 109 | @Override |
97 | 110 | public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> details) { |
98 | 111 | HostResponse hostResponse = new HostResponse(); |
@@ -178,13 +191,7 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail |
178 | 191 |
|
179 | 192 | String hostTags = host.getTag(); |
180 | 193 | hostResponse.setHostTags(hostTags); |
181 | | - |
182 | | - hostResponse.setHaHost(false); |
183 | | - String haTag = ApiDBUtils.getHaTag(); |
184 | | - if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(hostTags) && |
185 | | - haTag.equalsIgnoreCase(hostTags)) { |
186 | | - hostResponse.setHaHost(true); |
187 | | - } |
| 194 | + hostResponse.setHaHost(containsHostHATag(hostTags)); |
188 | 195 |
|
189 | 196 | hostResponse.setHypervisorVersion(host.getHypervisorVersion()); |
190 | 197 |
|
@@ -266,26 +273,6 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail |
266 | 273 | return hostResponse; |
267 | 274 | } |
268 | 275 |
|
269 | | - @Override |
270 | | - public HostResponse setHostResponse(HostResponse response, HostJoinVO host) { |
271 | | - String tag = host.getTag(); |
272 | | - if (StringUtils.isNotEmpty(tag)) { |
273 | | - if (StringUtils.isNotEmpty(response.getHostTags())) { |
274 | | - response.setHostTags(response.getHostTags() + "," + tag); |
275 | | - } else { |
276 | | - response.setHostTags(tag); |
277 | | - } |
278 | | - |
279 | | - if (Boolean.FALSE.equals(response.getHaHost())) { |
280 | | - String haTag = ApiDBUtils.getHaTag(); |
281 | | - if (StringUtils.isNotEmpty(haTag) && haTag.equalsIgnoreCase(tag)) { |
282 | | - response.setHaHost(true); |
283 | | - } |
284 | | - } |
285 | | - } |
286 | | - return response; |
287 | | - } |
288 | | - |
289 | 276 | @Override |
290 | 277 | public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, EnumSet<HostDetails> details) { |
291 | 278 | HostForMigrationResponse hostResponse = new HostForMigrationResponse(); |
@@ -337,13 +324,7 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu |
337 | 324 |
|
338 | 325 | String hostTags = host.getTag(); |
339 | 326 | hostResponse.setHostTags(hostTags); |
340 | | - |
341 | | - hostResponse.setHaHost(false); |
342 | | - String haTag = ApiDBUtils.getHaTag(); |
343 | | - if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(hostTags) && |
344 | | - haTag.equalsIgnoreCase(hostTags)) { |
345 | | - hostResponse.setHaHost(true); |
346 | | - } |
| 327 | + hostResponse.setHaHost(containsHostHATag(hostTags)); |
347 | 328 |
|
348 | 329 | hostResponse.setHypervisorVersion(host.getHypervisorVersion()); |
349 | 330 |
|
@@ -408,26 +389,6 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu |
408 | 389 | return hostResponse; |
409 | 390 | } |
410 | 391 |
|
411 | | - @Override |
412 | | - public HostForMigrationResponse setHostForMigrationResponse(HostForMigrationResponse response, HostJoinVO host) { |
413 | | - String tag = host.getTag(); |
414 | | - if (tag != null) { |
415 | | - if (response.getHostTags() != null && response.getHostTags().length() > 0) { |
416 | | - response.setHostTags(response.getHostTags() + "," + tag); |
417 | | - } else { |
418 | | - response.setHostTags(tag); |
419 | | - } |
420 | | - |
421 | | - if (Boolean.FALSE.equals(response.getHaHost())) { |
422 | | - String haTag = ApiDBUtils.getHaTag(); |
423 | | - if (StringUtils.isNotEmpty(haTag) && haTag.equalsIgnoreCase(tag)) { |
424 | | - response.setHaHost(true); |
425 | | - } |
426 | | - } |
427 | | - } |
428 | | - return response; |
429 | | - } |
430 | | - |
431 | 392 | @Override |
432 | 393 | public List<HostJoinVO> newHostView(Host host) { |
433 | 394 | SearchCriteria<HostJoinVO> sc = hostIdSearch.create(); |
|
0 commit comments