Skip to content

Commit

Permalink
Merge pull request #2953 from SCADA-LTS/fix/#2755_Signaling_the_Data_…
Browse files Browse the repository at this point in the history
…Source_that_has_a_problem

Fix/#2755 signaling the data source that has a problem
  • Loading branch information
Limraj authored Sep 18, 2024
2 parents f251b21 + a38938c commit 1d22805
Show file tree
Hide file tree
Showing 130 changed files with 4,055 additions and 1,306 deletions.
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/jsp/scripting.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
var xid = jQuery("#xid");
// saveScript() nie zdarzy zapisac !!!
jQuery.ajax({
url: myLocation+"/script/execute/"+xid[0].value,
url: myLocation+"script/execute/"+xid[0].value,
type:"POST",
success: function(){
setUserMessage("<spring:message code="script.execute.success"/> ")
Expand Down
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/jsp/systemSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
jQuery.ajax({
type: 'GET',
dataType: 'text',
url:myLocation+"/api/resources/imagesRefresh",
url:myLocation+"api/resources/imagesRefresh",
success: function(msg){
alert("Success: the resource images has been refreshed");
},
Expand Down
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/snippet/warningContent.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<td><tag:img png="exclamation" title="common.valueUnreliable"/></td>
<td style="white-space:nowrap;" colspan="3">
<spring:message code="common.valueUnreliable"/>
<tag:img png="arrow_refresh" title="common.refresh" onclick="WatchListDwr.forcePointRead(${point.id})" style="display:inline"/>
<tag:img png="arrow_refresh" title="common.refresh" onclick="MiscDwr.forcePointRead(${point.id})" style="display:inline"/>
</td>
</tr>
</c:if>
Expand Down
9 changes: 9 additions & 0 deletions WebContent/WEB-INF/snippet/warningIcon.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%@ include file="/WEB-INF/snippet/common.jsp" %>
<c:choose>
<c:when test="${!empty invalid || !empty disabled || pointRT.attributes.UNRELIABLE || pointRT.attributes.DP_UPDATE_ERROR}">
<tag:img png="exclamation" title="common.valueUnreliable"/>
</c:when>
<c:otherwise>
<tag:img png="warn" title="common.warning"/>
</c:otherwise>
</c:choose>
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/snippet/watchListMessages.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</c:if>
<c:if test="${pointRT.attributes.UNRELIABLE || pointRT.attributes.DP_UPDATE_ERROR}">
<tag:img png="exclamation" title="common.valueUnreliable"/> <spring:message code="common.valueUnreliable"/>
<tag:img png="arrow_refresh" title="common.refresh" onclick="WatchListDwr.forcePointRead(${point.id})"/><br/>
<tag:img png="arrow_refresh" title="common.refresh" onclick="MiscDwr.forcePointRead(${point.id})"/><br/>
</c:if>
<c:forEach items="${events}" var="event">
<c:if test="${event.alarmLevel>0}">
Expand Down
4 changes: 4 additions & 0 deletions WebContent/WEB-INF/tags/alarmAck.tag
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<c:when test="${event.eventType.eventSourceId == applicationScope['constants.EventType.EventSources.DATA_SOURCE']}">
<a href="data_source_edit.shtm?dsid=${event.eventType.dataSourceId}"><tag:img png="icon_ds_edit" title="events.editDataSource"/></a>
</c:when>
<c:when test="${event.eventType.eventSourceId == applicationScope['constants.EventType.EventSources.DATA_SOURCE_POINT']}">
<a href="data_source_edit.shtm?dsid=${event.eventType.dataSourceId}&pid=${event.eventType.dataPointId}"><tag:img png="icon_ds_edit" title="events.editDataSource"/></a>
<a href="data_point_details.shtm?dpid=${event.eventType.dataPointId}"><tag:img png="icon_comp" title="events.pointDetails"/></a>
</c:when>
<c:when test="${event.eventType.eventSourceId == applicationScope['constants.EventType.EventSources.SYSTEM']}">
<c:choose>
<c:when test="${event.eventType.systemEventTypeId == applicationScope['constants.SystemEventType.TYPE_VERSION_CHECK']}">
Expand Down
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/tags/pointComponent.tag
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<div style="position:absolute;left:-16px;top:0px;z-index:${vc.z+1};">
<div id="c${vc.id}Warning" style="display:none;" onmouseover="showMenu('c${vc.id}Messages', 16, 0);"
onmouseout="hideLayer('c${vc.id}Messages');">
<tag:img png="warn" title="common.warning"/>
<div id="c${vc.id}WarningIcon"></div>
<div id="c${vc.id}Messages" onmouseout="hideLayer(this);" class="controlContent"></div>
</div>
<div id="c${vc.id}Changing" style="display:none;"><tag:img png="icon_edit" title="common.settingValue"/></div>
Expand Down
4 changes: 4 additions & 0 deletions WebContent/resources/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ mango.view.setMessages = function(state) {
var warningNode = $("c"+ state.id +"Warning");
if (warningNode && state.messages != null) {
$set("c"+ state.id +"Messages", state.messages);
var warningIconNode = $("c"+ state.id +"WarningIcon");
if(warningIconNode) {
$set("c"+ state.id +"WarningIcon", state.warningIcon);
}
if (state.messages)
show(warningNode);
else
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,20 @@ test {
includeTestsMatching "com.serotonin.mango.vo.report.ImageChartUtilsTestsSuite"
includeTestsMatching "org.scada_lts.serorepl.utils.StringUtilsTestsSuite"
includeTestsMatching "org.scada_lts.monitor.ConcurrentMonitoredValuesTest"
includeTestsMatching "com.serotonin.mango.rt.dataSource.DataPointUnreliableUtilsTest"
includeTestsMatching "com.serotonin.mango.rt.dataSource.InitializeDataSourceRtTestsSuite"
includeTestsMatching "com.serotonin.mango.util.AddLimitIfWithoutSqlDataSourceUtilsTest"
includeTestsMatching "com.serotonin.mango.util.StartStopDataPointsUtilsTestsSuite"
includeTestsMatching "org.scada_lts.utils.BlockingQueuesUtilsTest"
includeTestsMatching "org.scada_lts.web.security.XssProtectHtmlEscapeUtilsTest"
includeTestsMatching "org.scada_lts.web.security.XssUtilsTest"
}

failFast = true

testLogging {

//exceptionFormat = "full"
exceptionFormat = "full"
showStandardStreams = true

afterTest { desc, result ->
Expand Down
2 changes: 1 addition & 1 deletion src/br/org/scadabr/api/dao/MangoDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ public int configureDataPoint(int dataSourceId,
mangoPoint.setPointLocator(mangoLocator);
DwrResponseI18n validate = new DwrResponseI18n();
validate(mangoPoint, validate);
mangoLocator.validate(validate);
mangoLocator.validate(validate, point.getId());
if (validate.getHasMessages()) {
throw new ScadaBRAPIException(new APIError(
ErrorCode.INVALID_PARAMETER,
Expand Down
85 changes: 42 additions & 43 deletions src/br/org/scadabr/rt/dataSource/alpha2/Alpha2DataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
import com.serotonin.mango.rt.dataImage.SetPointSource;
import com.serotonin.mango.rt.dataImage.types.MangoValue;
import com.serotonin.mango.rt.dataSource.PollingDataSource;
import com.serotonin.mango.util.LoggingUtils;
import com.serotonin.web.i18n.LocalizableMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Alpha2DataSource extends PollingDataSource {

private static final Log LOG = LogFactory.getLog(Alpha2DataSource.class);
public static final int POINT_READ_EXCEPTION_EVENT = 1;
public static final int POINT_WRITE_EXCEPTION_EVENT = 2;
public static final int DATA_SOURCE_EXCEPTION_EVENT = 3;
Expand Down Expand Up @@ -65,6 +69,7 @@ protected void doPoll(long time) {
MangoValue value = MangoValue.stringToValue(deviceValue
.getValue(), rt.getDataTypeId());
rt.updatePointValue(new PointValueTime(value, time));
returnToNormal(POINT_READ_EXCEPTION_EVENT, time, rt);
}
}

Expand Down Expand Up @@ -131,18 +136,18 @@ public void setPointValue(DataPointRT dataPoint, PointValueTime valueTime,
master.runController();
else
master.stopController();
} else
} else {
master.write(devices);
} catch (Exception e) {
treatException(POINT_WRITE_EXCEPTION_EVENT, e, System
.currentTimeMillis());
returnToNormal(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), dataPoint);
}
} catch (Throwable e) {
treatException(POINT_WRITE_EXCEPTION_EVENT, e, System.currentTimeMillis(), dataPoint);
}

}

@Override
public void initialize() {
super.initialize();

SerialParameters parameters = new SerialParameters();
parameters.setBaudRate(vo.getBaudRate());
Expand All @@ -155,24 +160,33 @@ public void initialize() {
try {
master.init();
master.lineCheck();
} catch (Exception e) {
returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis());
} catch (Throwable e) {
treatException(DATA_SOURCE_EXCEPTION_EVENT, e, System
.currentTimeMillis());
return;
}
super.initialize();

}

@Override
public void terminate() {
super.terminate();
try {
master.terminate();
} catch (Exception e) {
e.printStackTrace();
if(master != null)
master.terminate();
returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis());
} catch (Throwable e) {
LOG.error(LoggingUtils.info(e, this), e);
raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true,
new LocalizableMessage("event.exception2",
vo.getName(), e.getMessage()));
}
}

private void treatException(int exceptionType, Exception e, long time) {
private void treatException(int exceptionType, Throwable e, long time) {
LOG.warn(LoggingUtils.info(e, this), e);
if (e instanceof COMMException) {
raiseEvent(exceptionType, time, true, new LocalizableMessage(
"alpha2.commException", vo.getName(), e.getMessage()));
Expand All @@ -190,37 +204,22 @@ private void treatException(int exceptionType, Exception e, long time) {
}
}

// public static void main(String[] args) {
// List<String> lista = new ArrayList<String>();
//
// for (int i = 0; i < 250; i++) {
// lista.add("device " + i);
// }
//
// final int maxNum = 82;
// List<List<String>> messages = new ArrayList<List<String>>();
//
// int numMessages = lista.size() % maxNum == 0 ? ((int) (lista.size() /
// maxNum))
// : ((int) (lista.size() / maxNum)) + 1;
//
// for (int i = 0; i < numMessages; i++) {
// List<String> temp;
// if (i == numMessages - 1) {
// temp = lista.subList(0 + (i * (maxNum)), lista.size());
// } else {
// int init = 0 + (i * (maxNum));
// int end = (maxNum) + ((maxNum) * i);
// temp = lista.subList(init, end);
//
// }
// messages.add(temp);
// }
// System.out.println("Enviar " + messages.size() + " mensagens!");
// for (List<String> list : messages) {
// System.out.println("Mensagem: " + list.size());
// }
//
// }

private void treatException(int exceptionType, Throwable e, long time, DataPointRT dataPointRT) {
LOG.warn(LoggingUtils.info(e, this), e);
if (e instanceof COMMException) {
raiseEvent(exceptionType, time, true, new LocalizableMessage(
"alpha2.commException", vo.getName(), e.getMessage()), dataPointRT);
} else if (e instanceof InvalidFrameReceivedException) {
raiseEvent(exceptionType, time, true, new LocalizableMessage(
"alpha2.invalidFrameException", vo.getName(), e
.getMessage()), dataPointRT);
} else if (e instanceof ErrorMessageReceivedException) {
raiseEvent(exceptionType, time, true, new LocalizableMessage(
"alpha2.errorMessageException", vo.getName(), e
.getMessage()), dataPointRT);
} else {
raiseEvent(exceptionType, time, true, new LocalizableMessage(
"alpha2.unknownException", vo.getName(), e.getMessage()), dataPointRT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.serotonin.mango.util.LoggingUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -43,6 +44,7 @@ protected void doPoll(long time) {
new LocalizableMessage("event.exception2", vo.getName(),
"Arquivo não encontrado!"));
} else {
returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, time);
String arquivo = readFile(file);

for (DataPointRT dataPoint : dataPoints) {
Expand All @@ -58,19 +60,21 @@ protected void doPoll(long time) {
} catch (Exception e) {
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2",
vo.getName(), e.getMessage()));
vo.getName(), e.getMessage()), dataPoint);
timestamp = time;
return;
}

}

dataPoint.updatePointValue(new PointValueTime(value,
timestamp));
returnToNormal(POINT_READ_EXCEPTION_EVENT, time, dataPoint);
} catch (Exception e) {
LOG.error(LoggingUtils.info(e, this), e);
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true,
new LocalizableMessage("event.exception2", vo
.getName(), e.getMessage()));
e.printStackTrace();
.getName(), e.getMessage()), dataPoint);
}

}
Expand Down Expand Up @@ -143,7 +147,7 @@ private String readFile(File file) {
} while (c != -1);
reader.close();
} catch (Exception e) {
e.printStackTrace();
LOG.error(LoggingUtils.info(e, this), e);
}
return sb.toString();
}
Expand Down
Loading

0 comments on commit 1d22805

Please sign in to comment.