Services refactored.
Added new Dto classes hierarchy. Added Lombok to reduce boilerplate code Controllers refactored. Added Javadoc and JSdoc Index template refactored.
This commit is contained in:
parent
46640d72c6
commit
e6bf510f9b
9
pom.xml
9
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<properties>
|
||||
<oshiVersion>5.0.1</oshiVersion>
|
||||
<jnaVersion>5.5.0</jnaVersion>
|
||||
<gsonVersion>2.8.6</gsonVersion>
|
||||
<lombokVersion>1.18.12</lombokVersion>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -40,9 +40,10 @@
|
|||
<version>${jnaVersion}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gsonVersion}</version>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>${lombokVersion}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
|
@ -1,340 +0,0 @@
|
|||
package org.bsoftware.ward.components.dto.implementation;
|
||||
|
||||
import org.bsoftware.ward.components.dto.Dto;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* InfoDto is a values container for presenting server principal information
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Component
|
||||
public class InfoDto implements Dto
|
||||
{
|
||||
/**
|
||||
* Processor name field
|
||||
*/
|
||||
private String processorName;
|
||||
|
||||
/**
|
||||
* Core count field
|
||||
*/
|
||||
private String coreCount;
|
||||
|
||||
/**
|
||||
* Processor max frequency field
|
||||
*/
|
||||
private String maxClockSpeed;
|
||||
|
||||
/**
|
||||
* Processor architecture field
|
||||
*/
|
||||
private String processorBitDepth;
|
||||
|
||||
/**
|
||||
* OS info field
|
||||
*/
|
||||
private String operatingSystemInfo;
|
||||
|
||||
/**
|
||||
* Amount of total installed ram field
|
||||
*/
|
||||
private String totalRam;
|
||||
|
||||
/**
|
||||
* Ram generation field
|
||||
*/
|
||||
private String ramType;
|
||||
|
||||
/**
|
||||
* Processes count field
|
||||
*/
|
||||
private String procCount;
|
||||
|
||||
/**
|
||||
* Host0 storage name field
|
||||
*/
|
||||
private String storageName;
|
||||
|
||||
/**
|
||||
* Host0 storage name field
|
||||
*/
|
||||
private String totalStorage;
|
||||
|
||||
/**
|
||||
* Amount of total installed storage field
|
||||
*/
|
||||
private String diskCount;
|
||||
|
||||
/**
|
||||
* Total amount of virtual memory (Swap on Linux) field
|
||||
*/
|
||||
private String swapAmount;
|
||||
|
||||
/**
|
||||
* Map with uptime values field
|
||||
*/
|
||||
private Map<String, String> uptime;
|
||||
|
||||
/**
|
||||
* Getter for processorName field
|
||||
*
|
||||
* @return String processorName field value
|
||||
*/
|
||||
public String getProcessorName()
|
||||
{
|
||||
return processorName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for processorName field
|
||||
*
|
||||
* @param processorName new field value
|
||||
*/
|
||||
public void setProcessorName(String processorName)
|
||||
{
|
||||
this.processorName = processorName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for coreCount field
|
||||
*
|
||||
* @return String coreCount field value
|
||||
*/
|
||||
public String getCoreCount()
|
||||
{
|
||||
return coreCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for coreCount field
|
||||
*
|
||||
* @param coreCount new field value
|
||||
*/
|
||||
public void setCoreCount(String coreCount)
|
||||
{
|
||||
this.coreCount = coreCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for maxClockSpeed field
|
||||
*
|
||||
* @return String maxClockSpeed field value
|
||||
*/
|
||||
public String getMaxClockSpeed()
|
||||
{
|
||||
return maxClockSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for maxClockSpeed field
|
||||
*
|
||||
* @param maxClockSpeed new field value
|
||||
*/
|
||||
public void setMaxClockSpeed(String maxClockSpeed)
|
||||
{
|
||||
this.maxClockSpeed = maxClockSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for processorBitDepth field
|
||||
*
|
||||
* @return String processorBitDepth field value
|
||||
*/
|
||||
public String getProcessorBitDepth()
|
||||
{
|
||||
return processorBitDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for processorBitDepth field
|
||||
*
|
||||
* @param processorBitDepth new field value
|
||||
*/
|
||||
public void setProcessorBitDepth(String processorBitDepth)
|
||||
{
|
||||
this.processorBitDepth = processorBitDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for machineName field
|
||||
*
|
||||
* @return String operatingSystemInfo field value
|
||||
*/
|
||||
public String getOperatingSystemInfo()
|
||||
{
|
||||
return operatingSystemInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for machineName field
|
||||
*
|
||||
* @param operatingSystemInfo new field value
|
||||
*/
|
||||
public void setOperatingSystemInfo(String operatingSystemInfo)
|
||||
{
|
||||
this.operatingSystemInfo = operatingSystemInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for totalRam field
|
||||
*
|
||||
* @return String totalRam field value
|
||||
*/
|
||||
public String getTotalRam()
|
||||
{
|
||||
return totalRam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for totalRam field
|
||||
*
|
||||
* @param totalRam new field value
|
||||
*/
|
||||
public void setTotalRam(String totalRam)
|
||||
{
|
||||
this.totalRam = totalRam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for ramType field
|
||||
*
|
||||
* @return String ramType field value
|
||||
*/
|
||||
public String getRamType()
|
||||
{
|
||||
return ramType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for ramType field
|
||||
*
|
||||
* @param ramType new field value
|
||||
*/
|
||||
public void setRamType(String ramType)
|
||||
{
|
||||
this.ramType = ramType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for procCount field
|
||||
*
|
||||
* @return String procCount field value
|
||||
*/
|
||||
public String getProcCount()
|
||||
{
|
||||
return procCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for procCount field
|
||||
*
|
||||
* @param procCount new field value
|
||||
*/
|
||||
public void setProcCount(String procCount)
|
||||
{
|
||||
this.procCount = procCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for storageName field
|
||||
*
|
||||
* @return String storageName field value
|
||||
*/
|
||||
public String getStorageName()
|
||||
{
|
||||
return storageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for storageName field
|
||||
*
|
||||
* @param storageName new field value
|
||||
*/
|
||||
public void setStorageName(String storageName)
|
||||
{
|
||||
this.storageName = storageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for totalStorage field
|
||||
*
|
||||
* @return String totalStorage field value
|
||||
*/
|
||||
public String getTotalStorage()
|
||||
{
|
||||
return totalStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for totalStorage field
|
||||
*
|
||||
* @param totalStorage new field value
|
||||
*/
|
||||
public void setTotalStorage(String totalStorage)
|
||||
{
|
||||
this.totalStorage = totalStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for diskCount field
|
||||
*
|
||||
* @return String diskCount field value
|
||||
*/
|
||||
public String getDiskCount()
|
||||
{
|
||||
return diskCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for diskCount field
|
||||
*
|
||||
* @param diskCount new field value
|
||||
*/
|
||||
public void setDiskCount(String diskCount)
|
||||
{
|
||||
this.diskCount = diskCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for swapAmount field
|
||||
*
|
||||
* @return String swapAmount field value
|
||||
*/
|
||||
public String getSwapAmount()
|
||||
{
|
||||
return swapAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for swapAmount field
|
||||
*
|
||||
* @param swapAmount new field value
|
||||
*/
|
||||
public void setSwapAmount(String swapAmount)
|
||||
{
|
||||
this.swapAmount = swapAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for uptime field
|
||||
*
|
||||
* @return Map<String, String> uptime field value
|
||||
*/
|
||||
public Map<String, String> getUptime()
|
||||
{
|
||||
return uptime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for uptime field
|
||||
*
|
||||
* @param uptime new field value
|
||||
*/
|
||||
public void setUptime(Map<String, String> uptime)
|
||||
{
|
||||
this.uptime = uptime;
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package org.bsoftware.ward.components.dto.implementation;
|
||||
|
||||
import org.bsoftware.ward.components.dto.Dto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* UsageDto is a values container for presenting server usage
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Component
|
||||
public class UsageDto implements Dto
|
||||
{
|
||||
/**
|
||||
* Processor usage field
|
||||
*/
|
||||
private int processor;
|
||||
|
||||
/**
|
||||
* Ram usage field
|
||||
*/
|
||||
private int ram;
|
||||
|
||||
/**
|
||||
* Storage usage field
|
||||
*/
|
||||
private int storage;
|
||||
|
||||
/**
|
||||
* Getter for processor field
|
||||
*
|
||||
* @return int processor field value
|
||||
*/
|
||||
public int getProcessor()
|
||||
{
|
||||
return processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for processor field
|
||||
*
|
||||
* @param processor new field value
|
||||
*/
|
||||
public void setProcessor(int processor)
|
||||
{
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for ram field
|
||||
*
|
||||
* @return int ram field value
|
||||
*/
|
||||
public int getRam()
|
||||
{
|
||||
return ram;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for ram field
|
||||
*
|
||||
* @param ram new field value
|
||||
*/
|
||||
public void setRam(int ram)
|
||||
{
|
||||
this.ram = ram;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for storage field
|
||||
*
|
||||
* @return int storage field value
|
||||
*/
|
||||
public int getStorage()
|
||||
{
|
||||
return storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for processor field
|
||||
*
|
||||
* @param storage new field value
|
||||
*/
|
||||
public void setStorage(int storage)
|
||||
{
|
||||
this.storage = storage;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.bsoftware.ward.components.wrappers;
|
||||
|
||||
import org.bsoftware.ward.components.dto.Dto;
|
||||
import org.bsoftware.ward.dto.Dto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -26,7 +26,7 @@ public class RestResponseEntityWrapper
|
|||
*
|
||||
* @param body object, which implements Dto interface
|
||||
* @param httpStatus object, which already provides Json headers
|
||||
* @return completed ResponseEntity object
|
||||
* @return ResponseEntity object with Json headers and Dto
|
||||
*/
|
||||
public <T extends Dto> ResponseEntity<?> wrap(T body, HttpStatus httpStatus)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bsoftware.ward.controllers;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -16,6 +15,16 @@ import javax.servlet.http.HttpServletResponse;
|
|||
@RequestMapping(value = "/error")
|
||||
public class ErrorController implements org.springframework.boot.web.servlet.error.ErrorController
|
||||
{
|
||||
/**
|
||||
* Error code for page not found exception
|
||||
*/
|
||||
private static final int NOT_FOUND = 404;
|
||||
|
||||
/**
|
||||
* Error code for internal server error exception
|
||||
*/
|
||||
private static final int INTERNAL_SERVER_ERROR = 500;
|
||||
|
||||
/**
|
||||
* Get request to display error page, which corresponds status code
|
||||
*
|
||||
|
@ -25,13 +34,20 @@ public class ErrorController implements org.springframework.boot.web.servlet.err
|
|||
@GetMapping
|
||||
public String getError(HttpServletResponse httpServletResponse)
|
||||
{
|
||||
if (httpServletResponse.getStatus() == HttpStatus.NOT_FOUND.value())
|
||||
switch (httpServletResponse.getStatus())
|
||||
{
|
||||
return "error/404";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "error/500";
|
||||
case ErrorController.NOT_FOUND:
|
||||
{
|
||||
return "error/404";
|
||||
}
|
||||
case INTERNAL_SERVER_ERROR:
|
||||
{
|
||||
return "error/500";
|
||||
}
|
||||
default:
|
||||
{
|
||||
return "500";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@ public class IndexController
|
|||
* @return String name of html template with values from model param
|
||||
*/
|
||||
@GetMapping
|
||||
public String getIndex(Model model)
|
||||
public String getIndex(Model model) throws Exception
|
||||
{
|
||||
model.addAttribute("info", infoService.get());
|
||||
model.addAttribute("infoDto", infoService.get());
|
||||
|
||||
return "index";
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class UsageController
|
|||
/**
|
||||
* Get request to display current usage information for processor, RAM and storage
|
||||
*
|
||||
* @return completed ResponseEntity to servlet
|
||||
* @return ResponseEntity to servlet
|
||||
*/
|
||||
@GetMapping
|
||||
public ResponseEntity<?> getUsage()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bsoftware.ward.components.dto;
|
||||
package org.bsoftware.ward.dto;
|
||||
|
||||
/**
|
||||
* Dto interface marks other classes to work with RestResponseEntityWrapper as dto
|
||||
* Dto interface marks other classes to work with RestResponseEntityWrapper and services as dto
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.0
|
|
@ -0,0 +1,36 @@
|
|||
package org.bsoftware.ward.dto.implementation;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bsoftware.ward.dto.Dto;
|
||||
|
||||
/**
|
||||
* InfoDto is a container for other info dtos
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.1
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class InfoDto implements Dto
|
||||
{
|
||||
/**
|
||||
* Processor info dto field
|
||||
*/
|
||||
private ProcessorDto processorDto;
|
||||
|
||||
/**
|
||||
* machine info dto field
|
||||
*/
|
||||
private MachineDto machineDto;
|
||||
|
||||
/**
|
||||
* Storage info dto field
|
||||
*/
|
||||
private StorageDto storageDto;
|
||||
|
||||
/**
|
||||
* Uptime info dto field
|
||||
*/
|
||||
private UptimeDto uptimeDto;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.bsoftware.ward.dto.implementation;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bsoftware.ward.dto.Dto;
|
||||
|
||||
/**
|
||||
* MachineDto is a values container for presenting machine principal information
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class MachineDto implements Dto
|
||||
{
|
||||
/**
|
||||
* OS info field
|
||||
*/
|
||||
private String operatingSystemInfo;
|
||||
|
||||
/**
|
||||
* Amount of total installed ram field
|
||||
*/
|
||||
private String totalRam;
|
||||
|
||||
/**
|
||||
* Ram generation field
|
||||
*/
|
||||
private String ramType;
|
||||
|
||||
/**
|
||||
* Processes count field
|
||||
*/
|
||||
private String procCount;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.bsoftware.ward.dto.implementation;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bsoftware.ward.dto.Dto;
|
||||
|
||||
/**
|
||||
* ProcessorDto is a values container for presenting processor principal information
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ProcessorDto implements Dto
|
||||
{
|
||||
/**
|
||||
* Processor name field
|
||||
*/
|
||||
private String processorName;
|
||||
|
||||
/**
|
||||
* Core count field
|
||||
*/
|
||||
private String coreCount;
|
||||
|
||||
/**
|
||||
* Processor max frequency field
|
||||
*/
|
||||
private String maxClockSpeed;
|
||||
|
||||
/**
|
||||
* Processor architecture field
|
||||
*/
|
||||
private String processorBitDepth;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.bsoftware.ward.dto.implementation;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bsoftware.ward.dto.Dto;
|
||||
|
||||
/**
|
||||
* StorageDto is a values container for presenting storage principal information
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class StorageDto implements Dto
|
||||
{
|
||||
/**
|
||||
* Host0 storage name field
|
||||
*/
|
||||
private String storageName;
|
||||
|
||||
/**
|
||||
* Amount of total installed storage field
|
||||
*/
|
||||
private String totalStorage;
|
||||
|
||||
/**
|
||||
* Disk count field
|
||||
*/
|
||||
private String diskCount;
|
||||
|
||||
/**
|
||||
* Total amount of virtual memory (Swap on Linux) field
|
||||
*/
|
||||
private String swapAmount;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.bsoftware.ward.dto.implementation;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bsoftware.ward.dto.Dto;
|
||||
|
||||
/**
|
||||
* StorageDto is a values container for presenting uptime principal information
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UptimeDto implements Dto
|
||||
{
|
||||
/**
|
||||
* Uptime days field
|
||||
*/
|
||||
private String days;
|
||||
|
||||
/**
|
||||
* Uptime hours field
|
||||
*/
|
||||
private String hours;
|
||||
|
||||
/**
|
||||
* Uptime minutes field
|
||||
*/
|
||||
private String minutes;
|
||||
|
||||
/**
|
||||
* Uptime seconds field
|
||||
*/
|
||||
private String seconds;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.bsoftware.ward.dto.implementation;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bsoftware.ward.dto.Dto;
|
||||
|
||||
/**
|
||||
* UsageDto is a values container for presenting server usage
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.1
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UsageDto implements Dto
|
||||
{
|
||||
/**
|
||||
* Processor usage field
|
||||
*/
|
||||
private int processorUsage;
|
||||
|
||||
/**
|
||||
* Ram usage field
|
||||
*/
|
||||
private int ramUsage;
|
||||
|
||||
/**
|
||||
* Storage usage field
|
||||
*/
|
||||
private int storageUsage;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.bsoftware.ward.services;
|
||||
|
||||
import org.bsoftware.ward.components.dto.Dto;
|
||||
import org.bsoftware.ward.dto.Dto;
|
||||
|
||||
/**
|
||||
* Service interface makes to all services return dto object
|
||||
|
@ -14,7 +14,7 @@ public interface Service
|
|||
/**
|
||||
* Get info from the service
|
||||
*
|
||||
* @return dto object
|
||||
* @return Dto object
|
||||
*/
|
||||
<T extends Dto> T get();
|
||||
<T extends Dto> T get() throws Exception;
|
||||
}
|
|
@ -1,21 +1,19 @@
|
|||
package org.bsoftware.ward.services.implementation;
|
||||
|
||||
import org.bsoftware.ward.components.dto.implementation.InfoDto;
|
||||
import org.bsoftware.ward.dto.implementation.*;
|
||||
import org.bsoftware.ward.components.utilities.ConverterUtility;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.*;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* InfoService provides various information about machine, such as processor name, core count, Ram amount, e.t.c.
|
||||
* InfoService provides various information about machine, such as processor name, core count, Ram amount, etc.
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.1
|
||||
* @version 1.0.2
|
||||
*/
|
||||
@Service
|
||||
public class InfoService implements org.bsoftware.ward.services.Service
|
||||
|
@ -33,16 +31,14 @@ public class InfoService implements org.bsoftware.ward.services.Service
|
|||
private ConverterUtility converterUtility;
|
||||
|
||||
/**
|
||||
* Dto to store all info values
|
||||
*/
|
||||
private InfoDto infoDto;
|
||||
|
||||
/**
|
||||
* Takes InfoDto and put in to it processor information
|
||||
* Gets processor information
|
||||
*
|
||||
* @return ProcessorDto with filled fields
|
||||
*/
|
||||
private void getProcessorInfo()
|
||||
private ProcessorDto getProcessorDto()
|
||||
{
|
||||
ProcessorDto processorDto = new ProcessorDto();
|
||||
|
||||
CentralProcessor centralProcessor = systemInfo.getHardware().getProcessor();
|
||||
|
||||
String processorName = centralProcessor.getProcessorIdentifier().getName();
|
||||
|
@ -50,44 +46,57 @@ public class InfoService implements org.bsoftware.ward.services.Service
|
|||
{
|
||||
processorName = processorName.substring(0, processorName.indexOf('@') - 1);
|
||||
}
|
||||
infoDto.setProcessorName(processorName.trim());
|
||||
processorDto.setProcessorName(processorName.trim());
|
||||
|
||||
int coreCount = centralProcessor.getLogicalProcessorCount();
|
||||
infoDto.setCoreCount(coreCount + ((coreCount > 1) ? " Cores" : " Core"));
|
||||
infoDto.setMaxClockSpeed(converterUtility.getConvertedFrequency(centralProcessor.getMaxFreq()));
|
||||
processorDto.setCoreCount(coreCount + ((coreCount > 1) ? " Cores" : " Core"));
|
||||
processorDto.setMaxClockSpeed(converterUtility.getConvertedFrequency(centralProcessor.getMaxFreq()));
|
||||
|
||||
String processorBitDepthPrefix = centralProcessor.getProcessorIdentifier().isCpu64bit() ? "64" : "32";
|
||||
infoDto.setProcessorBitDepth(processorBitDepthPrefix + "-bit Arch");
|
||||
processorDto.setProcessorBitDepth(processorBitDepthPrefix + "-bit Arch");
|
||||
|
||||
return processorDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes InfoDto and put in to it machine information
|
||||
* Gets machine information
|
||||
*
|
||||
* @return MachineDto with filled fields
|
||||
*/
|
||||
private void getMachineInfo()
|
||||
private MachineDto getMachineDto() throws Exception
|
||||
{
|
||||
MachineDto machineDto = new MachineDto();
|
||||
|
||||
OperatingSystem operatingSystem = systemInfo.getOperatingSystem();
|
||||
OperatingSystem.OSVersionInfo osVersionInfo = systemInfo.getOperatingSystem().getVersionInfo();
|
||||
GlobalMemory globalMemory = systemInfo.getHardware().getMemory();
|
||||
|
||||
infoDto.setOperatingSystemInfo(operatingSystem.getFamily() + " " + osVersionInfo.getVersion() + ", " + osVersionInfo.getCodeName());
|
||||
machineDto.setOperatingSystemInfo(operatingSystem.getFamily() + " " + osVersionInfo.getVersion() + ", " + osVersionInfo.getCodeName());
|
||||
|
||||
infoDto.setTotalRam(converterUtility.getConvertedCapacity(globalMemory.getTotal()) + " Ram");
|
||||
List<PhysicalMemory> physicalMem = globalMemory.getPhysicalMemory();
|
||||
if (physicalMem.isEmpty()) {
|
||||
infoDto.setRamType("Unknown");
|
||||
} else {
|
||||
infoDto.setRamType(physicalMem.get(0).getMemoryType());
|
||||
machineDto.setTotalRam(converterUtility.getConvertedCapacity(globalMemory.getTotal()) + " Ram");
|
||||
|
||||
List<PhysicalMemory> physicalMemory = globalMemory.getPhysicalMemory();
|
||||
if (physicalMemory.isEmpty())
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
machineDto.setRamType(physicalMemory.get(0).getMemoryType());
|
||||
|
||||
int processCount = operatingSystem.getProcessCount();
|
||||
infoDto.setProcCount(processCount + ((processCount > 1) ? " Procs" : " Proc"));
|
||||
machineDto.setProcCount(processCount + ((processCount > 1) ? " Procs" : " Proc"));
|
||||
|
||||
return machineDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes InfoDto and put in to it storage information
|
||||
* Gets storage information
|
||||
*
|
||||
* @return StorageDto with filled fields
|
||||
*/
|
||||
private void getStorageInfo()
|
||||
private StorageDto getStorageDto()
|
||||
{
|
||||
StorageDto storageDto = new StorageDto();
|
||||
|
||||
List<HWDiskStore> hwDiskStores = systemInfo.getHardware().getDiskStores();
|
||||
GlobalMemory globalMemory = systemInfo.getHardware().getMemory();
|
||||
|
||||
|
@ -96,47 +105,55 @@ public class InfoService implements org.bsoftware.ward.services.Service
|
|||
{
|
||||
storageName = storageName.substring(0, storageName.indexOf("(Standard disk drives)") - 1);
|
||||
}
|
||||
infoDto.setStorageName(storageName.trim());
|
||||
storageDto.setStorageName(storageName.trim());
|
||||
|
||||
long totalStorage = hwDiskStores.stream().mapToLong(HWDiskStore::getSize).sum();
|
||||
infoDto.setTotalStorage(converterUtility.getConvertedCapacity(totalStorage) + " Total");
|
||||
storageDto.setTotalStorage(converterUtility.getConvertedCapacity(totalStorage) + " Total");
|
||||
|
||||
int diskCount = hwDiskStores.size();
|
||||
infoDto.setDiskCount(diskCount + ((diskCount > 1) ? " Disks" : " Disk"));
|
||||
storageDto.setDiskCount(diskCount + ((diskCount > 1) ? " Disks" : " Disk"));
|
||||
|
||||
infoDto.setSwapAmount(converterUtility.getConvertedCapacity(globalMemory.getVirtualMemory().getSwapTotal()) + " Swap");
|
||||
storageDto.setSwapAmount(converterUtility.getConvertedCapacity(globalMemory.getVirtualMemory().getSwapTotal()) + " Swap");
|
||||
|
||||
return storageDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes InfoDto and put in to it uptime information
|
||||
* Gets uptime information
|
||||
*
|
||||
* @return UptimeDto with filled fields
|
||||
*/
|
||||
@SuppressWarnings("IntegerDivisionInFloatingPointContext")
|
||||
private void getUptimeInfo()
|
||||
private UptimeDto getUptimeDto()
|
||||
{
|
||||
UptimeDto uptimeDto = new UptimeDto();
|
||||
|
||||
long uptimeInSeconds = systemInfo.getOperatingSystem().getSystemUptime();
|
||||
Map<String, String> uptimeMap = new HashMap<>();
|
||||
|
||||
uptimeMap.put("days", String.format("%02d", (int) Math.floor(uptimeInSeconds / 86400)));
|
||||
uptimeMap.put("hours", String.format("%02d", (int) Math.floor((uptimeInSeconds % 86400) / 3600)));
|
||||
uptimeMap.put("minutes", String.format("%02d", (int) Math.floor((uptimeInSeconds / 60) % 60)));
|
||||
uptimeMap.put("seconds", String.format("%02d", (int) Math.floor(uptimeInSeconds % 60)));
|
||||
uptimeDto.setDays(String.format("%02d", (int) Math.floor(uptimeInSeconds / 86400)));
|
||||
uptimeDto.setHours(String.format("%02d", (int) Math.floor((uptimeInSeconds % 86400) / 3600)));
|
||||
uptimeDto.setMinutes(String.format("%02d", (int) Math.floor((uptimeInSeconds / 60) % 60)));
|
||||
uptimeDto.setSeconds(String.format("%02d", (int) Math.floor(uptimeInSeconds % 60)));
|
||||
|
||||
infoDto.setUptime(uptimeMap);
|
||||
return uptimeDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to deliver dto to corresponding controller
|
||||
*
|
||||
* @return completed InfoDto with server info
|
||||
* @return InfoDto filled with server info
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public InfoDto get()
|
||||
public InfoDto get() throws Exception
|
||||
{
|
||||
getProcessorInfo();
|
||||
getMachineInfo();
|
||||
getStorageInfo();
|
||||
getUptimeInfo();
|
||||
InfoDto infoDto = new InfoDto();
|
||||
|
||||
infoDto.setProcessorDto(getProcessorDto());
|
||||
infoDto.setMachineDto(getMachineDto());
|
||||
infoDto.setStorageDto(getStorageDto());
|
||||
infoDto.setUptimeDto(getUptimeDto());
|
||||
|
||||
return infoDto;
|
||||
}
|
||||
|
||||
|
@ -145,13 +162,11 @@ public class InfoService implements org.bsoftware.ward.services.Service
|
|||
*
|
||||
* @param systemInfo autowired SystemInfo object
|
||||
* @param converterUtility autowired ConverterUtility object
|
||||
* @param infoDto autowired InfoDto object
|
||||
*/
|
||||
@Autowired
|
||||
public InfoService(SystemInfo systemInfo, ConverterUtility converterUtility, InfoDto infoDto)
|
||||
public InfoService(SystemInfo systemInfo, ConverterUtility converterUtility)
|
||||
{
|
||||
this.systemInfo = systemInfo;
|
||||
this.converterUtility = converterUtility;
|
||||
this.infoDto = infoDto;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.bsoftware.ward.services.implementation;
|
||||
|
||||
import org.bsoftware.ward.components.dto.implementation.UsageDto;
|
||||
import org.bsoftware.ward.dto.implementation.UsageDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import oshi.SystemInfo;
|
||||
|
@ -15,7 +15,7 @@ import java.util.Arrays;
|
|||
* UsageService provides principal information of processor, RAM and storage usage to rest controller
|
||||
*
|
||||
* @author Rudolf Barbu
|
||||
* @version 1.0.2
|
||||
* @version 1.0.3
|
||||
*/
|
||||
@Service
|
||||
public class UsageService implements org.bsoftware.ward.services.Service
|
||||
|
@ -27,14 +27,11 @@ public class UsageService implements org.bsoftware.ward.services.Service
|
|||
private SystemInfo systemInfo;
|
||||
|
||||
/**
|
||||
* Dto to store all usage values
|
||||
* Gets processor usage
|
||||
*
|
||||
* @return int that display processor usage
|
||||
*/
|
||||
private UsageDto usageDto;
|
||||
|
||||
/**
|
||||
* Takes UsageDto and put in to it processor usage for last second in 0-100% range
|
||||
*/
|
||||
private void getProcessorUsage()
|
||||
private int getProcessorUsage()
|
||||
{
|
||||
CentralProcessor centralProcessor = systemInfo.getHardware().getProcessor();
|
||||
|
||||
|
@ -48,47 +45,54 @@ public class UsageService implements org.bsoftware.ward.services.Service
|
|||
long currTotalTicks = Arrays.stream(currTicksArray).sum();
|
||||
long currIdleTicks = currTicksArray[CentralProcessor.TickType.IDLE.getIndex()];
|
||||
|
||||
usageDto.setProcessor((int) Math.round((1 - ((double) (currIdleTicks - prevIdleTicks)) / ((double) (currTotalTicks - prevTotalTicks))) * 100));
|
||||
return (int) Math.round((1 - ((double) (currIdleTicks - prevIdleTicks)) / ((double) (currTotalTicks - prevTotalTicks))) * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes UsageDto and put in to it current RAM usage in 0-100% range
|
||||
* Gets ram usage
|
||||
*
|
||||
* @return int that display ram usage
|
||||
*/
|
||||
private void getRamUsage()
|
||||
private int getRamUsage()
|
||||
{
|
||||
GlobalMemory globalMemory = systemInfo.getHardware().getMemory();
|
||||
|
||||
long totalMemory = globalMemory.getTotal();
|
||||
long availableMemory = globalMemory.getAvailable();
|
||||
|
||||
usageDto.setRam((int) Math.round(100 - (((double) availableMemory / totalMemory) * 100)));
|
||||
return (int) Math.round(100 - (((double) availableMemory / totalMemory) * 100));
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes UsageDto and put in to it current storage usage in 0-100% range
|
||||
* Gets storage usage
|
||||
*
|
||||
* @return int that display storage usage
|
||||
*/
|
||||
private void getStorageUsage()
|
||||
private int getStorageUsage()
|
||||
{
|
||||
FileSystem fileSystem = systemInfo.getOperatingSystem().getFileSystem();
|
||||
|
||||
long totalStorage = fileSystem.getFileStores().stream().mapToLong(OSFileStore::getTotalSpace).sum();
|
||||
long freeStorage = fileSystem.getFileStores().stream().mapToLong(OSFileStore::getFreeSpace).sum();
|
||||
|
||||
usageDto.setStorage((int) Math.round(((double) (totalStorage - freeStorage) / totalStorage) * 100));
|
||||
return (int) Math.round(((double) (totalStorage - freeStorage) / totalStorage) * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to deliver dto to corresponding controller
|
||||
*
|
||||
* @return completed UsageDto with server usage info
|
||||
* @return UsageDto filled with usage info
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public UsageDto get()
|
||||
{
|
||||
getProcessorUsage();
|
||||
getRamUsage();
|
||||
getStorageUsage();
|
||||
UsageDto usageDto = new UsageDto();
|
||||
|
||||
usageDto.setProcessorUsage(getProcessorUsage());
|
||||
usageDto.setRamUsage(getRamUsage());
|
||||
usageDto.setStorageUsage(getStorageUsage());
|
||||
|
||||
return usageDto;
|
||||
}
|
||||
|
||||
|
@ -96,12 +100,10 @@ public class UsageService implements org.bsoftware.ward.services.Service
|
|||
* Used for autowiring necessary objects
|
||||
*
|
||||
* @param systemInfo autowired SystemInfo object
|
||||
* @param usageDto autowired UsageDto object
|
||||
*/
|
||||
@Autowired
|
||||
public UsageService(SystemInfo systemInfo, UsageDto usageDto)
|
||||
public UsageService(SystemInfo systemInfo)
|
||||
{
|
||||
this.systemInfo = systemInfo;
|
||||
this.usageDto = usageDto;
|
||||
}
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* Initializes dynamic background
|
||||
*/
|
||||
function backgroundInitialization()
|
||||
{
|
||||
VANTA.FOG
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<div class = "hw-logo blue-light"></div>
|
||||
<div class = "label-hw-info">
|
||||
<div class = "hw-type">Processor</div>
|
||||
<div class = "hw-name" th:text = "${info.processorName}"></div>
|
||||
<div class = "hw-name" th:text = "${infoDto.processorDto.processorName}"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class = "usage">
|
||||
|
@ -64,9 +64,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class = "detailed-hw-info">
|
||||
<div class = "first-label" th:text = "${info.coreCount}"></div>
|
||||
<div class = "second-label" th:text = "${info.maxClockSpeed}"></div>
|
||||
<div class = "third-label" th:text = "${info.processorBitDepth}"></div>
|
||||
<div class = "first-label" th:text = "${infoDto.processorDto.coreCount}"></div>
|
||||
<div class = "second-label" th:text = "${infoDto.processorDto.maxClockSpeed}"></div>
|
||||
<div class = "third-label" th:text = "${infoDto.processorDto.processorBitDepth}"></div>
|
||||
</div>
|
||||
<div class = "dividers">
|
||||
<div class = "first-divider"></div>
|
||||
|
@ -81,7 +81,7 @@
|
|||
<div class = "hw-logo red-light"></div>
|
||||
<div class = "label-hw-info">
|
||||
<div class = "hw-type">Machine</div>
|
||||
<div class = "hw-name" th:text = "${info.operatingSystemInfo}"></div>
|
||||
<div class = "hw-name" th:text = "${infoDto.machineDto.operatingSystemInfo}"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class = "usage">
|
||||
|
@ -116,9 +116,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class = "detailed-hw-info">
|
||||
<div class = "first-label" th:text = "${info.totalRam}"></div>
|
||||
<div class = "second-label" th:text = "${info.ramType}"></div>
|
||||
<div class = "third-label" th:text = "${info.procCount}"></div>
|
||||
<div class = "first-label" th:text = "${infoDto.machineDto.totalRam}"></div>
|
||||
<div class = "second-label" th:text = "${infoDto.machineDto.ramType}"></div>
|
||||
<div class = "third-label" th:text = "${infoDto.machineDto.procCount}"></div>
|
||||
</div>
|
||||
<div class = "dividers">
|
||||
<div class = "first-divider"></div>
|
||||
|
@ -133,7 +133,7 @@
|
|||
<div class = "hw-logo green-light"></div>
|
||||
<div class = "label-hw-info">
|
||||
<div class = "hw-type">Storage</div>
|
||||
<div class = "hw-name" th:text = "${info.storageName}"></div>
|
||||
<div class = "hw-name" th:text = "${infoDto.storageDto.storageName}"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class = "usage">
|
||||
|
@ -168,9 +168,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class = "detailed-hw-info">
|
||||
<div class = "first-label" th:text = "${info.totalStorage}"></div>
|
||||
<div class = "second-label" th:text = "${info.diskCount}"></div>
|
||||
<div class = "third-label" th:text = "${info.swapAmount}"></div>
|
||||
<div class = "first-label" th:text = "${infoDto.storageDto.totalStorage}"></div>
|
||||
<div class = "second-label" th:text = "${infoDto.storageDto.diskCount}"></div>
|
||||
<div class = "third-label" th:text = "${infoDto.storageDto.swapAmount}"></div>
|
||||
</div>
|
||||
<div class = "dividers">
|
||||
<div class = "first-divider"></div>
|
||||
|
@ -196,10 +196,10 @@
|
|||
</div>
|
||||
<div class = "uptime-rectangle-grid">
|
||||
<div class = "values-grid">
|
||||
<div><p id = "uptime-days" th:text = "${info.uptime.days}"></p></div>
|
||||
<div><p id = "uptime-hours" th:text = "${info.uptime.hours}"></p></div>
|
||||
<div><p id = "uptime-minutes" th:text = "${info.uptime.minutes}"></p></div>
|
||||
<div><p id = "uptime-seconds" th:text = "${info.uptime.seconds}"></p></div>
|
||||
<div><p id = "uptime-days" th:text = "${infoDto.uptimeDto.days}"></p></div>
|
||||
<div><p id = "uptime-hours" th:text = "${infoDto.uptimeDto.hours}"></p></div>
|
||||
<div><p id = "uptime-minutes" th:text = "${infoDto.uptimeDto.minutes}"></p></div>
|
||||
<div><p id = "uptime-seconds" th:text = "${infoDto.uptimeDto.seconds}"></p></div>
|
||||
</div>
|
||||
<script th:inline = "javascript"> uptimeInitialization(); </script>
|
||||
<div class = "labels-grid">
|
||||
|
|
Loading…
Reference in New Issue