Skip to content

Commit

Permalink
Merge pull request #2754 from SCADA-LTS/fix/#2748_Meta_Data_Sources_r…
Browse files Browse the repository at this point in the history
…un_at_the_end_during_context_initialization

#2748 Meta Data Sources run at the end during context initialization -
  • Loading branch information
Limraj authored Nov 17, 2023
2 parents a6a54d8 + 0c260cb commit 113d651
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/com/serotonin/mango/MangoContextListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ private void initialized(ServletContextEvent evt) {
.currentTimeMillis(), false, new LocalizableMessage(
"event.system.startup"));


log.info("Scada-LTS context started");

try {
PointHierarchyCache.getInstance();
log.info("Cache point hierarchy initialized");
Expand All @@ -186,6 +185,8 @@ private void initialized(ServletContextEvent evt) {
}

initSchedule();

log.info("Scada-LTS context started");
}

public void contextDestroyed(ServletContextEvent evt) {
Expand Down
55 changes: 32 additions & 23 deletions src/com/serotonin/mango/rt/RuntimeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

import com.serotonin.mango.db.dao.*;
import com.serotonin.mango.rt.dataImage.*;
Expand Down Expand Up @@ -151,25 +152,13 @@ synchronized public void initialize(boolean safe) {
}

// Initialize data sources that are enabled.
DataSourceDao dataSourceDao = new DataSourceDao();
List<DataSourceVO<?>> configs = dataSourceDao.getDataSources();
List<DataSourceVO<?>> pollingRound = new ArrayList<DataSourceVO<?>>();
for (DataSourceVO<?> config : configs) {

boolean isCheckToTrayEnableRun = (config instanceof ICheckReactivation);
boolean isToTrayEnable = false;
if (isCheckToTrayEnableRun) {
isToTrayEnable = ((ICheckReactivation) config).checkToTrayEnable();
}

if (config.isEnabled() || isToTrayEnable ) {
if (safe) {
config.setEnabled(false);
dataSourceDao.saveDataSource(config);
} else if (initializeDataSource(config))
pollingRound.add(config);
}
}
DataSourceService dataSourceService = new DataSourceService();
List<DataSourceVO<?>> configs = dataSourceService.getDataSources();
List<DataSourceVO<?>> pollingRound = new ArrayList<>();
List<DataSourceVO<?>> nonMetaDataSources = configs.stream().filter(dataSource -> dataSource.getType() != DataSourceVO.Type.META).collect(Collectors.toList());
List<DataSourceVO<?>> metaDataSources = configs.stream().filter(dataSource -> dataSource.getType() == DataSourceVO.Type.META).collect(Collectors.toList());
initializeDataSources(safe, dataSourceService, nonMetaDataSources, pollingRound);
initializeDataSources(safe, dataSourceService, metaDataSources, pollingRound);

// Set up point links.
PointLinkDao pointLinkDao = new PointLinkDao();
Expand Down Expand Up @@ -312,16 +301,16 @@ public boolean isDataSourceRunning(int dataSourceId) {
}

public List<DataSourceVO<?>> getDataSources() {
return new DataSourceDao().getDataSources();
return new DataSourceService().getDataSources();
}

public DataSourceVO<?> getDataSource(int dataSourceId) {
return new DataSourceDao().getDataSource(dataSourceId);
return new DataSourceService().getDataSource(dataSourceId);
}

public void deleteDataSource(int dataSourceId) {
stopDataSource(dataSourceId);
new DataSourceDao().deleteDataSource(dataSourceId);
new DataSourceService().deleteDataSource(dataSourceId);
Common.ctx.getEventManager().cancelEventsForDataSource(dataSourceId);
}

Expand All @@ -334,7 +323,7 @@ public void saveDataSource(DataSourceVO<?> vo) {
// In case this is a new data source, we need to save to the database
// first so that it has a proper id.
LOG.debug("Saving DS: " + vo.getName());
new DataSourceDao().saveDataSource(vo);
new DataSourceService().saveDataSource(vo);
LOG.debug("DS saved!");
// If the data source is enabled, start it.
if (vo.isEnabled()) {
Expand Down Expand Up @@ -1056,4 +1045,24 @@ private void stopResetDailyLimitSentEmails(int mailingListId) {
reset.terminate();
resetDailyLimitSentEmails.remove(mailingListId);
}

private void initializeDataSources(boolean safe, DataSourceService dataSourceService,
List<DataSourceVO<?>> configs, List<DataSourceVO<?>> pollingRound) {
for (DataSourceVO<?> config : configs) {

boolean isCheckToTrayEnableRun = (config instanceof ICheckReactivation);
boolean isToTrayEnable = false;
if (isCheckToTrayEnableRun) {
isToTrayEnable = ((ICheckReactivation) config).checkToTrayEnable();
}

if (config.isEnabled() || isToTrayEnable ) {
if (safe) {
config.setEnabled(false);
dataSourceService.saveDataSource(config);
} else if (initializeDataSource(config))
pollingRound.add(config);
}
}
}
}
2 changes: 0 additions & 2 deletions src/com/serotonin/mango/util/SendUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,10 @@ private static void validateEmail(EventInstance evt, NotificationType notificati
String messageErrorEventInstance = "Event Instance null \n";
String messageErrorNotyficationType = "Notification type is null \n";
String messageErrorEmails = " Don't have e-mail \n";
String messageErrorAlias = " Don't have alias\n";
String messages = "";
if (evt == null || evt.getEventType() == null) messages += messageErrorEventInstance;
if (notificationType == null) messages += messageErrorNotyficationType;
if (addresses == null || addresses.size() == 0) messages += messageErrorEmails;
if (alias == null) messages += messageErrorAlias;

if (messages.length() > 0) {
throw new IllegalArgumentException(getInfoEmail(evt, notificationType, alias) + messages );
Expand Down

0 comments on commit 113d651

Please sign in to comment.