use of com.serotonin.m2m2.module.Module in project ma-core-public by infiniteautomation.
the class ModulesDwr method toggleDeletion.
@DwrPermission(admin = true)
public boolean toggleDeletion(String moduleName) {
Module module = ModuleRegistry.getModule(moduleName);
module.setMarkedForDeletion(!module.isMarkedForDeletion());
return module.isMarkedForDeletion();
}
use of com.serotonin.m2m2.module.Module in project ma-core-public by infiniteautomation.
the class MockMangoLifecycle method initialize.
/**
* Startup a dummy Mango with a basic infrastructure
*/
public void initialize() {
Common.MA_HOME = System.getProperty("ma.home");
if (Common.MA_HOME == null)
Common.MA_HOME = ".";
// Add in modules
for (Module module : modules) ModuleRegistry.addModule(module);
Providers.add(IMangoLifecycle.class, this);
// TODO Licensing Providers.add(ICoreLicense.class, new CoreLicenseDefinition());
// TODO Licensing Providers.add(ITimedLicenseRegistrar.class, new TimedLicenseRegistrar());
Common.free = false;
// Startup a simulation timer provider
Providers.add(TimerProvider.class, getSimulationTimerProvider());
// Make sure that Common and other classes are properly loaded
Common.envProps = getEnvProps();
MangoRestSpringConfiguration.initializeObjectMapper();
Common.JSON_CONTEXT.addResolver(new EventTypeResolver(), EventType.class);
Common.JSON_CONTEXT.addResolver(new BaseChartRenderer.Resolver(), ChartRenderer.class);
Common.JSON_CONTEXT.addResolver(new BaseTextRenderer.Resolver(), TextRenderer.class);
Common.JSON_CONTEXT.addResolver(new EmailRecipientResolver(), EmailRecipient.class);
Common.JSON_CONTEXT.addResolver(new VirtualSerialPortConfigResolver(), VirtualSerialPortConfig.class);
Common.JSON_CONTEXT.addConverter(new MapWrapConverter(), MapWrap.class);
for (Module module : ModuleRegistry.getModules()) {
module.preInitialize(true, false);
}
// Start the Database so we can use Daos (Base Dao requires this)
if (Common.databaseProxy == null) {
Common.databaseProxy = getDatabaseProxy();
Common.databaseProxy.initialize(null);
}
// Ensure we start with the proper timer
Common.backgroundProcessing = getBackgroundProcessing();
Common.backgroundProcessing.initialize(false);
for (Module module : ModuleRegistry.getModules()) {
module.postDatabase(true, false);
}
// Utilities
// So we can add users etc.
EventType.initialize();
SystemEventType.initialize();
AuditEventType.initialize();
// Setup Common Object Mapper
Common.objectMapper = new CommonObjectMapper();
// Do this last as Event Types have listeners
for (SystemSettingsListenerDefinition def : ModuleRegistry.getSystemSettingListenerDefinitions()) def.registerListener();
// Event Manager
Common.eventManager = getEventManager();
Common.eventManager.initialize(false);
for (EventManagerListenerDefinition def : ModuleRegistry.getDefinitions(EventManagerListenerDefinition.class)) Common.eventManager.addListener(def);
Common.runtimeManager = getRuntimeManager();
Common.runtimeManager.initialize(false);
if (Common.serialPortManager == null)
Common.serialPortManager = getSerialPortManager();
for (Module module : ModuleRegistry.getModules()) {
module.postInitialize(true, false);
}
for (Runnable task : STARTUP_TASKS) {
try {
task.run();
} catch (Exception e) {
fail(e.getMessage());
}
}
}
use of com.serotonin.m2m2.module.Module in project ma-core-public by infiniteautomation.
the class ImportTask method runImpl.
@Override
protected void runImpl() {
try {
BackgroundContext.set(user);
if (!importers.isEmpty()) {
if (importerIndex >= importers.size()) {
// A run through the importers has been completed.
if (importerSuccess) {
// If there were successes with the importers and there are still more to do, run through
// them again.
importerIndex = 0;
importerSuccess = false;
} else if (!importedItems) {
try {
for (ImportItem importItem : importItems) {
if (!importItem.isComplete()) {
importItem.importNext(importContext);
return;
}
}
// We may have imported a dependency in a module
importedItems = true;
importerIndex = 0;
} catch (Exception e) {
addException(e);
}
} else {
// Run the import items.
for (Importer importer : importers) importer.copyMessages();
importers.clear();
processDataPointPaths(hierarchyImporter, dpPathPairs);
completed = true;
return;
}
}
// Run the next importer
Importer importer = importers.get(importerIndex);
try {
importer.doImport();
if (importer.success()) {
// The import was successful. Note the success and remove the importer from the list.
importerSuccess = true;
importers.remove(importerIndex);
} else {
// The import failed. Leave it in the list since the run of another importer
// may resolved the problem.
importerIndex++;
}
} catch (Exception e) {
// Uh oh...
LOG.error(e.getMessage(), e);
addException(e);
importers.remove(importerIndex);
}
return;
}
// Run the import items.
try {
for (ImportItem importItem : importItems) {
if (!importItem.isComplete()) {
importItem.importNext(importContext);
return;
}
}
processDataPointPaths(hierarchyImporter, dpPathPairs);
processUpdatedDetectors(eventDetectorPoints);
completed = true;
} catch (Exception e) {
addException(e);
}
} finally {
BackgroundContext.remove();
// Compute progress, but only declare if we are < 100 since we will declare 100 when done
// Our progress is 100 - chunk*importersLeft
int importItemsLeft = 1;
if (completed)
// Since we know we ran the processDataPointPaths method
importItemsLeft = 0;
for (ImportItem item : importItems) if (!item.isComplete())
importItemsLeft++;
this.progress = 100f - progressChunk * ((float) importers.size() + (float) importItemsLeft);
if (progress < 100f)
declareProgress(this.progress);
}
}
use of com.serotonin.m2m2.module.Module in project ma-core-public by infiniteautomation.
the class SystemSettingsDao method validate.
/**
* Validate the system settings passed in, only validating settings that exist in the map.
*
* @param settings
* @param voResponse
*/
public void validate(Map<String, Object> settings, ProcessResult response) {
Object setting = null;
try {
setting = settings.get(EMAIL_CONTENT_TYPE);
if (setting != null) {
if (setting instanceof Number) {
int emailContentType = ((Number) setting).intValue();
switch(emailContentType) {
case MangoEmailContent.CONTENT_TYPE_BOTH:
case MangoEmailContent.CONTENT_TYPE_HTML:
case MangoEmailContent.CONTENT_TYPE_TEXT:
break;
default:
response.addContextualMessage(EMAIL_CONTENT_TYPE, "validate.invalideValue");
}
} else {
// String Code
if (MangoEmailContent.CONTENT_TYPE_CODES.getId((String) setting) < 0)
response.addContextualMessage(EMAIL_CONTENT_TYPE, "emport.error.invalid", EMAIL_CONTENT_TYPE, (String) setting, MangoEmailContent.CONTENT_TYPE_CODES.getCodeList());
}
}
} catch (NumberFormatException e) {
response.addContextualMessage(EMAIL_CONTENT_TYPE, "validate.illegalValue");
}
validatePeriodType(POINT_DATA_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(DATA_POINT_EVENT_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(DATA_SOURCE_EVENT_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(SYSTEM_EVENT_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(PUBLISHER_EVENT_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(AUDIT_EVENT_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(NONE_ALARM_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(INFORMATION_ALARM_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(IMPORTANT_ALARM_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(WARNING_ALARM_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(URGENT_ALARM_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(CRITICAL_ALARM_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(LIFE_SAFETY_ALARM_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(EVENT_PURGE_PERIOD_TYPE, settings, response);
validatePeriodType(FUTURE_DATE_LIMIT_PERIOD_TYPE, settings, response);
try {
setting = settings.get(CHART_BACKGROUND_COLOUR);
if (setting != null)
ColorUtils.toColor((String) setting);
} catch (InvalidArgumentException e) {
response.addContextualMessage(CHART_BACKGROUND_COLOUR, "systemSettings.validation.invalidColour");
}
try {
setting = settings.get(PLOT_BACKGROUND_COLOUR);
if (setting != null)
ColorUtils.toColor((String) setting);
} catch (InvalidArgumentException e) {
response.addContextualMessage(PLOT_BACKGROUND_COLOUR, "systemSettings.validation.invalidColour");
}
try {
setting = settings.get(PLOT_GRIDLINE_COLOUR);
if (setting != null)
ColorUtils.toColor((String) setting);
} catch (InvalidArgumentException e) {
response.addContextualMessage(PLOT_GRIDLINE_COLOUR, "systemSettings.validation.invalidColour");
}
setting = settings.get(BACKUP_FILE_LOCATION);
if (setting != null) {
File tmp = new File((String) setting);
if (!tmp.exists()) {
// Doesn't exist, push up message
response.addContextualMessage(BACKUP_FILE_LOCATION, "systemSettings.validation.backupLocationNotExists");
}
if (!tmp.canWrite()) {
response.addContextualMessage(BACKUP_FILE_LOCATION, "systemSettings.validation.cannotWriteToBackupFileLocation");
}
}
// Validate the Hour and Minute
Integer backupHour = getIntValue(BACKUP_HOUR, settings);
if (backupHour != null)
if ((backupHour > 23) || (backupHour < 0)) {
response.addContextualMessage(BACKUP_HOUR, "systemSettings.validation.backupHourInvalid");
}
Integer backupMinute = getIntValue(BACKUP_MINUTE, settings);
if (backupMinute != null)
if ((backupMinute > 59) || (backupMinute < 0)) {
response.addContextualMessage(BACKUP_MINUTE, "systemSettings.validation.backupMinuteInvalid");
}
validatePeriodType(BACKUP_PERIOD_TYPE, settings, response);
// Validate the number of backups to keep
Integer backupFileCount = getIntValue(BACKUP_FILE_COUNT, settings);
if (backupFileCount != null)
if (backupFileCount < 1) {
response.addContextualMessage(BACKUP_FILE_COUNT, "systemSettings.validation.backupFileCountInvalid");
}
// Validate
setting = settings.get(DATABASE_BACKUP_FILE_LOCATION);
if (setting != null) {
File tmp = new File((String) setting);
if (!tmp.exists()) {
// Doesn't exist, push up message
response.addContextualMessage(DATABASE_BACKUP_FILE_LOCATION, "systemSettings.validation.databaseBackupLocationNotExists");
}
if (!tmp.canWrite()) {
response.addContextualMessage(DATABASE_BACKUP_FILE_LOCATION, "systemSettings.validation.cannotWriteToDatabaseBackupFileLocation");
}
}
// Validate the Hour and Minute
Integer databaseBackupHour = getIntValue(DATABASE_BACKUP_HOUR, settings);
if (databaseBackupHour != null)
if ((databaseBackupHour > 23) || (databaseBackupHour < 0)) {
response.addContextualMessage(DATABASE_BACKUP_HOUR, "systemSettings.validation.databaseBackupHourInvalid");
}
Integer databaseBackupMinute = getIntValue(DATABASE_BACKUP_MINUTE, settings);
if (databaseBackupMinute != null)
if ((databaseBackupMinute > 59) || (databaseBackupMinute < 0)) {
response.addContextualMessage(DATABASE_BACKUP_MINUTE, "systemSettings.validation.databaseBackupMinuteInvalid");
}
validatePeriodType(DATABASE_BACKUP_PERIOD_TYPE, settings, response);
// Validate the number of backups to keep
Integer databaseBackupFileCount = getIntValue(DATABASE_BACKUP_FILE_COUNT, settings);
if (databaseBackupFileCount != null)
if (databaseBackupFileCount < 1) {
response.addContextualMessage(DATABASE_BACKUP_FILE_COUNT, "systemSettings.validation.databaseBackupFileCountInvalid");
}
// Thread Pool Sizes
Integer corePoolSize = getIntValue(HIGH_PRI_CORE_POOL_SIZE, settings);
Integer maxPoolSize = getIntValue(HIGH_PRI_MAX_POOL_SIZE, settings);
if ((corePoolSize != null) && (corePoolSize < 0)) {
response.addContextualMessage(HIGH_PRI_CORE_POOL_SIZE, "validate.greaterThanOrEqualTo", 0);
}
if ((maxPoolSize != null) && (maxPoolSize < BackgroundProcessing.HIGH_PRI_MAX_POOL_SIZE_MIN)) {
response.addContextualMessage(HIGH_PRI_MAX_POOL_SIZE, "validate.greaterThanOrEqualTo", BackgroundProcessing.HIGH_PRI_MAX_POOL_SIZE_MIN);
}
if ((maxPoolSize != null) && (maxPoolSize < corePoolSize)) {
response.addContextualMessage(HIGH_PRI_MAX_POOL_SIZE, "systemSettings.threadPools.validate.maxPoolMustBeGreaterThanCorePool");
}
// For Medium and Low the Max has no effect because they use a LinkedBlockingQueue and will just block until a
// core pool thread is available
corePoolSize = getIntValue(MED_PRI_CORE_POOL_SIZE, settings);
if (corePoolSize < BackgroundProcessing.MED_PRI_MAX_POOL_SIZE_MIN) {
response.addContextualMessage(MED_PRI_CORE_POOL_SIZE, "validate.greaterThanOrEqualTo", BackgroundProcessing.MED_PRI_MAX_POOL_SIZE_MIN);
}
corePoolSize = getIntValue(LOW_PRI_CORE_POOL_SIZE, settings);
if (corePoolSize < BackgroundProcessing.LOW_PRI_MAX_POOL_SIZE_MIN) {
response.addContextualMessage(LOW_PRI_CORE_POOL_SIZE, "validate.greaterThanOrEqualTo", BackgroundProcessing.LOW_PRI_MAX_POOL_SIZE_MIN);
}
// Validate Upgrade Version State
setting = settings.get(UPGRADE_VERSION_STATE);
if (setting != null) {
if (setting instanceof Number) {
// Legacy Integer Value
try {
int value = ((Number) setting).intValue();
switch(value) {
case UpgradeVersionState.DEVELOPMENT:
case UpgradeVersionState.ALPHA:
case UpgradeVersionState.BETA:
case UpgradeVersionState.RELEASE_CANDIDATE:
case UpgradeVersionState.PRODUCTION:
break;
default:
response.addContextualMessage(UPGRADE_VERSION_STATE, "validate.invalidValue");
break;
}
} catch (NumberFormatException e) {
response.addContextualMessage(UPGRADE_VERSION_STATE, "validate.illegalValue");
}
} else {
// Must be a code
if (Common.VERSION_STATE_CODES.getId((String) setting) < 0)
response.addContextualMessage(UPGRADE_VERSION_STATE, "emport.error.invalid", UPGRADE_VERSION_STATE, (String) setting, Common.VERSION_STATE_CODES.getCodeList());
}
}
// Validate point hierarchy settings
setting = settings.get(HIERARCHY_PATH_SEPARATOR);
if (setting != null) {
if (StringUtils.isEmpty((String) setting))
response.addContextualMessage(HIERARCHY_PATH_SEPARATOR, "validate.cannotContainEmptyString");
}
// Validate the Module Settings
for (SystemSettingsDefinition def : ModuleRegistry.getSystemSettingsDefinitions()) def.validateSettings(settings, response);
// Ensure no one can change the superadmin permission
if (settings.get(SuperadminPermissionDefinition.PERMISSION) != null)
response.addContextualMessage(SuperadminPermissionDefinition.PERMISSION, "validate.readOnly");
}
use of com.serotonin.m2m2.module.Module in project ma-modules-public by infiniteautomation.
the class ModulesRestController method markForDeletion.
@ApiOperation(value = "Set Marked For Deletion state of Module", notes = "Marking a module for deletion will un-install it upon restart")
@RequestMapping(method = RequestMethod.PUT, produces = { "application/json" }, value = "/deletion-state/{moduleName}")
public ResponseEntity<ModuleModel> markForDeletion(@ApiParam(value = "Module name", required = false, allowMultiple = false) @PathVariable(required = false) String moduleName, @ApiParam(value = "Deletion State", required = true, defaultValue = "false", allowMultiple = false) @RequestParam(required = true) boolean delete, @ApiParam(value = "Module model", required = false) @RequestBody(required = false) ModuleModel model, HttpServletRequest request) {
RestProcessResult<ModuleModel> result = new RestProcessResult<ModuleModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (user.isAdmin()) {
Module module = ModuleRegistry.getModule(moduleName == null ? model.getName() : moduleName);
if (module != null) {
module.setMarkedForDeletion(delete);
if (module.isMarkedForDeletion() != delete)
throw new ModuleRestV2Exception(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.modules.error.dependencyFailure"));
return result.createResponseEntity(new ModuleModel(module));
} else {
result.addRestMessage(getDoesNotExistMessage());
}
} else {
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity(model);
}
Aggregations