Skip to content

Commit

Permalink
Merge pull request #765 from SCADA-LTS/feature_m/#761
Browse files Browse the repository at this point in the history
#761 correctings for reactivation data source httpRetriver
  • Loading branch information
grzesiekb authored Dec 4, 2018
2 parents 16980e4 + e2fbdac commit 706ded3
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 46 deletions.
90 changes: 67 additions & 23 deletions ScadaLTS-UI-1/src/components/form/SleepAndReactivationDS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
<table>
<tr>
<td>
<input v-model="reactivationValue" type="number" min="1" max="31" class="form-control number-width" style="display: inline"/>
<input v-model="reactivationTimeValue" type="number" min="1" max="31" class="form-control number-width" style="display: inline"/>
</td>
<td>
<btn-group style="display: inline">
<btn input-type="radio" :input-value="STR_REACTIVATION_TYPE_TIME_MIN" v-model="reactivationTimeType">Minute</btn>
<btn input-type="radio" :input-value="STR_REACTIVATION_TYPE_TIME_HOUR" v-model="reactivationTimeType">Hour</btn>
<btn input-type="radio" :input-value="STR_REACTIVATION_TYPE_TIME_DAY" v-model="reactivationTimeType">Day</btn>
</btn-group>

</td>
</tr>
<tr>
<td></td>
<td>
<div>
<btn v-if="!runingReactivation" size="xs" type="success" v-on:click="startReactivation()">Start reactivation</btn>
<btn v-if="runingReactivation" size="xs" type="danger" v-on:click="stopReactivation()">Stop reactivation</btn>
</div>
</td>
</tr>
</table>
Expand Down Expand Up @@ -55,19 +63,25 @@ export default {
INT_REACTIVATION_TYPE_TIME_MIN: 0,
INT_REACTIVATION_TYPE_TIME_HOUR: 1,
INT_REACTIVATION_TYPE_TIME_DAY: 2,
INT_REACTIVATION_NO_TIME: -1,
STR_REACTIVATION_TYPE_NONE: "none",
STR_REACTIVATION_TYPE_SLEEP: "sleep",
STR_REACTIVATION_TYPE_STOP: "stop",
TIME_REFRESH: 1000,
STR_REACTIVATION_RESPONSE_STARTED: "started",
STR_REACTIVATION_RESPONSE_STOPED: "stoped",
STR_REACTIVATION_RESPONSE_NO_CHANGE: "nothing_changed",
//
reactivation: this.defaultReactivation(),
reactivationTimeType: this.defaultTimeType(),
reactivationTimeValue: this.defaultValue(),
reactivationTimeValue: this.defaultTimeValue(),
idDs:0,
sleep:false,
runingReactivation: false,
timeToNextTryEnableDs:0
timeToNextTryEnableDs: 0
};
},
methods: {
Expand All @@ -77,16 +91,48 @@ export default {
defaultTimeType() {
return this.STR_REACTIVATION_TYPE_TIME_MIN
},
defaultValue() {
defaultTimeValue() {
return 1
},
checkWhenNextTryEnableDs() {
const apiCheckReactivation = `./api/check-reactivation/${this.idDs}`;
const apiCheckReactivation = `./api/check-time-reactivation/${this.idDs}`;
axios.get(apiCheckReactivation).then(response => {
this.timeToNextTryEnableDs = response.data;
if ( response.data == this.INT_REACTIVATION_NO_TIME) {
this.runingReactivation= false;
this.timeToNextTryEnableDs = 0;
} else {
this.timeToNextTryEnableDs = response.data;
this.runingReactivation= true;
}
}).catch(error => {
this.runingReactivation = false;
console.log(error);
});
},
startReactivation() {
const apiStartReactivation= `./api/enable-reactivation/${this.idDs}`;
axios.post(apiStartReactivation).then(response => {
if (
(response.data == this.STR_REACTIVATION_RESPONSE_STARTED) ||
(response.data == this.STR_REACTIVATION_RESPONSE_NO_CHANGE) ) {
this.runingReactivation = true;
}
}).catch(error => {
console.log(error);
});
},
stopReactivation() {
const apiStopReactivation = `./api/disable-reactivation/${this.idDs}`;
axios.post(apiStopReactivation).then(response => {
if (
(response.data == this.STR_REACTIVATION_RESPONSE_STOPED) ||
(response.data == this.STR_REACTIVATION_RESPONSE_NO_CHANGE) ) {
this.runingReactivation = false;
this.timeToNextTryEnableDs = 0;
}
}).catch(error => {
console.log(error);
});
}
},
created() {
Expand All @@ -108,28 +154,19 @@ export default {
this.reactivationTimeType = this.STR_REACTIVATION_TYPE_TIME_DAY
}
this.reactivationValue = editDSNewUI.reactivation.value;
this.reactivationTimeValue = editDSNewUI.reactivation.value;
this.idDs = editDSNewUI.id;
setInterval(
function() {
this.checkWhenNextTryEnableDs();
this.checkWhenNextTryEnableDs();
}.bind(this),
this.TIME_REFRESH
);
},
watch: {
reactivationType() {
if (this.reactivationTimeType == this.STR_REACTIVATION_TYPE_TIME_MIN) {
editDSNewUI.reactivation.type = this.INT_REACTIVATION_TYPE_TIME_MIN
} else if (this.reactivationType == this.STR_REACTIVATION_TYPE_TIME_HOUR) {
editDSNewUI.reactivation.type = this.INT_REACTIVATION_TYPE_TIME_HOUR;
} else if (this.reactivationType == this.STR_REACTIVATION_TYPE_TIME_DAY) {
editDSNewUI.reactivation.type = this.INT_REACTIVATION_TYPE_TIME_DAY;
}
},
reactivation() {
if (this.reactivation == this.STR_REACTIVATION_TYPE_SLEEP) {
editDSNewUI.stop = false;
Expand All @@ -142,22 +179,29 @@ export default {
editDSNewUI.reactivation.sleep = false;
}
},
reactivationValue() {
editDSNewUI.reactivation.value = this.reactivationValue;
reactivationTimeType() {
if (this.reactivationTimeType == this.STR_REACTIVATION_TYPE_TIME_MIN) {
editDSNewUI.reactivation.type = this.INT_REACTIVATION_TYPE_TIME_MIN
} else if (this.reactivationTimeType == this.STR_REACTIVATION_TYPE_TIME_HOUR) {
editDSNewUI.reactivation.type = this.INT_REACTIVATION_TYPE_TIME_HOUR;
} else if (this.reactivationTimeType == this.STR_REACTIVATION_TYPE_TIME_DAY) {
editDSNewUI.reactivation.type = this.INT_REACTIVATION_TYPE_TIME_DAY;
}
},
reactivationTimeValue() {
editDSNewUI.reactivation.value = this.reactivationTimeValue;
}
},
filters: {
infoTime: function (date) {
var seconds = parseInt(date/1000);
var days = Math.floor(seconds / (3600*24));
seconds -= days*3600*24;
var hrs = Math.floor(seconds / 3600);
seconds -= hrs*3600;
var mnts = Math.floor(seconds / 60);
seconds -= mnts*60;
return days+" days, "+hrs+" Hrs, "+mnts+" Minutes, "+seconds+" Seconds";
}
},
};
Expand Down
3 changes: 1 addition & 2 deletions WebContent/WEB-INF/jsp/dataSourceEdit/editHttpRetriever.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
saveDataSourceCB
);
}
function appendPointListColumnFunctions(pointListColumnHeaders, pointListColumnFunctions) {
pointListColumnHeaders[pointListColumnHeaders.length] = "<fmt:message key="dsEdit.httpRetriever.regex"/>";
pointListColumnFunctions[pointListColumnFunctions.length] =
Expand Down Expand Up @@ -146,7 +146,6 @@
var timeRegexLen = $get("timeRegex").trim().length;
display("timeFormatRow", timeRegexLen > 0);
}
</script>

<c:set var="dsDesc"><fmt:message key="dsEdit.httpRetriever.desc"/></c:set>
Expand Down
7 changes: 7 additions & 0 deletions WebContent/WEB-INF/jsp/views.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
table {
border-collapse: separate !important;
border-spacing: 2px !important;
padding: 3px;
}
.rowTable {
background-color: #F0F0F0;
}
.rowTableAlt {
background-color: #DCDCDC;
}
</style>
<script type="text/javascript" src="resources/app/bower_components/sweetalert2/dist/sweetalert2.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/snippet/alarmList.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</tr>
<c:if test="${empty events}"><tr><td colspan="6"><b><fmt:message key="events.emptyList"/></b></td></tr></c:if>
<c:forEach items="${events}" var="event" varStatus="status">
<tr class="row<c:if test="${status.index % 2 == 1}">Alt</c:if>">
<tr class="rowTable<c:if test="${status.index % 2 == 1}">Alt</c:if>">
<c:if test="${!hideIdColumn}"><td align="center">${event.id}</td></c:if>
<c:if test="${!hideAlarmLevelColumn}"><td align="center"><tag:eventIcon event="${event}"/></td></c:if>
<c:if test="${!hideTimestampColumn}"><td align="center">${sst:time(event.activeTimestamp)}</td></c:if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.ds.StartStopDsRT;
import org.scada_lts.ds.model.ReactivationDs;
import org.scada_lts.ds.reactivation.MenagerReactivation;
import org.scada_lts.ds.reactivation.ReactivationManager;
import org.scada_lts.ds.reactivation.ReactivationConnectHttpRetriever;
import org.scada_lts.ds.state.SleepStateDs;
import org.scada_lts.ds.state.StopChangeEnableStateDs;
Expand Down Expand Up @@ -172,7 +172,7 @@ public String getData(String url, int timeoutSeconds, int retries, boolean stop,
new Thread(stopDsRT).start();
} else if (retries == i && r.isSleep()) {
ReactivationConnectHttpRetriever rhr = new ReactivationConnectHttpRetriever();
MenagerReactivation.getInstance().addProcess(rhr, r, vo);
ReactivationManager.getInstance().addProcess(rhr, r, vo);
StartStopDsRT stopDsRT = new StartStopDsRT(vo.getId(),false, new SleepStateDs());
new Thread(stopDsRT).start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ public void jsonSerialize(Map<String, Object> map) {
serializeUpdatePeriodType(map, updatePeriodType);
}

@Override
public boolean checkToTrayEnable() {
return isEnabled() || isStop() || reactivation.isSleep();
}
Expand Down
17 changes: 14 additions & 3 deletions src/com/serotonin/mango/web/dwr/DataSourceEditDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import com.serotonin.db.IntValuePair;
import com.serotonin.io.StreamUtils;
import org.scada_lts.ds.model.ReactivationDs;
import org.scada_lts.ds.reactivation.ReactivationManager;
import org.scada_lts.modbus.SerialParameters;
import com.serotonin.mango.Common;
import com.serotonin.mango.DataTypes;
Expand Down Expand Up @@ -139,7 +140,6 @@
import com.serotonin.mango.vo.dataSource.jmx.JmxPointLocatorVO;
import com.serotonin.mango.vo.dataSource.mbus.MBusDataSourceVO;
import com.serotonin.mango.vo.dataSource.mbus.MBusPointLocatorVO;
import com.serotonin.mango.vo.dataSource.mbus.MBusSearchByAddressing;
import com.serotonin.mango.vo.dataSource.mbus.PrimaryAddressingSearch;
import com.serotonin.mango.vo.dataSource.mbus.SecondaryAddressingSearch;
import com.serotonin.mango.vo.dataSource.meta.MetaDataSourceVO;
Expand Down Expand Up @@ -201,7 +201,6 @@
import com.serotonin.modbus4j.locator.BaseLocator;
import com.serotonin.modbus4j.msg.ModbusRequest;
import com.serotonin.modbus4j.msg.ReadResponse;
import com.serotonin.modbus4j.serial.SerialPortWrapper;
import com.serotonin.util.IpAddressUtils;
import com.serotonin.util.StringUtils;
import com.serotonin.viconics.RequestFailureException;
Expand Down Expand Up @@ -235,6 +234,7 @@ public DwrResponseI18n editInit() {
}

private DwrResponseI18n tryDataSourceSave(DataSourceVO<?> ds) {

DwrResponseI18n response = new DwrResponseI18n();

ds.validate(response);
Expand Down Expand Up @@ -1299,7 +1299,18 @@ public DwrResponseI18n saveHttpRetrieverDataSourceWithReactivationOptions(String
ReactivationDs rDs = new ReactivationDs(sleep, typeReactivation, valueReactivation);
ds.setReactivation(rDs);

return tryDataSourceSave(ds);
DwrResponseI18n result;

if (ds.getId() > 0) {
ReactivationManager.getInstance().stopReactivation(ds.getId());
}
result = tryDataSourceSave(ds);

if (sleep) {
ReactivationManager.getInstance().startReactivation(ds.getId());
}

return result;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution

Key keyJob = jobExecutionContext.getJobDetail().getKey();

Map.Entry entry = MenagerReactivation.getInstance().getId(keyJob.getName());
Map.Entry entry = ReactivationManager.getInstance().getId(keyJob.getName());
int id = (int) entry.getValue();
String name = (String) entry.getKey();

Expand All @@ -46,7 +46,7 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution
} finally {
StartStopDsRT stopDsRT = new StartStopDsRT(id,true, new StartSleepStateDs());
new Thread(stopDsRT).start();
MenagerReactivation.getInstance().removeInfoAboutJob(keyJob.getName());
ReactivationManager.getInstance().removeInfoAboutJob(keyJob.getName());
}
} else {
// nothing to do
Expand Down
Loading

0 comments on commit 706ded3

Please sign in to comment.