Search in sources :

Example 1 with EquipmentConfiguration

use of cern.c2mon.shared.common.process.EquipmentConfiguration in project c2mon by c2mon.

the class ConfigurationController method onSubEquipmentUnitRemove.

/**
 * Updates the DAQ by removing a whole SubEquipment.
 *
 * @param subEquipmentUnitRemove the subequipment unit to be removed
 *
 * @return a change report with information about the success of the update.
 */
public ChangeReport onSubEquipmentUnitRemove(SubEquipmentUnitRemove subEquipmentUnitRemove) {
    log.debug("onSubEquipmentUnitRemove - entering onSubEquipmentUnitRemove()..");
    ProcessConfiguration configuration = ProcessConfigurationHolder.getInstance();
    ChangeReport changeReport = new ChangeReport(subEquipmentUnitRemove);
    changeReport.setState(CHANGE_STATE.SUCCESS);
    // Check if the parent equipment exists
    EquipmentConfiguration parentEquipmentConfiguration = configuration.getEquipmentConfiguration(subEquipmentUnitRemove.getParentEquipmentId());
    if (parentEquipmentConfiguration == null) {
        changeReport.appendError("Parent Equipment unit id: " + subEquipmentUnitRemove.getParentEquipmentId() + " for SubEquipment unit " + subEquipmentUnitRemove.getSubEquipmentId() + " is unknown");
        changeReport.setState(CHANGE_STATE.FAIL);
        return changeReport;
    }
    // Find the SubEquipment configuration
    SubEquipmentConfiguration subEquipmentConfiguration = parentEquipmentConfiguration.getSubEquipmentConfiguration(subEquipmentUnitRemove.getSubEquipmentId());
    if (subEquipmentConfiguration == null) {
        changeReport.appendWarn("SubEquipment unit id: " + subEquipmentUnitRemove.getSubEquipmentId() + " is unknown");
    } else {
        parentEquipmentConfiguration.getSubEquipmentConfigurations().remove(subEquipmentConfiguration.getId());
    }
    return changeReport;
}
Also used : ProcessConfiguration(cern.c2mon.shared.common.process.ProcessConfiguration) SubEquipmentConfiguration(cern.c2mon.shared.common.process.SubEquipmentConfiguration) SubEquipmentConfiguration(cern.c2mon.shared.common.process.SubEquipmentConfiguration) EquipmentConfiguration(cern.c2mon.shared.common.process.EquipmentConfiguration)

Example 2 with EquipmentConfiguration

use of cern.c2mon.shared.common.process.EquipmentConfiguration in project c2mon by c2mon.

the class ConfigurationController method onCommandTagUpdate.

/**
 * Updates a command tag.
 *
 * @param commandTagUpdateChange The object with all the information to update
 *                               the tag.
 *
 * @return A change report with information about the success of the update.
 */
public synchronized ChangeReport onCommandTagUpdate(final CommandTagUpdate commandTagUpdateChange) {
    ChangeReport changeReport = new ChangeReport(commandTagUpdateChange);
    long equipmentId = commandTagUpdateChange.getEquipmentId();
    long commandTagId = commandTagUpdateChange.getCommandTagId();
    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();
            }
        }
    }
    Map<Long, SourceCommandTag> sourceCommandTags = getSourceCommandTags(equipmentId);
    if (sourceCommandTags == null) {
        changeReport.appendError("Equipment does not exists: " + equipmentId);
        return changeReport;
    }
    if (sourceCommandTags.containsKey(commandTagId)) {
        try {
            SourceCommandTag sourceCommandTag = sourceCommandTags.get(commandTagId);
            SourceCommandTag oldSourceCommandTag = sourceCommandTag.clone();
            synchronized (sourceCommandTag) {
                configurationUpdater.updateCommandTag(commandTagUpdateChange, sourceCommandTag);
                try {
                    sourceCommandTag.validate();
                } catch (ConfigurationException e) {
                    sourceCommandTags.put(commandTagId, oldSourceCommandTag);
                    changeReport.appendError("Error validating command tag");
                    changeReport.appendError(StackTraceHelper.getStackTrace(e));
                    return changeReport;
                }
            }
            changeReport.appendInfo("Core Command Tag update successfully applied.");
            ICommandTagChanger commandTagChanger = commandTagChangers.get(equipmentId);
            commandTagChanger.onUpdateCommandTag(sourceCommandTag, oldSourceCommandTag, changeReport);
            if (changeReport.getState().equals(CHANGE_STATE.SUCCESS)) {
                List<ICoreCommandTagChanger> coreChangers = coreCommandTagChangers.get(equipmentId);
                if (coreChangers != null) {
                    for (ICoreCommandTagChanger coreCommandTagChanger : coreChangers) {
                        coreCommandTagChanger.onUpdateCommandTag(sourceCommandTag, oldSourceCommandTag, changeReport);
                    }
                }
                changeReport.appendInfo("Change fully applied.");
            } else {
                sourceCommandTags.put(commandTagId, oldSourceCommandTag);
            }
        } catch (Exception e) {
            changeReport.appendError("Error while applying command tag changes: " + e.getMessage());
        }
    } else {
        changeReport.appendError("Command Tag " + commandTagId + " to update was not found.");
    }
    return changeReport;
}
Also used : ProcessConfiguration(cern.c2mon.shared.common.process.ProcessConfiguration) ConfigurationException(cern.c2mon.shared.common.ConfigurationException) ISourceCommandTag(cern.c2mon.shared.common.command.ISourceCommandTag) SourceCommandTag(cern.c2mon.shared.common.command.SourceCommandTag) SubEquipmentConfiguration(cern.c2mon.shared.common.process.SubEquipmentConfiguration) EquipmentConfiguration(cern.c2mon.shared.common.process.EquipmentConfiguration) ConfigurationException(cern.c2mon.shared.common.ConfigurationException) ConfUnknownTypeException(cern.c2mon.daq.tools.processexceptions.ConfUnknownTypeException)

