use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class BackgroundProcessingRestController method getMediumPriorityThreadPoolSettings.
@ApiOperation(value = "Get the Medium Priority Service Thread Pool Settings", notes = "active count and largest pool size are read only")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/medium-priority-thread-pool-settings")
public ResponseEntity<ThreadPoolSettingsModel> getMediumPriorityThreadPoolSettings(HttpServletRequest request) {
RestProcessResult<ThreadPoolSettingsModel> result = new RestProcessResult<ThreadPoolSettingsModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
int corePoolSize = Common.backgroundProcessing.getMediumPriorityServiceCorePoolSize();
int maximumPoolSize = Common.backgroundProcessing.getMediumPriorityServiceMaximumPoolSize();
int activeCount = Common.backgroundProcessing.getMediumPriorityServiceActiveCount();
int largestPoolSize = Common.backgroundProcessing.getMediumPriorityServiceLargestPoolSize();
ThreadPoolSettingsModel model = new ThreadPoolSettingsModel(corePoolSize, maximumPoolSize, activeCount, largestPoolSize);
return result.createResponseEntity(model);
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to access medium priority thread pool settings.");
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class BackgroundProcessingRestController method setHighPrioritySettings.
@ApiOperation(value = "Update high priority queue settings", notes = "")
@RequestMapping(method = RequestMethod.PUT, produces = { "application/json" }, value = "/high-priority-thread-pool-settings")
public ResponseEntity<ThreadPoolSettingsModel> setHighPrioritySettings(@ApiParam(value = "Settings", required = true, allowMultiple = false) @RequestBody ThreadPoolSettingsModel model, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<ThreadPoolSettingsModel> result = new RestProcessResult<ThreadPoolSettingsModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
// Validate the settings
ThreadPoolExecutor executor = (ThreadPoolExecutor) Common.timer.getExecutorService();
int currentCorePoolSize = executor.getCorePoolSize();
int currentMaxPoolSize = executor.getMaximumPoolSize();
if ((model.getMaximumPoolSize() != null) && (model.getMaximumPoolSize() < BackgroundProcessing.HIGH_PRI_MAX_POOL_SIZE_MIN)) {
// Test to ensure we aren't setting too low
model.getMessages().add(new RestValidationMessage(new TranslatableMessage("validate.greaterThanOrEqualTo", BackgroundProcessing.HIGH_PRI_MAX_POOL_SIZE_MIN), RestMessageLevel.ERROR, "corePoolSize"));
result.addRestMessage(this.getValidationFailedError());
} else if (!validate(model, currentCorePoolSize, currentMaxPoolSize)) {
result.addRestMessage(this.getValidationFailedError());
} else {
if (model.getCorePoolSize() != null) {
executor.setCorePoolSize(model.getCorePoolSize());
SystemSettingsDao.instance.setIntValue(SystemSettingsDao.HIGH_PRI_CORE_POOL_SIZE, model.getCorePoolSize());
} else {
// Get the info for the user
int corePoolSize = executor.getCorePoolSize();
model.setCorePoolSize(corePoolSize);
}
if (model.getMaximumPoolSize() != null) {
executor.setMaximumPoolSize(model.getMaximumPoolSize());
SystemSettingsDao.instance.setIntValue(SystemSettingsDao.HIGH_PRI_MAX_POOL_SIZE, model.getMaximumPoolSize());
} else {
// Get the info for the user
int maximumPoolSize = executor.getMaximumPoolSize();
model.setMaximumPoolSize(maximumPoolSize);
}
// Get the settings for the model
int activeCount = executor.getActiveCount();
int largestPoolSize = executor.getLargestPoolSize();
model.setActiveCount(activeCount);
model.setLargestPoolSize(largestPoolSize);
}
return result.createResponseEntity(model);
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to set high priority thread pool settings.");
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class BackgroundProcessingRestController method setMediumPrioritySettings.
@ApiOperation(value = "Update medium priority queue settings", notes = "Only corePoolSize and maximumPoolSize are used")
@RequestMapping(method = RequestMethod.PUT, produces = { "application/json" }, value = "/medium-priority-thread-pool-settings")
public ResponseEntity<ThreadPoolSettingsModel> setMediumPrioritySettings(@ApiParam(value = "Settings", required = true, allowMultiple = false) @RequestBody ThreadPoolSettingsModel model, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<ThreadPoolSettingsModel> result = new RestProcessResult<ThreadPoolSettingsModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
// Validate the settings
int currentCorePoolSize = SystemSettingsDao.getIntValue(SystemSettingsDao.MED_PRI_CORE_POOL_SIZE);
if ((model.getCorePoolSize() != null) && (model.getCorePoolSize() < BackgroundProcessing.MED_PRI_MAX_POOL_SIZE_MIN)) {
// Test to ensure we aren't setting too low
model.getMessages().add(new RestValidationMessage(new TranslatableMessage("validate.greaterThanOrEqualTo", BackgroundProcessing.MED_PRI_MAX_POOL_SIZE_MIN), RestMessageLevel.ERROR, "corePoolSize"));
result.addRestMessage(this.getValidationFailedError());
} else if (!validate(model, currentCorePoolSize, model.getCorePoolSize() == null ? currentCorePoolSize : model.getCorePoolSize())) {
result.addRestMessage(this.getValidationFailedError());
} else {
if (model.getCorePoolSize() != null) {
Common.backgroundProcessing.setMediumPriorityServiceCorePoolSize(model.getCorePoolSize());
SystemSettingsDao.instance.setIntValue(SystemSettingsDao.MED_PRI_CORE_POOL_SIZE, model.getCorePoolSize());
} else {
// Get the info for the user
int corePoolSize = Common.backgroundProcessing.getMediumPriorityServiceCorePoolSize();
model.setCorePoolSize(corePoolSize);
}
if (model.getMaximumPoolSize() == null) {
// Get the info for the user
int maximumPoolSize = Common.backgroundProcessing.getMediumPriorityServiceMaximumPoolSize();
model.setMaximumPoolSize(maximumPoolSize);
}
// Get the settings for the model
int activeCount = Common.backgroundProcessing.getMediumPriorityServiceActiveCount();
int largestPoolSize = Common.backgroundProcessing.getMediumPriorityServiceLargestPoolSize();
model.setActiveCount(activeCount);
model.setLargestPoolSize(largestPoolSize);
}
return result.createResponseEntity(model);
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to set medium priority thread pool settings.");
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getDataPointById.
@ApiOperation(value = "Get data point by ID", notes = "Returned as CSV or JSON, only points that user has read permission to are returned")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv", "application/sero-json" }, value = "/by-id/{id}")
public ResponseEntity<DataPointModel> getDataPointById(@ApiParam(value = "Valid Data Point ID", required = true, allowMultiple = false) @PathVariable int id, HttpServletRequest request) {
RestProcessResult<DataPointModel> result = new RestProcessResult<DataPointModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataPointVO vo = DataPointDao.instance.get(id);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
// Check permissions
try {
if (Permissions.hasDataPointReadPermission(user, vo))
return result.createResponseEntity(new DataPointModel(vo));
else {
LOG.warn("User: " + user.getUsername() + " tried to access data point with xid " + vo.getXid());
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} catch (PermissionException e) {
LOG.warn(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getDataPoint.
@ApiOperation(value = "Get data point by XID", notes = "Returned as CSV or JSON, only points that user has read permission to are returned")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv", "application/sero-json" }, value = "/{xid}")
public ResponseEntity<DataPointModel> getDataPoint(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<DataPointModel> result = new RestProcessResult<DataPointModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataPointVO vo = DataPointDao.instance.getByXid(xid);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
// Check permissions
try {
if (Permissions.hasDataPointReadPermission(user, vo))
return result.createResponseEntity(new DataPointModel(vo));
else {
LOG.warn("User: " + user.getUsername() + " tried to access data point with xid " + vo.getXid());
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} catch (PermissionException e) {
LOG.warn(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
Aggregations