Search in sources :

Example 66 with XConfiguration

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

the class TestCoordActionInputCheckXCommand method addRecordToCoordJobTable.

private CoordinatorJobBean addRecordToCoordJobTable(String jobId, Date start, Date end, String dataInType) throws CommandException {
    CoordinatorJobBean coordJob = new CoordinatorJobBean();
    coordJob.setId(jobId);
    coordJob.setAppName("testApp");
    coordJob.setAppPath("testAppPath");
    coordJob.setStatus(CoordinatorJob.Status.RUNNING);
    coordJob.setCreatedTime(new Date());
    coordJob.setLastModifiedTime(new Date());
    coordJob.setUser("testUser");
    coordJob.setGroup("testGroup");
    coordJob.setTimeZone("UTC");
    coordJob.setTimeUnit(Timeunit.DAY);
    coordJob.setMatThrottling(2);
    try {
        coordJob.setStartTime(start);
        coordJob.setEndTime(end);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Could not set Date/time");
    }
    String testDir = getTestCaseDir();
    XConfiguration jobConf = new XConfiguration();
    jobConf.set(OozieClient.USER_NAME, getTestUser());
    String confStr = jobConf.toXmlString(false);
    coordJob.setConf(confStr);
    String appXml = "<coordinator-app xmlns='uri:oozie:coordinator:0.2' name='NAME' frequency=\"1\" start='2009-02-01T01:00" + TZ + "' end='2009-02-03T23:59" + TZ + "' timezone='UTC' freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<controls>";
    appXml += "<timeout>10</timeout>";
    appXml += "<concurrency>2</concurrency>";
    appXml += "<execution>LIFO</execution>";
    appXml += "</controls>";
    appXml += "<input-events>";
    appXml += "<data-in name='A' dataset='a'>";
    appXml += "<dataset name='a' frequency='7' initial-instance='2009-01-01T01:00" + TZ + "' timezone='UTC'" + " freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<uri-template>" + getTestCaseFileUri("${YEAR}/${MONTH}/${DAY}") + "</uri-template>";
    appXml += "</dataset>";
    if (dataInType.equals("future")) {
        appXml += "<start-instance>${coord:" + dataInType + "(0,5)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(3,5)}</end-instance>";
    } else if (dataInType.equals("latest")) {
        appXml += "<start-instance>${coord:" + dataInType + "(-3)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(0)}</end-instance>";
    } else if (dataInType.equals("current")) {
        appXml += "<start-instance>${coord:" + dataInType + "(-3)}</start-instance>";
        appXml += "<end-instance>${coord:" + dataInType + "(1)}</end-instance>";
    }
    appXml += "</data-in>";
    appXml += "</input-events>";
    appXml += "<output-events>";
    appXml += "<data-out name='LOCAL_A' dataset='local_a'>";
    appXml += "<dataset name='local_a' frequency='7' initial-instance='2009-01-01T01:00" + TZ + "' timezone='UTC'" + " freq_timeunit='DAY' end_of_duration='NONE'>";
    appXml += "<uri-template>" + getTestCaseFileUri("${YEAR}/${MONTH}/${DAY}") + "</uri-template>";
    appXml += "</dataset>";
    appXml += "<start-instance>${coord:current(-3)}</start-instance>";
    appXml += "<instance>${coord:current(0)}</instance>";
    appXml += "</data-out>";
    appXml += "</output-events>";
    appXml += "<action>";
    appXml += "<workflow>";
    appXml += "<app-path>hdfs:///tmp/workflows/</app-path>";
    appXml += "<configuration>";
    appXml += "<property>";
    appXml += "<name>inputA</name>";
    appXml += "<value>${coord:dataIn('A')}</value>";
    appXml += "</property>";
    appXml += "<property>";
    appXml += "<name>inputB</name>";
    appXml += "<value>${coord:dataOut('LOCAL_A')}</value>";
    appXml += "</property>";
    appXml += "</configuration>";
    appXml += "</workflow>";
    appXml += "</action>";
    appXml += "</coordinator-app>";
    coordJob.setJobXml(appXml);
    coordJob.setLastActionNumber(0);
    coordJob.setFrequency("1");
    coordJob.setExecutionOrder(Execution.FIFO);
    coordJob.setConcurrency(1);
    JPAService jpaService = Services.get().get(JPAService.class);
    if (jpaService != null) {
        try {
            jpaService.execute(new CoordJobInsertJPAExecutor(coordJob));
        } catch (JPAExecutorException e) {
            throw new CommandException(e);
        }
    } else {
        fail("Unable to insert the test job record to table");
    }
    return coordJob;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 67 with XConfiguration

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

the class TestCoordActionNotificationXCommand method testCoordNotificationTimeout.

public void testCoordNotificationTimeout() throws Exception {
    XConfiguration conf = new XConfiguration();
    conf.set(OozieClient.COORD_ACTION_NOTIFICATION_URL, container.getServletURL("/hang/*"));
    String runConf = conf.toXmlString(false);
    CoordinatorActionBean coord = Mockito.mock(CoordinatorActionBean.class);
    Mockito.when(coord.getId()).thenReturn("1");
    Mockito.when(coord.getStatus()).thenReturn(CoordinatorAction.Status.SUCCEEDED);
    Mockito.when(coord.getRunConf()).thenReturn(runConf);
    CoordActionNotificationXCommand command = new CoordActionNotificationXCommand(coord);
    command.retries = 3;
    long start = System.currentTimeMillis();
    command.call();
    long end = System.currentTimeMillis();
    Assert.assertTrue(end - start >= 50);
    Assert.assertTrue(end - start <= 10000);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean)

Example 68 with XConfiguration

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

the class TestBundleKillXCommand method testBundleKill3.

/**
 * Test : Kill bundle job
 *
 * @throws Exception
 */
public void testBundleKill3() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Configuration jobConf = null;
    try {
        jobConf = new XConfiguration(new StringReader(job.getConf()));
    } catch (IOException ioe) {
        log.warn("Configuration parse error. read from DB :" + job.getConf(), ioe);
        throw new CommandException(ErrorCode.E1005, ioe);
    }
    Path appPath = new Path(jobConf.get(OozieClient.BUNDLE_APP_PATH), "bundle.xml");
    jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
    BundleSubmitXCommand submitCmd = new BundleSubmitXCommand(jobConf);
    submitCmd.call();
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(submitCmd.getJob().getId());
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.PREP, job.getStatus());
    new BundleKillXCommand(job.getId()).call();
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(Job.Status.KILLED, job.getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) BundleJobBean(org.apache.oozie.BundleJobBean) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 69 with XConfiguration

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

