Skip to content

Commit

Permalink
Merge pull request #2619 from SCADA-LTS/feature/#2618_Improved_stabil…
Browse files Browse the repository at this point in the history
…ity_for_a_large_number_of_events

#2618 Improved stability for a large number of events - disabled old …
  • Loading branch information
Limraj authored Aug 7, 2023
2 parents 1b58360 + 0086fa1 commit b5c37ab
Show file tree
Hide file tree
Showing 57 changed files with 457 additions and 203 deletions.
16 changes: 16 additions & 0 deletions WebContent/WEB-INF/jsp/systemSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
$set("<c:out value="<%= SystemSettingsDAO.VIEW_FORCE_FULL_SCREEN_MODE %>"/>", settings.<c:out value="<%= SystemSettingsDAO.VIEW_FORCE_FULL_SCREEN_MODE %>"/>);
$set("<c:out value="<%= SystemSettingsDAO.VIEW_HIDE_SHORTCUT_DISABLE_FULL_SCREEN %>"/>", settings.<c:out value="<%= SystemSettingsDAO.VIEW_HIDE_SHORTCUT_DISABLE_FULL_SCREEN %>"/>);
$set("<c:out value="<%= SystemSettingsDAO.EVENT_PENDING_LIMIT %>"/>", settings.<c:out value="<%= SystemSettingsDAO.EVENT_PENDING_LIMIT %>"/>);
$set("<c:out value="<%= SystemSettingsDAO.EVENT_PENDING_CACHE_ENABLED %>"/>", settings.<c:out value="<%= SystemSettingsDAO.EVENT_PENDING_CACHE_ENABLED %>"/>);
var sel = $("<c:out value="<%= SystemSettingsDAO.LANGUAGE %>"/>");
<c:forEach items="${availableLanguages}" var="lang">
sel.options[sel.options.length] = new Option("${lang.value}", "${lang.key}");
Expand Down Expand Up @@ -269,6 +271,8 @@
$get("<c:out value="<%= SystemSettingsDAO.DATAPOINT_RUNTIME_VALUE_SYNCHRONIZED %>"/>"),
$get("<c:out value="<%= SystemSettingsDAO.VIEW_FORCE_FULL_SCREEN_MODE %>"/>"),
$get("<c:out value="<%= SystemSettingsDAO.VIEW_HIDE_SHORTCUT_DISABLE_FULL_SCREEN %>"/>"),
$get("<c:out value="<%= SystemSettingsDAO.EVENT_PENDING_LIMIT %>"/>"),
$get("<c:out value="<%= SystemSettingsDAO.EVENT_PENDING_CACHE_ENABLED %>"/>"),
function(response) {
stopImageFader("saveMiscSettingsImg");
if (response.hasMessages)
Expand Down Expand Up @@ -872,6 +876,18 @@
<input type="checkbox" id="<c:out value="<%= SystemSettingsDAO.VIEW_HIDE_SHORTCUT_DISABLE_FULL_SCREEN %>"/>" />
</td>
</tr>
<tr>
<td class="formLabelRequired"><fmt:message key="systemsettings.event.pendingCacheEnabled"/></td>
<td class="formField">
<input id="<c:out value="<%= SystemSettingsDAO.EVENT_PENDING_CACHE_ENABLED %>"/>" type="checkbox" />
</td>
</tr>
<tr>
<td class="formLabelRequired"><fmt:message key="systemsettings.event.pendingLimit"/></td>
<td class="formField">
<input id="<c:out value="<%= SystemSettingsDAO.EVENT_PENDING_LIMIT %>"/>" type="number" class="formShort"/>
</td>
</tr>
<tr>
<td colspan="2" id="miscMessage" class="formError"></td>
</tr>
Expand Down
4 changes: 3 additions & 1 deletion scadalts-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1053,5 +1053,7 @@
"systemsettings.view.hideShortcutDisableFullScreen": "Hide shortcut to disable full screen",
"userDetails.view.forceAdminTitle": "The function is enforced by the Admin",
"userDetails.view.enableFullScreen": "Enable full screen mode",
"userDetails.view.hideShortcutDisableFullScreen": "Hide shortcut to disable full screen"
"userDetails.view.hideShortcutDisableFullScreen": "Hide shortcut to disable full screen",
"systemsettings.event.pendingLimit": "Event Pending Limit",
"systemsettings.event.pendingCacheEnabled": "Enabled Event Pending Cache"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,23 @@
@change="watchDataChange()"
></v-switch>
</v-col>
</v-row>
<v-col cols="12">
<v-switch
v-model="miscSettings.eventPendingCacheEnabled"
:label="$t('systemsettings.event.pendingCacheEnabled')"
@change="watchDataChange()"
></v-switch>
</v-col>
<v-col cols="12">
<v-text-field
v-model="miscSettings.eventPendingLimit"
:label="$t('systemsettings.event.pendingLimit')"
@change="watchDataChange()"
type="number"
dense
></v-text-field>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-col>
Expand Down
14 changes: 8 additions & 6 deletions src/br/org/scadabr/api/dao/MangoDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import com.serotonin.util.StringUtils;
import com.serotonin.web.dwr.DwrResponseI18n;
import org.scada_lts.ds.state.ApiChangeEnableStateDs;

import org.scada_lts.mango.adapter.MangoEvent;
import org.scada_lts.mango.service.EventService;
import java.util.*;

public class MangoDaoImpl implements ScadaBRAPIDao {
Expand All @@ -51,6 +52,7 @@ private void checkUser() throws ScadaBRAPIException {
}

private PointHierarchy pH;
private final MangoEvent eventService = new EventService();

@Override
public List<ItemValue> getItemValueList(String[] itemList,
Expand Down Expand Up @@ -537,7 +539,7 @@ public List<ItemValue> getDataHistory(String itemQName,
public List<EventNotification> getEventNotifications(
AlarmLevel minimumAlarmLevel) throws ScadaBRAPIException {
List<EventNotification> alarms = new ArrayList<EventNotification>();
List<EventInstance> events = new EventDao().getPendingEvents(1);
List<EventInstance> events = eventService.getPendingEvents(1);
checkUser();
if (events == null || events.size() == 0) {
APIError error = new APIError();
Expand Down Expand Up @@ -565,7 +567,7 @@ public EventNotification ackEvent(int eventId) throws ScadaBRAPIException {

if (eventInstance != null) {
// alternateAckSource? - REM
new EventDao().ackEvent(eventId, 1, 0, 0);
eventService.ackEvent(eventId, 1, 0, 0);
// new EventDao().ackEvent(eventId, 1);
return APIUtils.toEventNotification(eventInstance);
} else {
Expand All @@ -577,7 +579,7 @@ public EventNotification ackEvent(int eventId) throws ScadaBRAPIException {
}

private EventInstance getEvent(int eventId) {
List<EventInstance> events = new EventDao().getPendingEvents(1);
List<EventInstance> events = eventService.getPendingEvents(1);
for (EventInstance eventInstance : events) {
if (eventInstance.getId() == eventId)
return eventInstance;
Expand All @@ -588,7 +590,7 @@ private EventInstance getEvent(int eventId) {
private List<EventInstance> getAcknowledgedEvents() {
// Adicionados parametros novos (?)
// return new EventDao().search(0, -1, null, -1, null, 20000, 1, null);
return new EventDao().search(0, -1, null, -1, null, 1, null, 0, 5000,
return eventService.search(0, -1, null, -1, null, 1, null, 0, 5000,
null);
}

Expand Down Expand Up @@ -632,7 +634,7 @@ public EventMessage[] annotateEvent(int eventId, EventMessage message)
checkUser();
EventInstance event = getEvent(eventId);
if (event != null) {
new EventDao().insertEventComment(eventId,
eventService.insertEventComment(eventId,
APIUtils.toUserComment(message));

event = getEvent(eventId);
Expand Down
48 changes: 4 additions & 44 deletions src/br/org/scadabr/view/component/AlarmListComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
import com.serotonin.json.JsonRemoteEntity;
import com.serotonin.json.JsonRemoteProperty;
import com.serotonin.mango.Common;
import com.serotonin.mango.db.dao.EventDao;
import com.serotonin.mango.rt.event.AlarmLevels;
import com.serotonin.mango.rt.event.EventInstance;
import com.serotonin.mango.view.ImplDefinition;
import com.serotonin.mango.web.dwr.BaseDwr;
import org.scada_lts.mango.service.EventService;

@JsonRemoteEntity
public class AlarmListComponent extends CustomComponent {
Expand Down Expand Up @@ -58,16 +57,11 @@ public String generateContent() {
Map<String, Object> model = new HashMap<String, Object>();
WebContext webContext = WebContextFactory.get();
HttpServletRequest request = webContext.getHttpServletRequest();
List<EventInstance> toViewEvents = new EventDao().getPendingEvents(Common
.getUser().getId());

List<EventInstance> events = new ArrayList<>(toViewEvents);
filter(events, minAlarmLevel);

int max = events.size() > maxListSize ? maxListSize : events.size();
List<EventInstance> toViewEvents = new EventService().getPendingEventsAlarmLevelMin(Common
.getUser().getId(), minAlarmLevel, maxListSize, true);

model.put("nome", "marlon");
model.put("events", events.subList(0, max));
model.put("events",toViewEvents);
model.put("width", width > 0 ? width : 500);
model.put("hideIdColumn", hideIdColumn);
model.put("hideAlarmLevelColumn", hideAlarmLevelColumn);
Expand All @@ -80,40 +74,6 @@ public String generateContent() {
return content;
}

private void filter(List<EventInstance> list, int alarmLevel) {

if (AlarmLevels.INFORMATION == alarmLevel) {
removeAlarmLevel(list, AlarmLevels.NONE);
}
if (AlarmLevels.URGENT == alarmLevel) {
removeAlarmLevel(list, AlarmLevels.NONE);
removeAlarmLevel(list, AlarmLevels.INFORMATION);
}
if (AlarmLevels.CRITICAL == alarmLevel) {
removeAlarmLevel(list, AlarmLevels.NONE);
removeAlarmLevel(list, AlarmLevels.INFORMATION);
removeAlarmLevel(list, AlarmLevels.URGENT);
}
if (AlarmLevels.LIFE_SAFETY == alarmLevel) {
removeAlarmLevel(list, AlarmLevels.NONE);
removeAlarmLevel(list, AlarmLevels.INFORMATION);
removeAlarmLevel(list, AlarmLevels.URGENT);
removeAlarmLevel(list, AlarmLevels.CRITICAL);
}
}

private void removeAlarmLevel(List<EventInstance> source, int alarmLevel) {
List<EventInstance> copy = new ArrayList<EventInstance>();

for (EventInstance eventInstance : source) {
if (eventInstance.getAlarmLevel() == alarmLevel)
copy.add(eventInstance);
}

source.removeAll(copy);

}

@Override
public boolean containsValidVisibleDataPoint(int dataPointId) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/com/serotonin/mango/db/dao/EventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*
* @author Grzesiek Bylica Abil'I.T. development team, sdt@abilit.eu
*/
@Deprecated
public class EventDao {

private MangoEvent eventService = new EventService();
Expand Down
28 changes: 20 additions & 8 deletions src/com/serotonin/mango/rt/event/type/SystemEventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
*/
package com.serotonin.mango.rt.event.type;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import com.serotonin.json.JsonException;
import com.serotonin.json.JsonObject;
import com.serotonin.json.JsonReader;
import com.serotonin.json.JsonRemoteEntity;
import com.serotonin.mango.Common;
import com.serotonin.mango.util.LoggingUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.scada_lts.dao.SystemSettingsDAO;
import com.serotonin.mango.rt.event.AlarmLevels;
import com.serotonin.mango.util.ExportCodes;
Expand All @@ -40,6 +43,7 @@ public class SystemEventType extends EventType {
// / Static stuff
// /
//
private static final Log LOG = LogFactory.getLog(SystemEventType.class);
private static final String SYSTEM_SETTINGS_PREFIX = "systemEventAlarmLevel";

public static final int TYPE_SYSTEM_STARTUP = 1;
Expand Down Expand Up @@ -74,7 +78,7 @@ public class SystemEventType extends EventType {

public static List<EventTypeVO> getSystemEventTypes() {
if (systemEventTypes == null) {
systemEventTypes = new ArrayList<EventTypeVO>();
systemEventTypes = new CopyOnWriteArrayList<>();

addEventTypeVO(TYPE_SYSTEM_STARTUP, "event.system.startup",
AlarmLevels.INFORMATION);
Expand Down Expand Up @@ -118,18 +122,26 @@ public static EventTypeVO getEventType(int type) {

public static void setEventTypeAlarmLevel(int type, int alarmLevel) {
EventTypeVO et = getEventType(type);
et.setAlarmLevel(alarmLevel);
if(et != null) {
et.setAlarmLevel(alarmLevel);

SystemSettingsDAO dao = new SystemSettingsDAO();
dao.setIntValue(SYSTEM_SETTINGS_PREFIX + type, alarmLevel);
SystemSettingsDAO dao = new SystemSettingsDAO();
dao.setIntValue(SYSTEM_SETTINGS_PREFIX + type, alarmLevel);
} else {
LOG.warn(LoggingUtils.eventTypeInfo(type, alarmLevel));
}
}

public static void raiseEvent(SystemEventType type, long time, boolean rtn,
LocalizableMessage message) {
EventTypeVO vo = getEventType(type.getSystemEventTypeId());
int alarmLevel = vo.getAlarmLevel();
Common.ctx.getEventManager().raiseEvent(type, time, rtn, alarmLevel,
message, null);
if(vo != null) {
int alarmLevel = vo.getAlarmLevel();
Common.ctx.getEventManager().raiseEvent(type, time, rtn, alarmLevel,
message, null);
} else {
LOG.warn(LoggingUtils.systemEventTypInfo(type));
}
}

public static void returnToNormal(SystemEventType type, long time) {
Expand Down
4 changes: 2 additions & 2 deletions src/com/serotonin/mango/rt/maint/DataPurge.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.serotonin.ShouldNeverHappenException;
import com.serotonin.mango.Common;
import com.serotonin.mango.db.dao.DataPointDao;
import com.serotonin.mango.db.dao.EventDao;
import com.serotonin.mango.db.dao.PointValueDao;
import com.serotonin.mango.db.dao.ReportDao;
import org.scada_lts.dao.SystemSettingsDAO;
Expand All @@ -40,6 +39,7 @@
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.timer.CronTimerTrigger;
import com.serotonin.timer.TimerTask;
import org.scada_lts.mango.service.EventService;

public class DataPurge {
private final Log log = LogFactory.getLog(DataPurge.class);
Expand Down Expand Up @@ -132,7 +132,7 @@ private void eventPurge() {
cutoff = DateUtils.minus(cutoff, SystemSettingsDAO.getIntValue(SystemSettingsDAO.EVENT_PURGE_PERIOD_TYPE),
SystemSettingsDAO.getIntValue(SystemSettingsDAO.EVENT_PURGE_PERIODS));

int deleteCount = new EventDao().purgeEventsBefore(cutoff.getMillis());
int deleteCount = new EventService().purgeEventsBefore(cutoff.getMillis());
if (deleteCount > 0)
log.info("Event purge ended, " + deleteCount + " events deleted");
}
Expand Down
25 changes: 25 additions & 0 deletions src/com/serotonin/mango/util/LoggingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import com.serotonin.mango.rt.dataImage.SetPointSource;
import com.serotonin.mango.rt.dataSource.DataSourceRT;
import com.serotonin.mango.rt.event.EventInstance;
import com.serotonin.mango.rt.event.type.SystemEventType;
import com.serotonin.mango.view.component.ScriptComponent;
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.mango.vo.User;
import com.serotonin.mango.vo.dataSource.DataSourceVO;
import com.serotonin.mango.vo.event.EventHandlerVO;
import com.serotonin.mango.vo.event.EventTypeVO;
import com.serotonin.mango.vo.event.PointEventDetectorVO;
import com.serotonin.mango.vo.link.PointLinkVO;
import com.serotonin.mango.vo.mailingList.MailingList;
Expand Down Expand Up @@ -164,4 +166,27 @@ public static String mailingListInfo(MailingList mailingList) {
String info = "mailingList: {0} (id: {1}, xid: {2})";
return MessageFormat.format(info, mailingList.getName(), mailingList.getId(), mailingList.getXid());
}

public static String eventTypeInfo(EventTypeVO event) {
if(event == null)
return "";
String info = "event type: {0} (typeId: {1}, typeRef1: {2}, typeRef2: {3}, alarmLevel: {4}, eventDetectorKey: {4})";
return MessageFormat.format(info, event.getDescription(), event.getTypeId(), event.getTypeRef1(), event.getTypeRef2(), event.getAlarmLevel(), event.getEventDetectorKey());
}

public static String systemEventTypInfo(SystemEventType event) {
if(event == null)
return "";
String info = "system event type (systemEventTypeId: {0}, dataSourceId: {1}, dataPointId: {2}, eventSourceId: {3}, " +
"duplicateHandling: {4}, referenceId1: {5}, referenceId2: {6}, compoundEventDetectorId: {7}, scheduleId: {8}, " +
"publisherId: {9}, systemMessage: {10})";
return MessageFormat.format(info, event.getSystemEventTypeId(), event.getDataSourceId(), event.getDataPointId(),
event.getEventSourceId(), event.getDuplicateHandling(), event.getReferenceId1(), event.getReferenceId2(),
event.getCompoundEventDetectorId(), event.getScheduleId(), event.getPublisherId(), event.isSystemMessage());
}

public static String eventTypeInfo(int type, int alarmLevel) {
String info = "event type: {0} (alarmLevel: {1})";
return MessageFormat.format(info, type, alarmLevel);
}
}
4 changes: 2 additions & 2 deletions src/com/serotonin/mango/vo/event/EventHandlerVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.serotonin.mango.Common;
import com.serotonin.mango.DataTypes;
import com.serotonin.mango.db.dao.DataPointDao;
import com.serotonin.mango.db.dao.EventDao;
import com.serotonin.mango.db.dao.MailingListDao;
import com.serotonin.mango.db.dao.UserDao;
import com.serotonin.mango.rt.event.handlers.EmailHandlerRT;
Expand All @@ -58,6 +57,7 @@
import com.serotonin.util.StringUtils;
import com.serotonin.web.dwr.DwrResponseI18n;
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.mango.service.EventService;
import org.scada_lts.mango.service.ScriptService;

@JsonRemoteEntity
Expand Down Expand Up @@ -819,7 +819,7 @@ private void readObject(ObjectInputStream in) throws IOException,

public void jsonSerialize(Map<String, Object> map) {
DataPointDao dataPointDao = new DataPointDao();
map.put("eventType", new EventDao().getEventHandlerType(id));
map.put("eventType", new EventService().getEventHandlerType(id));

map.put("xid", xid);
map.put("handlerType", TYPE_CODES.getCode(handlerType));
Expand Down
Loading

0 comments on commit b5c37ab

Please sign in to comment.