Search in sources :

Example 16 with DataTagAddress

use of cern.c2mon.shared.common.datatag.DataTagAddress in project c2mon by c2mon.

the class TimeDifferenceMovingAverageTimeDeadbandActivator method checkTag.

/**
 * Checks if the source data tag should have time deadband filtering activated.
 * @param tag The tag to be checked.
 * @param currentAverage The current average of time between to data tags.
 */
private void checkTag(final SourceDataTag tag, final long currentAverage) {
    DataTagAddress address = tag.getAddress();
    LOGGER.debug("Tag: '" + tag.getId() + "' - Current average: " + currentAverage + "ms");
    if (address != null) {
        if (address.isTimeDeadbandEnabled()) {
            if (currentAverage >= deactivationDiff) {
                LOGGER.info("Tag: '" + tag.getId() + "' - Removing tag from time deadband filtering.");
                address.setTimeDeadband(0);
            }
        } else {
            if (currentAverage <= minDiff && currentAverage != -1) {
                LOGGER.info("Tag: '" + tag.getId() + "' - Adding tag to time deadband filtering.");
                address.setTimeDeadband(timeDeadbandTime);
            }
        }
    }
}
Also used : DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress)

Example 17 with DataTagAddress

use of cern.c2mon.shared.common.datatag.DataTagAddress in project c2mon by c2mon.

the class EntityUtils method createDataTag.

public static DataTag createDataTag() {
    DataTagCacheObject tag = new DataTagCacheObject(1L, "cpu.loadavg", Long.class.getName(), DataTagConstants.MODE_OPERATIONAL);
    tag.setProcessId(50L);
    tag.setEquipmentId(150L);
    tag.setDescription("Average CPU usage");
    tag.setAddress(new DataTagAddress());
    tag.setMaxValue(0);
    tag.setMinValue(4.0);
    tag.setSourceTimestamp(new Timestamp(System.currentTimeMillis()));
    tag.setDaqTimestamp(new Timestamp(System.currentTimeMillis()));
    tag.setCacheTimestamp(new Timestamp(System.currentTimeMillis()));
    tag.setDataTagQuality(new DataTagQualityImpl());
    tag.setLogged(true);
    Metadata metadata = new Metadata();
    metadata.addMetadata("building", "1");
    metadata.addMetadata("array", Collections.singletonList("test"));
    metadata.addMetadata("responsiblePerson", "Fred");
    tag.setMetadata(metadata);
    return tag;
}
Also used : DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) Metadata(cern.c2mon.server.common.metadata.Metadata) DataTagCacheObject(cern.c2mon.server.common.datatag.DataTagCacheObject) DataTagQualityImpl(cern.c2mon.shared.common.datatag.DataTagQualityImpl) Timestamp(java.sql.Timestamp)

Example 18 with DataTagAddress

use of cern.c2mon.shared.common.datatag.DataTagAddress in project c2mon by c2mon.

the class TagRecordConverterTest method createTestCacheTag.

private DataTagCacheObject createTestCacheTag(Object value, Class<?> dataType) {
    DataTagCacheObject tag = new DataTagCacheObject(10L);
    tag.setName("testName");
    tag.setDataType(dataType.getName());
    tag.setAddress(new DataTagAddress());
    tag.setEquipmentId(11L);
    tag.setProcessId(1L);
    tag.setDescription("Description");
    tag.setValueDescription("valueDescription");
    tag.setMode((short) 1);
    tag.setJapcAddress("japcAdress");
    tag.setDipAddress("dipAdress");
    tag.setDaqTimestamp(new Timestamp(1234567890));
    tag.setSourceTimestamp(new Timestamp(1234567890));
    tag.setCacheTimestamp(new Timestamp(1234567890));
    tag.getDataTagQuality().addInvalidStatus(TagQualityStatus.INACCESSIBLE, "desc1");
    tag.getDataTagQuality().addInvalidStatus(TagQualityStatus.UNINITIALISED, "desc1");
    tag.getDataTagQuality().addInvalidStatus(TagQualityStatus.VALUE_OUT_OF_BOUNDS, "desc1");
    tag.setValue(value);
    return tag;
}
Also used : DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) DataTagCacheObject(cern.c2mon.server.common.datatag.DataTagCacheObject) Timestamp(java.sql.Timestamp)

