Search in sources :

Example 1 with ReductionDefinitions

use of alma.alarmsystem.alarmmessage.generated.ReductionDefinitions in project ACS by ACS-Community.

the class ReductionManager method saveToCDB.

public void saveToCDB() {
    Set<String> keyset = _objState.keySet();
    String[] objs = new String[keyset.size()];
    keyset.toArray(objs);
    ReductionDefinitions rds = ((ACSAlarmDAOImpl) _alarmDAO).getReductionRules();
    boolean flush = false;
    try {
        for (int i = 0; i < objs.length; i++) {
            ObjectState os = _objState.get(objs[i]);
            String[] spl = objs[i].split(",");
            String[] p = spl[0].split(":");
            String[] c = spl[1].split(":");
            ReductionLinkType rl = new ReductionLinkType();
            AlarmDefinition ad;
            Parent gp = new Parent();
            ad = new AlarmDefinition();
            ad.setFaultFamily(p[0]);
            ad.setFaultMember(p[1]);
            ad.setFaultCode(Integer.parseInt(p[2]));
            gp.setAlarmDefinition(ad);
            Child gc = new Child();
            ad = new AlarmDefinition();
            ad.setFaultFamily(c[0]);
            ad.setFaultMember(c[1]);
            ad.setFaultCode(Integer.parseInt(c[2]));
            gc.setAlarmDefinition(ad);
            rl.setParent(gp);
            rl.setChild(gc);
            if (spl[2].compareTo("n") == 0)
                rl.setType(ReductionLinkTypeTypeType.NODE);
            else
                rl.setType(ReductionLinkTypeTypeType.MULTIPLICITY);
            rl.validate();
            switch(os.getAction()) {
                case //Error, no state assigned.
                -1:
                    break;
                case 0:
                    break;
                case 1:
                    ((ACSAlarmDAOImpl) _alarmDAO).addReductionRule(rds, rl);
                    flush = true;
                    break;
                case 2:
                    ((ACSAlarmDAOImpl) _alarmDAO).updateReductionRule(rds, rl);
                    flush = true;
                    break;
                case 3:
                    ((ACSAlarmDAOImpl) _alarmDAO).deleteReductionRule(rds, rl);
                    flush = true;
                    break;
                default:
                    //Shouldn't happen.
                    break;
            }
        }
        keyset = _thrState.keySet();
        objs = new String[keyset.size()];
        keyset.toArray(objs);
        for (int i = 0; i < objs.length; i++) {
            AlarmDefinition al;
            String[] p = objs[i].split(":");
            al = new AlarmDefinition();
            al.setFaultFamily(p[0]);
            al.setFaultMember(p[1]);
            al.setFaultCode(Integer.parseInt(p[2]));
            ReductionRule rr = getMRParentByTriplet(p[0], p[1], Integer.parseInt(p[2]));
            Threshold th = new Threshold();
            th.setAlarmDefinition(al);
            if (rr == null)
                th.setValue(0);
            else
                th.setValue(rr.getThreshold());
            ObjectState ts = _thrState.get(objs[i]);
            th.validate();
            switch(ts.getAction()) {
                case //Error, no state assigned.
                -1:
                    break;
                case 0:
                    break;
                case 1:
                    ((ACSAlarmDAOImpl) _alarmDAO).addThreshold(rds, th);
                    flush = true;
                    break;
                case 2:
                    ((ACSAlarmDAOImpl) _alarmDAO).updateThreshold(rds, th);
                    flush = true;
                    break;
                case 3:
                    ((ACSAlarmDAOImpl) _alarmDAO).deleteThreshold(rds, th);
                    flush = true;
                    break;
                default:
                    //Shouldn't happen.
                    break;
            }
        }
        _objState.clear();
        _thrState.clear();
        if (flush)
            ((ACSAlarmDAOImpl) _alarmDAO).flushReductionRules(rds);
        for (ReductionRule rr : _nodeReductionRules) for (Alarm al : rr.getChildren()) if (rr.getIsNodeReduction())
            _objState.put(new String(rr.getParent().getAlarmId() + "," + al.getAlarmId() + ",n"), new ObjectState(false));
        for (ReductionRule rr : _multiReductionRules) {
            for (Alarm al : rr.getChildren()) if (!rr.getIsNodeReduction())
                _objState.put(new String(rr.getParent().getAlarmId() + "," + al.getAlarmId() + ",m"), new ObjectState(false));
            _thrState.put(rr.getParent().getAlarmId(), new ObjectState(false));
        }
    } catch (ValidationException e) {
        e.printStackTrace();
    }
}
Also used : ValidationException(org.exolab.castor.xml.ValidationException) Parent(alma.alarmsystem.alarmmessage.generated.Parent) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType) Alarm(cern.laser.business.data.Alarm) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl) Child(alma.alarmsystem.alarmmessage.generated.Child) Threshold(alma.alarmsystem.alarmmessage.generated.Threshold)

