Search in sources :

Example 1 with ReductionLinkType

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

the class ACSAlarmDAOImpl method updateReductionRule.

public void updateReductionRule(ReductionDefinitions rds, ReductionLinkType rl) {
    if (rl == null)
        throw new IllegalArgumentException("Null Reduction Link argument");
    //alma.alarmsystem.alarmmessage.generated.ReductionDefinitions rds = getReductionRules();
    //Store changes in the CDB.
    boolean removed = false;
    alma.alarmsystem.alarmmessage.generated.ReductionLinkType[] tmp = rds.getLinksToCreate().getReductionLink();
    for (int i = 0; i < tmp.length; i++) {
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition p1 = tmp[i].getParent().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition c1 = tmp[i].getChild().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition p2 = rl.getParent().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition c2 = rl.getChild().getAlarmDefinition();
        String n1 = new String(p1.getFaultFamily() + ":" + p1.getFaultMember() + ":" + p1.getFaultCode());
        String n2 = new String(c1.getFaultFamily() + ":" + c1.getFaultMember() + ":" + c1.getFaultCode());
        String n3 = new String(p2.getFaultFamily() + ":" + p2.getFaultMember() + ":" + p2.getFaultCode());
        String n4 = new String(c2.getFaultFamily() + ":" + c2.getFaultMember() + ":" + c2.getFaultCode());
        if (n1.compareTo(n3) == 0 && n2.compareTo(n4) == 0 && tmp[i].getType().getType() == rl.getType().getType())
            removed = rds.getLinksToCreate().removeReductionLink(tmp[i]);
    }
    if (!removed)
        throw new IllegalStateException("Reduction Rule doesn't exist");
    rds.getLinksToCreate().addReductionLink(rl);
//Store new values in the CDB.
//flushReductionRules(rds);
}
Also used : AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType)

Example 2 with ReductionLinkType

use of alma.alarmsystem.alarmmessage.generated.ReductionLinkType 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 3 with ReductionLinkType

use of alma.alarmsystem.alarmmessage.generated.ReductionLinkType 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 ReductionLinkType

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

the class ACSAlarmDAOImpl method addReductionRule.

public void addReductionRule(ReductionDefinitions rds, ReductionLinkType rl) {
    if (rl == null)
        throw new IllegalArgumentException("Null Reduction Link argument");
    //alma.alarmsystem.alarmmessage.generated.ReductionDefinitions rds = getReductionRules();
    //Store changes in the CDB.
    alma.alarmsystem.alarmmessage.generated.ReductionLinkType[] tmp = rds.getLinksToCreate().getReductionLink();
    for (int i = 0; i < tmp.length; i++) {
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition p1 = tmp[i].getParent().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition c1 = tmp[i].getChild().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition p2 = rl.getParent().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition c2 = rl.getChild().getAlarmDefinition();
        String n1 = new String(p1.getFaultFamily() + ":" + p1.getFaultMember() + ":" + p1.getFaultCode());
        String n2 = new String(c1.getFaultFamily() + ":" + c1.getFaultMember() + ":" + c1.getFaultCode());
        String n3 = new String(p2.getFaultFamily() + ":" + p2.getFaultMember() + ":" + p2.getFaultCode());
        String n4 = new String(c2.getFaultFamily() + ":" + c2.getFaultMember() + ":" + c2.getFaultCode());
        if (n1.compareTo(n3) == 0 && n2.compareTo(n4) == 0 && tmp[i].getType().getType() == rl.getType().getType())
            throw new IllegalStateException("Reduction Rule already exist");
    }
    rds.getLinksToCreate().addReductionLink(rl);
    //Reflect the changes into the AlarmDAO
    alma.alarmsystem.alarmmessage.generated.AlarmDefinition in = rl.getParent().getAlarmDefinition();
    Alarm p = getAlarm(in.getFaultFamily() + ":" + in.getFaultMember() + ":" + in.getFaultCode());
    in = rl.getChild().getAlarmDefinition();
    Alarm c = getAlarm(in.getFaultFamily() + ":" + in.getFaultMember() + ":" + in.getFaultCode());
    if (rl.getType().getType() == ReductionLinkTypeTypeType.NODE_TYPE)
        p.addNodeChild(c);
    else if (rl.getType().getType() == ReductionLinkTypeTypeType.MULTIPLICITY_TYPE)
        p.addMultiplicityChild(c);
//Store new values in the CDB.
//flushReductionRules(rds);
}
Also used : Alarm(cern.laser.business.data.Alarm) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType)

