use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestActionUserRetry method testUserRetry.
public void testUserRetry() throws JPAExecutorException, IOException, CommandException {
Configuration conf = new XConfiguration();
String workflowUri = getTestCaseFileUri("workflow.xml");
// @formatter:off
String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.3\" name=\"wf-fork\">" + "<start to=\"fork1\"/>" + "<fork name=\"fork1\">" + "<path start=\"action1\"/>" + "<path start=\"action2\"/>" + "</fork>" + "<action name=\"action1\" retry-max=\"2\" retry-interval=\"0\">" + "<test xmlns=\"uri:test\">" + "<signal-value>${wf:conf('signal-value')}</signal-value>" + "<external-status>${wf:conf('external-status')}</external-status> " + "<error>${wf:conf('error')}</error>" + "<avoid-set-execution-data>${wf:conf('avoid-set-execution-data')}</avoid-set-execution-data>" + "<avoid-set-end-data>${wf:conf('avoid-set-end-data')}</avoid-set-end-data>" + "<running-mode>${wf:conf('running-mode')}</running-mode>" + "</test>" + "<ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<action name=\"action2\">" + "<fs></fs><ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<join name=\"join1\" to=\"end\"/>" + "<kill name=\"kill\"><message>killed</message></kill>" + "<end name=\"end\"/>" + "</workflow-app>";
// @Formatter:on
writeToFile(appXml, workflowUri);
conf.set(OozieClient.APP_PATH, workflowUri);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("error", "start.error");
conf.set("external-status", "error");
conf.set("signal-value", "based_on_action_status");
SubmitXCommand sc = new SubmitXCommand(conf);
final String jobId = sc.call();
new StartXCommand(jobId).call();
final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
final JPAService jpaService = Services.get().get(JPAService.class);
waitFor(20 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
return (action != null && action.getUserRetryCount() == 2);
}
});
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
assertNotNull(action);
assertEquals(2, action.getUserRetryCount());
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestCoordSubmitXCommand method testSubmitWithDoneFlag.
/**
* Test Done Flag in Schema
*
* @throws Exception
*/
public void testSubmitWithDoneFlag() throws Exception {
Configuration conf = new XConfiguration();
File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
String appXml = "<coordinator-app name=\"NAME\" frequency=\"${coord:days(1)}\" start=\"2009-02-01T01:00Z\"" + " end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.2\"> <controls> <timeout>10</timeout> <concurrency>2</concurrency> " + "<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>file:///tmp/coord/workflows/${YEAR}/${DAY}</uri-template> " + "<done-flag>consume_me</done-flag> </dataset>" + "<dataset name=\"local_b\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>file:///tmp/coord/workflowsb/${YEAR}/${DAY}</uri-template> " + "<done-flag>${MY_DONE_FLAG}</done-flag> </dataset>" + "</datasets> <input-events> " + "<data-in name=\"A\" dataset=\"a\"> <instance>${coord:latest(0)}</instance> </data-in> " + "<data-in name=\"B\" dataset=\"local_b\"> <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("MY_DONE_FLAG", "complete");
CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
String jobId = sc.call();
assertEquals(jobId.substring(jobId.length() - 2), "-C");
checkCoordJobs(jobId);
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestCoordSubmitXCommand method testBasicSubmitWithCronFrequency.
private void testBasicSubmitWithCronFrequency(String appXml, Boolean isValidFrequency) throws Exception {
Configuration conf = new XConfiguration();
File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
writeToFile(appXml, appPathFile);
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set(OozieClient.USER_NAME, getTestUser());
CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
if (isValidFrequency) {
String jobId = sc.call();
assertEquals(jobId.substring(jobId.length() - 2), "-C");
CoordinatorJobBean job = (CoordinatorJobBean) sc.getJob();
assertEquals(job.getTimeUnitStr(), "CRON");
} else {
try {
String jobId = sc.call();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("Invalid coordinator cron frequency"));
}
}
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestCoordSubmitXCommand method testSubmitWithSLAAlertsDisable.
public void testSubmitWithSLAAlertsDisable() throws Exception {
Configuration conf = new XConfiguration();
File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
// CASE 1: Failure case i.e. multiple data-in instances
Reader reader = IOUtils.getResourceAsReader("coord-action-sla.xml", -1);
Writer writer = new FileWriter(appPathFile);
IOUtils.copyCharStream(reader, writer);
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
conf.set("frequency", "coord:days(1)");
conf.set(OozieClient.USER_NAME, getTestUser());
reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
appPathFile = new File(getTestCaseDir(), "workflow.xml");
writer = new FileWriter(appPathFile);
IOUtils.copyCharStream(reader, writer);
conf.set("wfAppPath", appPathFile.getPath());
Date nominalTime = new Date();
conf.set("nominal_time", DateUtils.formatDateOozieTZ(nominalTime));
String coordId = new CoordSubmitXCommand(conf).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
SLAService slaService = services.get(SLAService.class);
SLACalculator calc = slaService.getSLACalculator();
SLACalcStatus slaCalc = calc.get(coordId + "@" + 1);
assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
Configuration conf1 = new Configuration(conf);
// CASE I: "ALL"
conf1.set(OozieClient.SLA_DISABLE_ALERT, "ALL");
coordId = new CoordSubmitXCommand(conf1).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaService = services.get(SLAService.class);
calc = slaService.getSLACalculator();
slaCalc = calc.get(coordId + "@" + 1);
assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// CASE II: Date Range
Configuration conf2 = new Configuration(conf);
Date startRangeDate = new Date(nominalTime.getTime() - 3600 * 1000);
conf2.set(OozieClient.SLA_DISABLE_ALERT, DateUtils.formatDateOozieTZ(startRangeDate) + "::" + DateUtils.formatDateOozieTZ(nominalTime));
coordId = new CoordSubmitXCommand(conf2).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// CASE III: Coord name (negative test)
Configuration conf3 = new Configuration(conf);
conf3.set(OozieClient.SLA_DISABLE_ALERT_COORD, "test-coord-sla-x");
coordId = new CoordSubmitXCommand(conf3).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// CASE IV: Older than n(hours)
Date otherNominalTime = new Date(nominalTime.getTime() - 73 * 3600 * 1000);
conf = new XConfiguration();
appPathFile = new File(getTestCaseDir(), "coordinator.xml");
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set("wfAppPath", appPathFile.getPath());
conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(otherNominalTime));
conf.setInt(OozieClient.SLA_DISABLE_ALERT_OLDER_THAN, 72);
coordId = new CoordSubmitXCommand(conf).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// catchup mode
conf = new XConfiguration();
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set("wfAppPath", appPathFile.getPath());
conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
coordId = new CoordSubmitXCommand(conf).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
// normal mode
conf = new XConfiguration();
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
conf.set("wfAppPath", appPathFile.getPath());
conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
coordId = new CoordSubmitXCommand(conf).call();
new CoordMaterializeTransitionXCommand(coordId, 3600).call();
slaCalc = calc.get(coordId + "@" + 1);
assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class TestCoordSubmitXCommand method testSubmitNoControls.
/**
* Don't include controls in XML.
*
* @throws Exception
*/
public void testSubmitNoControls() throws Exception {
Configuration conf = new XConfiguration();
File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
String appXml = "<coordinator-app name=\"NAME\" frequency=\"10\" start=\"2009-02-01T01:00Z\"" + " end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.2\"> " + "<action> <workflow> <app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration> <property> <name>inputA</name> <value>blah</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);
String jobId = sc.call();
assertEquals(jobId.substring(jobId.length() - 2), "-C");
checkCoordJobs(jobId);
}
Aggregations