Search in sources :

Example 6 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class JsonRestServlet method logHeaderInfo.

private void logHeaderInfo(HttpServletRequest request) {
    XLog log = XLog.getLog(getClass());
    StringBuilder traceInfo = new StringBuilder(4096);
    // Display request URL and request.getHeaderNames();
    Enumeration<String> names = (Enumeration<String>) request.getHeaderNames();
    traceInfo.append("Request URL: ").append(getRequestUrl(request)).append("\nRequest Headers:\n");
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String value = request.getHeader(name);
        traceInfo.append(name).append(" : ").append(value).append("\n");
    }
    log.trace(traceInfo);
}
Also used : XLog(org.apache.oozie.util.XLog)

Example 7 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class XLogService method init.

/**
 * Initialize the log service.
 *
 * @param services services instance.
 * @throws ServiceException thrown if the log service could not be initialized.
 */
public void init(Services services) throws ServiceException {
    String oozieHome = Services.getOozieHome();
    String oozieLogs = System.getProperty(OOZIE_LOG_DIR, oozieHome + "/logs");
    System.setProperty(OOZIE_LOG_DIR, oozieLogs);
    try {
        LogManager.resetConfiguration();
        log4jFileName = System.getProperty(LOG4J_FILE, DEFAULT_LOG4J_PROPERTIES);
        if (log4jFileName.contains("/")) {
            throw new ServiceException(ErrorCode.E0011, log4jFileName);
        }
        if (!log4jFileName.endsWith(".properties")) {
            throw new ServiceException(ErrorCode.E0012, log4jFileName);
        }
        String configPath = ConfigurationService.getConfigurationDirectory();
        File log4jFile = new File(configPath, log4jFileName);
        if (log4jFile.exists()) {
            fromClasspath = false;
        } else {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            URL log4jUrl = cl.getResource(log4jFileName);
            if (log4jUrl == null) {
                throw new ServiceException(ErrorCode.E0013, log4jFileName, configPath);
            }
            fromClasspath = true;
        }
        if (fromClasspath) {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            URL log4jUrl = cl.getResource(log4jFileName);
            PropertyConfigurator.configure(log4jUrl);
        } else {
            interval = Long.parseLong(System.getProperty(LOG4J_RELOAD, DEFAULT_RELOAD_INTERVAL));
            PropertyConfigurator.configureAndWatch(log4jFile.toString(), interval * 1000);
        }
        log = new XLog(LogFactory.getLog(getClass()));
        log.info(XLog.OPS, STARTUP_MESSAGE, BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VERSION), BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_USER_NAME), BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_TIME), BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VC_REVISION), BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VC_URL));
        String from = (fromClasspath) ? "CLASSPATH" : configPath;
        String reload = (fromClasspath) ? "disabled" : Long.toString(interval) + " sec";
        log.info("Log4j configuration file [{0}]", log4jFileName);
        log.info("Log4j configuration file loaded from [{0}]", from);
        log.info("Log4j reload interval [{0}]", reload);
        XLog.Info.reset();
        XLog.Info.defineParameter(USER);
        XLog.Info.defineParameter(GROUP);
        XLogFilter.reset();
        XLogFilter.defineParameter(USER);
        XLogFilter.defineParameter(GROUP);
        // Getting configuration for oozie log via WS
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        InputStream is = (fromClasspath) ? cl.getResourceAsStream(log4jFileName) : new FileInputStream(log4jFile);
        extractInfoForLogWebService(is);
    } catch (IOException ex) {
        throw new ServiceException(ErrorCode.E0010, ex.getMessage(), ex);
    }
}
Also used : XLog(org.apache.oozie.util.XLog) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 8 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class RecoveryService method mergeConfig.

/**
 * Merge Bundle job config and the configuration from the coord job to pass
 * to Coord Engine
 *
 * @param coordElem the coordinator configuration
 * @return Configuration merged configuration
 * @throws CommandException thrown if failed to merge configuration
 */
private static Configuration mergeConfig(Element coordElem, BundleJobBean bundleJob) throws CommandException {
    XLog.Info.get().clear();
    XLog log = XLog.getLog("RecoveryService");
    String jobConf = bundleJob.getConf();
    // Step 1: runConf = jobConf
    Configuration runConf = null;
    try {
        runConf = new XConfiguration(new StringReader(jobConf));
    } catch (IOException e1) {
        log.warn("Configuration parse error in:" + jobConf);
        throw new CommandException(ErrorCode.E1306, e1.getMessage(), e1);
    }
    // Step 2: Merge local properties into runConf
    // extract 'property' tags under 'configuration' block in the coordElem
    // convert Element to XConfiguration
    Element localConfigElement = coordElem.getChild("configuration", coordElem.getNamespace());
    if (localConfigElement != null) {
        String strConfig = XmlUtils.prettyPrint(localConfigElement).toString();
        Configuration localConf;
        try {
            localConf = new XConfiguration(new StringReader(strConfig));
        } catch (IOException e1) {
            log.warn("Configuration parse error in:" + strConfig);
            throw new CommandException(ErrorCode.E1307, e1.getMessage(), e1);
        }
        // copy configuration properties in the coordElem to the runConf
        XConfiguration.copy(localConf, runConf);
    }
    // Step 3: Extract value of 'app-path' in coordElem, save it as a
    // new property called 'oozie.coord.application.path', and normalize.
    String appPath = coordElem.getChild("app-path", coordElem.getNamespace()).getValue();
    runConf.set(OozieClient.COORDINATOR_APP_PATH, appPath);
    // Normalize coordinator appPath here;
    try {
        JobUtils.normalizeAppPath(runConf.get(OozieClient.USER_NAME), runConf.get(OozieClient.GROUP_NAME), runConf);
    } catch (IOException e) {
        throw new CommandException(ErrorCode.E1001, runConf.get(OozieClient.COORDINATOR_APP_PATH));
    }
    return runConf;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) XLog(org.apache.oozie.util.XLog) Element(org.jdom.Element) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 9 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class TestXLogStreamingService method testAuditLog.

