Search in sources :

Example 1 with AlarmDefinition

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

the class ACSCategoryDAOImpl method flushCategory.

public void flushCategory() {
    if (conf == null || !conf.isWriteable())
        throw new IllegalStateException("no writable configuration accessor");
    CategoryDefinitions acds = new CategoryDefinitions();
    CategoryDefinitionListType ctc = new CategoryDefinitionListType();
    acds.setCategoriesToCreate(ctc);
    AlarmCategoryDefinitions linksTop = new AlarmCategoryDefinitions();
    AlarmCategoryLinkDefinitionListType cltc = new AlarmCategoryLinkDefinitionListType();
    linksTop.setCategoryLinksToCreate(cltc);
    Iterator<Category> i = catPathToCategory.values().iterator();
    while (i.hasNext()) {
        CategoryDefinition cd = new CategoryDefinition();
        CategoryImpl ci = (CategoryImpl) i.next();
        cd.setDescription(ci.getDescription());
        cd.setPath(ci.getPath());
        ctc.addCategoryDefinition(cd);
        Iterator<?> aidsi = ci.getAlarmIds().iterator();
        while (aidsi.hasNext()) {
            String aid = (String) aidsi.next();
            Alarm a = alarmDao.getAlarm(aid);
            if (a == null)
                throw new RuntimeException("Category has a link to a non-existent alarm");
            AlarmCategoryLinkType link = new AlarmCategoryLinkType();
            alma.alarmsystem.alarmmessage.generated.Alarm linkAlarm = new alma.alarmsystem.alarmmessage.generated.Alarm();
            alma.alarmsystem.alarmmessage.generated.Category linkCat = new alma.alarmsystem.alarmmessage.generated.Category();
            link.setAlarm(linkAlarm);
            link.setCategory(linkCat);
            AlarmDefinition linkAlarmDef = new AlarmDefinition();
            CategoryDefinition linkCatDef = new CategoryDefinition();
            linkAlarm.setAlarmDefinition(linkAlarmDef);
            linkCat.setCategoryDefinition(linkCatDef);
            linkAlarmDef.setFaultCode(a.getTriplet().getFaultCode().intValue());
            linkAlarmDef.setFaultFamily(a.getTriplet().getFaultFamily());
            linkAlarmDef.setFaultMember(a.getTriplet().getFaultMember());
            linkCatDef.setPath(ci.getPath());
            cltc.addAlarmCategoryLink(link);
        }
    }
    StringWriter catList = new StringWriter();
    try {
        acds.marshal(catList);
    } catch (Exception e) {
        throw new RuntimeException("Failed to encode categories", e);
    }
    StringWriter linkList = new StringWriter();
    try {
        acds.marshal(linkList);
    } catch (Exception e) {
        throw new RuntimeException("Failed to encode link", e);
    }
    try {
        conf.setConfiguration(CATEGORY_DEFINITION_PATH, catList.toString());
        conf.setConfiguration(ALARM_CATEGORY_DEFINITION_PATH, linkList.toString());
    } catch (Exception e) {
        throw new RuntimeException("Failed to store configuration", e);
    }
}
Also used : Category(cern.laser.business.data.Category) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) AlarmCategoryLinkType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType) CategoryDefinitions(alma.alarmsystem.alarmmessage.generated.CategoryDefinitions) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) CategoryImpl(cern.laser.business.data.CategoryImpl) StringWriter(java.io.StringWriter) Alarm(cern.laser.business.data.Alarm) AlarmCategoryLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType) CategoryDefinitionListType(alma.alarmsystem.alarmmessage.generated.CategoryDefinitionListType) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) CategoryDefinition(alma.alarmsystem.alarmmessage.generated.CategoryDefinition)

Example 2 with AlarmDefinition

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

the class ACSCategoryDAOImpl method linkWithAlarms.

