Search in sources :

Example 1 with SourceDataTag

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

the class ConfigurationController method onDataTagRemove.

/**
 * Removes a data tag from an equipment.
 *
 * @param dataTagRemoveChange The change with all the data to remove the tag.
 *
 * @return A change report with success information.
 */
public synchronized ChangeReport onDataTagRemove(final DataTagRemove dataTagRemoveChange) {
    log.debug("Entering onDataTagRemove: ");
    ChangeReport changeReport = new ChangeReport(dataTagRemoveChange);
    Long equipmentId = dataTagRemoveChange.getEquipmentId();
    Map<Long, SourceDataTag> sourceDataTags = getSourceDataTags(equipmentId);
    if (sourceDataTags == null) {
        changeReport.appendError("Equipment does not exist: " + equipmentId);
        return changeReport;
    }
    log.debug("onDataTagRemove - removing " + dataTagRemoveChange.getDataTagId());
    SourceDataTag sourceDataTag = sourceDataTags.get(dataTagRemoveChange.getDataTagId());
    if (sourceDataTag != null) {
        log.debug("onDataTagRemove - Core removed data tag with id " + dataTagRemoveChange.getDataTagId() + " successfully from equipment " + equipmentId);
        changeReport.appendInfo("Core removed data tag with id " + dataTagRemoveChange.getDataTagId() + " successfully from equipment " + equipmentId);
        List<ICoreDataTagChanger> coreChangers = coreDataTagChangers.get(equipmentId);
        if (coreChangers != null) {
            for (ICoreDataTagChanger dataTagChanger : coreChangers) {
                dataTagChanger.onRemoveDataTag(sourceDataTag, changeReport);
            }
        }
        IDataTagChanger dataTagChanger = dataTagChangers.get(equipmentId);
        if (dataTagChanger != null) {
            dataTagChanger.onRemoveDataTag(sourceDataTag, changeReport);
        // changeReport.setState(CHANGE_STATE.SUCCESS);
        } else {
            changeReport.appendError("It was not possible to apply the changes" + "to the implementation part. No data tag changer was found.");
            changeReport.setState(CHANGE_STATE.REBOOT);
        }
        freshnessMonitor.removeDataTag(sourceDataTag);
        // remove the tag from the core's map
        sourceDataTags.remove(dataTagRemoveChange.getDataTagId());
    } else {
        log.debug("onDataTagRemove - The data tag with id " + dataTagRemoveChange.getDataTagId() + " to remove was not found" + " in equipment with id " + equipmentId);
        // The data tag which should be removed was not found which means the same
        // result as foudn and removed.
        changeReport.appendWarn("The data tag with id " + dataTagRemoveChange.getDataTagId() + " to remove was not found" + " in equipment with id " + equipmentId);
        changeReport.setState(CHANGE_STATE.SUCCESS);
    }
    log.debug("Exiting onDataTagRemove: ");
    return changeReport;
}
Also used : ISourceDataTag(cern.c2mon.shared.common.datatag.ISourceDataTag) SourceDataTag(cern.c2mon.shared.common.datatag.SourceDataTag)

Example 2 with SourceDataTag

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

the class ConfigurationController method onDataTagAdd.

/**
 * This is called if a data tag should be added to the configuration. It
 * applies the changes to the core and calls then the lower layer to also
 * perform the changes.
 *
 * @param dataTagAddChange The data tag add change.
 *
 * @return A report with information if the change was successful.
 */