Example 5 with ReductionLinkType

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

the class ACSAlarmDAOImpl method deleteReductionRule.

public void deleteReductionRule(ReductionDefinitions rds, ReductionLinkType rl) {
    if (rl == null)
        throw new IllegalArgumentException("Null Reduction Link argument");
    //alma.alarmsystem.alarmmessage.generated.ReductionDefinitions rds = getReductionRules();
    boolean removed = false;
    alma.alarmsystem.alarmmessage.generated.ReductionLinkType[] tmp = rds.getLinksToCreate().getReductionLink();
    for (int i = 0; i < tmp.length; i++) {
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition p1 = tmp[i].getParent().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition c1 = tmp[i].getChild().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition p2 = rl.getParent().getAlarmDefinition();
        alma.alarmsystem.alarmmessage.generated.AlarmDefinition c2 = rl.getChild().getAlarmDefinition();
        String n1 = new String(p1.getFaultFamily() + ":" + p1.getFaultMember() + ":" + p1.getFaultCode());
        String n2 = new String(c1.getFaultFamily() + ":" + c1.getFaultMember() + ":" + c1.getFaultCode());
        String n3 = new String(p2.getFaultFamily() + ":" + p2.getFaultMember() + ":" + p2.getFaultCode());
        String n4 = new String(c2.getFaultFamily() + ":" + c2.getFaultMember() + ":" + c2.getFaultCode());
        if (n1.compareTo(n3) == 0 && n2.compareTo(n4) == 0 && tmp[i].getType().getType() == rl.getType().getType())
            removed = rds.getLinksToCreate().removeReductionLink(tmp[i]);
    }
    if (!removed)
        throw new IllegalStateException("Reduction Rule doesn't exist");
    //Reflect the changes into the AlarmDAO
    alma.alarmsystem.alarmmessage.generated.AlarmDefinition in = rl.getParent().getAlarmDefinition();
    Alarm p = getAlarm(in.getFaultFamily() + ":" + in.getFaultMember() + ":" + in.getFaultCode());
    in = rl.getChild().getAlarmDefinition();
    Alarm c = getAlarm(in.getFaultFamily() + ":" + in.getFaultMember() + ":" + in.getFaultCode());
    if (rl.getType().getType() == ReductionLinkTypeTypeType.NODE_TYPE)
        p.removeNodeChild(c);
    else if (rl.getType().getType() == ReductionLinkTypeTypeType.MULTIPLICITY_TYPE)
        p.removeMultiplicityChild(c);
//Store new values in the CDB.
//flushReductionRules(rds);
}
Also used : AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) ReductionLinkType(alma.alarmsystem.alarmmessage.generated.ReductionLinkType) Alarm(cern.laser.business.data.Alarm)

Aggregations

ReductionLinkType (alma.alarmsystem.alarmmessage.generated.ReductionLinkType)7 AlarmDefinition (alma.alarmsystem.alarmmessage.generated.AlarmDefinition)5 Child (alma.alarmsystem.alarmmessage.generated.Child)4 Parent (alma.alarmsystem.alarmmessage.generated.Parent)4 ReductionDefinitions (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions)4 Alarm (cern.laser.business.data.Alarm)4 Threshold (alma.alarmsystem.alarmmessage.generated.Threshold)3 ReductionLinkDefinitionListType (alma.alarmsystem.alarmmessage.generated.ReductionLinkDefinitionListType)2 Thresholds (alma.alarmsystem.alarmmessage.generated.Thresholds)2 ValidationException (org.exolab.castor.xml.ValidationException)2 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)1 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)1 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 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1