use of com.serotonin.m2m2.vo.FileStore in project ma-modules-public by infiniteautomation.
the class ServerRestController method getSystemInfo.
@ApiOperation(value = "System Info", notes = "Provides disk use, db sizes and point, event counts", response = Map.class)
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/system-info")
public ResponseEntity<SystemInfoModel> getSystemInfo(HttpServletRequest request) {
RestProcessResult<SystemInfoModel> result = new RestProcessResult<SystemInfoModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (user.isAdmin()) {
SystemInfoModel model = new SystemInfoModel();
// Database size
model.setSqlDbSizeBytes(Common.databaseProxy.getDatabaseSizeInBytes());
// Do we have any NoSQL Data
if (Common.databaseProxy.getNoSQLProxy() != null) {
String pointValueStoreName = Common.envProps.getString("db.nosql.pointValueStoreName", "mangoTSDB");
model.setNoSqlDbSizeBytes(Common.databaseProxy.getNoSQLProxy().getDatabaseSizeInBytes(pointValueStoreName));
}
// Filedata data
DirectoryInfo fileDatainfo = DirectoryUtils.getSize(new File(Common.getFiledataPath()));
model.setFileDataSizeBytes(fileDatainfo.getSize());
// Point history counts.
model.setTopPoints(DataPointDao.instance.getTopPointHistoryCounts());
model.setEventCount(EventDao.instance.getEventCount());
// Disk Info
FileSystem fs = FileSystems.getDefault();
List<DiskInfoModel> disks = new ArrayList<DiskInfoModel>();
model.setDisks(disks);
for (Path root : fs.getRootDirectories()) {
try {
FileStore store = Files.getFileStore(root);
DiskInfoModel disk = new DiskInfoModel();
disk.setName(root.getRoot().toString());
disk.setTotalSpaceBytes(store.getTotalSpace());
disk.setUsableSpaceBytes(store.getUsableSpace());
disks.add(disk);
} catch (IOException e) {
}
}
// CPU Info
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
model.setLoadAverage(osBean.getSystemLoadAverage());
// OS Info
model.setArchitecture(osBean.getArch());
model.setOperatingSystem(osBean.getName());
model.setOsVersion(osBean.getVersion());
return result.createResponseEntity(model);
} else {
result.addRestMessage(HttpStatus.UNAUTHORIZED, new TranslatableMessage("common.default", "User not admin"));
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.FileStore in project ma-modules-public by infiniteautomation.
the class ScriptRestController method evalScript.
@Async
@ApiOperation(value = "Evaluate a filestore file as a script on the backend using a scripting engine")
@RequestMapping(method = RequestMethod.POST, value = "/eval-file-store/{fileStoreName}/**")
public CompletableFuture<Void> evalScript(@ApiParam(value = "File store name", required = true) @PathVariable(required = true) String fileStoreName, @ApiParam(value = "Script engine name", required = false) @RequestParam(required = false) String engineName, @ApiParam(value = "Script file character set", required = false, defaultValue = "UTF-8") @RequestParam(required = false, defaultValue = "UTF-8") String fileCharset, @ApiParam(value = "Script roles", required = false, allowMultiple = true) @RequestParam(required = false) String[] roles, @ApiIgnore @RemainingPath String path, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request, HttpServletResponse response) throws IOException {
Path filePath = fileStoreService.getPathForRead(fileStoreName, path);
if (!Files.exists(filePath)) {
throw new NotFoundException();
}
if (engineName == null) {
engineName = scriptService.findEngineForFile(filePath);
}
Charset fileCharsetParsed = Charset.forName(fileCharset);
Set<Role> roleSet;
if (roles != null) {
roleSet = Arrays.stream(roles).map(xid -> this.roleService.get(xid).getRole()).collect(Collectors.toSet());
} else {
roleSet = user.getRoles();
}
EvalContext evalContext = new EvalContext();
Reader reader = new BufferedReader(new InputStreamReader(request.getInputStream(), Charset.forName(request.getCharacterEncoding())));
Writer writer = new OutputStreamWriter(response.getOutputStream(), Charset.forName(response.getCharacterEncoding()));
evalContext.setReader(reader);
evalContext.setWriter(writer);
evalContext.addBinding("reader", reader);
evalContext.addBinding("writer", writer);
if (permissionService.hasPermission(user, requestResponsePermission.getPermission())) {
evalContext.addBinding("request", request);
evalContext.addBinding("response", response);
}
this.scriptService.eval(new PathMangoScript(engineName, roleSet, filePath, fileCharsetParsed), evalContext);
return CompletableFuture.completedFuture(null);
}
use of com.serotonin.m2m2.vo.FileStore in project ma-modules-public by infiniteautomation.
the class UserFileStoresRestController method updateUserFileStore.
@ApiOperation(value = "Update a user file store")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}")
public ResponseEntity<FileStoreModel> updateUserFileStore(@ApiParam(value = "File store XID", required = true) @PathVariable("xid") String xid, @ApiParam(value = "Updated file store", required = true) @RequestBody FileStoreModel fileStore, UriComponentsBuilder builder) {
FileStore updated = this.fileStoreService.update(xid, fileStore.toVO());
URI location = builder.path("/user-file-stores/{xid}").buildAndExpand(updated.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new FileStoreModel(updated), headers, HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.FileStore in project ma-modules-public by infiniteautomation.
the class UserFileStoresRestController method getUserFileStoreModel.
@ApiOperation(value = "Get a user file store model")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}")
public MappingJacksonValue getUserFileStoreModel(@PathVariable("xid") String xid, @AuthenticationPrincipal PermissionHolder user) {
FileStore fs = this.fileStoreService.get(xid);
// Seeing the permissions fields should require write protection
MappingJacksonValue resultWithView = new MappingJacksonValue(new FileStoreModel(fs));
if (fileStoreService.hasEditPermission(user, fs)) {
resultWithView.setSerializationView(RoleViews.ShowRoles.class);
} else {
resultWithView.setSerializationView(Object.class);
}
return resultWithView;
}
use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class FileStoreDao method mapRecord.
@Override
public FileStore mapRecord(Record record) {
FileStore result = new FileStore();
result.setId(record.get(table.id));
result.setXid(record.get(table.xid));
result.setName(record.get(table.name));
result.setReadPermission(new MangoPermission(record.get(table.readPermissionId)));
result.setWritePermission(new MangoPermission(record.get(table.writePermissionId)));
return result;
}
Aggregations