Search in sources :

Example 6 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap in project ACS by ACS-Community.

the class HibernateWDALImpl method updateManagersTableMap.

protected void updateManagersTableMap(String curl) {
    m_logger.info("clear_cache(curl): ManagersTable1");
    Map<String, Object> rootMap = (Map<String, Object>) rootNode;
    Map<String, Object> managersMap = (Map<String, Object>) rootMap.get("Managers");
    m_logger.info("clear_cache(curl): ManagersTable2");
    try {
        Session session = hibernateUtil.getSession();
        Criterion cr = Restrictions.eq("Name", curl);
        List managerList = getListForConfiguration(session, alma.TMCDB.maci.Manager.class, cr);
        m_logger.info("clear_cache(curl): ManagersTable3");
        if (!managerList.isEmpty())
            managersMap.put("Manager", managerList.get(0));
        else
            managersMap.put("Manager", getDefaultMangerConfig());
        m_logger.info("clear_cache(curl): ManagersTable4");
        String additionalServices = getAcsServices(session, config);
        m_logger.info("clear_cache(curl): ManagersTable5");
        if (additionalServices != null) {
            alma.TMCDB.maci.Manager manager = (alma.TMCDB.maci.Manager) managersMap.get("Manager");
            String currentServices = manager.getServiceComponents();
            m_logger.info("clear_cache(curl): ManagersTable6");
            if (currentServices == null || currentServices.length() == 0)
                manager.setServiceComponents(additionalServices);
            else
                // there might be duplicates, but they do not harm
                manager.setServiceComponents(currentServices + "," + additionalServices);
            m_logger.info("clear_cache(curl): ManagersTable7");
        }
    } catch (Throwable th) {
        th.printStackTrace();
    }
    m_logger.info("clear_cache(curl): ManagersTable8");
}
Also used : Manager(alma.acs.tmcdb.Manager) ClientLogManager(alma.acs.logging.ClientLogManager) Criterion(org.hibernate.criterion.Criterion) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Session(org.hibernate.Session)

Example 7 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap in project ACS by ACS-Community.

the class HibernateWDALImpl method getContainersTableMap.

public Map<String, Object> getContainersTableMap() {
    final String keyField = "Name";
    final Class type = alma.TMCDB.maci.Container.class;
    Map<String, Object> map = new RootMap<String, Object>();
    try {
        Session session = hibernateUtil.getSession();
        Method accessor = DOMJavaClassIntrospector.getAccessorMethod(type, keyField);
        Field field = null;
        if (accessor == null) {
            try {
                field = type.getField(keyField);
            } catch (Throwable th) {
                throw new IllegalStateException("failed to obtain key ");
            }
        }
        List list = getListForConfiguration(session, type);
        // Sort the list by path + component to ensure that parent containers are added before their children
        Comparator<alma.TMCDB.maci.Container> comparator = new Comparator<alma.TMCDB.maci.Container>() {

            public int compare(alma.TMCDB.maci.Container o1, alma.TMCDB.maci.Container o2) {
                String fullName1 = ((o1.Path == null ? "" : o1.Path) + "/") + o1.getName();
                String fullName2 = ((o2.Path == null ? "" : o2.Path) + "/") + o2.getName();
                return fullName1.compareTo(fullName2);
            }
        };
        Collections.sort(list, comparator);
        for (Object data : list) {
            String baseKey;
            if (accessor != null)
                baseKey = accessor.invoke(data, (Object[]) null).toString();
            else
                //if (field != null)
                baseKey = field.get(data).toString();
            // baseKey should not be null
            Map parentMap = map;
            alma.TMCDB.maci.Container container = (alma.TMCDB.maci.Container) data;
            // do not include this
            if (DUMMY_CONTAINER_FLAG.equals(container.getDeployInfo().getTypeModifiers()))
                continue;
            // some cleaning
            if (container.getDeployInfo() != null && container.getDeployInfo().getHost() == null)
                container.setDeployInfo(null);
            // now find its map
            String path = getNormalizedPath(container.Path);
            while (path != null && path.length() > 0) {
                // remove trailing slashes, to have unique curl (used for key)
                if (path.charAt(0) == '/') {
                    path = path.substring(1);
                    continue;
                }
                int pos = path.indexOf('/');
                String parentPath = (pos > 0) ? path.substring(0, pos) : path;
                String subpath = (pos > 0) ? path.substring(pos + 1, path.length()) : null;
                alma.TMCDB.maci.ContainerNode parentContainer = (alma.TMCDB.maci.ContainerNode) parentMap.get(parentPath);
                if (parentContainer == null) {
                    parentContainer = new alma.TMCDB.maci.ContainerNode();
                    parentMap.put(parentPath, parentContainer);
                }
                parentMap = parentContainer._;
                path = subpath;
            }
            // unique key generation
            int count = 0;
            String key = baseKey;
            while (parentMap.containsKey(key)) key = baseKey + String.valueOf(++count);
            parentMap.put(key, data);
            if (data instanceof alma.TMCDB.maci.Container) {
                alma.TMCDB.maci.Container cont = (alma.TMCDB.maci.Container) data;
                m_logger.finer("Loaded container name=" + cont.Path + cont.getName() + ", implLang=" + cont.getImplLang());
            } else {
                m_logger.warning("Bad container class '" + data.getClass().getName() + "' read from TMCDB.");
            }
        }
    } catch (Throwable th) {
        th.printStackTrace();
    }
    return map;
}
Also used : RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) Method(java.lang.reflect.Method) Comparator(java.util.Comparator) Field(java.lang.reflect.Field) Container(alma.acs.tmcdb.Container) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Session(org.hibernate.Session)