public void testAuditLog() throws Exception {
    setupXLog();
    XLogFilter xf = new XLogAuditFilter(new XLogUserFilterParam(null));
    xf.setParameter("USER", "oozie");
    xf.setLogLevel("DEBUG|INFO");
    File log4jFile = new File(getTestCaseConfDir(), "test-log4j.properties");
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    InputStream is = cl.getResourceAsStream("test-no-dash-log4j.properties");
    Properties log4jProps = new Properties();
    log4jProps.load(is);
    // prevent conflicts with other tests by changing the log file location
    log4jProps.setProperty("log4j.appender.oozie.File", getTestCaseDir() + "/oozie.log");
    log4jProps.setProperty("log4j.appender.oozieaudit.File", getTestCaseDir() + "/oozie-audit.log");
    log4jProps.store(new FileOutputStream(log4jFile), "");
    setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
    try {
        new Services().init();
        XLog auditLog = XLog.getLog("oozieaudit");
        xf.setParameter(DagXLogInfoService.JOB, "0000000-150322000230582-oozie-puru-C");
        auditLog.info("2015-03-22 00:04:35,494  INFO oozieaudit:520 - IP [127.0.0.1], USER [purushah], GROUP [null], " + "APP [-], JOBID [0000000-150322000230582-oozie-puru-C], OPERATION [start], " + "PARAMETER [null], STATUS [SUCCESS], HTTPCODE [200], ERRORCODE [null], ERRORMESSAGE [L1]");
        auditLog.info("2015-03-22 00:05:13,823  INFO oozieaudit:520 - IP [127.0.0.1], USER [purushah], GROUP [null], " + "APP [-], JOBID [0000000-150322000230582-oozie-puru-C], OPERATION [suspend], " + "PARAMETER [0000000-150322000230582-oozie-puru-C], STATUS [SUCCESS], HTTPCODE [200], ERRORCODE [null], " + "ERRORMESSAGE [L2]");
        auditLog.info("2015-03-22 00:05:13,823  INFO oozieaudit:520 - IP [127.0.0.1], USER [purushah], GROUP [null], " + "APP [-], JOBID [0000001-150322000230582-oozie-puru-C], OPERATION [suspend], " + "PARAMETER [0000001-150322000230582-oozie-puru-C], STATUS [SUCCESS], HTTPCODE [200], ERRORCODE [null], " + "ERRORMESSAGE [L3]");
        String out = doStreamAuditLog(xf);
        String[] outArr = out.split("\n");
        // Lines 2 and 4 are filtered out because they have the wrong user
        assertEquals(2, outArr.length);
        assertTrue(outArr[0].contains("L1"));
        assertTrue(out.contains("L2"));
        assertFalse(out.contains("L3"));
    } finally {
        Services.get().destroy();
    }
}
Also used : XLogAuditFilter(org.apache.oozie.util.XLogAuditFilter) XLogFilter(org.apache.oozie.util.XLogFilter) XLog(org.apache.oozie.util.XLog) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam) File(java.io.File)

Example 10 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class XTestCase method waitFor.

/**
 * Wait for a condition, expressed via a {@link Predicate} to become true.
 *
 * @param timeout maximum time in milliseconds to wait for the predicate to become true.
 * @param predicate predicate waiting on.
 * @return the waited time.
 */
protected long waitFor(int timeout, Predicate predicate) {
    ParamChecker.notNull(predicate, "predicate");
    XLog log = new XLog(LogFactory.getLog(getClass()));
    long started = System.currentTimeMillis();
    long mustEnd = System.currentTimeMillis() + (long) (WAITFOR_RATIO * timeout);
    long lastEcho = 0;
    try {
        long waiting = mustEnd - System.currentTimeMillis();
        log.info("Waiting up to [{0}] msec", waiting);
        boolean eval;
        while (!(eval = predicate.evaluate()) && System.currentTimeMillis() < mustEnd) {
            if ((System.currentTimeMillis() - lastEcho) > 1000) {
                waiting = mustEnd - System.currentTimeMillis();
                log.info("Waiting up to [{0}] msec", waiting);
                lastEcho = System.currentTimeMillis();
            }
            Thread.sleep(1000);
        }
        if (!eval) {
            log.info("Waiting timed out after [{0}] msec", timeout);
        }
        return System.currentTimeMillis() - started;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : XLog(org.apache.oozie.util.XLog) ServiceException(org.apache.oozie.service.ServiceException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) PersistenceException(javax.persistence.PersistenceException) RollbackException(org.apache.openjpa.persistence.RollbackException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) StoreException(org.apache.oozie.store.StoreException) ArgumentException(org.apache.openjpa.persistence.ArgumentException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

XLog (org.apache.oozie.util.XLog)21 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)5 URI (java.net.URI)4 URIHandlerService (org.apache.oozie.service.URIHandlerService)4 File (java.io.File)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Configuration (org.apache.hadoop.conf.Configuration)3 CommandException (org.apache.oozie.command.CommandException)3 URIHandler (org.apache.oozie.dependency.URIHandler)3 ELEvaluator (org.apache.oozie.util.ELEvaluator)3 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 Context (org.apache.oozie.dependency.URIHandler.Context)2 Instrumentation (org.apache.oozie.util.Instrumentation)2 WorkflowException (org.apache.oozie.workflow.WorkflowException)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 StringReader (java.io.StringReader)1