use of com.serotonin.m2m2.web.mvc.rest.v1.model.backgroundProcessing.ThreadPoolSettingsModel in project ma-modules-public by infiniteautomation.
the class BackgroundProcessingRestController method setLowPrioritySettings.
@ApiOperation(value = "Update low priority service settings", notes = "Only corePoolSize and maximumPoolSize are used")
@RequestMapping(method = RequestMethod.PUT, produces = { "application/json" }, value = "/low-priority-thread-pool-settings")
public ResponseEntity<ThreadPoolSettingsModel> setLowPrioritySettings(@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.LOW_PRI_CORE_POOL_SIZE);
if ((model.getCorePoolSize() != null) && (model.getCorePoolSize() < BackgroundProcessing.LOW_PRI_MAX_POOL_SIZE_MIN)) {
// Test to ensure we aren't setting too low
model.getMessages().add(new RestValidationMessage(new TranslatableMessage("validate.greaterThanOrEqualTo", BackgroundProcessing.LOW_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.setLowPriorityServiceCorePoolSize(model.getCorePoolSize());
SystemSettingsDao.instance.setIntValue(SystemSettingsDao.LOW_PRI_CORE_POOL_SIZE, model.getCorePoolSize());
} else {
// Get the info for the user
int corePoolSize = Common.backgroundProcessing.getLowPriorityServiceCorePoolSize();
model.setCorePoolSize(corePoolSize);
}
if (model.getMaximumPoolSize() == null) {
// Get the info for the user
int maximumPoolSize = Common.backgroundProcessing.getLowPriorityServiceMaximumPoolSize();
model.setMaximumPoolSize(maximumPoolSize);
}
// Get the settings for the model
int activeCount = Common.backgroundProcessing.getLowPriorityServiceActiveCount();
int largestPoolSize = Common.backgroundProcessing.getLowPriorityServiceLargestPoolSize();
model.setActiveCount(activeCount);
model.setLargestPoolSize(largestPoolSize);
}
return result.createResponseEntity(model);
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to set low priority thread pool settings.");
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.backgroundProcessing.ThreadPoolSettingsModel in project ma-modules-public by infiniteautomation.
the class BackgroundProcessingRestController method getHighPriorityThreadPoolSettings.
@ApiOperation(value = "Get the High Priority Service Thread Pool Settings", notes = "active count and largest pool size are read only")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/high-priority-thread-pool-settings")
public ResponseEntity<ThreadPoolSettingsModel> getHighPriorityThreadPoolSettings(HttpServletRequest request) {
RestProcessResult<ThreadPoolSettingsModel> result = new RestProcessResult<ThreadPoolSettingsModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
ThreadPoolExecutor executor = (ThreadPoolExecutor) Common.timer.getExecutorService();
int corePoolSize = executor.getCorePoolSize();
int maximumPoolSize = executor.getMaximumPoolSize();
int activeCount = executor.getActiveCount();
int largestPoolSize = executor.getLargestPoolSize();
ThreadPoolSettingsModel model = new ThreadPoolSettingsModel(corePoolSize, maximumPoolSize, activeCount, largestPoolSize);
return result.createResponseEntity(model);
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to access high priority thread pool settings.");
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
} else {
return result.createResponseEntity();
}
}
Aggregations