Search in sources :

Example 51 with XConfiguration

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

the class TestCoordSubmitXCommand method testSubmitDatasetInitialInstance.

/**
 * Checking that any dataset initial-instance is not set to a date earlier than the server default Jan 01, 1970 00:00Z UTC
 * @throws Exception
 */
public void testSubmitDatasetInitialInstance() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    Reader reader = IOUtils.getResourceAsReader("coord-dataset-initial-instance.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "coordinator.xml"));
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    try {
        sc.call();
        fail("Expected to catch errors due to invalid dataset initial instance");
    } catch (CommandException cx) {
        assertEquals(sc.getJob().getStatus(), Job.Status.FAILED);
        assertEquals(cx.getErrorCode(), ErrorCode.E1021);
        if (!(cx.getMessage().contains("earlier than the default initial instance"))) {
            fail("Unexpected failure - " + cx.getMessage());
        }
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Reader(java.io.Reader) CommandException(org.apache.oozie.command.CommandException) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 52 with XConfiguration

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

the class TestCoordSubmitXCommand method testBasicSubmitWithDryRun.

public void testBasicSubmitWithDryRun() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    String appXml = "<coordinator-app name=\"${appName}-foo\" frequency=\"${coord:days(1)}\" start=\"2009-02-01T01:00Z\" " + "end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.2\"> <controls> " + "<execution>LIFO</execution> </controls> <datasets> " + "<dataset name=\"a\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template>  </dataset> " + "<dataset name=\"local_a\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template>  </dataset> " + "</datasets> <input-events> " + "<data-in name=\"A\" dataset=\"a\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "</input-events> " + "<output-events> <data-out name=\"LOCAL_A\" dataset=\"local_a\"> " + "<instance>${coord:current(-1)}</instance> </data-out> </output-events> <action> <workflow>" + " <app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration> <property> <name>inputA</name> <value>${coord:dataIn('A')}</value> </property> " + "<property> <name>inputB</name> <value>${coord:dataOut('LOCAL_A')}</value> " + "</property></configuration> </workflow> </action> </coordinator-app>";
    writeToFile(appXml, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("appName", "var-app-name");
    CoordSubmitXCommand sc = new CoordSubmitXCommand(true, conf);
    String dryrunStr = sc.call();
    String[] actions = dryrunStr.split("action for new instance");
    assertEquals(actions.length, 2);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) File(java.io.File)

Example 53 with XConfiguration

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

the class TestCoordSubmitXCommand method testBasicSubmitWithStartTimeAfterEndTime.

public void testBasicSubmitWithStartTimeAfterEndTime() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    String appXml = "<coordinator-app name=\"NAME\" frequency=\"${coord:days(1)}\" start=\"2010-02-01T01:00Z\"" + " end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.2\"> <controls> " + "<execution>LIFO</execution> </controls> <datasets> " + "<dataset name=\"a\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template>" + "  </dataset> " + "<dataset name=\"local_a\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template>" + "  </dataset> " + "</datasets> <input-events> " + "<data-in name=\"A\" dataset=\"a\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "</input-events> " + "<output-events> <data-out name=\"LOCAL_A\" dataset=\"local_a\"> " + "<instance>${coord:current(-1)}</instance> </data-out> </output-events> <action> <workflow>" + " <app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration> <property> <name>inputA</name> <value>${coord:dataIn('A')}</value> </property> " + "<property> <name>inputB</name> <value>${coord:dataOut('LOCAL_A')}</value> " + "</property></configuration> </workflow> </action> </coordinator-app>";
    writeToFile(appXml, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    try {
        sc.call();
        fail("Expected to catch errors due to incorrectly specified Start and End Time");
    } catch (CommandException e) {
        assertEquals(sc.getJob().getStatus(), Job.Status.FAILED);
        assertEquals(e.getErrorCode(), ErrorCode.E1003);
        assertTrue(e.getMessage().contains("Coordinator Start Time must be earlier than End Time."));
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CommandException(org.apache.oozie.command.CommandException) File(java.io.File)

Example 54 with XConfiguration

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

the class TestCoordSubmitXCommand method testSubmitWithTimeout.

/**
 * Test timeout setting
 *
 * @throws Exception
 */
public void testSubmitWithTimeout() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    // timeout unit = DAY
    String appXml1 = "<coordinator-app name=\"NAME\" frequency=\"${coord:days(1)}\" " + "start=\"2009-02-01T01:00Z\" end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='uri:oozie:coordinator:0.2'> " + "<controls> <timeout>${coord:days(10)}</timeout> </controls> " + "<action> <workflow> <app-path>hdfs:///tmp/workflows/</app-path> </workflow> " + "</action> </coordinator-app>";
    writeToFile(appXml1, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    String jobId = sc.call();
    assertEquals(jobId.substring(jobId.length() - 2), "-C");
    CoordinatorJobBean job = checkCoordJobs(jobId);
    assertEquals(job.getTimeout(), 14400);
    // timeout unit = HOUR
    String appXml2 = "<coordinator-app name=\"NAME\" frequency=\"${coord:days(1)}\" " + "start=\"2009-02-01T01:00Z\" end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='uri:oozie:coordinator:0.2'> " + "<controls> <timeout>${coord:hours(10)}</timeout> </controls> " + "<action> <workflow> <app-path>hdfs:///tmp/workflows/</app-path> </workflow> " + "</action> </coordinator-app>";
    writeToFile(appXml2, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    sc = new CoordSubmitXCommand(conf);
    jobId = sc.call();
    job = checkCoordJobs(jobId);
    assertEquals(job.getTimeout(), 600);
    // timeout unit = MINUTE
    String appXml3 = "<coordinator-app name=\"NAME\" frequency=\"${coord:days(1)}\" " + "start=\"2009-02-01T01:00Z\" end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='uri:oozie:coordinator:0.2'> " + "<controls> <timeout>${coord:minutes(10)}</timeout> </controls> " + "<action> <workflow> <app-path>hdfs:///tmp/workflows/</app-path> </workflow> " + "</action> </coordinator-app>";
    writeToFile(appXml3, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    sc = new CoordSubmitXCommand(conf);
    jobId = sc.call();
    job = checkCoordJobs(jobId);
    assertEquals(job.getTimeout(), 10);
    // timeout unit = MONTH
    String appXml4 = "<coordinator-app name=\"NAME\" frequency=\"${coord:months(1)}\" " + "start=\"2009-02-01T01:00Z\" end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='uri:oozie:coordinator:0.2'> " + "<controls> <timeout>${coord:months(1)}</timeout> </controls> " + "<action> <workflow> <app-path>hdfs:///tmp/workflows/</app-path> </workflow> " + "</action> </coordinator-app>";
    writeToFile(appXml4, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    sc = new CoordSubmitXCommand(conf);
    jobId = sc.call();
    job = checkCoordJobs(jobId);
    assertEquals(job.getTimeout(), 43200);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) File(java.io.File)

Example 55 with XConfiguration

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

the class TestCoordUpdateXCommand method testReRunRefresh.

// test coord re-run with refresh. will use the updated coord definition.
public void testReRunRefresh() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile1 = new File(getTestCaseDir(), "coordinator.xml");
    String jobId = setupCoord(conf, "coord-multiple-input-instance3.xml");
    sleep(1000);
    final int actionNum = 1;
    final String actionId = jobId + "@" + actionNum;
    final OozieClient coordClient = LocalOozie.getCoordClient();
    waitFor(120 * 1000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            CoordinatorAction bean = coordClient.getCoordActionInfo(actionId);
            return (bean.getStatus() == CoordinatorAction.Status.WAITING || bean.getStatus() == CoordinatorAction.Status.SUBMITTED);
        }
    });
    CoordinatorAction bean = coordClient.getCoordActionInfo(actionId);
    assertEquals(bean.getMissingDependencies(), "!!${coord:latest(0)}#${coord:latest(-1)}");
    CoordinatorJobBean job = getCoordJobs(jobId);
    Reader reader = IOUtils.getResourceAsReader("coord-multiple-input-instance4.xml", -1);
    Writer writer = new FileWriter(appPathFile1);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile1.toURI().toString());
    new CoordUpdateXCommand(false, conf, jobId).call();
    job = getCoordJobs(jobId);
    Element processedJobXml = XmlUtils.parseXml(job.getJobXml());
    Namespace namespace = processedJobXml.getNamespace();
    String text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:future(0, 1)}");
    new CoordActionsKillXCommand(jobId, RestConstants.JOB_COORD_SCOPE_ACTION, Integer.toString(actionNum)).call();
    coordClient.reRunCoord(jobId, RestConstants.JOB_COORD_SCOPE_ACTION, Integer.toString(actionNum), true, true);
    bean = coordClient.getCoordActionInfo(actionId);
    sleep(1000);
    assertEquals(bean.getMissingDependencies(), "!!${coord:future(0, 1)}");
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Element(org.jdom.Element) Reader(java.io.Reader) StringReader(java.io.StringReader) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Namespace(org.jdom.Namespace) XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

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