Search in sources :

Example 1 with CoordSubmitXCommand

use of org.apache.oozie.command.coord.CoordSubmitXCommand in project oozie by apache.

the class TestSLAEventGeneration method testCoordinatorActionCommandsSubmitAndStart.

/**
 * Test for SLA Events generated through Coordinator Action commands
 * CoordSubmitX and CoordStartX
 *
 * @throws Exception
 */
@Test
public void testCoordinatorActionCommandsSubmitAndStart() throws Exception {
    // reduce noise from WF Job events (also default) by setting it to only
    // coord action
    ehs.setAppTypes(new HashSet<String>(Arrays.asList(new String[] { "coordinator_action" })));
    ehs.getEventQueue().clear();
    SLAService slas = services.get(SLAService.class);
    String coordXml = IOUtils.getResourceAsString("coord-action-sla.xml", -1);
    Path appPath = getFsTestCaseDir();
    writeToFile(coordXml, appPath, "coordinator.xml");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPath.toString());
    String wfXml = IOUtils.getResourceAsString("wf-credentials.xml", -1);
    writeToFile(wfXml, appPath, "workflow.xml");
    conf.set("wfAppPath", appPath.toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    cal.setTime(new Date());
    // for start_miss
    cal.add(Calendar.MINUTE, -20);
    Date nominal = cal.getTime();
    String nominalTime = DateUtils.formatDateOozieTZ(nominal);
    conf.set("nominal_time", nominalTime);
    conf.set("start", "2009-01-02T08:01Z");
    conf.set("frequency", "coord:days(1)");
    conf.set("end", "2009-01-03T08:00Z");
    cal.setTime(nominal);
    // as per the sla xml
    cal.add(Calendar.MINUTE, 10);
    String expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
    cal.setTime(nominal);
    // as per the sla xml
    cal.add(Calendar.MINUTE, 30);
    String expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());
    String appName = "test-coord-sla";
    // testing creation of new sla registration via Submit + Materialize
    // command
    String jobId = new CoordSubmitXCommand(conf).call();
    // waiting for materialize command to run
    Thread.sleep(500);
    final CoordActionGetJPAExecutor getCmd = new CoordActionGetJPAExecutor(jobId + "@1");
    CoordinatorActionBean action = jpa.execute(getCmd);
    String actionId = action.getId();
    SLACalcStatus slaEvent = slas.getSLACalculator().get(actionId);
    assertEquals(actionId, slaEvent.getId());
    assertEquals(appName, slaEvent.getAppName());
    assertEquals(AppType.COORDINATOR_ACTION, slaEvent.getAppType());
    assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
    assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
    assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
    assertEquals(30 * 60 * 1000, slaEvent.getExpectedDuration());
    assertEquals(alert_events, slaEvent.getAlertEvents());
    slas.runSLAWorker();
    slaEvent = skipToSLAEvent();
    assertTrue(SLAStatus.NOT_STARTED == slaEvent.getSLAStatus());
    assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
    // test that sla processes the Job Event from Start command
    ehs.getEventQueue().clear();
    action.setStatus(CoordinatorAction.Status.SUBMITTED);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    new CoordActionStartXCommand(actionId, getTestUser(), appName, jobId).call();
    slaEvent = slas.getSLACalculator().get(actionId);
    // resetting for testing sla event
    slaEvent.setEventProcessed(0);
    SLASummaryBean suBean = new SLASummaryBean();
    suBean.setId(actionId);
    suBean.setEventProcessed(0);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, suBean);
    ehs.new EventWorker().run();
    slaEvent = skipToSLAEvent();
    assertEquals(actionId, slaEvent.getId());
    assertNotNull(slaEvent.getActualStart());
    assertEquals(SLAStatus.IN_PROCESS, slaEvent.getSLAStatus());
    assertEquals(CoordinatorAction.Status.RUNNING.name(), slaEvent.getJobStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) SLAService(org.apache.oozie.sla.service.SLAService) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) CoordActionStartXCommand(org.apache.oozie.command.coord.CoordActionStartXCommand) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) Test(org.junit.Test)

Example 2 with CoordSubmitXCommand

use of org.apache.oozie.command.coord.CoordSubmitXCommand in project oozie by apache.

the class TestCoordinatorInputLogic method _testCoordSubmit.