Example 8 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap in project ACS by ACS-Community.

the class HibernateWDALAlarmPluginImpl method loadEpilogue.

/* (non-Javadoc)
	 * @see com.cosylab.cdb.jdal.hibernate.plugin.HibernateWDALPlugin#loadEpilogue(org.hibernate.Session, alma.acs.tmcdb.Configuration, java.util.Map)
	 */
@SuppressWarnings("unchecked")
public static void loadEpilogue(Session session, Configuration config, Map<String, Object> rootMap, Logger m_logger) {
    try {
        DOMConfigurationAccessor conf = new DOMConfigurationAccessor();
        conf.setSession(session);
        Map<String, Object> alarmsRoot = new RootMap<String, Object>();
        Map<String, Object> administrativeRoot = new RootMap<String, Object>();
        alarmsRoot.put("Administrative", administrativeRoot);
        administrativeRoot.put("AlarmSystemConfiguration", new AlarmSystemConfiguration());
        Categories categoriesMap = new Categories(session, config, conf, rootMap, m_logger);
        administrativeRoot.put("Categories", categoriesMap);
        conf.put(Categories.CATEGORY_DEFINITION_PATH, categoriesMap);
        // categories
        int counter = 0;
        List<AlarmCategory> categories = session.createCriteria(AlarmCategory.class).add(Restrictions.eq("configuration", config)).list();
        for (AlarmCategory category : categories) {
            ArrayList<String> families = new ArrayList<String>();
            for (FaultFamily family : category.getFaultFamilies()) families.add(family.getFamilyName());
            categoriesMap.put("category" + String.valueOf(counter++), new alma.TMCDB.alarm.Category(category.getPath(), category.getDescription(), category.getIsDefault(), families.toArray(new String[families.size()])));
        }
        // fault families
        Map<String, alma.TMCDB.alarm.FaultFamily> faultFamiliesMap = new FaultFamiliesMap(session, config, conf, rootMap, m_logger);
        alarmsRoot.put("AlarmDefinitions", faultFamiliesMap);
        conf.put(FaultFamiliesMap.ALARM_CATEGORY_DEFINITION_PATH, faultFamiliesMap);
        counter = 0;
        List<FaultFamily> families = session.createCriteria(FaultFamily.class).add(Restrictions.eq("configuration", config)).addOrder(Order.asc("familyName")).list();
        for (FaultFamily family : families) {
            Contact contact = family.getContact();
            alma.TMCDB.alarm.FaultFamily faultFamily = new alma.TMCDB.alarm.FaultFamily(family.getFamilyName(), family.getAlarmSource(), family.getHelpURL(), new alma.TMCDB.alarm.Contact(contact.getContactName(), contact.getEmail(), contact.getGsm()));
            faultFamiliesMap.put("fault-family" + String.valueOf(counter++), faultFamily);
            // fault codes
            int codeCounter = 0;
            List<FaultCode> faultCodes = session.createCriteria(FaultCode.class).add(Restrictions.eq("faultFamily", family)).list();
            for (FaultCode faultCode : faultCodes) {
                faultFamily._.put("fault-code" + String.valueOf(codeCounter++), new alma.TMCDB.alarm.FaultCode(faultCode.getCodeValue(), faultCode.getIsInstant(), faultCode.getPriority(), faultCode.getCause(), faultCode.getAction(), faultCode.getConsequence(), faultCode.getProblemDescription()));
            }
            // default fault member
            DefaultMember defaultMember = (DefaultMember) session.createCriteria(DefaultMember.class).add(Restrictions.eq("faultFamily", family)).uniqueResult();
            if (defaultMember != null) {
                alma.TMCDB.alarm.Location location = getLocation(session, defaultMember.getLocation());
                faultFamily._.put("fault-member-default", new FaultMemberDefault(location));
            }
            // fault members
            int faultMemberCounter = 0;
            List<FaultMember> faultMembers = session.createCriteria(FaultMember.class).add(Restrictions.eq("faultFamily", family)).list();
            for (FaultMember faultMember : faultMembers) {
                alma.TMCDB.alarm.Location location = getLocation(session, faultMember.getLocation());
                faultFamily._.put("fault-member" + String.valueOf(faultMemberCounter++), new alma.TMCDB.alarm.FaultMember(faultMember.getMemberName(), location));
            }
        }
        // reductions
        ReductionDefinitions redDefs = new ReductionDefinitions(session, config, conf, rootMap, m_logger);
        administrativeRoot.put("ReductionDefinitions", redDefs);
        int linkCount = 0;
        List<alma.acs.tmcdb.ReductionLink> links = session.createCriteria(alma.acs.tmcdb.ReductionLink.class).add(Restrictions.eq("configuration", config)).list();
        for (alma.acs.tmcdb.ReductionLink link : links) {
            alma.acs.tmcdb.AlarmDefinition parent = link.getAlarmDefinitionByParentalarmdefid();
            alma.acs.tmcdb.AlarmDefinition child = link.getAlarmDefinitionByChildalarmdefid();
            ReductionLinks toLink;
            if (link.getAction() == ReductionLinkAction.CREATE)
                toLink = redDefs.getLinksToCreate();
            else if (link.getAction() == ReductionLinkAction.REMOVE)
                toLink = redDefs.getLinksToRemove();
            else
                throw new RuntimeException("unsupported reduction link action '" + link.getAction() + "' for ReductionLink with id: " + link.getReductionLinkId());
            toLink._.put("link" + (linkCount++), new ReductionLink(link.getType().toString(), new AlarmDefinition(parent.getFaultFamily(), parent.getFaultMember(), parent.getFaultCode()), new AlarmDefinition(child.getFaultFamily(), child.getFaultMember(), child.getFaultCode())));
        }
        int thresholdCount = 0;
        List<alma.acs.tmcdb.ReductionThreshold> thresholds = session.createCriteria(alma.acs.tmcdb.ReductionThreshold.class).add(Restrictions.eq("configuration", config)).list();
        for (alma.acs.tmcdb.ReductionThreshold threshold : thresholds) {
            alma.acs.tmcdb.AlarmDefinition alarm = threshold.getAlarmDefinition();
            redDefs.getThresholds()._.put("threshold" + (thresholdCount++), new alma.TMCDB.alarm.ReductionThreshold(threshold.getValue(), new AlarmDefinition(alarm.getFaultFamily(), alarm.getFaultMember(), alarm.getFaultCode())));
        }
        // alarm configuration
        rootMap.put("Alarms", alarmsRoot);
    } catch (Throwable th) {
        m_logger.log(Level.SEVERE, "Failed to load all the alarm data.", th);
    }
}
Also used : FaultCode(alma.acs.tmcdb.FaultCode) RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) ArrayList(java.util.ArrayList) ReductionThreshold(alma.acs.tmcdb.ReductionThreshold) ReductionDefinitions(alma.TMCDB.alarm.ReductionDefinitions) DefaultMember(alma.acs.tmcdb.DefaultMember) FaultFamiliesMap(alma.TMCDB.alarm.FaultFamiliesMap) ReductionLink(alma.TMCDB.alarm.ReductionLink) ReductionThreshold(alma.acs.tmcdb.ReductionThreshold) AlarmCategory(alma.acs.tmcdb.AlarmCategory) FaultMember(alma.acs.tmcdb.FaultMember) DOMConfigurationAccessor(alma.TMCDB.alarm.DOMConfigurationAccessor) Categories(alma.TMCDB.alarm.Categories) AlarmDefinition(alma.TMCDB.alarm.AlarmDefinition) Contact(alma.acs.tmcdb.Contact) FaultMemberDefault(alma.TMCDB.alarm.FaultMemberDefault) ReductionLinks(alma.TMCDB.alarm.ReductionLinks) FaultFamily(alma.acs.tmcdb.FaultFamily) AlarmSystemConfiguration(alma.TMCDB.alarm.AlarmSystemConfiguration)