Example 19 with DataTagAddress

use of cern.c2mon.shared.common.datatag.DataTagAddress in project c2mon by c2mon.

the class AbstractDataTagFacade method configureCacheObject.

/**
 * Updates configuration fields of the cache object with those contained
 * in the properties object. By "configuration fields" we are referring
 * to fields open to reconfiguration during runtime. In particular, values
 * and timestamps are not modified by this method: updates due to incoming
 * data should be processed using the other update and invalidate methods.
 *
 * <p>This method is thread-safe (it performs the required synchronization
 * on the cache object residing in the cache.
 *
 * <p>This method should preferably be performed on an object outside the cache
 * before being applied to the object residing in the cache, since changes cannot
 * be rolled back if the validation fails.
 *
 * <p>The returned change object can be used to inform the data when an update is
 * performed (not used during DataTag creation).
 *
 * throws ConfigurationException if the reconfigured cache object fails validation checks (unchecked)
 * throws IllegalArgumentException thrown when creating DAQ change event for HardwareAddress (unchecked)
 *
 * @param dataTag the cache object to reconfigure (the object is modified by this method)
 * @param properties the properties that need reconfiguring
 * @return a DataTagUpdate object with the changes needed to be passed to the DAQ
 * @throws IllegalAccessException thrown when creating DAQ change event for HardwareAddress
 */
@Override
public final DataTagUpdate configureCacheObject(final T dataTag, final Properties properties) throws ConfigurationException, IllegalArgumentException, IllegalAccessException {
    DataTagCacheObject dataTagCacheObject = (DataTagCacheObject) dataTag;
    DataTagUpdate dataTagUpdate = setCommonProperties(dataTagCacheObject, properties);
    String tmpStr;
    // referenced via the equipment's aliveTag and commFaultTag fields
    if (equipmentFacade != null && !(dataTagCacheObject instanceof ControlTag)) {
        if ((tmpStr = properties.getProperty("equipmentId")) != null) {
            try {
                dataTagCacheObject.setEquipmentId(Long.valueOf(tmpStr));
                dataTagCacheObject.setProcessId(equipmentFacade.getProcessIdForAbstractEquipment(dataTagCacheObject.getEquipmentId()));
            } catch (NumberFormatException e) {
                throw new ConfigurationException(ConfigurationException.INVALID_PARAMETER_VALUE, "NumberFormatException: " + "Unable to convert parameter \"equipmentId\" to Long: " + tmpStr);
            }
        } else // TIMS-951: Allow attachment of DataTags to SubEquipments
        if ((tmpStr = properties.getProperty("subEquipmentId")) != null) {
            try {
                dataTagCacheObject.setSubEquipmentId(Long.valueOf(tmpStr));
                dataTagCacheObject.setProcessId(subEquipmentFacade.getProcessIdForAbstractEquipment(dataTagCacheObject.getSubEquipmentId()));
            } catch (NumberFormatException e) {
                throw new ConfigurationException(ConfigurationException.INVALID_PARAMETER_VALUE, "NumberFormatException: " + "Unable to convert parameter \"subEquipmentId\" to Long: " + tmpStr);
            }
        }
    }
    if ((tmpStr = properties.getProperty("minValue")) != null) {
        if (tmpStr.equals("null")) {
            dataTagCacheObject.setMinValue(null);
            dataTagUpdate.setMinValue(null);
        } else {
            Comparable comparableMin = (Comparable) TypeConverter.cast(tmpStr, dataTagCacheObject.getDataType());
            dataTagCacheObject.setMinValue(comparableMin);
            dataTagUpdate.setMinValue((Number) comparableMin);
        }
    }
    if ((tmpStr = properties.getProperty("maxValue")) != null) {
        if (tmpStr.equals("null")) {
            dataTagCacheObject.setMaxValue(null);
            dataTagUpdate.setMaxValue(null);
        } else {
            Comparable comparableMax = (Comparable) TypeConverter.cast(tmpStr, dataTagCacheObject.getDataType());
            dataTagCacheObject.setMaxValue(comparableMax);
            dataTagUpdate.setMaxValue((Number) comparableMax);
        }
    }
    // TAG address
    tmpStr = properties.getProperty("address");
    if (tmpStr != null) {
        DataTagAddress dataTagAddress = DataTagAddress.fromConfigXML(tmpStr);
        dataTagCacheObject.setAddress(dataTagAddress);
        setUpdateDataTagAddress(dataTagAddress, dataTagUpdate);
    }
    if (dataTag.getEquipmentId() != null)
        dataTagUpdate.setEquipmentId(dataTag.getEquipmentId());
    return dataTagUpdate;
}
Also used : ControlTag(cern.c2mon.server.common.control.ControlTag) DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) ConfigurationException(cern.c2mon.shared.common.ConfigurationException) DataTagUpdate(cern.c2mon.shared.daq.config.DataTagUpdate) DataTagCacheObject(cern.c2mon.server.common.datatag.DataTagCacheObject)

