Search in sources :

Example 1 with ACSAlarmDAOImpl

use of cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl 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 ACSAlarmDAOImpl

use of cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl in project ACS by ACS-Community.

the class DAOManager method getAlarmDAO.

public AlarmDAO getAlarmDAO() {
    if (_conf == null) {
        throw new IllegalStateException("DAOManager not connected to DAL");
    }
    if (_alarmDAOImpl == null) {
        _alarmDAOImpl = new ACSAlarmDAOImpl(_contServ.getLogger());
        ((ACSAlarmDAOImpl) _alarmDAOImpl).setConfAccessor(_conf);
    }
    return _alarmDAOImpl;
}
Also used : ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Example 3 with ACSAlarmDAOImpl

use of cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl in project ACS by ACS-Community.

the class AlarmManager method addFaultMember.

/**
	 * Adds a new Fault Member to a given Fault Family.
	 * @param ff The Fault Family to which the Fault Member will be added
	 * @param fm The Fault Member to be added
	 * @throws NullPointerException If the given Fault Family (or its name),
	 * the given Fault Member (or its name) or both are null
	 * @throws IllegalOperationException If the Fault Member already exists
	 * or the Fault Family doesn't exist
	 */
public void addFaultMember(FaultFamily ff, FaultMember fm) throws NullPointerException, IllegalOperationException {
    if (ff == null || ff.getName() == null)
        throw new NullPointerException("The Fault Family (or its name) to which the Fault Member will be added is null");
    if (fm == null || fm.getName() == null)
        throw new NullPointerException("The Fault Member (or its name) to be added is null");
    for (Iterator<FaultFamily> iterator = _ffList.iterator(); iterator.hasNext(); ) {
        FaultFamily fft = (FaultFamily) iterator.next();
        if (fft.getName().compareTo(ff.getName()) == 0) {
            for (Iterator<FaultMember> iterator2 = Arrays.asList(fft.getFaultMember()).iterator(); iterator2.hasNext(); ) {
                FaultMember fmt = (FaultMember) iterator2.next();
                if (fmt.getName().compareTo(fm.getName()) == 0) {
                    throw new IllegalOperationException("The Fault Member " + fm.getName() + " already exists");
                }
            }
            fft.addFaultMember(fm);
            ObjectState os = _objState.get(fft.getName());
            if (os == null)
                throw new IllegalOperationException("There is no ObjectState associated with the given Fault Family");
            os.update();
            Vector<FaultFamily> ffs = new Vector<FaultFamily>();
            ffs.add(ff);
            ((ACSAlarmDAOImpl) _alarmDAO).removeAlarmsMap(ffs);
            ((ACSAlarmDAOImpl) _alarmDAO).generateAlarmsMap(ffs);
            return;
        }
    }
    throw new IllegalOperationException("The Fault Family " + ff.getName() + " doesn't exists");
}
Also used : FaultMember(alma.acs.alarmsystem.generated.FaultMember) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Vector(java.util.Vector) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Example 4 with ACSAlarmDAOImpl

use of cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl in project ACS by ACS-Community.

the class AlarmManager method saveToCDB.

public void saveToCDB() {
    Set<String> keyset = _objState.keySet();
    String[] objs = new String[keyset.size()];
    keyset.toArray(objs);
    for (int i = 0; i < objs.length; i++) {
        try {
            ObjectState os = _objState.get(objs[i]);
            FaultFamily ff = getFaultFamily(objs[i]);
            if (ff != null)
                ff.validate();
            switch(os.getAction()) {
                case //Error, no state assigned.
                -1:
                    break;
                case 0:
                    break;
                case 1:
                    ((ACSAlarmDAOImpl) _alarmDAO).addFaultFamily(ff);
                    break;
                case 2:
                    ((ACSAlarmDAOImpl) _alarmDAO).updateFaultFamily(ff);
                    break;
                case 3:
                    ff = new FaultFamily();
                    ff.setName(objs[i]);
                    ((ACSAlarmDAOImpl) _alarmDAO).removeFaultFamily(ff);
                    break;
                default:
                    //Shouldn't happen.
                    break;
            }
            _objState.remove(objs[i]);
            _objState.put(objs[i], new ObjectState(false));
        } catch (ValidationException e) {
            e.printStackTrace();
        }
    }
}
Also used : ValidationException(org.exolab.castor.xml.ValidationException) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Example 5 with ACSAlarmDAOImpl

