@@ -113,9 +113,7 @@ private boolean containsHostHATag(final String tags) {
113113 return result ;
114114 }
115115
116- @ Override
117- public HostResponse newHostResponse (HostJoinVO host , EnumSet <HostDetails > details ) {
118- HostResponse hostResponse = new HostResponse ();
116+ private void setNewHostResponseBase (HostJoinVO host , EnumSet <HostDetails > details , HostResponse hostResponse ) {
119117 hostResponse .setId (host .getUuid ());
120118 hostResponse .setCapabilities (host .getCapabilities ());
121119 hostResponse .setClusterId (host .getClusterUuid ());
@@ -187,7 +185,6 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail
187185 DecimalFormat decimalFormat = new DecimalFormat ("#.##" );
188186 if (host .getType () == Host .Type .Routing ) {
189187 float cpuOverprovisioningFactor = ApiDBUtils .getCpuOverprovisioningFactor (host .getClusterId ());
190- hostResponse .setCpuNumber ((int )(host .getCpus () * cpuOverprovisioningFactor ));
191188 if (details .contains (HostDetails .all ) || details .contains (HostDetails .capacity )) {
192189 // set allocated capacities
193190 Long mem = host .getMemReservedCapacity () + host .getMemUsedCapacity ();
@@ -298,124 +295,19 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail
298295 hostResponse .setUsername (host .getUsername ());
299296
300297 hostResponse .setObjectName ("host" );
298+ }
301299
300+ @ Override
301+ public HostResponse newHostResponse (HostJoinVO host , EnumSet <HostDetails > details ) {
302+ HostResponse hostResponse = new HostResponse ();
303+ setNewHostResponseBase (host , details , hostResponse );
302304 return hostResponse ;
303305 }
304306
305307 @ Override
306308 public HostForMigrationResponse newHostForMigrationResponse (HostJoinVO host , EnumSet <HostDetails > details ) {
307309 HostForMigrationResponse hostResponse = new HostForMigrationResponse ();
308- hostResponse .setId (host .getUuid ());
309- hostResponse .setCapabilities (host .getCapabilities ());
310- hostResponse .setClusterId (host .getClusterUuid ());
311- hostResponse .setCpuNumber (host .getCpus ());
312- hostResponse .setZoneId (host .getZoneUuid ());
313- hostResponse .setDisconnectedOn (host .getDisconnectedOn ());
314- hostResponse .setHypervisor (host .getHypervisorType ().getHypervisorDisplayName ());
315- hostResponse .setHostType (host .getType ());
316- hostResponse .setLastPinged (new Date (host .getLastPinged ()));
317- hostResponse .setManagementServerId (host .getManagementServerId ());
318- hostResponse .setName (host .getName ());
319- hostResponse .setPodId (host .getPodUuid ());
320- hostResponse .setRemoved (host .getRemoved ());
321- hostResponse .setCpuSpeed (host .getSpeed ());
322- hostResponse .setState (host .getStatus ());
323- hostResponse .setIpAddress (host .getPrivateIpAddress ());
324- hostResponse .setVersion (host .getVersion ());
325- hostResponse .setCreated (host .getCreated ());
326-
327- if (details .contains (HostDetails .all ) || details .contains (HostDetails .capacity ) || details .contains (HostDetails .stats ) || details .contains (HostDetails .events )) {
328-
329- hostResponse .setOsCategoryId (host .getOsCategoryUuid ());
330- hostResponse .setOsCategoryName (host .getOsCategoryName ());
331- hostResponse .setZoneName (host .getZoneName ());
332- hostResponse .setPodName (host .getPodName ());
333- if (host .getClusterId () > 0 ) {
334- hostResponse .setClusterName (host .getClusterName ());
335- hostResponse .setClusterType (host .getClusterType ().toString ());
336- }
337- }
338-
339- DecimalFormat decimalFormat = new DecimalFormat ("#.##" );
340- if (host .getType () == Host .Type .Routing ) {
341- if (details .contains (HostDetails .all ) || details .contains (HostDetails .capacity )) {
342- // set allocated capacities
343- Long mem = host .getMemReservedCapacity () + host .getMemUsedCapacity ();
344- Long cpu = host .getCpuReservedCapacity () + host .getCpuUsedCapacity ();
345-
346- hostResponse .setMemoryTotal (host .getTotalMemory ());
347- Float memWithOverprovisioning = host .getTotalMemory () * ApiDBUtils .getMemOverprovisioningFactor (host .getClusterId ());
348- hostResponse .setMemWithOverprovisioning (decimalFormat .format (memWithOverprovisioning ));
349- String memoryAllocatedPercentage = decimalFormat .format ((float ) mem / memWithOverprovisioning * 100.0f ) +"%" ;
350- hostResponse .setMemoryAllocated (memoryAllocatedPercentage );
351- hostResponse .setMemoryAllocatedPercentage (memoryAllocatedPercentage );
352- hostResponse .setMemoryAllocatedBytes (mem );
353-
354- String hostTags = host .getTag ();
355- hostResponse .setHostTags (hostTags );
356- hostResponse .setHaHost (containsHostHATag (hostTags ));
357- hostResponse .setImplicitHostTags (host .getImplicitTag ());
358-
359- hostResponse .setHypervisorVersion (host .getHypervisorVersion ());
360-
361- hostResponse .setCpuAllocatedValue (cpu );
362- String cpuAlloc = decimalFormat .format (((float )cpu / (float )(host .getCpus () * host .getSpeed ())) * 100f ) + "%" ;
363- hostResponse .setCpuAllocated (cpuAlloc );
364- hostResponse .setCpuAllocatedPercentage (cpuAlloc );
365- float cpuWithOverprovisioning = host .getCpus () * host .getSpeed () * ApiDBUtils .getCpuOverprovisioningFactor (host .getClusterId ());
366- hostResponse .setCpuAllocatedWithOverprovisioning (calculateResourceAllocatedPercentage (cpu , cpuWithOverprovisioning ));
367- hostResponse .setCpuWithOverprovisioning (decimalFormat .format (cpuWithOverprovisioning ));
368- }
369-
370- if (details .contains (HostDetails .all ) || details .contains (HostDetails .stats )) {
371- // set CPU/RAM/Network stats
372- String cpuUsed = null ;
373- HostStats hostStats = ApiDBUtils .getHostStatistics (host .getId ());
374- if (hostStats != null ) {
375- float cpuUtil = (float )hostStats .getCpuUtilization ();
376- cpuUsed = decimalFormat .format (cpuUtil ) + "%" ;
377- hostResponse .setCpuUsed (cpuUsed );
378- hostResponse .setMemoryUsed ((new Double (hostStats .getUsedMemory ())).longValue ());
379- hostResponse .setNetworkKbsRead ((new Double (hostStats .getNetworkReadKBs ())).longValue ());
380- hostResponse .setNetworkKbsWrite ((new Double (hostStats .getNetworkWriteKBs ())).longValue ());
381-
382- }
383- }
384-
385- } else if (host .getType () == Host .Type .SecondaryStorage ) {
386- StorageStats secStorageStats = ApiDBUtils .getSecondaryStorageStatistics (host .getId ());
387- if (secStorageStats != null ) {
388- hostResponse .setDiskSizeTotal (secStorageStats .getCapacityBytes ());
389- hostResponse .setDiskSizeAllocated (secStorageStats .getByteUsed ());
390- }
391- }
392-
393- hostResponse .setLocalStorageActive (ApiDBUtils .isLocalStorageActiveOnHost (host .getId ()));
394-
395- if (details .contains (HostDetails .all ) || details .contains (HostDetails .events )) {
396- Set <com .cloud .host .Status .Event > possibleEvents = host .getStatus ().getPossibleEvents ();
397- if ((possibleEvents != null ) && !possibleEvents .isEmpty ()) {
398- String events = "" ;
399- Iterator <com .cloud .host .Status .Event > iter = possibleEvents .iterator ();
400- while (iter .hasNext ()) {
401- com .cloud .host .Status .Event event = iter .next ();
402- events += event .toString ();
403- if (iter .hasNext ()) {
404- events += "; " ;
405- }
406- }
407- hostResponse .setEvents (events );
408- }
409- }
410-
411- hostResponse .setResourceState (host .getResourceState ().toString ());
412-
413- // set async job
414- hostResponse .setJobId (host .getJobUuid ());
415- hostResponse .setJobStatus (host .getJobStatus ());
416-
417- hostResponse .setObjectName ("host" );
418-
310+ setNewHostResponseBase (host , details , hostResponse );
419311 return hostResponse ;
420312 }
421313
0 commit comments