Search in sources :

Example 1 with Status

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

the class CategoryClient method convertAlarmType.

/**
	 * Convert a CORBA alarm into a client alarm.
	 * 
	 * @param alarm The CORBA alarm
	 * @return the client alarm
	 */
private Alarm convertAlarmType(alma.alarmsystem.Alarm alarm) {
    Source source = new Source();
    Building building = new Building(alarm.alarmLocation.buildingNb, alarm.alarmLocation.site, alarm.alarmLocation.zone, alarm.alarmLocation.map);
    Location location = new Location(alarm.alarmLocation.locationId, alarm.alarmLocation.floor, alarm.alarmLocation.mnemonic, alarm.alarmLocation.position, alarm.alarmLocation.room);
    location.setBuilding(building);
    ResponsiblePerson responsiblePerson = new ResponsiblePerson(alarm.alarmResponsiblePerson.responsibleId, alarm.alarmResponsiblePerson.familyName, alarm.alarmResponsiblePerson.firstName, alarm.alarmResponsiblePerson.eMail, alarm.alarmResponsiblePerson.gsmNumber, alarm.alarmResponsiblePerson.phoneNumber);
    Properties userProperties = new Properties();
    for (org.omg.CosPropertyService.Property prop : alarm.alarmStatus.userProperties) {
        userProperties.put(prop.property_name, prop.property_value);
    }
    Status status = new StatusImpl(Boolean.valueOf(alarm.alarmStatus.active), Boolean.valueOf(alarm.alarmStatus.masked), Boolean.valueOf(alarm.alarmStatus.reduced), Boolean.FALSE, Boolean.FALSE, alarm.alarmStatus.sourceHostname, new Timestamp(alarm.alarmStatus.sourceTimestamp.miliseconds), new Timestamp(alarm.alarmStatus.userTimestamp.miliseconds), new Timestamp(alarm.alarmStatus.systemTimestamp.miliseconds), userProperties);
    Triplet triplet = new Triplet(alarm.alarmTriplet.faultFamily, alarm.alarmTriplet.faultMember, alarm.alarmTriplet.faultCode);
    Set<cern.laser.business.data.Category> categories = new HashSet<cern.laser.business.data.Category>();
    for (Category cat : alarm.categories) {
        CategoryImpl catImpl = new CategoryImpl(cat.categoryId, cat.name, cat.description, cat.path, cat.leaf);
        categories.add(catImpl);
    }
    cern.laser.business.data.Alarm businessAlarm = new AlarmImpl(alarm.alarmId, alarm.systemName, alarm.identifier, alarm.problemDescription, Integer.valueOf(alarm.priority), alarm.cause, alarm.action, alarm.consequence, alarm.piquetGSM, alarm.piquetEmail, alarm.helpURL, Boolean.valueOf(alarm.instant), source, location, responsiblePerson, categories, status, triplet, alarm.nodeParent, alarm.multiplicityParent, alarm.nodeChild, alarm.multiplicityChild);
    Alarm ret = new cern.laser.client.impl.data.AlarmImpl(businessAlarm);
    return ret;
}
Also used : Building(cern.laser.business.data.Building) Status(cern.laser.business.data.Status) Category(alma.alarmsystem.Category) Triplet(cern.laser.business.data.Triplet) StatusImpl(cern.laser.business.data.StatusImpl) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) Source(cern.laser.business.data.Source) CategoryImpl(cern.laser.business.data.CategoryImpl) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) AlarmImpl(cern.laser.business.data.AlarmImpl) Alarm(cern.laser.client.data.Alarm) Location(cern.laser.business.data.Location) HashSet(java.util.HashSet)

Example 2 with Status

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

the class AlarmMessageProcessorImpl method processChange.