public void linkWithAlarms() {
    if (conf == null)
        throw new IllegalStateException("null configuration accessor");
    if (alarmDao == null)
        throw new IllegalStateException("missing alarm DAO");
    String path = ALARM_CATEGORY_DEFINITION_PATH;
    String xml;
    try {
        xml = conf.getConfiguration(path);
    } catch (Exception e) {
        throw new RuntimeException("Failed to read " + path);
    }
    AlarmCategoryDefinitions acds;
    try {
        acds = (AlarmCategoryDefinitions) AlarmCategoryDefinitions.unmarshalAlarmCategoryDefinitions(new StringReader(xml));
    } catch (Exception e) {
        throw new RuntimeException("Failed to parse " + path);
    }
    AlarmCategoryLinkDefinitionListType cltc = acds.getCategoryLinksToCreate();
    if (cltc == null)
        throw new RuntimeException("Missing category-links-to-create in " + path);
    AlarmCategoryLinkType[] links = cltc.getAlarmCategoryLink();
    for (int a = 0; a < links.length; a++) {
        AlarmCategoryLinkType l = links[a];
        alma.alarmsystem.alarmmessage.generated.Alarm linkAlarm = l.getAlarm();
        alma.alarmsystem.alarmmessage.generated.Category linkCat = l.getCategory();
        if (linkAlarm == null || linkCat == null)
            throw new RuntimeException("Missing alarm or category in a link in " + path);
        AlarmDefinition ad = linkAlarm.getAlarmDefinition();
        CategoryDefinition cd = linkCat.getCategoryDefinition();
        if (ad == null || cd == null)
            throw new RuntimeException("Missing alarm-definition or category-definition in " + path);
        String lff = ad.getFaultFamily();
        String lfm = ad.getFaultMember();
        if (lff == null || lfm == null)
            throw new RuntimeException("Missing fault-family or fault-member in " + path);
        String alarmId = Triplet.toIdentifier(lff, lfm, new Integer(ad.getFaultCode()));
        String catPath = cd.getPath();
        if (catPath == null)
            throw new RuntimeException("Missing category path in " + path);
        Alarm alarm = alarmDao.getAlarm(alarmId);
        Category cat = getCategoryByPath(catPath);
        if (alarm == null)
            throw new RuntimeException("Missing alarm with ID " + alarmId);
        if (cat == null)
            throw new RuntimeException("Missing category with path " + catPath);
        cat.addAlarm(alarm);
    }
    Iterator<Category> i = catPathToCategory.values().iterator();
    while (i.hasNext()) {
        Category ci = i.next();
        String cPath = ci.getPath();
        int lastcolon = cPath.lastIndexOf(':');
        if (lastcolon >= 0) {
            String parentCPath = cPath.substring(0, lastcolon);
            CategoryImpl cp = (CategoryImpl) catPathToCategory.get(parentCPath);
            if (cp != null) {
                cp.addChildCategory(ci);
            }
        }
    }
}
Also used : Category(cern.laser.business.data.Category) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) AlarmCategoryLinkType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) CategoryImpl(cern.laser.business.data.CategoryImpl) Alarm(cern.laser.business.data.Alarm) StringReader(java.io.StringReader) AlarmCategoryLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) CategoryDefinition(alma.alarmsystem.alarmmessage.generated.CategoryDefinition)

Example 3 with AlarmDefinition

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

the class ACSCategoryDAOImpl method linkWithAlarms.

