Search in sources :

Example 1 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-modules-public by infiniteautomation.

the class RuntimeManagerRestController method relinquish.

@ApiOperation(value = "Relinquish the value of a data point", notes = "Only BACnet data points allow this", response = Void.class)
@RequestMapping(method = RequestMethod.POST, value = "/relinquish/{xid}")
public void relinquish(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal User user, HttpServletRequest request) {
    DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
    if (dataPoint == null)
        throw new NotFoundRestException();
    Permissions.ensureDataPointReadPermission(user, dataPoint);
    DataPointRT rt = Common.runtimeManager.getDataPoint(dataPoint.getId());
    if (rt == null)
        throw new GenericRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.error.pointNotEnabled", xid));
    // Get the Data Source and Relinquish the point
    DataSourceRT<?> dsRt = Common.runtimeManager.getRunningDataSource(rt.getDataSourceId());
    if (dsRt == null)
        throw new GenericRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.error.dataSourceNotEnabled", xid));
    dsRt.relinquish(rt);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) GenericRestException(com.infiniteautomation.mango.rest.v2.exception.GenericRestException) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class DataSourceEditDwr method getGeneralStatusMessages.

@DwrPermission(user = true)
public final ProcessResult getGeneralStatusMessages() {
    ProcessResult result = new ProcessResult();
    DataSourceVO<?> vo = Common.getUser().getEditDataSource();
    DataSourceRT<?> rt = Common.runtimeManager.getRunningDataSource(vo.getId());
    List<TranslatableMessage> messages = new ArrayList<>();
    result.addData("messages", messages);
    if (rt == null)
        messages.add(new TranslatableMessage("dsEdit.notEnabled"));
    else {
        rt.addStatusMessages(messages);
        if (messages.isEmpty())
            messages.add(new TranslatableMessage("dsEdit.noStatus"));
    }
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class DataSourceDwr method getPollTimes.

/**
 * Get the latest poll times and thier durations
 * @param id
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getPollTimes(int id) {
    ProcessResult result = new ProcessResult();
    DataSourceRT ds = Common.runtimeManager.getRunningDataSource(id);
    List<StringStringPair> polls = new ArrayList<StringStringPair>();
    if ((ds != null) && (ds instanceof PollingDataSource)) {
        List<LongLongPair> list = ((PollingDataSource) ds).getLatestPollTimes();
        String pollTime;
        for (LongLongPair poll : list) {
            StringBuilder duration = new StringBuilder();
            pollTime = Functions.getFullMilliSecondTime(poll.getKey());
            if (poll.getValue() >= 0) {
                // Format Duration Nicely
                Period period = new Period(poll.getValue());
                if (period.getHours() >= 1) {
                    duration.append(translate("common.duration.hours", period.getHours()));
                    duration.append(SPACE);
                }
                if (period.getMinutes() >= 1) {
                    duration.append(translate("common.duration.minutes", period.getMinutes()));
                    duration.append(SPACE);
                }
                if (period.getSeconds() >= 1) {
                    duration.append(translate("common.duration.seconds", period.getSeconds()));
                    duration.append(SPACE);
                }
                duration.append(translate("common.duration.millis", period.getMillis()));
            } else {
                duration.append(translate("event.ds.pollAborted"));
            }
            StringStringPair pair = new StringStringPair(pollTime, duration.toString());
            polls.add(pair);
        }
    }
    List<String> aborts = new ArrayList<String>();
    if ((ds != null) && (ds instanceof PollingDataSource)) {
        List<Long> list = ((PollingDataSource) ds).getLatestAbortedPollTimes();
        String pollTime;
        for (Long poll : list) {
            pollTime = Functions.getFullMilliSecondTime(poll);
            aborts.add(pollTime);
        }
    }
    result.addData("polls", polls);
    result.addData("aborts", aborts);
    return result;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) LongLongPair(com.serotonin.db.pair.LongLongPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) DataSourceRT(com.serotonin.m2m2.rt.dataSource.DataSourceRT) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 4 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class DataSourceDwr method getGeneralStatusMessages.

/**
 * Get the general status messages for a given data source
 *
 * @param id
 * @return
 */
@DwrPermission(user = true)
public final ProcessResult getGeneralStatusMessages(int id) {
    ProcessResult result = new ProcessResult();
    DataSourceRT rt = Common.runtimeManager.getRunningDataSource(id);
    List<TranslatableMessage> messages = new ArrayList<>();
    result.addData("messages", messages);
    if (rt == null)
        messages.add(new TranslatableMessage("dsEdit.notEnabled"));
    else {
        rt.addStatusMessages(messages);
        if (messages.isEmpty())
            messages.add(new TranslatableMessage("dsEdit.noStatus"));
    }
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DataSourceRT(com.serotonin.m2m2.rt.dataSource.DataSourceRT) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 5 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method startDataPointStartup.

/**
 * Only to be used at startup as synchronization has been reduced for performance
 * @param vo
 * @param latestValue
 */
private void startDataPointStartup(DataPointVO vo, List<PointValueTime> initialCache) {
    Assert.isTrue(vo.isEnabled(), "Data point not enabled");
    // Only add the data point if its data source is enabled.
    DataSourceRT<? extends DataSourceVO<?>> ds = getRunningDataSource(vo.getDataSourceId());
    if (ds != null) {
        // Change the VO into a data point implementation.
        DataPointRT dataPoint = new DataPointRT(vo, vo.getPointLocator().createRuntime(), ds.getVo(), initialCache);
        // Add/update it in the data image.
        synchronized (dataPoints) {
            dataPoints.compute(dataPoint.getId(), (k, rt) -> {
                if (rt != null) {
                    try {
                        getRunningDataSource(rt.getDataSourceId()).removeDataPoint(rt);
                    } catch (Exception e) {
                        LOG.error("Failed to stop point RT with ID: " + vo.getId() + " stopping point.", e);
                    }
                    DataPointListener l = getDataPointListeners(vo.getId());
                    if (l != null)
                        l.pointTerminated();
                    rt.terminate();
                }
                return dataPoint;
            });
        }
        // Initialize it.
        dataPoint.initialize();
        // If we are a polling data source then we need to wait to start our interval logging
        // until the first poll due to quantization
        boolean isPolling = ds instanceof PollingDataSource;
        // If we are not polling go ahead and start the interval logging, otherwise we will let the data source do it on the first poll
        if (!isPolling)
            dataPoint.initializeIntervalLogging(0l, false);
        DataPointListener l = getDataPointListeners(vo.getId());
        if (l != null)
            l.pointInitialized();
        // Add/update it in the data source.
        try {
            ds.addDataPoint(dataPoint);
        } catch (Exception e) {
            // This can happen if there is a corrupt DB with a point for a different
            // data source type linked to this data source...
            LOG.error("Failed to start point with xid: " + dataPoint.getVO().getXid() + " disabling point.", e);
            // TODO Fire Alarm to warn user.
            dataPoint.getVO().setEnabled(false);
            // Stop it
            saveDataPoint(dataPoint.getVO());
        }
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) DataPointListener(com.serotonin.m2m2.rt.dataImage.DataPointListener) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource)

Aggregations

DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)6 ArrayList (java.util.ArrayList)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)3 DataSourceRT (com.serotonin.m2m2.rt.dataSource.DataSourceRT)2 PollingDataSource (com.serotonin.m2m2.rt.dataSource.PollingDataSource)2 GenericRestException (com.infiniteautomation.mango.rest.v2.exception.GenericRestException)1 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)1 LongLongPair (com.serotonin.db.pair.LongLongPair)1 StringStringPair (com.serotonin.db.pair.StringStringPair)1 EnhancedPointValueDao (com.serotonin.m2m2.db.dao.EnhancedPointValueDao)1 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)1 DataPointListener (com.serotonin.m2m2.rt.dataImage.DataPointListener)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1