Search in sources :

Example 6 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class DALRead method main.

public static void main(String[] args) {
    Logger m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("DALRead", false);
    try {
        String curl;
        String strIOR = null;
        boolean rawOutput = false;
        if (args.length < 1) {
            System.out.println("Usage: cmd curl [-d ior -raw -h]");
            return;
        }
        curl = args[0];
        // test for IOR in cmd line
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-d")) {
                if (i < args.length - 1) {
                    strIOR = args[++i];
                }
            }
            if (args[i].equals("-raw")) {
                rawOutput = true;
            }
            if (args[i].equals("-h")) {
                System.out.println("Usage: cmd curl [-d ior -raw -h]");
                return;
            }
        }
        if (strIOR == null) {
            // use default
            strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
        }
        // create and initialize the ORB
        ORB orb = ORB.init(args, null);
        DAL dal = DALHelper.narrow(orb.string_to_object(strIOR));
        String xml = dal.get_DAO(curl);
        if (rawOutput) {
            m_logger.log(AcsLogLevel.INFO, "Curl data:\n" + xml);
            return;
        }
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        XMLHandler xmlSolver = new XMLHandler(false, m_logger);
        saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx();
            System.err.println(info);
            throw xmlErr;
        }
        System.out.println("Env " + System.getProperty("HOMEPATH"));
        // dump contents
        System.out.println("________________________________________________________");
        walk(xmlSolver.m_rootNode);
        System.out.println("________________________________________________________");
    } catch (AcsJCDBXMLErrorEx e) {
        e.printStackTrace();
        e.log(m_logger);
    } catch (CDBXMLErrorEx e) {
        AcsJCDBXMLErrorEx je = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(e);
        String smsg = "XML Error \tCURL='" + je.getCurl() + "'\n\t\tFilename='" + je.getFilename() + "'\n\t\tNodename='" + je.getNodename() + "'\n\t\tMSG='" + je.getErrorString() + "'";
        je.log(m_logger);
        m_logger.log(AcsLogLevel.NOTICE, smsg, je);
    } catch (CDBRecordDoesNotExistEx e) {
        AcsJCDBRecordDoesNotExistEx je = AcsJCDBRecordDoesNotExistEx.fromCDBRecordDoesNotExistEx(e);
        String smsg = "Record does not exist \tCURL='" + je.getCurl() + "'";
        je.log(m_logger);
        m_logger.log(AcsLogLevel.NOTICE, smsg, je);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : XMLHandler(com.cosylab.cdb.jdal.XMLHandler) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) Logger(java.util.logging.Logger) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx) AcsJCDBRecordDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)

Example 7 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class DALWrite method main.

public static void main(String[] args) {
    try {
        String strIOR = null;
        if (args.length < 3) {
            System.out.println("Usage: cmd curl field value [-d ior -h]");
            return;
        }
        String curl = args[0];
        String field = args[1];
        String value = args[2];
        // test for IOR in cmd line
        for (int i = 3; i < args.length; i++) {
            if (args[i].equals("-d")) {
                if (i < args.length - 1) {
                    strIOR = args[++i];
                }
            }
            if (args[i].equals("-h") || args[i].equals("-help")) {
                System.out.println("Usage: cmd curl field value [-d ior -h]");
                return;
            }
        }
        if (strIOR == null) {
            // use default
            strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
        }
        // create and initialize the ORB
        ORB orb = ORB.init(args, null);
        WDAL wdal = WDALHelper.narrow(orb.string_to_object(strIOR));
        WDAO wdao = wdal.get_WDAO_Servant(curl);
        System.out.println("Reading '" + curl + "/" + field + "'='" + wdao.get_string(field) + "'");
        wdao.set_string(field, value);
        System.out.println("Setting '" + curl + "/" + field + "'='" + value + "'");
    } catch (CDBXMLErrorEx e) {
        AcsJCDBXMLErrorEx e2 = new AcsJCDBXMLErrorEx(e);
        System.out.println("XMLerror : " + e2.getCurl());
        e.printStackTrace(System.out);
    } catch (Exception e) {
        System.out.println("ERROR : " + e);
        e.printStackTrace(System.out);
    }
}
Also used : CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)

Example 8 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class HibernateWDALImpl method parseXML.