Example 9 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap in project ACS by ACS-Community.

the class HibernateWDALAlarmPluginImpl method updateEpilogue.

/* (non-Javadoc)
	 * @see com.cosylab.cdb.jdal.hibernate.plugin.HibernateWDALPlugin#updateEpilogue(org.hibernate.Session, alma.acs.tmcdb.Configuration, java.util.Map)
	 */
@SuppressWarnings("unchecked")
public static void updateEpilogue(Session session, Configuration config, Map<String, Object> rootMap, Logger m_logger, String curl) {
    if (!curl.startsWith("Alarms"))
        return;
    else if (curl.matches("Alarms")) {
        loadEpilogue(session, config, rootMap, m_logger);
        return;
    }
    String c = curl.replaceFirst("Alarms/", "");
    try {
        DOMConfigurationAccessor conf = new DOMConfigurationAccessor();
        conf.setSession(session);
        Map<String, Object> alarmsRoot = new RootMap<String, Object>();
        Map<String, Object> administrativeRoot = new RootMap<String, Object>();
        alarmsRoot.put("Administrative", administrativeRoot);
        administrativeRoot.put("AlarmSystemConfiguration", new AlarmSystemConfiguration());
        Categories categoriesMap = new Categories(session, config, conf, rootMap, m_logger);
        administrativeRoot.put("Categories", categoriesMap);
        conf.put(Categories.CATEGORY_DEFINITION_PATH, categoriesMap);
        // categories
        int counter = 0;
        List<AlarmCategory> categories = session.createCriteria(AlarmCategory.class).add(Restrictions.eq("configuration", config)).list();
        for (AlarmCategory category : categories) {
            ArrayList<String> families = new ArrayList<String>();
            for (FaultFamily family : category.getFaultFamilies()) families.add(family.getFamilyName());
            categoriesMap.put("category" + String.valueOf(counter++), new alma.TMCDB.alarm.Category(category.getPath(), category.getDescription(), category.getIsDefault(), families.toArray(new String[families.size()])));
        }
        // fault families
        Map<String, alma.TMCDB.alarm.FaultFamily> faultFamiliesMap = new FaultFamiliesMap(session, config, conf, rootMap, m_logger);
        alarmsRoot.put("AlarmDefinitions", faultFamiliesMap);
        conf.put(FaultFamiliesMap.ALARM_CATEGORY_DEFINITION_PATH, faultFamiliesMap);
        counter = 0;
        List<FaultFamily> families = session.createCriteria(FaultFamily.class).add(Restrictions.eq("configuration", config)).addOrder(Order.asc("familyName")).list();
        for (FaultFamily family : families) {
            Contact contact = family.getContact();
            alma.TMCDB.alarm.FaultFamily faultFamily = new alma.TMCDB.alarm.FaultFamily(family.getFamilyName(), family.getAlarmSource(), family.getHelpURL(), new alma.TMCDB.alarm.Contact(contact.getContactName(), contact.getEmail(), contact.getGsm()));
            faultFamiliesMap.put("fault-family" + String.valueOf(counter++), faultFamily);
            // fault codes
            int codeCounter = 0;
            List<FaultCode> faultCodes = session.createCriteria(FaultCode.class).add(Restrictions.eq("faultFamily", family)).list();
            for (FaultCode faultCode : faultCodes) {
                faultFamily._.put("fault-code" + String.valueOf(codeCounter++), new alma.TMCDB.alarm.FaultCode(faultCode.getCodeValue(), faultCode.getIsInstant(), faultCode.getPriority(), faultCode.getCause(), faultCode.getAction(), faultCode.getConsequence(), faultCode.getProblemDescription()));
            }
            // default fault member
            DefaultMember defaultMember = (DefaultMember) session.createCriteria(DefaultMember.class).add(Restrictions.eq("faultFamily", family)).uniqueResult();
            if (defaultMember != null) {
                alma.TMCDB.alarm.Location location = getLocation(session, defaultMember.getLocation());
                faultFamily._.put("fault-member-default", new FaultMemberDefault(location));
            }
            // fault members
            int faultMemberCounter = 0;
            List<FaultMember> faultMembers = session.createCriteria(FaultMember.class).add(Restrictions.eq("faultFamily", family)).list();
            for (FaultMember faultMember : faultMembers) {
                alma.TMCDB.alarm.Location location = getLocation(session, faultMember.getLocation());
                faultFamily._.put("fault-member" + String.valueOf(faultMemberCounter++), new alma.TMCDB.alarm.FaultMember(faultMember.getMemberName(), location));
            }
        }
        // reductions
        ReductionDefinitions redDefs = new ReductionDefinitions(session, config, conf, rootMap, m_logger);
        administrativeRoot.put("ReductionDefinitions", redDefs);
        int linkCount = 0;
        List<alma.acs.tmcdb.ReductionLink> links = session.createCriteria(alma.acs.tmcdb.ReductionLink.class).add(Restrictions.eq("configuration", config)).list();
        for (alma.acs.tmcdb.ReductionLink link : links) {
            alma.acs.tmcdb.AlarmDefinition parent = link.getAlarmDefinitionByParentalarmdefid();
            alma.acs.tmcdb.AlarmDefinition child = link.getAlarmDefinitionByChildalarmdefid();
            ReductionLinks toLink;
            if (link.getAction() == ReductionLinkAction.CREATE)
                toLink = redDefs.getLinksToCreate();
            else if (link.getAction() == ReductionLinkAction.REMOVE)
                toLink = redDefs.getLinksToRemove();
            else
                throw new RuntimeException("unsupported reduction link action '" + link.getAction() + "' for ReductionLink with id: " + link.getReductionLinkId());
            toLink._.put("link" + (linkCount++), new ReductionLink(link.getType().toString(), new AlarmDefinition(parent.getFaultFamily(), parent.getFaultMember(), parent.getFaultCode()), new AlarmDefinition(child.getFaultFamily(), child.getFaultMember(), child.getFaultCode())));
        }
        int thresholdCount = 0;
        List<alma.acs.tmcdb.ReductionThreshold> thresholds = session.createCriteria(alma.acs.tmcdb.ReductionThreshold.class).add(Restrictions.eq("configuration", config)).list();
        for (alma.acs.tmcdb.ReductionThreshold threshold : thresholds) {
            alma.acs.tmcdb.AlarmDefinition alarm = threshold.getAlarmDefinition();
            redDefs.getThresholds()._.put("threshold" + (thresholdCount++), new alma.TMCDB.alarm.ReductionThreshold(threshold.getValue(), new AlarmDefinition(alarm.getFaultFamily(), alarm.getFaultMember(), alarm.getFaultCode())));
        }
        // alarm configuration
        rootMap.put("Alarms", alarmsRoot);
    } catch (Throwable th) {
        m_logger.log(Level.SEVERE, "Failed to update all the alarm data.", th);
    }
}
Also used : FaultCode(alma.acs.tmcdb.FaultCode) RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) ArrayList(java.util.ArrayList) ReductionThreshold(alma.acs.tmcdb.ReductionThreshold) ReductionDefinitions(alma.TMCDB.alarm.ReductionDefinitions) DefaultMember(alma.acs.tmcdb.DefaultMember) FaultFamiliesMap(alma.TMCDB.alarm.FaultFamiliesMap) ReductionLink(alma.TMCDB.alarm.ReductionLink) ReductionThreshold(alma.acs.tmcdb.ReductionThreshold) AlarmCategory(alma.acs.tmcdb.AlarmCategory) FaultMember(alma.acs.tmcdb.FaultMember) DOMConfigurationAccessor(alma.TMCDB.alarm.DOMConfigurationAccessor) Categories(alma.TMCDB.alarm.Categories) AlarmDefinition(alma.TMCDB.alarm.AlarmDefinition) Contact(alma.acs.tmcdb.Contact) FaultMemberDefault(alma.TMCDB.alarm.FaultMemberDefault) ReductionLinks(alma.TMCDB.alarm.ReductionLinks) FaultFamily(alma.acs.tmcdb.FaultFamily) AlarmSystemConfiguration(alma.TMCDB.alarm.AlarmSystemConfiguration)