Example 2 with ReductionDefinitions

use of alma.alarmsystem.alarmmessage.generated.ReductionDefinitions in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method getReductionDefinitions.

public ReductionDefinitions getReductionDefinitions() {
    if (conf == null) {
        throw new IllegalStateException("Missing dal");
    }
    String xml;
    try {
        xml = conf.getConfiguration(REDUCTION_DEFINITION_PATH);
    } catch (CDBRecordDoesNotExistEx cdbEx) {
        // No reduction rules defined in CDB
        logger.log(AcsLogLevel.WARNING, "No reduction rules defined in CDB");
        return null;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't read " + REDUCTION_DEFINITION_PATH, e);
    }
    ReductionDefinitions rds = null;
    try {
        rds = (ReductionDefinitions) ReductionDefinitions.unmarshalReductionDefinitions(new StringReader(xml));
    } catch (Exception e) {
        throw new RuntimeException("Couldn't parse " + REDUCTION_DEFINITION_PATH, e);
    }
    return rds;
}
Also used : StringReader(java.io.StringReader) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) MalformedURLException(java.net.MalformedURLException) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx)

Example 3 with ReductionDefinitions

use of alma.alarmsystem.alarmmessage.generated.ReductionDefinitions in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method loadReductionRules.

/**
	 * Load the reduction rules from the CDB.
	 * 
	 * Read the reduction rules from the CDB and set up the alarms accordingly
	 */
private void loadReductionRules() {
    ReductionDefinitions rds = getReductionDefinitions();
    if (rds == null)
        return;
    // Read the links to create from the CDB
    ReductionLinkDefinitionListType ltc = rds.getLinksToCreate();
    //	Read the thresholds from the CDB
    Thresholds thresholds = rds.getThresholds();
    if (thresholds != null) {
        // Store the thresholds in the HashMap
        Threshold[] threshold = thresholds.getThreshold();
        for (Threshold t : threshold) {
            StringBuilder alarmID = new StringBuilder();
            alarmID.append(t.getAlarmDefinition().getFaultFamily());
            alarmID.append(':');
            alarmID.append(t.getAlarmDefinition().getFaultMember());
            alarmID.append(':');
            alarmID.append(t.getAlarmDefinition().getFaultCode());
            Integer thresholdValue = Integer.valueOf(t.getValue());
            theThreshods.put(alarmID.toString(), thresholdValue);
        }
    }
    if (ltc != null) {
        ReductionLinkType[] rls = ltc.getReductionLink();
        for (ReductionLinkType link : rls) {
            LinkSpec newRule = new LinkSpec(link);
            reductionRules.add(newRule);
            if (logger.isLoggable(AcsLogLevel.DEBUG)) {
                Parent p = link.getParent();
                Child c = link.getChild();
                StringBuffer buf = new StringBuffer();
                buf.replace(0, buf.length(), "");
                if (newRule._isMultiplicity) {
                    buf.append("Found MULTIPLICITY RR: parent <");
                } else {
                    buf.append("Found NODE RR: parent=<");
                }
                buf.append(p.getAlarmDefinition().getFaultFamily());
                buf.append(", ");
                buf.append(p.getAlarmDefinition().getFaultMember());
                buf.append(", ");
                buf.append(p.getAlarmDefinition().getFaultCode());
                buf.append("> child=<");
                buf.append(c.getAlarmDefinition().getFaultFamily());
                buf.append(", ");
                buf.append(c.getAlarmDefinition().getFaultMember());
                buf.append(", ");
                buf.append(c.getAlarmDefinition().getFaultCode());
                buf.append('>');
                logger.log(AcsLogLevel.DEBUG, buf.toString());
            }
        }
    }
    logger.log(AcsLogLevel.DEBUG, reductionRules.size() + " reduction rules read from CDB");
    updateReductionRules();
}
Also used : Thresholds(alma.alarmsystem.alarmmessage.generated.Thresholds) Parent(alma.alarmsystem.alarmmessage.generated.Parent) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType) LinkSpec(com.cosylab.acs.laser.dao.utils.LinkSpec) ReductionLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.ReductionLinkDefinitionListType) Child(alma.alarmsystem.alarmmessage.generated.Child) Threshold(alma.alarmsystem.alarmmessage.generated.Threshold)