private void parseXML(String xml, XMLHandler xmlSolver) throws CDBXMLErrorEx {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        synchronized (xmlNodeMonitor) {
            saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
        }
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            CDBXMLErrorEx xmlErr = new CDBXMLErrorEx();
            m_logger.log(AcsLogLevel.NOTICE, info);
            throw xmlErr;
        }
    } catch (Throwable t) {
        String info = "SAXException: " + t.getMessage();
        m_logger.log(AcsLogLevel.NOTICE, info);
        AcsJCDBXMLErrorEx xmlErr = new AcsJCDBXMLErrorEx(t);
        xmlErr.setErrorString(info);
        throw xmlErr.toCDBXMLErrorEx();
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 9 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class LogConfig method initialize.

/**
	 * Initializes the values based on CDB settings, logging properties, etc. All subscribing classes are notified of
	 * the new configuration, see {@link LogConfigSubscriber#configureLogging(LogConfig)}.
	 * <p>
	 * This method can be called more than once: if some settings have changed, should be read in, and the logging
	 * classes should be notified of these changes. For example, the container could call this method when it gets
	 * notified that the logging configuration in the CDB has been changed at runtime.
	 * 
	 * @param cdbBeatsProperties
	 *            if true then the default logger level values from the CDB override the properties (env vars).
	 *            <code>True</code> is foreseen for dynamic updates from the CDB, whereas for the initial
	 *            configuration it should be a <code>false</code>.
	 * 
	 * @throws LogConfigException
	 *            if reading the configuration data failed and thus default values were used, or if there were problems
	 *            during configuration even though some of the configuring went ok (best-effort approach).
	 */
public void initialize(boolean cdbBeatsProperties) throws LogConfigException {
    StringBuffer errMsg = new StringBuffer();
    // schema binding class generated from LogggingConfig.xsd
    LoggingConfig newLoggingConfig = null;
    if (cdb != null) {
        try {
            if (cdbLoggingConfigPath != null) {
                String loggingConfigXml = getLogConfigXml(cdbLoggingConfigPath, "//" + CDBNAME_LoggingConfig);
                if (loggingConfigXml == null || loggingConfigXml.trim().isEmpty()) {
                    // the LoggingConfig child is mandatory for containers and manager
                    throw new LogConfigException("Node " + cdbLoggingConfigPath + " does not contain one LoggingConfig element.");
                }
                try {
                    newLoggingConfig = LoggingConfig.unmarshalLoggingConfig(new StringReader(loggingConfigXml));
                } catch (Throwable thr) {
                    log(Level.FINE, "Failed to unmarshal logging config xml '" + loggingConfigXml + "'.", thr);
                    throw thr;
                }
            } else {
                errMsg.append("CDB reference was set, but not the path to the logging configuration. ");
            }
            if (newLoggingConfig != null) {
                loggingConfig = newLoggingConfig;
                synchronized (namedLoggerConfigs) {
                    // but only null their configurations.
                    for (String loggerName : namedLoggerConfigs.keySet()) {
                        storeNamedLoggerConfig(loggerName, null);
                    }
                    // named logger levels from children of the <LoggingConfig/> 
                    NamedLogger[] namedLoggers = loggingConfig.get();
                    for (int i = 0; i < namedLoggers.length; i++) {
                        storeNamedLoggerConfig(namedLoggers[i].getName(), new LockableUnnamedLogger(namedLoggers[i]));
                    }
                    // check CDB config for all component loggers who got a CDB path configured
                    for (String loggerName : cdbComponentPaths.keySet()) {
                        // skip named logger if it's been already configured from the main XML, since those values have precedence
                        if (!namedLoggerConfigs.containsKey(loggerName)) {
                            String cdbPath = cdbComponentPaths.get(loggerName);
                            String xpath = "//_[@Name='" + loggerName + "']/" + CDBNAME_ComponentLogger;
                            String componentConfigXML = getLogConfigXml(cdbPath, xpath);
                            // the ComponentLogger xml child element is optional, we get a null if it's missing.
                            if (componentConfigXML != null) {
                                UnnamedLogger compLoggerConfig;
                                try {
                                    compLoggerConfig = UnnamedLogger.unmarshalUnnamedLogger(new StringReader(componentConfigXML));
                                } catch (Throwable thr) {
                                    log(Level.FINE, "Failed to unmarshal component config xml '" + componentConfigXML + "'.", thr);
                                    throw thr;
                                }
                                storeNamedLoggerConfig(loggerName, new LockableUnnamedLogger(compLoggerConfig));
                            }
                        }
                    }
                }
            } else {
                throw new LogConfigException("LoggingConfig binding class obtained from CDB node '" + cdbLoggingConfigPath + "' was null.");
            }
        } catch (CDBXMLErrorEx ex) {
            errMsg.append("Failed to read node " + cdbLoggingConfigPath + " from the CDB (msg='" + ex.errorTrace.shortDescription + "'). ");
        } catch (CDBRecordDoesNotExistEx ex) {
            errMsg.append("Node " + cdbLoggingConfigPath + " does not exist in the CDB (msg='" + ex.errorTrace.shortDescription + "'). ");
        } catch (CastorException ex) {
            errMsg.append("Failed to parse XML for CDB node " + cdbLoggingConfigPath + " into binding classes (ex=" + ex.getClass().getName() + ", msg='" + ex.getMessage() + "'). ");
        } catch (Throwable thr) {
            errMsg.append("Failed to read node " + cdbLoggingConfigPath + " from the CDB (ex=" + thr.getClass().getName() + ", msg='" + thr.getMessage() + "'). ");
        }
    }
    // consider the env var based properties only if the CDB was not considered or if the CDB settings should not override the env vars 
    if (cdb == null || !cdbBeatsProperties) {
        configureDefaultLevelsFromProperties();
        configureNamedLoggerLevelsFromProperties();
    }
    notifySubscribers();
    // present), we can publish a trace log
    if (newLoggingConfig != null) {
        StringWriter writer = new StringWriter();
        String newXML = null;
        try {
            newLoggingConfig.marshal(writer);
            newXML = writer.toString().trim();
        } catch (Throwable thr) {
            // nothing
            ;
        }
        String msg = "Updated logging configuration based on CDB entry " + newXML;
        msg += " with " + (cdbBeatsProperties ? "CDB" : "env vars") + " having precedence over " + (cdbBeatsProperties ? "env vars" : "CDB");
        log(Level.FINER, msg, null);
    // @TODO: also log something for named component loggers if any were considered 
    } else {
        log(Level.FINER, "Logging configuration has been initialized, but not from CDB settings.", null);
    }
    if (errMsg.length() > 0) {
        throw new LogConfigException("Log config initialization at least partially failed. " + errMsg.toString());
    }
}
Also used : NamedLogger(alma.maci.loggingconfig.NamedLogger) UnnamedLogger(alma.maci.loggingconfig.UnnamedLogger) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) CDBRecordDoesNotExistEx(alma.cdbErrType.CDBRecordDoesNotExistEx) StringWriter(java.io.StringWriter) LoggingConfig(alma.maci.loggingconfig.LoggingConfig) StringReader(java.io.StringReader) CastorException(org.exolab.castor.core.exceptions.CastorException)