public void linkWithAlarms() {
    if (conf == null)
        throw new IllegalStateException("null configuration accessor");
    if (alarmDao == null)
        throw new IllegalStateException("missing alarm DAO");
    String path = ALARM_CATEGORY_DEFINITION_PATH;
    String xml;
    try {
        xml = conf.getConfiguration(path);
    } catch (Exception e) {
        throw new RuntimeException("Failed to read " + path);
    }
    AlarmCategoryDefinitions acds;
    try {
        acds = (AlarmCategoryDefinitions) AlarmCategoryDefinitions.unmarshalAlarmCategoryDefinitions(new StringReader(xml));
    } catch (Exception e) {
        throw new RuntimeException("Failed to parse " + path);
    }
    AlarmCategoryLinkDefinitionListType cltc = acds.getCategoryLinksToCreate();
    if (cltc == null)
        throw new RuntimeException("Missing category-links-to-create in " + path);
    AlarmCategoryLinkType[] links = cltc.getAlarmCategoryLink();
    for (int a = 0; a < links.length; a++) {
        AlarmCategoryLinkType l = links[a];
        alma.alarmsystem.alarmmessage.generated.Alarm linkAlarm = l.getAlarm();
        alma.alarmsystem.alarmmessage.generated.Category linkCat = l.getCategory();
        if (linkAlarm == null || linkCat == null)
            throw new RuntimeException("Missing alarm or category in a link in " + path);
        AlarmDefinition ad = linkAlarm.getAlarmDefinition();
        CategoryDefinition cd = linkCat.getCategoryDefinition();
        if (ad == null || cd == null)
            throw new RuntimeException("Missing alarm-definition or category-definition in " + path);
        String lff = ad.getFaultFamily();
        String lfm = ad.getFaultMember();
        if (lff == null || lfm == null)
            throw new RuntimeException("Missing fault-family or fault-member in " + path);
        String alarmId = Triplet.toIdentifier(lff, lfm, new Integer(ad.getFaultCode()));
        String catPath = cd.getPath();
        if (catPath == null)
            throw new RuntimeException("Missing category path in " + path);
        Alarm alarm = alarmDao.getAlarm(alarmId);
        Category cat = getCategoryByPath(catPath);
        if (alarm == null)
            throw new RuntimeException("Missing alarm with ID " + alarmId);
        if (cat == null)
            throw new RuntimeException("Missing category with path " + catPath);
        cat.addAlarm(alarm);
    }
    Iterator i = catPathToCategory.values().iterator();
    while (i.hasNext()) {
        CategoryImpl ci = (CategoryImpl) i.next();
        String cPath = ci.getPath();
        int lastcolon = cPath.lastIndexOf(':');
        if (lastcolon >= 0) {
            String parentCPath = cPath.substring(0, lastcolon);
            CategoryImpl cp = (CategoryImpl) catPathToCategory.get(parentCPath);
            if (cp != null) {
                cp.addChildCategory(ci);
            }
        }
    }
}
Also used : Category(cern.laser.business.data.Category) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) AlarmCategoryLinkType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) CategoryImpl(cern.laser.business.data.CategoryImpl) Alarm(cern.laser.business.data.Alarm) StringReader(java.io.StringReader) Iterator(java.util.Iterator) AlarmCategoryLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) CategoryDefinition(alma.alarmsystem.alarmmessage.generated.CategoryDefinition)

Example 4 with AlarmDefinition

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

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

the class ACSCategoryDAOImpl method flushCategory.