Example 4 with ReductionDefinitions

use of alma.alarmsystem.alarmmessage.generated.ReductionDefinitions in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method loadReductionRules.

/**
	 * Load the reduction rules from the CDB.
	 * 
	 * Read the reduction rules from the CDB and set up the alarms accordingly
	 */
private void loadReductionRules() {
    if (conf == null) {
        throw new IllegalStateException("Missing dal");
    }
    // The reduction rules (<parent, child>)
    ArrayList<LinkSpec> reductionRules = new ArrayList<LinkSpec>();
    String xml;
    try {
        xml = conf.getConfiguration(REDUCTION_DEFINITION_PATH);
    } catch (CDBRecordDoesNotExistEx cdbEx) {
        // No reduction rules defined in CDB
        logger.log(AcsLogLevel.WARNING, "No reduction rules defined in CDB");
        return;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't read " + REDUCTION_DEFINITION_PATH, e);
    }
    ReductionDefinitions rds;
    try {
        rds = (ReductionDefinitions) ReductionDefinitions.unmarshalReductionDefinitions(new StringReader(xml));
    } catch (Exception e) {
        throw new RuntimeException("Couldn't parse " + REDUCTION_DEFINITION_PATH, e);
    }
    // Read the links to create from the CDB
    ReductionLinkDefinitionListType ltc = rds.getLinksToCreate();
    //	Read the thresholds from the CDB
    Thresholds thresholds = rds.getThresholds();
    if (ltc != null) {
        ReductionLinkType[] rls = ltc.getReductionLink();
        for (ReductionLinkType link : rls) {
            Parent p = link.getParent();
            Child c = link.getChild();
            if (p == null || c == null) {
                throw new RuntimeException("Missing child or parent in a reduction link");
            }
            boolean isMulti;
            if ("MULTIPLICITY".equals(link.getType())) {
                isMulti = true;
            } else if ("NODE".equals(link.getType())) {
                isMulti = false;
            } else {
                throw new RuntimeException("Unknown reduction-link type: " + link.getType());
            }
            if (p.getAlarmDefinition() == null || c.getAlarmDefinition() == null)
                throw new RuntimeException("Missing alarm-definition in child or parent");
            LinkSpec newRule = new LinkSpec(toMatcher(p.getAlarmDefinition()), toMatcher(c.getAlarmDefinition()), isMulti);
            reductionRules.add(newRule);
            StringBuffer buf = new StringBuffer();
            buf.replace(0, buf.length(), "");
            if (newRule.isMultiplicity) {
                buf.append("Found MULTIPLICITY RR: parent <");
            } else {
                buf.append("Found NODE RR: parent=<");
            }
            buf.append(newRule.parent.family + ", " + newRule.parent.member + ", " + newRule.parent.minCode + "-" + newRule.parent.minCode + ">");
            buf.append(" child=<" + newRule.child.family + ", " + newRule.child.member + ", " + newRule.child.minCode + "-" + newRule.child.minCode + ">");
            logger.log(AcsLogLevel.DEBUG, buf.toString());
        }
    }
    logger.log(AcsLogLevel.DEBUG, reductionRules.size() + " reduction rules read from CDB");
    Collection<Alarm> cc = alarmDefs.values();
    AlarmImpl[] allAlarms = new AlarmImpl[cc.size()];
    cc.toArray(allAlarms);
    LinkSpec[] ls = new LinkSpec[reductionRules.size()];
    reductionRules.toArray(ls);
    int num = allAlarms.length;
    int numls = ls.length;
    for (int a = 0; a < num; a++) {
        AlarmImpl parent = allAlarms[a];
        for (LinkSpec lsb : ls) {
            if (lsb.matchParent(parent)) {
                AlarmRefMatcher childMatcher = lsb.child;
                boolean isMulti = lsb.isMultiplicity();
                for (int c = 0; c < num; c++) {
                    if (a == c) {
                        continue;
                    }
                    AlarmImpl aic = allAlarms[c];
                    if (childMatcher.isMatch(aic)) {
                        if (isMulti) {
                            parent.addMultiplicityChild(aic);
                            logger.log(AcsLogLevel.DEBUG, "Added MULTI RR node child " + aic.getAlarmId() + " to " + parent.getAlarmId());
                        } else {
                            parent.addNodeChild(aic);
                            logger.log(AcsLogLevel.DEBUG, "Added NODE RR node child " + aic.getAlarmId() + " to " + parent.getAlarmId());
                        }
                    }
                }
            }
        }
    }
    if (thresholds != null && thresholds.getThresholdCount() > 0) {
        Threshold[] ta = thresholds.getThreshold();
        for (AlarmImpl alarm : allAlarms) {
            String alarmFF = alarm.getTriplet().getFaultFamily();
            String alarmFM = alarm.getTriplet().getFaultMember();
            Integer alarmFC = alarm.getTriplet().getFaultCode();
            for (Threshold threshold : ta) {
                String thresholdFF = threshold.getAlarmDefinition().getFaultFamily();
                String thresholdFM = threshold.getAlarmDefinition().getFaultMember();
                int thresholdFC = threshold.getAlarmDefinition().getFaultCode();
                int thresholdVal = threshold.getValue();
                if (alarmFF.equals(thresholdFF) && alarmFM.equals(thresholdFM) && alarmFC == thresholdFC) {
                    alarm.setMultiplicityThreshold(thresholdVal);
                    logger.log(AcsLogLevel.DEBUG, "Threshold = " + thresholdVal + " set in alarm " + alarm.getAlarmId());
                }
            }
        }
    }
}
Also used : Parent(alma.alarmsystem.alarmmessage.generated.Parent) ArrayList(java.util.ArrayList) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType) StringReader(java.io.StringReader) Child(alma.alarmsystem.alarmmessage.generated.Child) Threshold(alma.alarmsystem.alarmmessage.generated.Threshold) Thresholds(alma.alarmsystem.alarmmessage.generated.Thresholds) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) PatternSyntaxException(java.util.regex.PatternSyntaxException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Alarm(cern.laser.business.data.Alarm) AlarmImpl(cern.laser.business.data.AlarmImpl) ReductionLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.ReductionLinkDefinitionListType)