the class TestBundleSubmitXCommand method testJobXmlCommentRemoved.

/**
 * https://issues.apache.org/jira/browse/OOZIE-945
 *
 * @throws Exception
 */
public void testJobXmlCommentRemoved() throws Exception {
    // this retrieves bundle-submit-job.xml
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Configuration jobConf = null;
    try {
        jobConf = new XConfiguration(new StringReader(job.getConf()));
    } catch (IOException ioe) {
        log.warn("Configuration parse error. read from DB :" + job.getConf(), ioe);
        throw new CommandException(ErrorCode.E1005, ioe);
    }
    Path appPath = new Path(jobConf.get(OozieClient.BUNDLE_APP_PATH), "bundle.xml");
    jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
    BundleSubmitXCommand command = new BundleSubmitXCommand(true, jobConf);
    BundleJobBean bundleBean = (BundleJobBean) command.getJob();
    bundleBean.setStartTime(new Date());
    bundleBean.setEndTime(new Date());
    command.call();
    // result includes bundle-submit-job.xml file instead of jobId since this is a dryRun mode
    String result = command.submit();
    // bundle-submit-job.xml contains the Apache license but this result should not contain the comment block
    assertTrue("submit result should not contain <!-- ", !result.contains("<!--"));
    assertTrue("submit result should not contain --> ", !result.contains("-->"));
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) BundleJobBean(org.apache.oozie.BundleJobBean) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 70 with XConfiguration

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

the class TestSubWorkflowActionExecutor method testConfigNotPropagation.

public void testConfigNotPropagation() throws Exception {
    Path subWorkflowAppPath = getFsTestCaseDir();
    FileSystem fs = getFileSystem();
    Path workflowPath = new Path(subWorkflowAppPath, "workflow.xml");
    Writer writer = new OutputStreamWriter(fs.create(workflowPath));
    writer.write(APP1);
    writer.close();
    XConfiguration protoConf = getBaseProtoConf();
    WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
    String defaultConf = workflow.getConf();
    XConfiguration newConf = new XConfiguration(new StringReader(defaultConf));
    newConf.set("abc", "xyz");
    workflow.setConf(newConf.toXmlString());
    final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1' name='subwf'>" + "      <app-path>" + workflowPath.toString() + "</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>");
    SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor();
    subWorkflow.start(new Context(workflow, action), action);
    final OozieClient oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), SubWorkflowActionExecutor.LOCAL);
    waitFor(JOB_TIMEOUT, new Predicate() {

        public boolean evaluate() throws Exception {
            return oozieClient.getJobInfo(action.getExternalId()).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, oozieClient.getJobInfo(action.getExternalId()).getStatus());
    subWorkflow.check(new Context(workflow, action), action);
    assertEquals(WorkflowAction.Status.DONE, action.getStatus());
    subWorkflow.end(new Context(workflow, action), action);
    assertEquals(WorkflowAction.Status.OK, action.getStatus());
    WorkflowJob wf = oozieClient.getJobInfo(action.getExternalId());
    Configuration childConf = getWorkflowConfig(wf);
    assertNull(childConf.get("abc"));
    assertEquals("A", childConf.get("a"));
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) WorkflowJob(org.apache.oozie.client.WorkflowJob)

Aggregations

XConfiguration (org.apache.oozie.util.XConfiguration)373 Configuration (org.apache.hadoop.conf.Configuration)241 Path (org.apache.hadoop.fs.Path)106 StringReader (java.io.StringReader)97 File (java.io.File)92 IOException (java.io.IOException)78 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)75 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)70 CommandException (org.apache.oozie.command.CommandException)68 Element (org.jdom.Element)66 Writer (java.io.Writer)58 Date (java.util.Date)50 FileSystem (org.apache.hadoop.fs.FileSystem)48 FileWriter (java.io.FileWriter)45 Reader (java.io.Reader)43 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)37 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)28 OutputStream (java.io.OutputStream)27 FileOutputStream (java.io.FileOutputStream)25