Search in sources :

Example 21 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method startPublisher.

@Override
public void startPublisher(PublisherVO vo) {
    // Ensure that the publisher is saved and enabled.
    Assert.isTrue(vo.getId() > 0, "Publisher must be saved");
    Assert.isTrue(vo.isEnabled(), "Publisher must be enabled");
    ensureState(ILifecycleState.INITIALIZING, ILifecycleState.RUNNING);
    PublisherRT<? extends PublisherVO, ? extends PublishedPointVO, ? extends SendThread> publisher = runningPublishers.computeIfAbsent(vo.getId(), k -> vo.createPublisherRT());
    long startTime = System.nanoTime();
    // Initialize the runtime of the publisher.
    publisher.initialize(false);
    long duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
    stateMessage = new TranslatableMessage("runtimeManager.initialize.publisher", vo.getName(), duration);
    LOG.info(String.format("%s took %dms to start", publisher.readableIdentifier(), duration));
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 22 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointGroupInitializer method processItem.

@Override
protected Void processItem(List<PublishedPointVO> subgroup, int itemId) throws Exception {
    long startTs = 0L;
    if (log.isInfoEnabled()) {
        startTs = Common.timer.currentTimeMillis();
        log.info("Initializing group {} of {} published points", itemId, subgroup.size());
    }
    // Now start them
    int failedCount = 0;
    for (PublishedPointVO point : subgroup) {
        try {
            Common.runtimeManager.startPublishedPoint(point);
        } catch (Exception e) {
            // Ensure only 1 can fail at a time
            failedCount++;
            log.error("Failed to start published point", e);
        }
    }
    if (log.isInfoEnabled()) {
        log.info("Group {} successfully initialized {} of {} published points in {} ms", itemId, subgroup.size() - failedCount, subgroup.size(), Common.timer.currentTimeMillis() - startTs);
    }
    return null;
}
Also used : PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO)

Example 23 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublisherRTQueueMonitorTest method testQueueMonitor.

@Test(timeout = 1 * 60 * 1000)
public void testQueueMonitor() {
    // create DS and DP and enable them (need to be running)
    MockDataSourceVO dataSource = this.createMockDataSource(true);
    DataPointVO dataPoint = this.createMockDataPoint(dataSource, new MockPointLocatorVO(DataType.NUMERIC, true), true);
    // create publisher with a published point (this is a listener) for the DP
    TestPublisherVO publisherVO = (TestPublisherVO) createMockPublisher(true);
    List<PublishedPointVO> points = createMockPublishedPoints(publisherVO, Collections.singletonList(dataPoint), true);
    // get the running data point RT from the Common.runtimeManager
    DataPointRT rt = Common.runtimeManager.getDataPoint(dataPoint.getId());
    // MockBackgroundProcessing
    // set PV(s) to the RT
    // Note: the publish point will be notified by DataPointEventNotifyWorkItem
    PointValueTime newValue = new PointValueTime(1.0, this.timer.currentTimeMillis());
    rt.setPointValue(newValue, null);
    try {
        /* Waiting for the PublishQueue.add to happen...
             * because I know that PublishQueue.lastSizeCheck is 0,
             * the fist time the PublishQueue.sizeCheck() will happen
             */
        publisherVO.getAddedFuture().get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    // confirm publish queue is of certain size
    String monitor = QUEUE_SIZE_MONITOR_ID + publisherVO.getXid();
    Assert.assertNotNull(Common.MONITORED_VALUES.getMonitor(monitor).getName());
    Assert.assertEquals(1, Common.MONITORED_VALUES.getMonitor(monitor).getValue());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) ExecutionException(java.util.concurrent.ExecutionException) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) Test(org.junit.Test)

Example 24 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointServiceTest method testSetPublishedPointState.

@Test
public void testSetPublishedPointState() {
    // Start out with a running publisher and an enabled point
    IDataPoint dp = createMockDataPoints(1).get(0);
    MockPublisherVO publisher = createMockPublisher(true);
    MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dp);
    pp.setName(dp.getName());
    pp.setEnabled(true);
    PublishedPointVO vo = service.insert(pp);
    assertTrue(service.setPublishedPointState(vo.getXid(), false, false));
    // Ensure it is not running
    assertNull(getRuntimeManager().getPublishedPoint(vo.getId()));
    assertTrue(service.setPublishedPointState(vo.getXid(), true, false));
    // Ensure it is running
    assertNotNull(getRuntimeManager().getPublishedPoint(vo.getId()));
}
Also used : IDataPoint(com.serotonin.m2m2.vo.IDataPoint) MockPublisherVO(com.serotonin.m2m2.vo.publish.mock.MockPublisherVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

Example 25 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointServiceTest method testNonAdminUpdate.

@Test(expected = PermissionException.class)
public void testNonAdminUpdate() {
    PublishedPointVO vo = insertNewVO(readUser);
    PublishedPointVO fromDb = service.get(vo.getId());
    assertVoEqual(vo, fromDb);
    PublishedPointVO updated = updateVO(vo);
    runAs.runAs(readUser, () -> {
        service.update(vo.getId(), updated);
    });
}
Also used : MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

Aggregations

PublishedPointVO (com.serotonin.m2m2.vo.publish.PublishedPointVO)34 MockPublishedPointVO (com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO)16 Test (org.junit.Test)12 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)9 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)8 MockPublisherVO (com.serotonin.m2m2.vo.publish.mock.MockPublisherVO)8 JsonException (com.serotonin.json.JsonException)6 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)6 PublisherVO (com.serotonin.m2m2.vo.publish.PublisherVO)6 NonNull (org.checkerframework.checker.nullness.qual.NonNull)6 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)4 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 PublisherRT (com.serotonin.m2m2.rt.publish.PublisherRT)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ArrayList (java.util.ArrayList)4 URI (java.net.URI)3 HttpHeaders (org.springframework.http.HttpHeaders)3