Example 10 with CDBXMLErrorEx

use of alma.cdbErrType.CDBXMLErrorEx in project ACS by ACS-Community.

the class WDALImpl method get_WDAO_Servant.

/* (non-Javadoc)
	 * @see com.cosylab.CDB.WDALOperations#get_WDAO_servant(java.lang.String)
	 */
public WDAO get_WDAO_Servant(String curl) throws CDBXMLErrorEx {
    dalImpl.totalDALInvocationCounter.incrementAndGet();
    // if we already have WDAO
    synchronized (wdaoMap) {
        if (wdaoMap.containsKey(curl)) {
            return wdaoMap.get(curl);
        }
    }
    try {
        // use dao from delegate (logically: base) implementation so we can change objects already active i.e. if Manager creates DAO /MACI/Managers/Manager
        // later we instantiate a WDAO of the same curl and change values that Manager looks at 
        org.omg.PortableServer.Servant daoServant = poa.reference_to_servant(dalImpl.get_DAO_Servant(curl));
        DAOImpl daoImpl = (DAOImpl) ((DAOPOATie) daoServant)._delegate();
        WDAOImpl wdaoImpl = new WDAOImpl(this, curl, daoImpl, poa, logger);
        // create object id
        String name = "WDAO-" + curl;
        byte[] id = name.getBytes();
        // activate object
        poa.activate_object_with_id(id, wdaoImpl);
        WDAO href = WDAOHelper.narrow(poa.servant_to_reference(wdaoImpl));
        // map reference
        wdaoMap.put(curl, href);
        return href;
    } catch (Throwable t) {
        String info = "WDAL::get_WDAO_Servant " + t;
        CDBXMLErrorEx xmlErr = new CDBXMLErrorEx();
        logger.log(AcsLogLevel.NOTICE, info);
        throw xmlErr;
    }
}
Also used : WDAO(com.cosylab.CDB.WDAO) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)

Aggregations

CDBXMLErrorEx (alma.cdbErrType.CDBXMLErrorEx)10 AcsJCDBXMLErrorEx (alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx)8 StringReader (java.io.StringReader)3 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)2 WDAO (com.cosylab.CDB.WDAO)2 StringWriter (java.io.StringWriter)2 StringTokenizer (java.util.StringTokenizer)2 NamingException (javax.naming.NamingException)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 InputSource (org.xml.sax.InputSource)2 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)1 LoggingConfig (alma.maci.loggingconfig.LoggingConfig)1 NamedLogger (alma.maci.loggingconfig.NamedLogger)1 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)1 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)1 WDAL (com.cosylab.CDB.WDAL)1 XMLHandler (com.cosylab.cdb.jdal.XMLHandler)1 XMLTreeNode (com.cosylab.cdb.jdal.XMLTreeNode)1 IOException (java.io.IOException)1