public void flushCategory() {
    if (conf == null || !conf.isWriteable())
        throw new IllegalStateException("no writable configuration accessor");
    CategoryDefinitions acds = new CategoryDefinitions();
    CategoryDefinitionListType ctc = new CategoryDefinitionListType();
    acds.setCategoriesToCreate(ctc);
    AlarmCategoryDefinitions linksTop = new AlarmCategoryDefinitions();
    AlarmCategoryLinkDefinitionListType cltc = new AlarmCategoryLinkDefinitionListType();
    linksTop.setCategoryLinksToCreate(cltc);
    Iterator<Category> i = catPathToCategory.values().iterator();
    while (i.hasNext()) {
        CategoryDefinition cd = new CategoryDefinition();
        CategoryImpl ci = (CategoryImpl) i.next();
        cd.setDescription(ci.getDescription());
        cd.setPath(ci.getPath());
        ctc.addCategoryDefinition(cd);
        Iterator aidsi = ci.getAlarmIds().iterator();
        while (aidsi.hasNext()) {
            String aid = (String) aidsi.next();
            Alarm a = alarmDao.getAlarm(aid);
            if (a == null)
                throw new RuntimeException("Category has a link to a non-existent alarm");
            AlarmCategoryLinkType link = new AlarmCategoryLinkType();
            alma.alarmsystem.alarmmessage.generated.Alarm linkAlarm = new alma.alarmsystem.alarmmessage.generated.Alarm();
            alma.alarmsystem.alarmmessage.generated.Category linkCat = new alma.alarmsystem.alarmmessage.generated.Category();
            link.setAlarm(linkAlarm);
            link.setCategory(linkCat);
            AlarmDefinition linkAlarmDef = new AlarmDefinition();
            CategoryDefinition linkCatDef = new CategoryDefinition();
            linkAlarm.setAlarmDefinition(linkAlarmDef);
            linkCat.setCategoryDefinition(linkCatDef);
            linkAlarmDef.setFaultCode(a.getTriplet().getFaultCode().intValue());
            linkAlarmDef.setFaultFamily(a.getTriplet().getFaultFamily());
            linkAlarmDef.setFaultMember(a.getTriplet().getFaultMember());
            linkCatDef.setPath(ci.getPath());
            cltc.addAlarmCategoryLink(link);
        }
    }
    StringWriter catList = new StringWriter();
    try {
        acds.marshal(catList);
    } catch (Exception e) {
        throw new RuntimeException("Failed to encode categories", e);
    }
    StringWriter linkList = new StringWriter();
    try {
        acds.marshal(linkList);
    } catch (Exception e) {
        throw new RuntimeException("Failed to encode link", e);
    }
    try {
        conf.setConfiguration(CATEGORY_DEFINITION_PATH, catList.toString().replaceFirst("xsi:type=\".*\"", ""));
        conf.setConfiguration(ALARM_CATEGORY_DEFINITION_PATH, linkList.toString().replaceFirst("xsi:type=\".*\"", ""));
    } catch (Exception e) {
        throw new RuntimeException("Failed to store configuration", e);
    }
}
Also used : Category(cern.laser.business.data.Category) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) AlarmCategoryLinkType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType) CategoryDefinitions(alma.alarmsystem.alarmmessage.generated.CategoryDefinitions) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) CategoryImpl(cern.laser.business.data.CategoryImpl) StringWriter(java.io.StringWriter) Alarm(cern.laser.business.data.Alarm) Iterator(java.util.Iterator) AlarmCategoryLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType) CategoryDefinitionListType(alma.alarmsystem.alarmmessage.generated.CategoryDefinitionListType) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) CategoryDefinition(alma.alarmsystem.alarmmessage.generated.CategoryDefinition)

Aggregations

AlarmDefinition (alma.alarmsystem.alarmmessage.generated.AlarmDefinition)6 Alarm (cern.laser.business.data.Alarm)5 AlarmCategoryDefinitions (alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions)4 AlarmCategoryLinkDefinitionListType (alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType)4 AlarmCategoryLinkType (alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType)4 CategoryDefinition (alma.alarmsystem.alarmmessage.generated.CategoryDefinition)4 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)4 Category (cern.laser.business.data.Category)4 CategoryImpl (cern.laser.business.data.CategoryImpl)4 ValidationException (org.exolab.castor.xml.ValidationException)3 CategoryDefinitionListType (alma.alarmsystem.alarmmessage.generated.CategoryDefinitionListType)2 CategoryDefinitions (alma.alarmsystem.alarmmessage.generated.CategoryDefinitions)2 Child (alma.alarmsystem.alarmmessage.generated.Child)2 Parent (alma.alarmsystem.alarmmessage.generated.Parent)2 ReductionDefinitions (alma.alarmsystem.alarmmessage.generated.ReductionDefinitions)2 ReductionLinkType (alma.alarmsystem.alarmmessage.generated.ReductionLinkType)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 Iterator (java.util.Iterator)2