|
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(); |
@@ -180,13 +193,7 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail |
180 | 193 |
|
181 | 194 | String hostTags = host.getTag(); |
182 | 195 | hostResponse.setHostTags(hostTags); |
183 | | - |
184 | | - hostResponse.setHaHost(false); |
185 | | - String haTag = ApiDBUtils.getHaTag(); |
186 | | - if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(hostTags) && |
187 | | - haTag.equalsIgnoreCase(hostTags)) { |
188 | | - hostResponse.setHaHost(true); |
189 | | - } |
| 196 | + hostResponse.setHaHost(containsHostHATag(hostTags)); |
190 | 197 |
|
191 | 198 | hostResponse.setHypervisorVersion(host.getHypervisorVersion()); |
192 | 199 |
|
@@ -268,26 +275,6 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail |
268 | 275 | return hostResponse; |
269 | 276 | } |
270 | 277 |
|
271 | | - @Override |
272 | | - public HostResponse setHostResponse(HostResponse response, HostJoinVO host) { |
273 | | - String tag = host.getTag(); |
274 | | - if (StringUtils.isNotEmpty(tag)) { |
275 | | - if (StringUtils.isNotEmpty(response.getHostTags())) { |
276 | | - response.setHostTags(response.getHostTags() + "," + tag); |
277 | | - } else { |
278 | | - response.setHostTags(tag); |
279 | | - } |
280 | | - |
281 | | - if (Boolean.FALSE.equals(response.getHaHost())) { |
282 | | - String haTag = ApiDBUtils.getHaTag(); |
283 | | - if (StringUtils.isNotEmpty(haTag) && haTag.equalsIgnoreCase(tag)) { |
284 | | - response.setHaHost(true); |
285 | | - } |
286 | | - } |
287 | | - } |
288 | | - return response; |
289 | | - } |
290 | | - |
291 | 278 | @Override |
292 | 279 | public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, EnumSet<HostDetails> details) { |
293 | 280 | HostForMigrationResponse hostResponse = new HostForMigrationResponse(); |
@@ -339,13 +326,7 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu |
339 | 326 |
|
340 | 327 | String hostTags = host.getTag(); |
341 | 328 | hostResponse.setHostTags(hostTags); |
342 | | - |
343 | | - hostResponse.setHaHost(false); |
344 | | - String haTag = ApiDBUtils.getHaTag(); |
345 | | - if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(hostTags) && |
346 | | - haTag.equalsIgnoreCase(hostTags)) { |
347 | | - hostResponse.setHaHost(true); |
348 | | - } |
| 329 | + hostResponse.setHaHost(containsHostHATag(hostTags)); |
349 | 330 |
|
350 | 331 | hostResponse.setHypervisorVersion(host.getHypervisorVersion()); |
351 | 332 |
|
@@ -410,26 +391,6 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu |
410 | 391 | return hostResponse; |
411 | 392 | } |
412 | 393 |
|
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 | | - if (Boolean.FALSE.equals(response.getHaHost())) { |
424 | | - String haTag = ApiDBUtils.getHaTag(); |
425 | | - if (StringUtils.isNotEmpty(haTag) && haTag.equalsIgnoreCase(tag)) { |
426 | | - response.setHaHost(true); |
427 | | - } |
428 | | - } |
429 | | - } |
430 | | - return response; |
431 | | - } |
432 | | - |
433 | 394 | @Override |
434 | 395 | public List<HostJoinVO> newHostView(Host host) { |
435 | 396 | SearchCriteria<HostJoinVO> sc = hostIdSearch.create(); |
|
0 commit comments