Search in sources :

Example 1 with RuntimeStatusModel

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;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) LongLongPair(com.serotonin.db.pair.LongLongPair) PollStatus(com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel.PollStatus) RuntimeStatusModel(com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel) ArrayList(java.util.ArrayList) Date(java.util.Date) RTException(com.serotonin.m2m2.rt.RTException) ActiveEventTypeModel(com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel.ActiveEventTypeModel) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RuntimeStatusModel (com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel)1 ActiveEventTypeModel (com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel.ActiveEventTypeModel)1 PollStatus (com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel.PollStatus)1 LongLongPair (com.serotonin.db.pair.LongLongPair)1 RTException (com.serotonin.m2m2.rt.RTException)1 PollingDataSource (com.serotonin.m2m2.rt.dataSource.PollingDataSource)1 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1