Search in sources :

Example 21 with FaultFamily

use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.

the class AlarmManagerTest method testGetAllAlarms.

public void testGetAllAlarms() {
    _am = AlarmManager.getInstance(_daoManager.getAlarmDAO());
    _am.loadFromCDB();
    List<FaultFamily> ffList = _am.getAllAlarms();
    assertNotNull(ffList);
    for (FaultFamily faultFamily : ffList) {
        assertNotNull(faultFamily);
    }
}
Also used : FaultFamily(alma.acs.alarmsystem.generated.FaultFamily)

Example 22 with FaultFamily

use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method generateAlarmsMap.

/**
	 * Generate the alarms from the definition of the fault families.
	 * The alarms will be added into the HashMap with their triplet as key.
	 * The default item has FM="*".
	 * 
	 * The sources read from the families are also added to the HashMap of the sources
	 *  
	 * @param families The FF read from the CDB
	 */
private void generateAlarmsMap(Vector<FaultFamily> families) {
    if (families == null) {
        throw new IllegalArgumentException("Invalid null vector of FFs");
    }
    for (FaultFamily family : families) {
        String FF = family.getName();
        String helpUrl = family.getHelpUrl();
        String source = family.getAlarmSource();
        Contact contactPerson = family.getContact();
        FaultMember[] FMs = family.getFaultMember();
        FaultMemberDefault defaultFM = family.getFaultMemberDefault();
        FaultCode[] FCs = family.getFaultCode();
        // There should be at least one FC in the CDB
        if (FCs == null || FCs.length == 0) {
            logger.log(AcsLogLevel.WARNING, "No FC defined for family " + family.getName());
            continue;
        }
        // There should be at least one FM or a default FM defined in the CDB
        if (defaultFM == null && (FMs == null || FMs.length == 0)) {
            logger.log(AcsLogLevel.WARNING, "No FM defined for family " + family.getName());
            continue;
        }
        // Iterate over the FCs
        for (FaultCode code : FCs) {
            int FC = code.getValue();
            int priority = code.getPriority();
            String action = code.getAction();
            String cause = code.getCause();
            String consequence = code.getConsequence();
            String problemDesc = code.getProblemDescription();
            boolean instant = code.getInstant();
            // Iterate over all the FMs
            for (FaultMember member : FMs) {
                alma.acs.alarmsystem.generated.Location loc = member.getLocation();
                if (loc == null) {
                    loc = new alma.acs.alarmsystem.generated.Location();
                }
                if (loc.getBuilding() == null) {
                    loc.setBuilding("");
                }
                if (loc.getFloor() == null) {
                    loc.setFloor("");
                }
                if (loc.getMnemonic() == null) {
                    loc.setMnemonic("");
                }
                if (loc.getPosition() == null) {
                    loc.setPosition("");
                }
                if (loc.getRoom() == null) {
                    loc.setRoom("");
                }
                String FM = member.getName();
                if (FM.equals(DEFAULT_FM)) {
                    logger.log(AcsLogLevel.ERROR, "In the CDB, FM=" + DEFAULT_FM + " in family " + FF + " is not allowed");
                }
                AlarmImpl alarm = new AlarmImpl();
                alarm.setMultiplicityChildrenIds(new HashSet());
                alarm.setMultiplicityParentIds(new HashSet());
                alarm.setNodeChildrenIds(new HashSet());
                alarm.setNodeParentIds(new HashSet());
                alarm.setAction(action);
                alarm.setTriplet(new Triplet(FF, FM, FC));
                alarm.setCategories(new HashSet<Category>());
                alarm.setCause(cause);
                alarm.setConsequence(consequence);
                alarm.setProblemDescription(problemDesc);
                try {
                    alarm.setHelpURL(new URL(helpUrl));
                } catch (MalformedURLException e) {
                    alarm.setHelpURL(null);
                }
                alarm.setInstant(instant);
                Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
                alarm.setLocation(location);
                if (contactPerson.getEmail() != null) {
                    alarm.setPiquetEmail(contactPerson.getEmail());
                } else {
                    alarm.setPiquetEmail("");
                }
                if (contactPerson.getGsm() != null) {
                    alarm.setPiquetGSM(contactPerson.getGsm());
                } else {
                    alarm.setPiquetGSM("");
                }
                alarm.setPriority(priority);
                ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
                alarm.setResponsiblePerson(responsible);
                SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
                Source src = new Source(srcDef, responsible);
                alarm.setSource(src);
                alarm.setIdentifier(alarm.getTriplet().toIdentifier());
                addAlarmToCache(alarm);
                if (!srcDefs.containsKey(source)) {
                    srcDefs.put(src.getSourceId(), src);
                    logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
                }
                logger.log(AcsLogLevel.DEBUG, "Alarm added " + alarm.getAlarmId());
            }
            // Add the default
            if (defaultFM != null) {
                alma.acs.alarmsystem.generated.Location loc = defaultFM.getLocation();
                if (loc == null) {
                    loc = new alma.acs.alarmsystem.generated.Location();
                }
                if (loc.getBuilding() == null) {
                    loc.setBuilding("");
                }
                if (loc.getFloor() == null) {
                    loc.setFloor("");
                }
                if (loc.getMnemonic() == null) {
                    loc.setMnemonic("");
                }
                if (loc.getPosition() == null) {
                    loc.setPosition("");
                }
                if (loc.getRoom() == null) {
                    loc.setRoom("");
                }
                AlarmImpl defaultAlarm = new AlarmImpl();
                defaultAlarm.setMultiplicityChildrenIds(new HashSet());
                defaultAlarm.setMultiplicityParentIds(new HashSet());
                defaultAlarm.setNodeChildrenIds(new HashSet());
                defaultAlarm.setNodeParentIds(new HashSet());
                defaultAlarm.setAction(action);
                defaultAlarm.setCategories(new HashSet<Category>());
                defaultAlarm.setCause(cause);
                defaultAlarm.setConsequence(consequence);
                defaultAlarm.setProblemDescription(problemDesc);
                try {
                    defaultAlarm.setHelpURL(new URL(helpUrl));
                } catch (MalformedURLException e) {
                    defaultAlarm.setHelpURL(null);
                }
                defaultAlarm.setInstant(instant);
                Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
                defaultAlarm.setLocation(location);
                defaultAlarm.setPiquetEmail(contactPerson.getEmail());
                defaultAlarm.setPiquetGSM(contactPerson.getGsm());
                defaultAlarm.setPriority(priority);
                ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
                defaultAlarm.setResponsiblePerson(responsible);
                SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
                Source src = new Source(srcDef, responsible);
                defaultAlarm.setSource(src);
                defaultAlarm.setIdentifier(defaultAlarm.getTriplet().toIdentifier());
                Triplet triplet = new Triplet(FF, DEFAULT_FM, FC);
                defaultAlarm.setTriplet(triplet);
                defaultAlarm.setIdentifier(triplet.toIdentifier());
                addAlarmToCache(defaultAlarm);
                if (!srcDefs.containsKey(source)) {
                    srcDefs.put(src.getSourceId(), src);
                    logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
                }
                logger.log(AcsLogLevel.DEBUG, "Default alarm added " + defaultAlarm.getAlarmId());
            }
        }
    }
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) MalformedURLException(java.net.MalformedURLException) SourceDefinition(cern.laser.business.definition.data.SourceDefinition) Category(cern.laser.business.data.Category) URL(java.net.URL) Source(cern.laser.business.data.Source) InputSource(org.xml.sax.InputSource) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) HashSet(java.util.HashSet) FaultMember(alma.acs.alarmsystem.generated.FaultMember) Triplet(cern.laser.business.data.Triplet) Contact(alma.acs.alarmsystem.generated.Contact) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) AlarmImpl(cern.laser.business.data.AlarmImpl) Location(cern.laser.business.data.Location)

