use of com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel in project ma-modules-public by infiniteautomation.
the class DataSourcesRestController method getRuntimeStatus.
@ApiOperation(value = "Get runtime status for data source", notes = "Only polling data sources have runtime status", response = RuntimeStatusModel.class)
@RequestMapping(method = RequestMethod.GET, value = "/status/{xid}")
public RuntimeStatusModel getRuntimeStatus(@ApiParam(value = "Valid Data Source XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user) {
DataSourceVO vo = service.get(xid);
RuntimeStatusModel model = new RuntimeStatusModel();
DataSourceRT<?> ds;
try {
ds = Common.runtimeManager.getRunningDataSource(vo.getId());
} catch (RTException e) {
return model;
}
model.setState(ds.getLifecycleState());
model.setActiveEventTypes(ds.eventTypeStatus().entrySet().stream().filter(Entry::getValue).map(e -> new ActiveEventTypeModel(e.getKey().getDescription(), e.getKey().getAlarmLevel())).collect(Collectors.toList()));
if (ds instanceof PollingDataSource) {
List<LongLongPair> list = ((PollingDataSource<?>) ds).getLatestPollTimes();
List<PollStatus> latestPolls = new ArrayList<>();
for (LongLongPair poll : list) {
latestPolls.add(new PollStatus(new Date(poll.getKey()), poll.getValue()));
}
model.setLatestPolls(latestPolls);
List<PollStatus> latestAbortedPolls = new ArrayList<>();
List<Long> aborted = ((PollingDataSource<?>) ds).getLatestAbortedPollTimes();
for (Long poll : aborted) latestAbortedPolls.add(new PollStatus(new Date(poll), -1L));
model.setLatestAbortedPolls(latestAbortedPolls);
}
return model;
}
Aggregations