public void processChange(FaultState faultState, String sourceName, String sourceHostname, Timestamp sourceTimestamp) throws Exception {
    alarmCache.acquire();
    try {
        logger.log(AcsLogLevel.DEBUG, "processing fault state: " + faultState.getFamily() + ":" + faultState.getMember() + ":" + faultState.getCode() + ", Descriptor=" + faultState.getDescriptor() + "\n");
        Timestamp system_timestamp = new Timestamp(System.currentTimeMillis());
        Alarm alarm = alarmCache.getCopy(Triplet.toIdentifier(faultState.getFamily(), faultState.getMember(), Integer.valueOf(faultState.getCode())));
        // process the change
        String defined_source_name = alarm.getSource().getName();
        if (!defined_source_name.equals(sourceName)) {
            logger.log(AcsLogLevel.ERROR, "source name mismatch : received " + sourceName + ", should be " + defined_source_name + ".\nFault State was discarded :\n" + faultState);
        } else {
            Status current_status = alarm.getStatus();
            boolean ordered = true;
            // check if fault state changes were received in the right order
            if ((current_status.getUserTimestamp() != null) && (faultState.getUserTimestamp() != null)) {
                if (faultState.getUserTimestamp().before(current_status.getUserTimestamp())) {
                    logger.log(AcsLogLevel.ERROR, "user timestamp not ordered : received " + faultState.getUserTimestamp() + ", was " + current_status.getUserTimestamp() + ".\nFault State was discarded :\n" + faultState);
                    ordered = false;
                }
            } else {
                if (sourceTimestamp.before(current_status.getSourceTimestamp())) {
                    logger.log(AcsLogLevel.ERROR, "source timestamp not ordered : received " + sourceTimestamp + ", was " + current_status.getSourceTimestamp() + ".\nFault State was discarded :\n" + faultState);
                    ordered = false;
                }
            }
            if (ordered) {
                //        StatusImpl new_status = null;
                //        StatusImpl alarm_status = alarm.getStatus();
                boolean notify_reduction_relatives = false;
                boolean alarm_updated = false;
                if (alarm.getInstant().booleanValue()) {
                    if (faultState.getDescriptor().equalsIgnoreCase(FaultState.INSTANT)) {
                        // process INSTANT fault state
                        updateStatus(faultState, current_status, Boolean.TRUE, sourceHostname, sourceTimestamp, system_timestamp);
                        alarm_updated = true;
                    //            new_status = new StatusImpl(Boolean.TRUE, current_status.getMasked(), current_status.getReduced(), new
                    // Boolean(
                    //                faultState.getActivatedByBackup()), new Boolean(faultState.getTerminatedByBackup()), sourceHostname,
                    //                sourceTimestamp, faultState.getUserTimestamp(), system_timestamp, faultState.getUserProperties());
                    } else {
                        logger.log(AcsLogLevel.ERROR, "invalid fault descriptor : received " + faultState.getDescriptor() + "  while expecting " + FaultState.INSTANT + ".\nFault State was discarded :\n" + faultState);
                    }
                } else {
                    if (faultState.getDescriptor().equalsIgnoreCase(FaultState.ACTIVE)) {
                        // process ACTIVE fault state
                        if (alarm.getStatus().getActive().equals(Boolean.FALSE)) {
                            updateStatus(faultState, current_status, Boolean.TRUE, sourceHostname, sourceTimestamp, system_timestamp);
                            //              new_status = new StatusImpl(Boolean.TRUE, current_status.getMasked(), current_status.getReduced(),
                            //                  new Boolean(faultState.getActivatedByBackup()), new Boolean(faultState.getTerminatedByBackup()),
                            //                  sourceHostname, sourceTimestamp, faultState.getUserTimestamp(), system_timestamp, faultState
                            //                      .getUserProperties());
                            notify_reduction_relatives = true;
                            alarm_updated = true;
                        } else {
                            logger.log(AcsLogLevel.WARNING, "Alarm already active: Fault State " + alarm.getAlarmId() + " discarded");
                        }
                    } else if (faultState.getDescriptor().equalsIgnoreCase(FaultState.TERMINATE)) {
                        // process TERMINATE fault state
                        if (alarm.getStatus().getActive().equals(Boolean.TRUE)) {
                            updateStatus(faultState, current_status, Boolean.FALSE, sourceHostname, sourceTimestamp, system_timestamp);
                            //              new_status = new StatusImpl(Boolean.FALSE, current_status.getMasked(), current_status.getReduced(),
                            //                  new Boolean(faultState.getActivatedByBackup()), new Boolean(faultState.getTerminatedByBackup()),
                            //                  sourceHostname, sourceTimestamp, faultState.getUserTimestamp(), system_timestamp, faultState
                            //                      .getUserProperties());
                            notify_reduction_relatives = true;
                            alarm_updated = true;
                        } else {
                            logger.log(AcsLogLevel.WARNING, "Alarm already terminated: Fault State " + alarm.getAlarmId() + " discarded");
                        }
                    } else if (faultState.getDescriptor().equalsIgnoreCase(FaultState.CHANGE)) {
                        // process CHANGE fault state
                        if (alarm.getStatus().getActive().equals(Boolean.FALSE)) {
                            logger.log(AcsLogLevel.ERROR, "changed alarm was terminated : " + alarm.getAlarmId());
                            notify_reduction_relatives = true;
                        } else {
                            updateStatus(faultState, current_status, Boolean.TRUE, sourceHostname, sourceTimestamp, system_timestamp);
                            //            new_status = new StatusImpl(Boolean.TRUE, current_status.getMasked(), current_status.getReduced(), new
                            // Boolean(
                            //                faultState.getActivatedByBackup()), new Boolean(faultState.getTerminatedByBackup()), sourceHostname,
                            //                sourceTimestamp, faultState.getUserTimestamp(), system_timestamp, faultState.getUserProperties());
                            alarm_updated = true;
                        }
                    } else {
                        logger.log(AcsLogLevel.ERROR, "invalid fault descriptor : received " + faultState.getDescriptor() + "  while expecting " + FaultState.ACTIVE + "|" + FaultState.TERMINATE + "|" + FaultState.CHANGE + ".\nFault State was discarded :\n" + faultState);
                    }
                }
                //        if (new_status != null) {
                if (alarm_updated) {
                    //          alarm.setStatus(new_status);
                    logger.log(AcsLogLevel.DEBUG, "applying change...");
                    if (alarm.getSource() != null && sourceHostname != null) {
                        alarm.getSource().setHostName(sourceHostname.toLowerCase());
                    }
                    alarmCache.put(alarm);
                    if (notify_reduction_relatives) {
                        notifyReductionRelatives(alarm);
                    }
                }
            }
        }
    } finally {
        alarmCache.release();
        logger.log(AcsLogLevel.DEBUG, "processed fault state:" + faultState.getFamily() + ":" + faultState.getMember() + ":" + faultState.getCode() + ", Descriptor=" + faultState.getDescriptor() + "\n");
    }
}
Also used : Status(cern.laser.business.data.Status) Alarm(cern.laser.business.data.Alarm) Timestamp(java.sql.Timestamp)

