use of cern.c2mon.shared.common.ConfigurationException in project c2mon by c2mon.
the class DriverKernel method validateCommandTags.
/**
* This will validate the command tags of this configuration and invalidate
* them via the equipment message sender if necessary.
*
* @param equipmentConfiguration The configuration to use.
* @param equipmentMessageSender The sender to use. TODO Invalidation of
* command tags not possible. Find a solution.
*/
private void validateCommandTags(final EquipmentConfiguration equipmentConfiguration, final EquipmentMessageSender equipmentMessageSender) {
Iterator<SourceCommandTag> commandTagIterator = equipmentConfiguration.getCommandTags().values().iterator();
while (commandTagIterator.hasNext()) {
SourceCommandTag sourceCommandTag = commandTagIterator.next();
try {
log.debug("Validating command tag #{}", sourceCommandTag.getId());
sourceCommandTag.validate();
} catch (ConfigurationException e) {
log.error("Error validating configuration for CommandTag {}", sourceCommandTag.getId(), e);
commandTagIterator.remove();
}
}
}
use of cern.c2mon.shared.common.ConfigurationException 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;
}
use of cern.c2mon.shared.common.ConfigurationException 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;
}
use of cern.c2mon.shared.common.ConfigurationException 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;
}
use of cern.c2mon.shared.common.ConfigurationException 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);
}
}
}
Aggregations