Example 10 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap in project ACS by ACS-Community.

the class HibernateWDALImpl method getTableMap.

public Map<String, Object> getTableMap(Session session, String keyField, Class type) {
    Map<String, Object> map = new RootMap<String, Object>();
    try {
        Method accessor = DOMJavaClassIntrospector.getAccessorMethod(type, keyField);
        Field field = null;
        if (accessor == null) {
            try {
                field = type.getField(keyField);
            } catch (Throwable th) {
                throw new IllegalStateException("failed to obtain key ");
            }
        }
        List list = getListForConfiguration(session, type);
        for (Object data : list) {
            String baseKey;
            if (accessor != null)
                baseKey = accessor.invoke(data, (Object[]) null).toString();
            else
                //if (field != null)
                baseKey = field.get(data).toString();
            // should not be null
            // unique key generation
            int count = 0;
            String key = baseKey;
            while (map.containsKey(key)) key = baseKey + String.valueOf(++count);
            map.put(key, data);
        }
    } catch (Throwable th) {
        th.printStackTrace();
    }
    return map;
}
Also used : RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Method(java.lang.reflect.Method)

Aggregations

RootMap (com.cosylab.cdb.jdal.hibernate.RootMap)14 ArrayList (java.util.ArrayList)13 LinkedList (java.util.LinkedList)11 List (java.util.List)11 Session (org.hibernate.Session)11 HashMap (java.util.HashMap)8 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 Field (java.lang.reflect.Field)6 Method (java.lang.reflect.Method)6 Criterion (org.hibernate.criterion.Criterion)5 ClientLogManager (alma.acs.logging.ClientLogManager)3 Component (alma.acs.tmcdb.Component)3 Container (alma.acs.tmcdb.Container)3 Comparator (java.util.Comparator)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 LinkedHashSet (java.util.LinkedHashSet)3 AlarmDefinition (alma.TMCDB.alarm.AlarmDefinition)2 AlarmSystemConfiguration (alma.TMCDB.alarm.AlarmSystemConfiguration)2