Example 5 with ReductionDefinitions

use of alma.alarmsystem.alarmmessage.generated.ReductionDefinitions in project ACS by ACS-Community.

the class ACSAlarmDAOImplTest method testGetReductionDefinitions.

public void testGetReductionDefinitions() {
    Parent p = new Parent();
    Child c = new Child();
    AlarmDefinition ad_p = new AlarmDefinition();
    AlarmDefinition ad_c = new AlarmDefinition();
    ad_p.setFaultFamily("A1");
    ad_p.setFaultMember("B1");
    ad_p.setFaultCode(1);
    ad_c.setFaultFamily("A2");
    ad_c.setFaultMember("B2");
    ad_c.setFaultCode(2);
    p.setAlarmDefinition(ad_p);
    c.setAlarmDefinition(ad_c);
    ReductionLinkType rl = new ReductionLinkType();
    rl.setParent(p);
    rl.setChild(c);
    rl.setType("NODE");
    ReductionDefinitions rds = _alarmDAO.getReductionRules();
    _alarmDAO.addReductionRule(rds, rl);
//_alarmDAO.flushReductionRules(rds);
}
Also used : Parent(alma.alarmsystem.alarmmessage.generated.Parent) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) ReductionDefinitions(alma.alarmsystem.alarmmessage.generated.ReductionDefinitions) Child(alma.alarmsystem.alarmmessage.generated.Child) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType)

Aggregations

ReductionDefinitions (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions)5 Child (alma.alarmsystem.alarmmessage.generated.Child)4 Parent (alma.alarmsystem.alarmmessage.generated.Parent)4 ReductionLinkType (alma.alarmsystem.alarmmessage.generated.ReductionLinkType)4 Threshold (alma.alarmsystem.alarmmessage.generated.Threshold)3 AlarmDefinition (alma.alarmsystem.alarmmessage.generated.AlarmDefinition)2 ReductionLinkDefinitionListType (alma.alarmsystem.alarmmessage.generated.ReductionLinkDefinitionListType)2 Thresholds (alma.alarmsystem.alarmmessage.generated.Thresholds)2 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)2 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)2 Alarm (cern.laser.business.data.Alarm)2 StringReader (java.io.StringReader)2 MalformedURLException (java.net.MalformedURLException)2 ValidationException (org.exolab.castor.xml.ValidationException)2 AlarmImpl (cern.laser.business.data.AlarmImpl)1 ACSAlarmDAOImpl (cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)1 LinkSpec (com.cosylab.acs.laser.dao.utils.LinkSpec)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1