Repository: oozie Updated Branches: refs/heads/master 8b4f53c75 -> 83ccfc592
OOZIE-2929 Coordinator SLA should support configuration variable (chiwen via andras.piros) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/83ccfc59 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/83ccfc59 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/83ccfc59 Branch: refs/heads/master Commit: 83ccfc592917db4b8a3dc74c35d0ccc5ba13e54f Parents: 8b4f53c Author: Andras Piros <[email protected]> Authored: Mon Oct 30 10:40:58 2017 +0100 Committer: Andras Piros <[email protected]> Committed: Mon Oct 30 10:40:58 2017 +0100 ---------------------------------------------------------------------- .../command/coord/CoordSubmitXCommand.java | 21 +++++++++++++ .../TestCoordMaterializeTransitionXCommand.java | 33 ++++++++++++++++++++ docs/src/site/twiki/DG_SLAMonitoring.twiki | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/83ccfc59/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java b/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java index 17e7fa0..fecf006 100644 --- a/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java +++ b/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java @@ -839,6 +839,7 @@ public class CoordSubmitXCommand extends SubmitTransitionXCommand { Element eSla = XmlUtils.getSLAElement(eAppXml.getChild("action", eAppXml.getNamespace())); if (eSla != null) { + resolveSLAContent(eSla); String slaXml = XmlUtils.prettyPrint(eSla).toString(); try { // EL evaluation @@ -853,6 +854,26 @@ public class CoordSubmitXCommand extends SubmitTransitionXCommand { } /** + * Resolve an SLA value. + * + * @param elem : XML Element where attribute is defiend + */ + private void resolveSLAContent(Element elem) { + for (Element tagElem : (List<Element>) elem.getChildren()) { + if (tagElem != null) { + try { + String val = CoordELFunctions.evalAndWrap(evalNofuncs, tagElem.getText().trim()); + tagElem.setText(val); + } + catch (Exception e) { + LOG.warn("Variable is not defined in job.properties. Here is the message: {0}", e.getMessage()); + continue; + } + } + } + } + + /** * Resolve input-events/data-in and output-events/data-out tags. * * @param eJobOrg : Job element http://git-wip-us.apache.org/repos/asf/oozie/blob/83ccfc59/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java b/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java index 2e39689..2a648d7 100644 --- a/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java +++ b/core/src/test/java/org/apache/oozie/command/coord/TestCoordMaterializeTransitionXCommand.java @@ -989,4 +989,37 @@ public class TestCoordMaterializeTransitionXCommand extends XDataTestCase { } return 0; } + + /** + * Test a coordinator SLA define EL functions as variable + * + * @throws Exception + */ + public void testSuccessedJobSlaParseElFunctionVariableInMaterializeActions() throws Exception { + Configuration conf = new XConfiguration(); + File appPathFile = new File(getTestCaseDir(), "coordinator.xml"); + String coordXml = "<coordinator-app name=\"NAME\" frequency=\"0 * * * *\"" + + " start=\"2017-06-12T01:00Z\" end=\"2017-06-12T02:00Z\" timezone=\"Asia/Shanghai\"" + + " xmlns=\"uri:oozie:coordinator:0.4\" xmlns:sla=\"uri:oozie:sla:0.2\">" + + "<controls> <execution>FIFO</execution> </controls>" + + "<action>" + + " <workflow> <app-path>hdfs:///tmp/workflows/</app-path> </workflow> " + + " <sla:info>" + + " <sla:nominal-time>${NOMINAL_TIME}</sla:nominal-time>" + + " <sla:should-start>${SHOULD_START}</sla:should-start>" + + " <sla:should-end>${SHOULD_END}</sla:should-end>" + + " </sla:info>" + + "</action>" + + "</coordinator-app>"; + writeToFile(coordXml, appPathFile); + conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString()); + conf.set(OozieClient.USER_NAME, getTestUser()); + conf.set("NOMINAL_TIME", "${coord:nominalTime()}"); + conf.set("SHOULD_START", "${5 * MINUTES}"); + conf.set("SHOULD_END", "${ SLA_OFFSET * HOURS}"); + conf.set("SLA_OFFSET", "10"); + CoordSubmitXCommand sc = new CoordSubmitXCommand(conf); + String jobId = sc.call(); + new CoordMaterializeTransitionXCommand(jobId, 60).call(); + } } http://git-wip-us.apache.org/repos/asf/oozie/blob/83ccfc59/docs/src/site/twiki/DG_SLAMonitoring.twiki ---------------------------------------------------------------------- diff --git a/docs/src/site/twiki/DG_SLAMonitoring.twiki b/docs/src/site/twiki/DG_SLAMonitoring.twiki index db2831f..2d6b138 100644 --- a/docs/src/site/twiki/DG_SLAMonitoring.twiki +++ b/docs/src/site/twiki/DG_SLAMonitoring.twiki @@ -109,7 +109,7 @@ This new schema is much more compact and meaningful, getting rid of redundant an * ==alert-events==: Specify the types of events for which *Email* alerts should be sent. Allowable values in this comma-separated list are start_miss, end_miss and duration_miss. *_met events can generally be deemed low priority and hence email alerting for these is not necessary. However, note that this setting is only for alerts via *email* alerts and not via JMS messages, where all events send out notifications, and user can filter them using desired selectors. This is optional and only applicable when alert-contact is configured. * ==alert-contact==: Specify a comma separated list of email addresses where you wish your alerts to be sent. This is optional and need not be configured if you just want to view your job SLA history in the UI and do not want to receive email alerts. -NOTE: All tags can be parameterized. +NOTE: All tags can be parameterized as a EL function or a fixed value. Same schema can be applied to and embedded under Workflow-Action as well as Coordinator-Action XML.