Example 20 with DataTagAddress

use of cern.c2mon.shared.common.datatag.DataTagAddress in project c2mon by c2mon.

the class ConfigureDataTagTest method createDataTagWithNonExistentEquipment.

@Test
public void createDataTagWithNonExistentEquipment() {
    // Setup Exception
    tagException.expect(ConfigurationParseException.class);
    DataTag tag = DataTag.create("myDataTag", Integer.class, new DataTagAddress()).id(21L).build();
    tag.setEquipmentId(10L);
    List<DataTag> dataTagList = Arrays.asList(tag);
    Configuration config = new Configuration(1L);
    config.setEntities(dataTagList);
    // setUp Mocks:
    EasyMock.expect(equipmentCache.hasKey(10L)).andReturn(false);
    // run test
    EasyMock.replay(equipmentCache);
    parser.parse(config);
    EasyMock.verify(equipmentCache);
}
Also used : DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) Configuration(cern.c2mon.shared.client.configuration.api.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DataTag(cern.c2mon.shared.client.configuration.api.tag.DataTag) ConfigurationDataTagUtil.buildCreateBasicDataTag(cern.c2mon.server.configuration.parser.util.ConfigurationDataTagUtil.buildCreateBasicDataTag) ConfigurationDataTagUtil.buildCreateAllFieldsDataTag(cern.c2mon.server.configuration.parser.util.ConfigurationDataTagUtil.buildCreateAllFieldsDataTag) Test(org.junit.Test)

Aggregations

DataTagAddress (cern.c2mon.shared.common.datatag.DataTagAddress)46 Timestamp (java.sql.Timestamp)13 Test (org.junit.Test)12 Configuration (cern.c2mon.shared.client.configuration.api.Configuration)11 DataTagCacheObject (cern.c2mon.server.common.datatag.DataTagCacheObject)10 DataTag (cern.c2mon.shared.client.configuration.api.tag.DataTag)10 ContextConfiguration (org.springframework.test.context.ContextConfiguration)8 SourceDataTag (cern.c2mon.shared.common.datatag.SourceDataTag)7 Properties (java.util.Properties)7 ConfigurationDataTagUtil.buildCreateAllFieldsDataTag (cern.c2mon.server.configuration.parser.util.ConfigurationDataTagUtil.buildCreateAllFieldsDataTag)5 ConfigurationDataTagUtil.buildCreateBasicDataTag (cern.c2mon.server.configuration.parser.util.ConfigurationDataTagUtil.buildCreateBasicDataTag)5 ControlTagCacheObject (cern.c2mon.server.common.control.ControlTagCacheObject)4 ConfigurationReport (cern.c2mon.shared.client.configuration.ConfigurationReport)4 Metadata (cern.c2mon.shared.client.metadata.Metadata)4 ConfigurationChangeEventReport (cern.c2mon.shared.daq.config.ConfigurationChangeEventReport)4 HashMap (java.util.HashMap)4 Metadata (cern.c2mon.server.common.metadata.Metadata)3 ConfigurationElement (cern.c2mon.shared.client.configuration.ConfigurationElement)3 SubEquipment (cern.c2mon.shared.client.configuration.api.equipment.SubEquipment)3 Tag (cern.c2mon.shared.client.configuration.api.tag.Tag)3