public synchronized ChangeReport onDataTagAdd(final DataTagAdd dataTagAddChange) {
    log.debug("onDataTagAdd - entering onDataTagAdd()");
    log.debug("changeId: " + dataTagAddChange.getChangeId());
    ChangeReport changeReport = new ChangeReport(dataTagAddChange);
    Long equipmentId = dataTagAddChange.getEquipmentId();
    ProcessConfiguration configuration = ProcessConfigurationHolder.getInstance();
    // Check if the equipment id is a SubEquipment id.
    if (!configuration.getEquipmentConfigurations().containsKey(equipmentId)) {
        for (EquipmentConfiguration equipmentConfiguration : configuration.getEquipmentConfigurations().values()) {
            if (equipmentConfiguration.getSubEquipmentConfigurations().containsKey(equipmentId)) {
                equipmentId = equipmentConfiguration.getId();
            }
        }
    }
    SourceDataTag sourceDataTag = dataTagAddChange.getSourceDataTag();
    Long dataTagId = sourceDataTag.getId();
    Map<Long, SourceDataTag> sourceDataTags = getSourceDataTags(equipmentId);
    if (sourceDataTags == null) {
        log.warn("cannot add data tag - equipment id: " + dataTagAddChange.getEquipmentId() + " is unknown");
        changeReport.appendError("Equipment does not exist: " + equipmentId);
        return changeReport;
    }
    try {
        sourceDataTag.validate();
    } catch (ConfigurationException e) {
        changeReport.appendError("Error validating data tag");
        changeReport.appendError(StackTraceHelper.getStackTrace(e));
        return changeReport;
    }
    if (sourceDataTags.containsKey(dataTagId)) {
        log.warn("onDataTagAdd - cannot add data tag id: " + dataTagId + " to equipment id: " + dataTagAddChange.getEquipmentId() + " This equipment already" + " has tag with that id");
        changeReport.appendError("DataTag " + dataTagId + " is already in equipment " + equipmentId);
    } else {
        sourceDataTags.put(dataTagId, sourceDataTag);
        changeReport.appendInfo("Core added data tag with id " + sourceDataTag.getId() + " successfully to equipment " + equipmentId);
        List<ICoreDataTagChanger> coreChangers = coreDataTagChangers.get(equipmentId);
        if (coreChangers != null) {
            for (ICoreDataTagChanger dataTagChanger : coreChangers) {
                dataTagChanger.onAddDataTag(sourceDataTag, changeReport);
            }
        }
        IDataTagChanger dataTagChanger = dataTagChangers.get(equipmentId);
        if (dataTagChanger != null) {
            dataTagChanger.onAddDataTag(sourceDataTag, changeReport);
        // changeReport.setState(CHANGE_STATE.SUCCESS);
        } else {
            changeReport.appendError("It was not possible to apply the changes" + "to the implementation part. No data tag changer was found.");
            changeReport.setState(CHANGE_STATE.REBOOT);
        }
    }
    log.debug("onDataTagAdd - exiting onDataTagAdd()");
    return changeReport;
}
Also used : ProcessConfiguration(cern.c2mon.shared.common.process.ProcessConfiguration) ISourceDataTag(cern.c2mon.shared.common.datatag.ISourceDataTag) SourceDataTag(cern.c2mon.shared.common.datatag.SourceDataTag) ConfigurationException(cern.c2mon.shared.common.ConfigurationException) SubEquipmentConfiguration(cern.c2mon.shared.common.process.SubEquipmentConfiguration) EquipmentConfiguration(cern.c2mon.shared.common.process.EquipmentConfiguration)

Example 3 with SourceDataTag

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

the class DriverKernel method validateDataTags.

/**
 * This will validate the data tags of this configuration and invalidate them
 * via the equipment message sender if necessary.
 *
 * @param conf                   The configuration to use.
 * @param equipmentMessageSender The sender to use.
 */
private void validateDataTags(final EquipmentConfiguration conf, final EquipmentMessageSender equipmentMessageSender) {
    for (SourceDataTag sourceDataTag : conf.getDataTags().values()) {
        try {
            log.debug("Validating data tag #{}", sourceDataTag.getId());
            sourceDataTag.validate();
        } catch (ConfigurationException e) {
            log.error("Error validating configuration for DataTag {}", sourceDataTag.getId(), e);
            SourceDataTagQuality quality = new SourceDataTagQuality(SourceDataTagQualityCode.INCORRECT_NATIVE_ADDRESS, e.getMessage());
            equipmentMessageSender.update(sourceDataTag.getId(), quality);
        }
    }
}
Also used : SourceDataTag(cern.c2mon.shared.common.datatag.SourceDataTag) ConfigurationException(cern.c2mon.shared.common.ConfigurationException) SourceDataTagQuality(cern.c2mon.shared.common.datatag.SourceDataTagQuality)

Example 4 with SourceDataTag

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

the class ProcessConfigurationLoaderTest method testCreateProcessConfiguration.