Example 3 with Status

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

the class AlarmCacheServerImpl method store.

public void store(Collection updated) {
    try {
        logger.log(AcsLogLevel.DELOUSE, "storing " + updated.size() + " alarm(s)...");
        Iterator iterator = updated.iterator();
        while (iterator.hasNext()) {
            Alarm alarm = (Alarm) iterator.next();
            Status status = alarm.getStatus();
            //        if (status.getStatusId() == null || status.getStatusId().equals("")) {
            //          if (LOGGER.isDebugEnabled()) LOGGER.debug("saving status ...");
            //          status.setStatusId(alarm.getAlarmId());
            //          alarmDAO.saveStatus(status);
            //        } else {
            //          if (LOGGER.isDebugEnabled()) LOGGER.debug("updating status ...");
            alarmDAO.updateStatus(status);
        //        }
        }
        logger.log(AcsLogLevel.DELOUSE, "stored");
    } catch (Exception e) {
        throw new LaserRuntimeException("unable to store alarm(s)", e);
    }
}
Also used : Status(cern.laser.business.data.Status) Alarm(cern.laser.business.data.Alarm) Iterator(java.util.Iterator) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserRuntimeException(cern.laser.business.LaserRuntimeException)

Example 4 with Status

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

the class AlarmPublisherImpl method publish.

