use of com.cosylab.acs.laser.dao.ACSResponsiblePersonDAOImpl in project ACS by ACS-Community.
the class LaserComponent method initialize.
public void initialize() {
this.logger = corbaServer.getLogger();
defaultTopicConnectionFactory = new ACSJMSTopicConnectionFactory(alSysContSvcs);
TopicConnection tc;
TopicSession ts = null;
try {
tc = defaultTopicConnectionFactory.createTopicConnection();
ts = tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topicAdminCacheLoader = new ACSJMSTopic("CMW.ALARM_SYSTEM.ADMIN_CACHE_LOADER");
subscriberAdminCacheLoader = ts.createSubscriber(topicAdminCacheLoader);
subscriberAdminCacheLoader.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
if (message instanceof TextMessage) {
logger.log(AcsLogLevel.DEBUG, "Received a JMS message");
} else {
logger.log(AcsLogLevel.WARNING, "Received a non text JMS message");
}
try {
alarmMessageProcessor.process(message);
} catch (Throwable t) {
logger.log(AcsLogLevel.ERROR, "Exception processing a message: " + t.getMessage(), t);
// There is nothing to do at this level: log the exception
// and be ready to process the next message
}
}
});
logger.log(AcsLogLevel.DEBUG, "JMS initialized");
} catch (Throwable t) {
System.err.println("Error initing JMS, " + t.getMessage());
t.printStackTrace(System.err);
logger.log(AcsLogLevel.ERROR, "Error initializing JMS", t);
coreAlarms.add(LaserCoreFaultCodes.JMS_INIT);
}
ConfigurationAccessor conf = null;
try {
conf = ConfigurationAccessorFactory.getInstance(alSysContSvcs);
} catch (Throwable t) {
System.err.println("Error getting CDB: " + t.getMessage());
t.printStackTrace(System.err);
logger.log(AcsLogLevel.WARNING, "Error getting CDB", t);
coreAlarms.add(LaserCoreFaultCodes.CDB_UNAVAILABLE);
}
adminUserDAO = new ACSAdminUserDAOImpl();
alarmDAO = new ACSAlarmDAOImpl(logger);
alarmDAO.setConfAccessor(conf);
categoryDAO = new ACSCategoryDAOImpl(logger, alarmDAO);
categoryDAO.setConfAccessor(conf);
responsiblePersonDAO = new ACSResponsiblePersonDAOImpl();
try {
alarmDAO.loadAlarms();
} catch (Throwable t) {
System.err.println("Error loading alarms: " + t.getMessage());
t.printStackTrace(System.err);
logger.log(AcsLogLevel.CRITICAL, "Error loading alarms from CDB", t);
coreAlarms.add(LaserCoreFaultCodes.ALARMS_CDB);
}
try {
categoryDAO.loadCategories();
} catch (Throwable t) {
System.err.println("Error loading categories: " + t.getMessage());
t.printStackTrace(System.err);
logger.log(AcsLogLevel.CRITICAL, "Error loading categories from CDB", t);
coreAlarms.add(LaserCoreFaultCodes.CATEGORIES_CDB);
}
sourceDAO = new ACSSourceDAOImpl(logger, alarmDAO.getSources());
sourceDAO.setConfAccessor(conf);
sourceDAO.setLaserSourceId("LASER");
sourceDAO.setAlarmDAO(alarmDAO);
sourceDAO.setResponsiblePersonDAO(responsiblePersonDAO);
adminUserDefinitionService = new AdminUserDefinitionServiceImpl();
alarmCacheServer = new AlarmCacheServerImpl(logger);
alarmDefinitionService = new AlarmDefinitionServiceImpl();
sourcesListener = new AlarmSourcesListenerCached(alSysContSvcs, logger, this);
statisticsCalculator = new StatsCalculator(this.logger, sourcesListener);
alarmMessageProcessor = new AlarmMessageProcessorImpl(this, logger, statisticsCalculator);
alarmPublisher = new AlarmPublisherImpl(logger);
alarmSourceMonitor = new AlarmSourceMonitorImpl();
categoryDefinitionService = new CategoryDefinitionServiceImpl();
coreService = new CoreServiceImpl();
heartbeat = new HeartbeatImpl();
mailAndSmsServer = new ACSMailAndSmsServer(logger);
sourceDefinitionService = new SourceDefinitionServiceImpl();
alarmCacheListener = new AlarmCacheListenerImpl(alarmCacheServer);
alarmCache = new ACSAlarmCacheImpl(alarmDAO, categoryDAO, alarmCacheListener, logger);
statisticsCalculator.start();
alarmDAO.setSurveillanceAlarmId("SURVEILLANCE:SOURCE:1");
alarmDAO.setResponsiblePersonDAO(responsiblePersonDAO);
// categoryDAO.setCategoryTreeRoot("ACS");
categoryDAO.setCategoryTreeRoot("ROOT");
categoryDAO.setSurveillanceCategoryPath("ACS.SURVEILLANCE");
responsiblePersonDAO.setAlarmDAO(alarmDAO);
adminUserDefinitionService.setCategoryDAO(categoryDAO);
adminUserDefinitionService.setAdminUserDAO(adminUserDAO);
alarmCacheServer.setAlarmDAO(alarmDAO);
alarmCacheServer.setAlarmPublisher(alarmPublisher);
alarmCacheServer.setMailAndSmsServer(mailAndSmsServer);
alarmDefinitionService.setAlarmCache(alarmCache);
alarmDefinitionService.setAdminUserDAO(adminUserDAO);
alarmDefinitionService.setAlarmDAO(alarmDAO);
alarmDefinitionService.setCategoryDAO(categoryDAO);
alarmDefinitionService.setResponsiblePersonDAO(responsiblePersonDAO);
alarmDefinitionService.setSourceDAO(sourceDAO);
alarmDefinitionService.setAlarmMessageProcessor(alarmMessageProcessor);
alarmDefinitionService.setAlarmPublisher(alarmPublisher);
alarmMessageProcessor.setAlarmCache(alarmCache);
alarmMessageProcessor.setSourceDAO(sourceDAO);
alarmPublisher.setTopicConnectionFactory(defaultTopicConnectionFactory);
alarmPublisher.setCategoryRootTopic("CMW.ALARM_SYSTEM.CATEGORIES");
alarmSourceMonitor.setSourceDAO(sourceDAO);
alarmSourceMonitor.setAlarmMessageProcessor(alarmMessageProcessor);
alarmSourceMonitor.setSourceMonitorFrequency(60000);
categoryDefinitionService.setAlarmCache(alarmCache);
categoryDefinitionService.setAdminUserDAO(adminUserDAO);
categoryDefinitionService.setAlarmDAO(alarmDAO);
categoryDefinitionService.setCategoryDAO(categoryDAO);
coreService.setAlarmCache(alarmCache);
coreService.setResponsiblePersonDAO(responsiblePersonDAO);
coreService.setSourceDAO(sourceDAO);
coreService.setAlarmDAO(alarmDAO);
coreService.setCategoryDAO(categoryDAO);
coreService.setAlarmPublisher(alarmPublisher);
// coreService.setDataSource(defaultDataSource);
coreService.setClientRootTopic("CMW.ALARM_SYSTEM.CLIENTS");
coreService.setRootCategoryPK(2064926);
coreService.setHeartbeatTopic("CMW.ALARM_SYSTEM.HEARTBEAT");
coreService.setHeartbeatFrequency(60000);
coreService.setSearchRootTopic("CMW.ALARM_SYSTEM.SEARCH");
heartbeat.setCoreService(coreService);
heartbeat.setTopicConnectionFactory(defaultTopicConnectionFactory);
sourceDefinitionService.setAlarmCache(alarmCache);
sourceDefinitionService.setAdminUserDAO(adminUserDAO);
sourceDefinitionService.setAlarmDAO(alarmDAO);
sourceDefinitionService.setCategoryDAO(categoryDAO);
sourceDefinitionService.setResponsiblePersonDAO(responsiblePersonDAO);
sourceDefinitionService.setSourceDAO(sourceDAO);
sourceDefinitionService.setAlarmDefinitionService(alarmDefinitionService);
alarmDAO.setAlarmProcessor(alarmMessageProcessor);
// Subscribe the source listener to all the source NCs
try {
sourcesListener.connectSources(sourceDAO.getAllSourceIDs());
logger.log(AcsLogLevel.DEBUG, "Successfully connected to sources NCs");
} catch (Throwable t) {
System.err.println("Error setting source listener: " + t.getMessage());
t.printStackTrace(System.err);
logger.log(AcsLogLevel.WARNING, "Error setting the source listener", t);
coreAlarms.add(LaserCoreFaultCodes.SOURCE_LISTENER);
}
sourcesListener.start();
}
use of com.cosylab.acs.laser.dao.ACSResponsiblePersonDAOImpl in project ACS by ACS-Community.
the class HibernateWDALAlarmPluginImpl method importAlarms.
public static void importAlarms(Session session, Configuration config, ConfigurationAccessor conf, Logger m_logger) throws Exception {
// clean up whatever is in the session
session.getTransaction().commit();
session.clear();
session.beginTransaction();
// create DAOs
ACSAlarmDAOImpl alarmDAO = new ACSAlarmDAOImpl(m_logger);
ACSCategoryDAOImpl categoryDAO = new ACSCategoryDAOImpl(m_logger, alarmDAO);
ACSResponsiblePersonDAOImpl responsiblePersonDAO = new ACSResponsiblePersonDAOImpl();
// configure
alarmDAO.setConfAccessor(conf);
alarmDAO.setSurveillanceAlarmId("SURVEILLANCE:SOURCE:1");
alarmDAO.setResponsiblePersonDAO(responsiblePersonDAO);
categoryDAO.setConfAccessor(conf);
//categoryDAO.setCategoryTreeRoot("ACS");
categoryDAO.setCategoryTreeRoot("ROOT");
categoryDAO.setSurveillanceCategoryPath("ACS.SURVEILLANCE");
responsiblePersonDAO.setAlarmDAO(alarmDAO);
// load
final List<alma.acs.alarmsystem.generated.FaultFamily> families = alarmDAO.loadAlarms();
final alma.acs.alarmsystem.generated.Category[] categories = categoryDAO.loadCategories();
Map<String, ArrayList<AlarmCategory>> categoryFaultFamilyLinks = new HashMap<String, ArrayList<AlarmCategory>>();
// store categories
if (categories != null)
for (alma.acs.alarmsystem.generated.Category daoCategory : categories) {
AlarmCategory category = (AlarmCategory) session.createCriteria(AlarmCategory.class).add(Restrictions.eq("configuration", config)).add(Restrictions.eq("alarmCategoryName", daoCategory.getPath())).uniqueResult();
if (category == null) {
category = new AlarmCategory();
category.setAlarmCategoryName(daoCategory.getPath());
category.setConfiguration(config);
}
category.setDescription(nonEmptyString(daoCategory.getDescription(), "(description)"));
category.setPath(daoCategory.getPath());
category.setIsDefault(daoCategory.getIsDefault());
session.saveOrUpdate(category);
// clear first (in case of update)
category.getFaultFamilies().clear();
// cache mappings
String[] faultFamilies = daoCategory.getAlarms().getFaultFamily();
for (String faultFamily : faultFamilies) {
ArrayList<AlarmCategory> list = categoryFaultFamilyLinks.get(faultFamily);
if (list == null) {
list = new ArrayList<AlarmCategory>();
categoryFaultFamilyLinks.put(faultFamily, list);
}
list.add(category);
}
}
// store fault families and contacts, etc.
if (families != null)
for (alma.acs.alarmsystem.generated.FaultFamily family : families) {
final alma.acs.alarmsystem.generated.Contact daoContact = family.getContact();
Contact contact = (Contact) session.createCriteria(Contact.class).add(Restrictions.eq("contactName", daoContact.getName())).uniqueResult();
if (contact == null) {
contact = new Contact();
contact.setContactName(nonEmptyString(daoContact.getName(), "(empty)"));
contact.setEmail(daoContact.getEmail());
contact.setGsm(daoContact.getGsm());
session.persist(contact);
} else // If contact exist, let's check if this contact contains different information. If so,
// issue an error
{
if (!trimAndNullToEmpty(contact.getEmail()).equals(trimAndNullToEmpty(daoContact.getEmail())) || !trimAndNullToEmpty(contact.getGsm()).equals(trimAndNullToEmpty(daoContact.getGsm()))) {
throw new RuntimeException("Data stored for contact '" + contact.getContactName() + "' in TMCDB " + "does not match that comming from the 'contact' node of fault family '" + family.getName() + "'. " + "TMCDB: <" + contact.getEmail() + ", " + contact.getGsm() + ">, " + "CDB: <" + daoContact.getEmail() + ", " + daoContact.getGsm() + ">");
}
}
FaultFamily faultFamily = (FaultFamily) session.createCriteria(FaultFamily.class).add(Restrictions.eq("configuration", config)).add(Restrictions.eq("familyName", family.getName())).uniqueResult();
if (faultFamily == null) {
faultFamily = new FaultFamily();
faultFamily.setFamilyName(family.getName());
faultFamily.setConfiguration(config);
}
faultFamily.setAlarmSource(family.getAlarmSource());
faultFamily.setHelpURL(family.getHelpUrl());
faultFamily.setContact(contact);
session.saveOrUpdate(faultFamily);
// clear first (in case of update)
faultFamily.getAlarmCategories().clear();
ArrayList<AlarmCategory> list = categoryFaultFamilyLinks.get(family.getName());
if (list != null)
for (AlarmCategory category : list) {
category.getFaultFamilies().add(faultFamily);
faultFamily.getAlarmCategories().add(category);
session.update(category);
session.update(faultFamily);
}
// default fault member
if (family.getFaultMemberDefault() != null) {
DefaultMember defaultMember = null;
// there can be only one
if (faultFamily.getDefaultMembers().size() != 0)
defaultMember = faultFamily.getDefaultMembers().iterator().next();
if (defaultMember == null) {
defaultMember = new DefaultMember();
defaultMember.setFaultFamily(faultFamily);
}
defaultMember.setLocation(getLocation(session, family.getFaultMemberDefault().getLocation()));
session.saveOrUpdate(defaultMember);
} else {
for (DefaultMember memberToRemove : faultFamily.getDefaultMembers()) {
faultFamily.getDefaultMembers().remove(memberToRemove);
session.delete(memberToRemove);
}
session.update(faultFamily);
}
// copy all
Set<FaultMember> faultMembersToRemove = new HashSet<FaultMember>(faultFamily.getFaultMembers());
// add fault members
for (alma.acs.alarmsystem.generated.FaultMember daoFaultMember : family.getFaultMember()) {
FaultMember faultMember = (FaultMember) session.createCriteria(FaultMember.class).add(Restrictions.eq("memberName", daoFaultMember.getName())).add(Restrictions.eq("faultFamily", faultFamily)).uniqueResult();
faultMembersToRemove.remove(faultMember);
if (faultMember == null) {
faultMember = new FaultMember();
faultMember.setMemberName(daoFaultMember.getName());
faultMember.setFaultFamily(faultFamily);
}
faultMember.setLocation(getLocation(session, daoFaultMember.getLocation()));
session.saveOrUpdate(faultMember);
}
if (faultMembersToRemove.size() > 0) {
for (FaultMember faultMemberToRemove : faultMembersToRemove) {
faultFamily.getFaultMembers().remove(faultMemberToRemove);
session.delete(faultMemberToRemove);
}
session.update(faultFamily);
}
// copy all
Set<FaultCode> faultCodesToRemove = new HashSet<FaultCode>(faultFamily.getFaultCodes());
// add fault codes
for (alma.acs.alarmsystem.generated.FaultCode daoFaultCode : family.getFaultCode()) {
FaultCode faultCode = (FaultCode) session.createCriteria(FaultCode.class).add(Restrictions.eq("faultFamily", faultFamily)).add(Restrictions.eq("codeValue", daoFaultCode.getValue())).uniqueResult();
faultCodesToRemove.remove(faultCode);
if (faultCode == null) {
faultCode = new FaultCode();
faultCode.setFaultFamily(faultFamily);
faultCode.setCodeValue(daoFaultCode.getValue());
}
faultCode.setPriority(daoFaultCode.getPriority());
faultCode.setCause(daoFaultCode.getCause());
faultCode.setAction(daoFaultCode.getAction());
faultCode.setConsequence(daoFaultCode.getConsequence());
faultCode.setProblemDescription(nonEmptyString(daoFaultCode.getProblemDescription(), "(description)"));
faultCode.setIsInstant(daoFaultCode.getInstant());
session.saveOrUpdate(faultCode);
}
if (faultCodesToRemove.size() > 0) {
for (FaultCode faultCodeToRemove : faultCodesToRemove) {
faultFamily.getFaultCodes().remove(faultCodeToRemove);
session.delete(faultCodeToRemove);
}
session.update(faultFamily);
}
}
try {
alma.alarmsystem.alarmmessage.generated.ReductionDefinitions redDefs = alarmDAO.getReductionDefinitions();
if (redDefs != null) {
if (redDefs.getLinksToCreate() != null)
saveReductionLinks(session, config, redDefs.getLinksToCreate().getReductionLink(), ReductionLinkAction.CREATE);
if (redDefs.getLinksToRemove() != null)
saveReductionLinks(session, config, redDefs.getLinksToRemove().getReductionLink(), ReductionLinkAction.REMOVE);
int count = 0;
if (redDefs.getThresholds() != null) {
alma.alarmsystem.alarmmessage.generated.Threshold[] thresholds = redDefs.getThresholds().getThreshold();
for (alma.alarmsystem.alarmmessage.generated.Threshold threshold : thresholds) {
// also commit first
if (count % 100 == 0) {
session.getTransaction().commit();
// cleanup first level cache
session.clear();
session.beginTransaction();
config = (Configuration) session.get(Configuration.class, config.getConfigurationId());
}
count++;
alma.acs.tmcdb.AlarmDefinition alarm = getAlarmDefinition(session, config, threshold.getAlarmDefinition(), false);
alma.acs.tmcdb.ReductionThreshold t = (alma.acs.tmcdb.ReductionThreshold) session.createQuery("from ReductionThreshold " + "where AlarmDefinitionId = " + alarm.getAlarmDefinitionId()).uniqueResult();
if (t == null) {
t = new ReductionThreshold();
t.setAlarmDefinition(alarm);
t.setConfiguration(config);
}
t.setValue(threshold.getValue());
session.saveOrUpdate(t);
}
}
}
} finally {
// clear cache (to free memory)
adCache.clear();
}
}
Aggregations