private String _testCoordSubmit(String coordinatorXml, Configuration conf, String inputLogic, String inputEvent, boolean dryRun) throws Exception {
    String appPath = "file://" + getTestCaseDir() + File.separator + "coordinator.xml";
    String content = IOUtils.getResourceAsString(coordinatorXml, -1);
    content = content.replace("=input-logic=", inputLogic);
    content = content.replace("=input-events=", inputEvent);
    Writer writer = new FileWriter(new URI(appPath).getPath());
    IOUtils.copyCharStream(new StringReader(content), writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nameNode", "hdfs://localhost:9000");
    conf.set("queueName", "default");
    conf.set("jobTracker", "localhost:9001");
    conf.set("examplesRoot", "examples");
    if (conf.get("A_done_flag") == null) {
        conf.set("A_done_flag", "_SUCCESS");
    }
    return new CoordSubmitXCommand(dryRun, conf).call();
}
Also used : FileWriter(java.io.FileWriter) StringReader(java.io.StringReader) URI(java.net.URI) CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) PrintWriter(java.io.PrintWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 3 with CoordSubmitXCommand

use of org.apache.oozie.command.coord.CoordSubmitXCommand in project oozie by apache.

the class TestCoordInputLogicPush method submitCoord.

public static String submitCoord(String testCaseDir, String coordinatorXml, Configuration conf, String inputLogic, TEST_TYPE... testType) throws Exception {
    String appPath = "file://" + testCaseDir + File.separator + "coordinator.xml";
    String content = IOUtils.getResourceAsString(coordinatorXml, -1);
    content = content.replaceAll("=input-logic=", inputLogic);
    for (int i = 1; i <= 6; i++) {
        if (i - 1 < testType.length) {
            content = content.replaceAll("=data-in-param-" + i + "=", getEnumText(testType[i - 1]));
        } else {
            content = content.replaceAll("=data-in-param-" + i + "=", getEnumText(testType[testType.length - 1]));
        }
    }
    Writer writer = new FileWriter(new URI(appPath).getPath());
    IOUtils.copyCharStream(new StringReader(content), writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nameNode", "hdfs://localhost:9000");
    conf.set("queueName", "default");
    conf.set("jobTracker", "localhost:9001");
    conf.set("examplesRoot", "examples");
    String coordId = null;
    try {
        coordId = new CoordSubmitXCommand(conf).call();
    } catch (CommandException e) {
        e.printStackTrace();
        fail("should not throw exception " + e.getMessage());
    }
    return coordId;
}
Also used : FileWriter(java.io.FileWriter) StringReader(java.io.StringReader) CommandException(org.apache.oozie.command.CommandException) URI(java.net.URI) CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) PrintWriter(java.io.PrintWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 4 with CoordSubmitXCommand

use of org.apache.oozie.command.coord.CoordSubmitXCommand in project oozie by apache.

the class TestCoordinatorInputLogic method setupCoord.

private String setupCoord(Configuration conf, String coordFile) throws CommandException, IOException {
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    Reader reader = IOUtils.getResourceAsReader(coordFile, -1);
    Writer writer = new FileWriter(appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    IOUtils.copyCharStream(reader, writer);
    sc = new CoordSubmitXCommand(conf);
    return sc.call();
}
Also used : FileWriter(java.io.FileWriter) Reader(java.io.Reader) StringReader(java.io.StringReader) File(java.io.File) CoordSubmitXCommand(org.apache.oozie.command.coord.CoordSubmitXCommand) PrintWriter(java.io.PrintWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

CoordSubmitXCommand (org.apache.oozie.command.coord.CoordSubmitXCommand)4 FileWriter (java.io.FileWriter)3 PrintWriter (java.io.PrintWriter)3 StringReader (java.io.StringReader)3 Writer (java.io.Writer)3 URI (java.net.URI)2 File (java.io.File)1 Reader (java.io.Reader)1 Date (java.util.Date)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CommandException (org.apache.oozie.command.CommandException)1 CoordActionStartXCommand (org.apache.oozie.command.coord.CoordActionStartXCommand)1 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)1 SLAService (org.apache.oozie.sla.service.SLAService)1 XConfiguration (org.apache.oozie.util.XConfiguration)1 Test (org.junit.Test)1