@Test
public void testCreateProcessConfiguration() throws ConfUnknownTypeException, ConfRejectedTypeException, IOException {
    ProcessConfiguration processConfiguration = getProcessConfiguration(PROCESS_CONFIGURATION_XML);
    assertEquals(4092L, processConfiguration.getProcessID().longValue());
    assertEquals(properties.getJms().getQueuePrefix() + ".command." + this.processHostName + "." + PROCESS_NAME + "." + PROCESS_PIK, processConfiguration.getJmsDaqCommandQueue());
    assertEquals(100730, processConfiguration.getAliveTagID());
    assertEquals(60000, processConfiguration.getAliveInterval());
    assertEquals(100, processConfiguration.getMaxMessageSize());
    assertEquals(1000, processConfiguration.getMaxMessageDelay());
    Map<Long, EquipmentConfiguration> equipmentMap = processConfiguration.getEquipmentConfigurations();
    assertEquals(2, equipmentMap.values().size());
    EquipmentConfiguration equipmentConfiguration1 = equipmentMap.get(1L);
    assertEquals("cern.c2mon.daq.testhandler.TestMessageHandler", equipmentConfiguration1.getHandlerClassName());
    assertEquals(47014L, equipmentConfiguration1.getCommFaultTagId());
    assertFalse(equipmentConfiguration1.getCommFaultTagValue());
    assertEquals(47321L, equipmentConfiguration1.getAliveTagId());
    assertEquals(120000L, equipmentConfiguration1.getAliveTagInterval());
    assertEquals("interval=100;eventProb=0.8;inRangeProb=1.0;outDeadBandProb=0.0;outDeadBandProb=0.0;switchProb=0.5;startIn=0.01;aliveInterval=30000", equipmentConfiguration1.getAddress());
    List<SubEquipmentConfiguration> subEquipmentConfigurations = new ArrayList<SubEquipmentConfiguration>(equipmentConfiguration1.getSubEquipmentConfigurations().values());
    assertEquals(2, subEquipmentConfigurations.size());
    assertTrue(subEquipmentConfigurations.get(0).getCommFaultTagValue());
    assertFalse(subEquipmentConfigurations.get(1).getCommFaultTagValue());
    Map<Long, SourceDataTag> sourceDataTagMap1 = equipmentConfiguration1.getDataTags();
    assertEquals(2, sourceDataTagMap1.size());
    SourceDataTag sourceDataTag1 = sourceDataTagMap1.get(1L);
    assertEquals("CP.PRE.AIRH4STP887:DEFAUT_PROCESSEUR", sourceDataTag1.getName());
    assertFalse(sourceDataTag1.isControl());
    assertEquals("Boolean", sourceDataTag1.getDataType());
    assertEquals(9999999, sourceDataTag1.getAddress().getTimeToLive());
    assertEquals(7, sourceDataTag1.getAddress().getPriority());
    assertTrue(sourceDataTag1.getAddress().isGuaranteedDelivery());
    PLCHardwareAddressImpl hardwareAddress = (PLCHardwareAddressImpl) sourceDataTag1.getHardwareAddress();
    assertEquals(5, hardwareAddress.getBlockType());
    assertEquals(0, hardwareAddress.getWordId());
    assertEquals(1, hardwareAddress.getBitId());
    assertTrue(0.0 - hardwareAddress.getPhysicalMinVal() < 0.0000000001);
    assertTrue(0.0 - hardwareAddress.getPhysicalMaxVal() < 0.0000000001);
    assertEquals(1, hardwareAddress.getResolutionFactor());
    assertEquals(0, hardwareAddress.getCommandPulseLength());
    assertEquals("INT999", hardwareAddress.getNativeAddress());
}
Also used : ProcessConfiguration(cern.c2mon.shared.common.process.ProcessConfiguration) SourceDataTag(cern.c2mon.shared.common.datatag.SourceDataTag) PLCHardwareAddressImpl(cern.c2mon.shared.common.datatag.address.impl.PLCHardwareAddressImpl) ArrayList(java.util.ArrayList) SubEquipmentConfiguration(cern.c2mon.shared.common.process.SubEquipmentConfiguration) SubEquipmentConfiguration(cern.c2mon.shared.common.process.SubEquipmentConfiguration) EquipmentConfiguration(cern.c2mon.shared.common.process.EquipmentConfiguration) Test(org.junit.Test)

Example 5 with SourceDataTag

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

