Search in sources :

Example 51 with Services

use of org.apache.oozie.service.Services in project oozie by apache.

the class TestTimestampedMessageParser method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    services = new Services();
    services.init();
}
Also used : Services(org.apache.oozie.service.Services)

Example 52 with Services

use of org.apache.oozie.service.Services in project oozie by apache.

the class TestXConfiguration method testSubstituteVarUnlimited.

public void testSubstituteVarUnlimited() throws ServiceException {
    Services services = new Services();
    services.get(ConfigurationService.class).getConf().set(XConfiguration.CONFIGURATION_SUBSTITUTE_DEPTH, "-1");
    services.init();
    int depth = ConfigurationService.getInt(XConfiguration.CONFIGURATION_SUBSTITUTE_DEPTH);
    assertEquals(-1, depth);
    XConfiguration.initalized = false;
    XConfiguration conf = new XConfiguration();
    conf.set("key0", "hello");
    int testMax = 100;
    for (int i = 1; i < testMax + 5; i++) {
        // key1, ${key0}
        conf.set(String.valueOf("key" + i), String.valueOf("${key" + (i - 1) + "}"));
    }
    assertEquals("hello", conf.get("key0"));
    assertEquals("hello", conf.get("key1"));
    assertEquals("hello", conf.get("key" + (testMax - 1)));
    services.destroy();
}
Also used : Services(org.apache.oozie.service.Services)

Example 53 with Services

use of org.apache.oozie.service.Services in project oozie by apache.

the class TestXConfiguration method testSubstituteVar.

public void testSubstituteVar() throws ServiceException {
    Services services = new Services();
    services.init();
    int depth = ConfigurationService.getInt(XConfiguration.CONFIGURATION_SUBSTITUTE_DEPTH);
    XConfiguration.initalized = false;
    XConfiguration conf = new XConfiguration();
    conf.set("key0", "hello");
    for (int i = 1; i < depth + 5; i++) {
        // key1, ${key0}
        conf.set(String.valueOf("key" + i), String.valueOf("${key" + (i - 1) + "}"));
    }
    assertEquals("hello", conf.get("key0"));
    assertEquals("hello", conf.get("key1"));
    assertEquals("hello", conf.get("key" + (depth - 1)));
    try {
        conf.get(String.valueOf("key" + (depth)));
        fail("Fail to apply substitution depth");
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("Variable substitution depth too large: " + depth));
    }
    services.destroy();
}
Also used : Services(org.apache.oozie.service.Services)

Example 54 with Services

use of org.apache.oozie.service.Services in project oozie by apache.

the class TestXLogFilter method testXLogFilter.

public void testXLogFilter() throws ServiceException, CommandException {
    Services services = new Services();
    services.init();
    try {
        XLogFilter xf2 = new XLogFilter();
        xf2.constructPattern();
        ArrayList<String> a = new ArrayList<String>();
        a.add("2009-06-24 02:43:13,958");
        a.add(" DEBUG");
        a.add(" WorkflowRunnerCallable:323 - " + XLog.Info.get().createPrefix() + " test log");
        assertEquals(true, xf2.matches(a));
    } finally {
        services.destroy();
    }
    XLogFilter.reset();
    XLogFilter.defineParameter("USER");
    XLogFilter.defineParameter("GROUP");
    XLogFilter.defineParameter("TOKEN");
    XLogFilter.defineParameter("APP");
    XLogFilter.defineParameter("JOB");
    XLogFilter.defineParameter("ACTION");
    XLogFilter xf = new XLogFilter();
    assertEquals(7, matches(xf));
    xf.setLogLevel(XLog.Level.WARN.toString());
    assertEquals(2, matches(xf));
    xf.setLogLevel(XLog.Level.WARN.toString());
    xf.setParameter("APP", "example-forkjoinwf");
    assertEquals(0, matches(xf));
    xf.setLogLevel(XLog.Level.DEBUG.toString() + "|" + XLog.Level.INFO.toString());
    xf.setParameter("JOB", "14-200904160239--example-forkjoinwf");
    assertEquals(2, matches(xf));
    XLogFilter xf1 = new XLogFilter();
    xf1.setParameter("USER", "oozie");
    assertEquals(3, matches(xf1));
    xf1.setParameter("GROUP", "oozie");
    assertEquals(2, matches(xf1));
    xf1.setParameter("TOKEN", "MYtoken");
    assertEquals(1, matches(xf1));
}
Also used : Services(org.apache.oozie.service.Services) ArrayList(java.util.ArrayList)

Example 55 with Services

use of org.apache.oozie.service.Services in project oozie by apache.

the class TestXLogUserFilterParam method testNoException_Withrecent.

// Test log duration - in range
public void testNoException_Withrecent() throws Exception {
    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.store(new FileOutputStream(log4jFile), "");
    setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
    new Services().init();
    Services.get().getConf().setInt(XLogFilter.MAX_SCAN_DURATION, 10);
    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    String param = XLogUserFilterParam.RECENT_LOG_OFFSET + "=9";
    paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
    XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
    Date startDate = new Date();
    Date endDate = new Date(startDate.getTime() + 60 * 60 * 1000 * 15);
    try {
        doStreamLog(filter, startDate, endDate);
    } catch (Exception e) {
        fail("should not throw exception");
    }
}
Also used : HashMap(java.util.HashMap) XLogFilter(org.apache.oozie.util.XLogFilter) InputStream(java.io.InputStream) Properties(java.util.Properties) Date(java.util.Date) Services(org.apache.oozie.service.Services) FileOutputStream(java.io.FileOutputStream) File(java.io.File) XLogUserFilterParam(org.apache.oozie.util.XLogUserFilterParam)

Aggregations

Services (org.apache.oozie.service.Services)247 JPAService (org.apache.oozie.service.JPAService)32 Configuration (org.apache.hadoop.conf.Configuration)21 Date (java.util.Date)17 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)16 File (java.io.File)14 Before (org.junit.Before)14 XConfiguration (org.apache.oozie.util.XConfiguration)11 Path (org.apache.hadoop.fs.Path)10 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)10 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)8 EmbeddedServletContainer (org.apache.oozie.test.EmbeddedServletContainer)8 FileOutputStream (java.io.FileOutputStream)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 IOException (java.io.IOException)6 Properties (java.util.Properties)6 ActionService (org.apache.oozie.service.ActionService)6 StringWriter (java.io.StringWriter)5 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)5