Example 23 with FaultFamily

use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.

the class AlarmManager method addFaultCode.

/**
	 * Adds a new Fault Code to a given Fault Family.
	 * @param ff The Fault Family to which the Fault Code will be added
	 * @param fm The Fault Code to be added
	 * @throws NullPointerException If the given Fault Family (or its name),
	 * the given Fault Code or both are null
	 * @throws IllegalOperationException If the Fault Code already exists
	 * or the Fault Family doesn't exist
	 */
public void addFaultCode(FaultFamily ff, FaultCode fc) throws NullPointerException, IllegalOperationException {
    if (ff == null || ff.getName() == null)
        throw new NullPointerException("The Fault Family (or its name) to which the Fault Code will be added is null");
    if (fc == null)
        throw new NullPointerException("The Fault Code 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<FaultCode> iterator2 = Arrays.asList(fft.getFaultCode()).iterator(); iterator2.hasNext(); ) {
                FaultCode fct = (FaultCode) iterator2.next();
                if (fct.getValue() == fc.getValue()) {
                    throw new IllegalOperationException("The Fault Code " + fc.getValue() + " already exists");
                }
            }
            fft.addFaultCode(fc);
            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 : FaultCode(alma.acs.alarmsystem.generated.FaultCode) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Vector(java.util.Vector) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Example 24 with FaultFamily

use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.

the class AlarmManager method updateFaultCode.

/**
	 * Modifies a Fault Code of a given Fault Family.
	 * @param ff The Fault Family to which belongs the Fault Code to be changed
	 * @param fc The Fault Code to be changed
	 * @param fci The Fault Code with the new values
	 * @throws NullPointerException If any (or both) of the given Fault Codes
	 * or the Fault Family (or its name) or both are null
	 * @throws IllegalOperationException If the Fault Family doesn't exists
	 */
public void updateFaultCode(FaultFamily ff, FaultCode fc, FaultCode fci) throws NullPointerException, IllegalOperationException {
    if (ff == null || ff.getName() == null)
        throw new NullPointerException("The Fault Family (or its name) is null");
    if (fc == null)
        throw new NullPointerException("The Fault Code to be changed is null");
    if (fci == null)
        throw new NullPointerException("The Fault Code with the new values is null");
    for (Iterator<FaultFamily> iterator = _ffList.iterator(); iterator.hasNext(); ) {
        FaultFamily fft = (FaultFamily) iterator.next();
        if (fft.getName().compareTo(ff.getName()) == 0) {
            for (Iterator<FaultCode> iterator2 = Arrays.asList(fft.getFaultCode()).iterator(); iterator2.hasNext(); ) {
                FaultCode fct = (FaultCode) iterator2.next();
                if (fct.getValue() == fci.getValue()) {
                    if (fc.getValue() == fci.getValue())
                        continue;
                    throw new IllegalOperationException("The Fault Code " + fci.getValue() + " already exists");
                }
            }
            for (Iterator<FaultCode> iterator2 = Arrays.asList(fft.getFaultCode()).iterator(); iterator2.hasNext(); ) {
                FaultCode fct = (FaultCode) iterator2.next();
                if (fct.getValue() == fc.getValue()) {
                    int value = fc.getValue();
                    fct.setValue(fci.getValue());
                    fct.setPriority(fci.getPriority());
                    fct.setCause(fci.getCause());
                    fct.setAction(fci.getAction());
                    fct.setConsequence(fci.getConsequence());
                    fct.setProblemDescription(fci.getProblemDescription());
                    ObjectState os = _objState.get(fft.getName());
                    if (os == null)
                        throw new IllegalOperationException("There is no ObjectState associated with the given Fault Family");
                    os.update();
                    if (value != fci.getValue()) {
                        Vector<FaultFamily> ffs = new Vector<FaultFamily>();
                        ffs.add(ff);
                        ((ACSAlarmDAOImpl) _alarmDAO).removeAlarmsMap(ffs);
                        ((ACSAlarmDAOImpl) _alarmDAO).generateAlarmsMap(ffs);
                    }
                    return;
                }
            }
            throw new IllegalOperationException("The Fault Value " + fc.getValue() + " doesn't exists");
        }
    }
    throw new IllegalOperationException("The Fault Family " + ff.getName() + " doesn't exists");
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Vector(java.util.Vector) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Example 25 with FaultFamily

use of alma.acs.alarmsystem.generated.FaultFamily in project ACS by ACS-Community.

the class AlarmManager method deleteFaultFamily.

/**
	 * Deletes a Fault Family. The Fault Family to be deleted is checked 
	 * against the existing Reduction Rules in order to preserve the 
	 * consistency of the application (i.e., a Fault Code cannot be 
	 * deleted if it is currently present in a Reduction Rule).
	 * @param ff The Fault Family to be deleted
	 * @return True if it deletes the given Fault Family, false otherwise
	 * @throws NullPointerException If the given Fault Family (or its name)
	 * is null
	 * @throws IllegalOperationException If the Fault Family is part of an 
	 * existing Reduction Rule
	 */
public boolean deleteFaultFamily(FaultFamily ff) throws NullPointerException, IllegalOperationException {
    if (ff == null || ff.getName() == null)
        throw new NullPointerException("The Fault Family (or its name) to be deleted is null");
    //Check Reduction Rules
    List<ReductionRule> rrL = _reductionManager.getNodeReductionRules();
    for (ReductionRule rr : rrL) {
        String[] tr = rr.getParent().getAlarmId().split(":");
        if (tr[0].compareTo(ff.getName()) == 0)
            throw new IllegalOperationException("The Fault Family is currently associated to a Reduction Rule");
    }
    //Check Categories
    List<Category> catL = _categoryManager.getAllCategories();
    for (Category c : catL) {
        String[] sFFL = c.getAlarms().getFaultFamily();
        if (sFFL.length > 1)
            continue;
        for (String sFF : sFFL) {
            if (sFF.compareTo(ff.getName()) == 0)
                throw new IllegalOperationException("There is a category that only has this FaultFamily");
        }
    }
    for (Iterator<FaultFamily> iterator = _ffList.iterator(); iterator.hasNext(); ) {
        FaultFamily fft = (FaultFamily) iterator.next();
        if (fft.getName().compareTo(ff.getName()) == 0) {
            iterator.remove();
            ObjectState os = _objState.get(fft.getName());
            if (os == null)
                throw new IllegalOperationException("There is no ObjectState associated with the given Fault Family");
            os.delete();
            for (Category c : catL) {
                Alarms als = c.getAlarms();
                if (als.removeFaultFamily(ff.getName())) {
                    c.setAlarms(als);
                    _categoryManager.updateCategory(c, c);
                }
            }
            Vector<FaultFamily> ffs = new Vector<FaultFamily>();
            ffs.add(ff);
            ((ACSAlarmDAOImpl) _alarmDAO).removeAlarmsMap(ffs);
            return true;
        }
    }
    return false;
}
Also used : Category(alma.acs.alarmsystem.generated.Category) Alarms(alma.acs.alarmsystem.generated.Alarms) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Vector(java.util.Vector) ACSAlarmDAOImpl(cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)

Aggregations

FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)47 FaultCode (alma.acs.alarmsystem.generated.FaultCode)19 FaultMember (alma.acs.alarmsystem.generated.FaultMember)19 Vector (java.util.Vector)14 ACSAlarmDAOImpl (cl.utfsm.acs.acg.dao.ACSAlarmDAOImpl)11 Contact (alma.acs.alarmsystem.generated.Contact)7 FaultMemberDefault (alma.acs.alarmsystem.generated.FaultMemberDefault)7 Point (org.eclipse.swt.graphics.Point)7 Alarm (cern.laser.business.data.Alarm)6 MalformedURLException (java.net.MalformedURLException)6 ArrayList (java.util.ArrayList)5 ValidationException (org.exolab.castor.xml.ValidationException)5 Category (alma.acs.alarmsystem.generated.Category)4 Location (alma.acs.alarmsystem.generated.Location)4 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)4 Source (cern.laser.business.data.Source)4 Alarms (alma.acs.alarmsystem.generated.Alarms)3 Triplet (cern.laser.business.data.Triplet)3 IllegalOperationException (cl.utfsm.acs.acg.core.IllegalOperationException)3 ReductionRule (cl.utfsm.acs.acg.core.ReductionRule)3