the class RequestControllerTest method getBasicConfigurationController.

/**
 * @return configurationController
 */
private ConfigurationController getBasicConfigurationController() {
    ConfigurationController configurationController = new ConfigurationController();
    ProcessConfiguration processConfiguration = new ProcessConfiguration();
    EquipmentConfiguration equipmentConfiguration = new EquipmentConfiguration();
    EquipmentConfiguration equipmentConfiguration2 = new EquipmentConfiguration();
    SourceCommandTag commandTag = new SourceCommandTag(1L, "hello");
    DataTagAddress address = new DataTagAddress();
    SourceDataTag sourceDataTag = new SourceDataTag(1L, "asd", false, (short) 0, "Integer", address);
    SourceDataTag sourceDataTag2 = new SourceDataTag(2L, "asd", false, (short) 0, "Integer", address);
    SourceDataTag sourceDataTag3 = new SourceDataTag(3L, "asd", false, (short) 0, "Integer", address);
    processConfiguration.setProcessID(1L);
    equipmentConfiguration.setId(1L);
    sourceDataTag.update(new ValueUpdate(25));
    sourceDataTag2.update(new ValueUpdate(25));
    sourceDataTag3.update(new ValueUpdate(25));
    configurationController.setProcessConfiguration(processConfiguration);
    processConfiguration.getEquipmentConfigurations().put(1L, equipmentConfiguration);
    processConfiguration.getEquipmentConfigurations().put(2L, equipmentConfiguration2);
    equipmentConfiguration.getCommandTags().put(1L, commandTag);
    equipmentConfiguration.getDataTags().put(1L, sourceDataTag);
    equipmentConfiguration2.getDataTags().put(2L, sourceDataTag2);
    equipmentConfiguration2.getDataTags().put(3L, sourceDataTag3);
    return configurationController;
}
Also used : ValueUpdate(cern.c2mon.shared.common.datatag.ValueUpdate) ConfigurationController(cern.c2mon.daq.common.conf.core.ConfigurationController) ProcessConfiguration(cern.c2mon.shared.common.process.ProcessConfiguration) DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) SourceDataTag(cern.c2mon.shared.common.datatag.SourceDataTag) SourceCommandTag(cern.c2mon.shared.common.command.SourceCommandTag) EquipmentConfiguration(cern.c2mon.shared.common.process.EquipmentConfiguration)

Aggregations

SourceDataTag (cern.c2mon.shared.common.datatag.SourceDataTag)25 Test (org.junit.Test)12 ISourceDataTag (cern.c2mon.shared.common.datatag.ISourceDataTag)8 DataTagAddress (cern.c2mon.shared.common.datatag.DataTagAddress)7 EquipmentConfiguration (cern.c2mon.shared.common.process.EquipmentConfiguration)6 ProcessConfiguration (cern.c2mon.shared.common.process.ProcessConfiguration)5 ConfigurationException (cern.c2mon.shared.common.ConfigurationException)4 SubEquipmentConfiguration (cern.c2mon.shared.common.process.SubEquipmentConfiguration)4 IEquipmentConfiguration (cern.c2mon.shared.common.process.IEquipmentConfiguration)3 OPCHardwareAddressImpl (cern.c2mon.shared.common.datatag.address.impl.OPCHardwareAddressImpl)2 ConfigurationController (cern.c2mon.daq.common.conf.core.ConfigurationController)1 ConfUnknownTypeException (cern.c2mon.daq.tools.processexceptions.ConfUnknownTypeException)1 ControlTag (cern.c2mon.server.common.control.ControlTag)1 SourceCommandTag (cern.c2mon.shared.common.command.SourceCommandTag)1 SourceDataTagQuality (cern.c2mon.shared.common.datatag.SourceDataTagQuality)1 ValueUpdate (cern.c2mon.shared.common.datatag.ValueUpdate)1 HardwareAddress (cern.c2mon.shared.common.datatag.address.HardwareAddress)1 PLCHardwareAddressImpl (cern.c2mon.shared.common.datatag.address.impl.PLCHardwareAddressImpl)1 DataTagAddressUpdate (cern.c2mon.shared.daq.config.DataTagAddressUpdate)1 DataTagUpdate (cern.c2mon.shared.daq.config.DataTagUpdate)1