Search in sources :

Example 1 with AlarmImpl

use of cern.laser.business.data.AlarmImpl in project ACS by ACS-Community.

the class SourceDefinitionServiceImpl method createSource.

public void createSource(String userId, SourceDefinition sourceDefinition) throws LaserDefinitionException {
    if (sourceDefinition == null) {
        throw new LaserDefinitionNotValidException("source is null");
    }
    Source source = sourceDAO.getSource(sourceDefinition.getSourceId());
    if (source != null) {
        throw new LaserDefinitionDuplicationException("source " + sourceDefinition.getSourceId() + " already exist");
    }
    if (sourceDefinition.getResponsiblePersonId() == null) {
        throw new LaserDefinitionNotValidException("responsible id for the source definition is null");
    }
    ResponsiblePerson responsible = responsiblePersonDAO.getResponsiblePerson(sourceDefinition.getResponsiblePersonId());
    if (responsible == null) {
        throw new LaserDefinitionNotValidException("responsible with id " + sourceDefinition.getResponsiblePersonId() + " does not exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
    LOGGER.info("user " + admin_user.getName() + " creating source : " + sourceDefinition);
    // create the source
    source = new Source(sourceDefinition, responsible);
    CategoryDefinition category_definition = new CategoryDefinition(SOURCE_CATEGORY_PATH_PREFIX + sourceDefinition.getName(), "Category for source " + sourceDefinition.getName());
    Category parent_category = categoryDAO.findCategoryByPath(category_definition.getParentPath());
    Category category = new CategoryImpl(category_definition);
    parent_category.addChildCategory(category);
    categoryDAO.saveCategory(category);
    admin_user.addAdministeredCategory(category);
    laser_user.addAdministeredCategory(category);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("default category " + category_definition.getPath() + "created for source " + sourceDefinition.getName());
    source.setSurveillanceAlarmId(alarmDAO.findLaserSurveillanceAlarmId());
    sourceDAO.saveSource(source);
    // create the source surveillance alarm
    AlarmDefinition surveillance_alarm_definition = (AlarmDefinition) SOURCE_SURVEILLANCE_ALARM_DEFINITION.clone();
    surveillance_alarm_definition.setFaultMember(sourceDefinition.getName());
    surveillance_alarm_definition.setIdentifier(sourceDefinition.getName());
    Alarm surveillance_alarm = new AlarmImpl(surveillance_alarm_definition, source, responsible);
    Category surveillance_category = categoryDAO.findBySurveillanceCategory();
    surveillance_category.addAlarm(surveillance_alarm);
    category.addAlarm(surveillance_alarm);
    alarmDAO.saveAlarm(surveillance_alarm);
    categoryDAO.updateCategory(surveillance_category);
    categoryDAO.updateCategory(category);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("surveillance alarm created for source " + sourceDefinition.getName());
    source.setSurveillanceAlarmId(surveillance_alarm.getAlarmId());
    sourceDAO.updateSource(source);
    admin_user.addAdministeredSource(source);
    laser_user.addAdministeredSource(source);
    adminUserDAO.updateAdminUser(admin_user);
    adminUserDAO.updateAdminUser(laser_user);
    LOGGER.info("source created");
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) AlarmDefinition(cern.laser.business.definition.data.AlarmDefinition) Alarm(cern.laser.business.data.Alarm) AlarmImpl(cern.laser.business.data.AlarmImpl) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) Source(cern.laser.business.data.Source) CategoryDefinition(cern.laser.business.definition.data.CategoryDefinition)

Example 2 with AlarmImpl

use of cern.laser.business.data.AlarmImpl in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method updateAlarmReductionRule.

/**
	 * Update the reduction rules involving the passed alarm
	 * 
	 * @param alarm The parent alarm whose reduction rule has to be
	 *  			updated
	 */
private void updateAlarmReductionRule(AlarmImpl alarm) {
    if (alarm == null) {
        throw new IllegalArgumentException("The passed alarm can't be null");
    }
    Collection<Alarm> cc = alarmDefs.values();
    AlarmImpl[] allAlarms = new AlarmImpl[cc.size()];
    cc.toArray(allAlarms);
    int num = allAlarms.length;
    LinkSpec[] ls = new LinkSpec[reductionRules.size()];
    reductionRules.toArray(ls);
    for (LinkSpec lsb : ls) {
        if (lsb.matchChild(alarm)) {
            AlarmRefMatcher parentMatcher = lsb._parent;
            boolean isMulti = lsb.isMultiplicity();
            for (int c = 0; c < num; c++) {
                if (alarm.getAlarmId().equals(allAlarms[c].getAlarmId())) {
                    continue;
                }
                AlarmImpl aic = allAlarms[c];
                if (parentMatcher.isMatch(aic)) {
                    if (isMulti) {
                        addMultiplicityChild(aic, alarm);
                        aic.setMultiplicityThreshold(theThreshods.get(aic.getAlarmId()));
                    } else {
                        addNodeChild(aic, alarm);
                    }
                }
            }
        } else if (lsb.matchParent(alarm)) {
            AlarmRefMatcher childMatcher = lsb._child;
            boolean isMulti = lsb.isMultiplicity();
            for (int c = 0; c < num; c++) {
                if (alarm.getAlarmId().equals(allAlarms[c].getAlarmId())) {
                    continue;
                }
                AlarmImpl aic = allAlarms[c];
                if (childMatcher.isMatch(aic)) {
                    if (isMulti) {
                        addMultiplicityChild(alarm, aic);
                        alarm.setMultiplicityThreshold(theThreshods.get(alarm.getAlarmId()));
                    } else {
                        addNodeChild(alarm, aic);
                    }
                }
            }
        }
    }
}
Also used : LinkSpec(com.cosylab.acs.laser.dao.utils.LinkSpec) Alarm(cern.laser.business.data.Alarm) AlarmImpl(cern.laser.business.data.AlarmImpl) AlarmRefMatcher(com.cosylab.acs.laser.dao.utils.AlarmRefMatcher)

Example 3 with AlarmImpl

use of cern.laser.business.data.AlarmImpl in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method getAlarm.

/**
	 * Get an alarm from the cache.
	 * 
	 * Get an alarm from the cache. If the alarm with the given triplet is not in the cache then it
	 * looks for a default alarm before returning null.
	 * 
	 * If a default alarm is found, then a new alarm is created by cloning the default alarm.
	 * The triplet of this new alarm is set to be equal to the passed alarm ID.
	 * 
	 * @param alarmId The ID of the alarm
	 * @return An alarm with the given ID if it exists in the CDB
	 * 	       If an alarm with the give ID does not exist but a matching default alarm
	 *         is defined then it return a clone of the default alarm
	 *         null If the alarm is not defined in the CDB and a default alarm does not exist
	 *         
	 * 
	 */
public Alarm getAlarm(String alarmId) {
    if (conf == null) {
        throw new IllegalStateException("Missing dal");
    }
    if (alarmId == null) {
        throw new IllegalArgumentException("Invalid null alarm ID");
    }
    AlarmImpl alarm = (AlarmImpl) alarmDefs.get(alarmId);
    if (alarm == null) {
        // The alarm is not in the HashMap
        // 
        // Does it exist a default alarm?
        String[] tripletItems = alarmId.split(":");
        if (tripletItems.length != 3) {
            logger.log(AcsLogLevel.ERROR, "Malformed alarm ID: " + alarmId);
            return null;
        }
        // Build the default alarm ID by replacing the FM with DEFAULT_FM
        String defaultTripletID = tripletItems[0] + ":" + DEFAULT_FM + ":" + tripletItems[2];
        logger.log(AcsLogLevel.DEBUG, alarmId + " not found: looking for default alarm " + defaultTripletID);
        AlarmImpl defaultalarm = (AlarmImpl) alarmDefs.get(defaultTripletID);
        if (defaultalarm == null) {
            // No available default alarm for this triplet
            logger.log(AcsLogLevel.WARNING, "No default alarm found for " + alarmId);
            return null;
        }
        logger.log(AcsLogLevel.DEBUG, "Default alarm found for " + alarmId);
        System.out.println("Default alarm found for " + alarmId);
        alarm = (AlarmImpl) defaultalarm.clone();
        Triplet alarmTriplet = new Triplet(tripletItems[0], tripletItems[1], Integer.parseInt(tripletItems[2]));
        alarm.setTriplet(alarmTriplet);
        alarm.setAlarmId(Triplet.toIdentifier(alarmTriplet.getFaultFamily(), alarmTriplet.getFaultMember(), alarmTriplet.getFaultCode()));
        // Add the alarm in the HashMap
        //
        // addAlarmToCache trigger the sending of the alarm to the clients
        // i.e. a default alarm is sent to the client twice
        addAlarmToCache(alarm);
        // Refresh the reduction rules with the newly added alarm
        updateAlarmReductionRule(alarm);
        updateAlarmThreshold(alarm);
    //dumpReductionRules();
    }
    return alarm;
}
Also used : Triplet(cern.laser.business.data.Triplet) AlarmImpl(cern.laser.business.data.AlarmImpl)

Example 4 with AlarmImpl

use of cern.laser.business.data.AlarmImpl in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method generateLaserCoreAlarms.

/**
	 * Add the alarms generated by the alarm component
	 */
private void generateLaserCoreAlarms() {
    Collection<AlarmImpl> coreAlarms = LaserCoreFaultCodes.generateAlarms();
    for (AlarmImpl alarm : coreAlarms) {
        addAlarmToCache(alarm);
        logger.log(AcsLogLevel.DEBUG, "Alarm added " + alarm.getAlarmId());
    }
}
Also used : AlarmImpl(cern.laser.business.data.AlarmImpl)

Example 5 with AlarmImpl

use of cern.laser.business.data.AlarmImpl in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method updateReductionRules.

/**
	 * Update the reduction rules.
	 * <P> 
	 * Reduction rules have the property that the parent is:
	 * <UL>
	 * 	<LI>always one single node 
	 *  <LI>is never a wildcard neither a regular expression
	 * </UL>
	 * 
	 * <P>
	 * <I>Performance notes</I>: at the OSF we had problems loading the configuration and
	 * creating an alarm from the default. In both cases the problems were in this method.
	 * To improve performances we made several changes and found that
	 * <UL>
	 * 	<LI>iterate over an array is faster then iterating over a {@link Collection}
	 *  <LI>comparing String seems slower then checking regurlar expression (once that it has been compiled into a pattern)  
	 * <UL>
	 */
private void updateReductionRules() {
    Collection<Alarm> cc = alarmDefs.values();
    AlarmImpl[] allAlarms = new AlarmImpl[cc.size()];
    cc.toArray(allAlarms);
    LinkSpec[] ls = new LinkSpec[reductionRules.size()];
    reductionRules.toArray(ls);
    int num = allAlarms.length;
    logger.log(AcsLogLevel.DEBUG, "Updating all expanded alarms with RR information");
    // Iterate over the alarms 
    for (int a = 0; a < num; a++) {
        for (LinkSpec lsb : ls) {
            if (lsb.matchChild(allAlarms[a])) {
                // This alarm is a child in this reduction rule lsb, let's
                // get the parent from the reduction rule itself
                String alarmParentID = lsb._parent.getMatcherAlarmID();
                Alarm parent = alarmDefs.get(alarmParentID);
                if (parent != null) {
                    if (lsb.isMultiplicity()) {
                        addMultiplicityChild(parent, allAlarms[a]);
                        parent.setMultiplicityThreshold(theThreshods.get(parent.getAlarmId()));
                    } else {
                        addNodeChild(parent, allAlarms[a]);
                    }
                } else {
                }
            }
        }
    }
    logger.log(AcsLogLevel.DEBUG, "All alarms updated with RR information");
}
Also used : LinkSpec(com.cosylab.acs.laser.dao.utils.LinkSpec) Alarm(cern.laser.business.data.Alarm) AlarmImpl(cern.laser.business.data.AlarmImpl)

Aggregations

AlarmImpl (cern.laser.business.data.AlarmImpl)25 Alarm (cern.laser.business.data.Alarm)13 Triplet (cern.laser.business.data.Triplet)8 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)7 Source (cern.laser.business.data.Source)7 Location (cern.laser.business.data.Location)5 HashSet (java.util.HashSet)5 Category (cern.laser.business.data.Category)4 Building (cern.laser.business.data.Building)3 CategoryImpl (cern.laser.business.data.CategoryImpl)3 StatusImpl (cern.laser.business.data.StatusImpl)3 SourceDefinition (cern.laser.business.definition.data.SourceDefinition)3 MalformedURLException (java.net.MalformedURLException)3 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 Properties (java.util.Properties)3 Contact (alma.acs.alarmsystem.generated.Contact)2 FaultCode (alma.acs.alarmsystem.generated.FaultCode)2 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)2