public void publish(AlarmChange alarmChange) {
    if (alarmChange == null) {
        logger.log(AcsLogLevel.WARNING, "alarm change is null");
        return;
    }
    try {
        logger.log(AcsLogLevel.DEBUG, "publishing alarm change for " + alarmChange.getCurrent().getAlarmId() + ", active= " + alarmChange.getCurrent().getStatus().getActive());
        Alarm alarm = alarmChange.getCurrent();
        Alarm previous = alarmChange.getPrevious();
        Iterator iterator = alarm.getCategories().iterator();
        while (iterator.hasNext()) {
            Category category = (Category) iterator.next();
            String destination = categoryRootTopic + "." + category.getPath();
            Topic topic = getTopicSession().createTopic(destination);
            //ObjectMessage message = getTopicSession().createObjectMessage((AlarmImpl) alarm);
            TextMessage message = getTopicSession().createTextMessage();
            setMessageProperties(message, alarm);
            Status previous_alarm_status = previous.getStatus();
            Status current_alarm_status = alarm.getStatus();
            message.setObjectProperty("REDUCED_MASKED_SET", Boolean.FALSE);
            /**
         * change belongs to the reduced set if and only if the transition is from whatever to (ACTIVE, NOT REDUCED, NOT
         * MASKED) or from (ACTIVE, NOT REDUCED, NOT MASKED) to whatever else or if there was not a transition but a
         * change of something NOT REDUCED and NOT MASKED
         */
            if (current_alarm_status.getActive().booleanValue() && !(current_alarm_status.getMasked().booleanValue() || current_alarm_status.getReduced().booleanValue())) {
                // transition to (ACTIVE, NOT REDUCED, NOT MASKED) or change of
                // something NOT REDUCED and NOT MASKED
                message.setObjectProperty("REDUCED_MASKED_SET", Boolean.TRUE);
            } else {
                // else
                if (previous_alarm_status.getActive().booleanValue() && !(previous_alarm_status.getMasked().booleanValue() || previous_alarm_status.getReduced().booleanValue())) {
                    message.setObjectProperty("REDUCED_MASKED_SET", Boolean.TRUE);
                }
            }
            message.setObjectProperty("NOT_REDUCED_MASKED_SET", Boolean.FALSE);
            /**
         * change belongs to the not reduced set if an only if the transition was from ACTIVE to NOT ACTIVE or from NOT
         * ACTIVE to ACTIVE or if it was not triggered by reduction or mask flags
         */
            if (current_alarm_status.getActive().booleanValue() != previous_alarm_status.getActive().booleanValue()) {
                // transition from ACTIVE to NOT ACTIVE or from NOT ACTIVE to ACTIVE
                message.setObjectProperty("NOT_REDUCED_MASKED_SET", Boolean.TRUE);
            } else if (current_alarm_status.getActive().booleanValue() && (current_alarm_status.getMasked().booleanValue() == previous_alarm_status.getMasked().booleanValue()) && (current_alarm_status.getReduced().booleanValue() == previous_alarm_status.getReduced().booleanValue())) {
                // change not triggered by reduction or mask flags
                message.setObjectProperty("NOT_REDUCED_MASKED_SET", Boolean.TRUE);
            }
            // I insert the xml representation of this object
            // in the text field of the message
            String xml = AlarmMessageConversion.getXML((AlarmImpl) alarm);
            message.setText(xml);
            getTopicPublisher().publish(topic, message);
            logger.log(AcsLogLevel.DEBUG, "change published on : " + destination);
        }
    } catch (Exception e) {
        logger.log(AcsLogLevel.ERROR, "unable to publish", e);
        close();
    }
}
Also used : Status(cern.laser.business.data.Status) Category(cern.laser.business.data.Category) Alarm(cern.laser.business.data.Alarm) Iterator(java.util.Iterator) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) NamingException(javax.naming.NamingException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserCreateException(cern.laser.business.LaserCreateException) JMSException(javax.jms.JMSException)

Aggregations

Status (cern.laser.business.data.Status)4 Alarm (cern.laser.business.data.Alarm)3 LaserRuntimeException (cern.laser.business.LaserRuntimeException)2 Timestamp (java.sql.Timestamp)2 Iterator (java.util.Iterator)2 Category (alma.alarmsystem.Category)1 LaserCreateException (cern.laser.business.LaserCreateException)1 AlarmImpl (cern.laser.business.data.AlarmImpl)1 Building (cern.laser.business.data.Building)1 Category (cern.laser.business.data.Category)1 CategoryImpl (cern.laser.business.data.CategoryImpl)1 Location (cern.laser.business.data.Location)1 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)1 Source (cern.laser.business.data.Source)1 StatusImpl (cern.laser.business.data.StatusImpl)1 Triplet (cern.laser.business.data.Triplet)1 Alarm (cern.laser.client.data.Alarm)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 JMSException (javax.jms.JMSException)1