use of cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl in project ACS by ACS-Community.

the class AlarmManager method deleteFaultMember.

/**
	 * Deletes a Fault Member of a given Fault Family. The Fault Member to be 
	 * deleted is checked against the existing Reduction Rules in order to 
	 * preserve the consistency of the application (i.e., a Fault Member cannot 
	 * be deleted if it is currently present in a Reduction Rule).
	 * @param ff The Fault Family of the Fault Member to be deleted
	 * @param fm The Fault Member to be deleted
	 * @return True if it deletes the given Fault Member, false otherwise
	 * @throws NullPointerException If the given Fault Family or Fault Member 
	 * is null
	 * @throws IllegalOperationException If the Fault Member is part of an 
	 * existing Reduction Rule
	 */
public boolean deleteFaultMember(FaultFamily ff, FaultMember fm) throws NullPointerException, IllegalOperationException {
    if (ff == null || ff.getName() == null)
        throw new NullPointerException("The Fault Family (or its name) owner of the Fault Member to be deleted is null");
    if (fm == null || fm.getName() == null)
        throw new NullPointerException("The Fault Member to be deleted (or its name) is null");
    List<ReductionRule> rrL = _reductionManager.getNodeReductionRules();
    for (ReductionRule rr : rrL) {
        String[] tr = rr.getParent().getAlarmId().split(":");
        if (tr[0].compareTo(ff.getName()) == 0 && tr[1].compareTo(fm.getName()) == 0)
            throw new IllegalOperationException("The Fault Member is currently associated to a Reduction Rule");
    }
    for (Iterator<FaultFamily> iterator = _ffList.iterator(); iterator.hasNext(); ) {
        FaultFamily fft = (FaultFamily) iterator.next();
        if (fft.getName().compareTo(ff.getName()) == 0) {
            for (Iterator<FaultMember> iterator2 = Arrays.asList(fft.getFaultMember()).iterator(); iterator2.hasNext(); ) {
                FaultMember fmt = (FaultMember) iterator2.next();
                if (fmt.getName().compareTo(fm.getName()) == 0) {
                    fft.removeFaultMember(fm);
                    ObjectState os = _objState.get(fft.getName());
                    if (os == null)
                        throw new IllegalOperationException("There is no ObjectState associated with the given Fault Family");
                    os.update();
                    Vector<FaultFamily> ffs = new Vector<FaultFamily>();
                    ffs.add(ff);
                    ((ACSAlarmDAOImpl) _alarmDAO).removeAlarmsMap(ffs);
                    ((ACSAlarmDAOImpl) _alarmDAO).generateAlarmsMap(ffs);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FaultMember(alma.acs.alarmsystem.generated.FaultMember) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Vector(java.util.Vector) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Aggregations

ACSAlarmDAOImpl (cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)16 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)11 Vector (java.util.Vector)10 FaultCode (alma.acs.alarmsystem.generated.FaultCode)3 FaultMember (alma.acs.alarmsystem.generated.FaultMember)3 Alarms (alma.acs.alarmsystem.generated.Alarms)2 Category (alma.acs.alarmsystem.generated.Category)2 Alarm (cern.laser.business.data.Alarm)2 ValidationException (org.exolab.castor.xml.ValidationException)2 FaultMemberDefault (alma.acs.alarmsystem.generated.FaultMemberDefault)1 AlarmDefinition (alma.alarmsystem.alarmmessage.generated.AlarmDefinition)1 Child (alma.alarmsystem.alarmmessage.generated.Child)1 Parent (alma.alarmsystem.alarmmessage.generated.Parent)1 ReductionDefinitions (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions)1 ReductionLinkType (alma.alarmsystem.alarmmessage.generated.ReductionLinkType)1 Threshold (alma.alarmsystem.alarmmessage.generated.Threshold)1 ACSCategoryDAOImpl (cl.utfsm.acs.acg.dao.ACSCategoryDAOImpl)1 ACSSourceDAOImpl (cl.utfsm.acs.acg.dao.ACSSourceDAOImpl)1