Example 3 with EquipmentConfiguration

use of cern.c2mon.shared.common.process.EquipmentConfiguration in project c2mon by c2mon.

the class ConfigurationController method onCommandTagAdd.

/**
 * This is called if a command 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 commandTagAddChange The command tag add change.
 *
 * @return A report with information if the change was successful.
 */
public synchronized ChangeReport onCommandTagAdd(final CommandTagAdd commandTagAddChange) {
    log.debug("entering onCommandTagAdd()");
    log.debug("changeId: " + commandTagAddChange.getChangeId());
    ChangeReport changeReport = new ChangeReport(commandTagAddChange);
    Long equipmentId = commandTagAddChange.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();
            }
        }
    }
    Map<Long, SourceCommandTag> sourceCommandTags = getSourceCommandTags(equipmentId);
    if (sourceCommandTags == null) {
        log.warn("cannot add command tag - equipment id: " + commandTagAddChange.getEquipmentId() + " is unknown");
        changeReport.appendError("Equipment does not exist: " + equipmentId);
        return changeReport;
    }
    SourceCommandTag sourceCommandTag = commandTagAddChange.getSourceCommandTag();
    try {
        sourceCommandTag.validate();
    } catch (ConfigurationException e) {
        changeReport.appendError("Error validating command tag");
        changeReport.appendError(StackTraceHelper.getStackTrace(e));
        return changeReport;
    }
    Long commandTagId = sourceCommandTag.getId();
    if (sourceCommandTags.containsKey(commandTagId)) {
        log.warn("cannot add command tag id: " + commandTagId + " to equipment id: " + commandTagAddChange.getEquipmentId() + " This equipment already has " + "tag with that id");
        changeReport.appendError("CommandTag " + commandTagId + " is already in equipment " + equipmentId);
    } else {
        sourceCommandTags.put(sourceCommandTag.getId(), sourceCommandTag);
        changeReport.appendInfo("Core added command tag with id " + sourceCommandTag.getId() + " successfully to equipment " + equipmentId);
        List<ICoreCommandTagChanger> coreChangers = coreCommandTagChangers.get(equipmentId);
        if (coreChangers != null) {
            for (ICoreCommandTagChanger commandTagChanger : coreChangers) {
                commandTagChanger.onAddCommandTag(sourceCommandTag, changeReport);
            }
        }
        ICommandTagChanger commandTagChanger = commandTagChangers.get(equipmentId);
        if (commandTagChanger != null) {
            commandTagChanger.onAddCommandTag(sourceCommandTag, changeReport);
        // changeReport.setState(CHANGE_STATE.SUCCESS);
        } else {
            changeReport.appendError("It was not possible to apply the changes" + "to the implementation part. No command tag changer was found.");
            changeReport.setState(CHANGE_STATE.REBOOT);
        }
    }
    return changeReport;
}
Also used : ProcessConfiguration(cern.c2mon.shared.common.process.ProcessConfiguration) ConfigurationException(cern.c2mon.shared.common.ConfigurationException) ISourceCommandTag(cern.c2mon.shared.common.command.ISourceCommandTag) SourceCommandTag(cern.c2mon.shared.common.command.SourceCommandTag) SubEquipmentConfiguration(cern.c2mon.shared.common.process.SubEquipmentConfiguration) EquipmentConfiguration(cern.c2mon.shared.common.process.EquipmentConfiguration)

Example 4 with EquipmentConfiguration

use of cern.c2mon.shared.common.process.EquipmentConfiguration 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 5 with EquipmentConfiguration

use of cern.c2mon.shared.common.process.EquipmentConfiguration 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)

Aggregations

EquipmentConfiguration (cern.c2mon.shared.common.process.EquipmentConfiguration)23 ProcessConfiguration (cern.c2mon.shared.common.process.ProcessConfiguration)18 SubEquipmentConfiguration (cern.c2mon.shared.common.process.SubEquipmentConfiguration)13 ConfigurationException (cern.c2mon.shared.common.ConfigurationException)7 ISourceDataTag (cern.c2mon.shared.common.datatag.ISourceDataTag)6 SourceDataTag (cern.c2mon.shared.common.datatag.SourceDataTag)6 ConfUnknownTypeException (cern.c2mon.daq.tools.processexceptions.ConfUnknownTypeException)5 SourceCommandTag (cern.c2mon.shared.common.command.SourceCommandTag)5 IEquipmentConfiguration (cern.c2mon.shared.common.process.IEquipmentConfiguration)5 Test (org.junit.Test)4 ISourceCommandTag (cern.c2mon.shared.common.command.ISourceCommandTag)3 Before (org.junit.Before)3 ConfigurationController (cern.c2mon.daq.common.conf.core.ConfigurationController)2 IProcessMessageSender (cern.c2mon.daq.common.messaging.IProcessMessageSender)2 FreshnessMonitor (cern.c2mon.daq.common.timer.FreshnessMonitor)2 DaqProperties (cern.c2mon.daq.config.DaqProperties)2 ArrayList (java.util.ArrayList)2 ICommandRunner (cern.c2mon.daq.common.ICommandRunner)1 IDynamicTimeDeadbandFilterer (cern.c2mon.daq.common.IDynamicTimeDeadbandFilterer)1 DefaultCommandTagChanger (cern.c2mon.daq.common.conf.core.DefaultCommandTagChanger)1