Search in sources :

Example 1 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
	 */
public 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());
                alarmDefs.put(alarm.getAlarmId(), 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());
                alarmDefs.put(defaultAlarm.getAlarmId(), 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 2 with FaultFamily

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

the class ACSAlarmDAOImpl method loadAlarms.

/**
	 * Load alarms from CDB.
	 * 
	 * Read the alarms by the alarm definitions file of the CDB.
	 * The initialization of the alarms is not complete at this stage.
	 * In fact the categories are assigned to alarms when reading the
	 * categories from the CDB by ACSCategoryDAOImpl
	 * 
	 *  
	 * @throws Exception In case of error while parsing XML definition files
	 * 
	 * @see ACSCategoryDAOImpl
	 */
public List<FaultFamily> loadAlarms() throws Exception {
    if (conf == null) {
        throw new IllegalStateException("Missing dal");
    }
    String xml;
    try {
        xml = conf.getConfiguration(ALARM_DEFINITION_PATH);
    } catch (Throwable t) {
        return new ArrayList<FaultFamily>();
    //throw new RuntimeException("Couldn't read alarm XML", t);
    }
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = factory.newDocumentBuilder();
    } catch (Exception e) {
        throw new Exception("Error building the DocumentBuilder from the DocumentBuilderFactory", e);
    }
    StringReader stringReader = new StringReader(xml);
    InputSource inputSource = new InputSource(stringReader);
    Document doc;
    try {
        doc = builder.parse(inputSource);
        if (doc == null) {
            throw new Exception("The builder returned a null Document after parsing");
        }
    } catch (Exception e) {
        throw new Exception("Error parsing XML: " + xml, e);
    }
    NodeList docChilds = doc.getChildNodes();
    if (docChilds == null || docChilds.getLength() != 1) {
        throw new Exception("Malformed xml: only one node (AlarmDefinitions) expected");
    }
    Node alarmDefNode = docChilds.item(0);
    if (alarmDefNode == null || alarmDefNode.getNodeName() != XML_DOCUMENT_TYPE) {
        throw new Exception("Malformed xml: " + XML_DOCUMENT_TYPE + " not found");
    }
    NodeList alarmDefsNodes = alarmDefNode.getChildNodes();
    Unmarshaller FF_unmarshaller = new Unmarshaller(FaultFamily.class);
    FF_unmarshaller.setValidation(false);
    FF_unmarshaller.setWhitespacePreserve(true);
    Vector<FaultFamily> cdbFamilies = new Vector<FaultFamily>();
    for (int t = 0; t < alarmDefsNodes.getLength(); t++) {
        Node alarmDef = alarmDefsNodes.item(t);
        FaultFamily family;
        try {
            family = (FaultFamily) FF_unmarshaller.unmarshal(alarmDef);
            if (family == null) {
                throw new Exception("Error unmarshalling a family node");
            }
            cdbFamilies.add(family);
        } catch (Exception e) {
            throw new Exception("Error parsing " + alarmDef.getNodeName(), e);
        }
        family.validate();
    }
    alarmDefs.clear();
    srcDefs.clear();
    generateAlarmsMap(cdbFamilies);
    loadReductionRules();
    return cdbFamilies;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) 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) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) Unmarshaller(org.exolab.castor.xml.Unmarshaller) Vector(java.util.Vector)

Example 3 with FaultFamily

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

the class SourceManager method deleteSource.

/**
	 * This method allows to delete a <code>Source</code> from the configuration of the Alarm System
	 * 
	 * @param source The source to be deleted
	 * @return true if the source was deleted correctly,
	 * 		   false otherwise
	 * @throws IllegalOperationException when there are not sources to be deleted
	 */
public boolean deleteSource(Source source) throws IllegalOperationException {
    AlarmManager am = AlarmSystemManager.getInstance().getAlarmManager();
    List<FaultFamily> allAlarms = am.getAllAlarms();
    for (Iterator<FaultFamily> iterator = allAlarms.iterator(); iterator.hasNext(); ) {
        FaultFamily faultFamily = (FaultFamily) iterator.next();
        if (faultFamily.getAlarmSource().compareTo(source.getName()) == 0) {
            throw new IllegalOperationException("Cannot delete source: sources in use by the FaultFamily " + faultFamily.getName());
        }
    }
    if (_sources.length == 0)
        return false;
    Source[] newSources = new Source[_sources.length - 1];
    for (int i = 0; i < _sources.length; i++) {
        if (_sources[i].getName().compareTo(source.getName()) == 0) {
            for (i++; i < _sources.length; i++) newSources[i - 1] = _sources[i];
            _sources = newSources;
            return true;
        } else if (i + 1 != _sources.length)
            newSources[i] = _sources[i];
    }
    return false;
}
Also used : FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) Source(cern.laser.business.data.Source)

Example 4 with FaultFamily

use of alma.acs.alarmsystem.generated.FaultFamily 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 5 with FaultFamily

use of alma.acs.alarmsystem.generated.FaultFamily 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)

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