Repository: oozie Updated Branches: refs/heads/master 6ac2679e9 -> 7d434279a
OOZIE-3340 [fluent-job] Create error handler ACTION only if needed (kmarton, andras.piros) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/7d434279 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/7d434279 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/7d434279 Branch: refs/heads/master Commit: 7d434279a42d35ef22e2941fde169ed086d62c97 Parents: 6ac2679 Author: Andras Piros <[email protected]> Authored: Wed Sep 26 14:58:13 2018 +0200 Committer: Andras Piros <[email protected]> Committed: Wed Sep 26 14:58:13 2018 +0200 ---------------------------------------------------------------------- .../oozie/fluentjob/api/action/ShellAction.java | 2 +- .../GraphNodesToWORKFLOWAPPConverter.java | 33 +++++++++++++++++--- .../fluentjob/api/mapping/TestGraphMapping.java | 12 ++++--- release-log.txt | 1 + 4 files changed, 38 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/7d434279/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/action/ShellAction.java ---------------------------------------------------------------------- diff --git a/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/action/ShellAction.java b/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/action/ShellAction.java index c1b79aa..48d8e88 100644 --- a/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/action/ShellAction.java +++ b/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/action/ShellAction.java @@ -27,7 +27,7 @@ import java.util.Map; /** * A class representing the Oozie shell action. - * Instances of this class should be built using the builder {@link EmailActionBuilder}. + * Instances of this class should be built using the builder {@link ShellActionBuilder}. * * The properties of the builder can only be set once, an attempt to set them a second time will trigger * an {@link IllegalStateException}. http://git-wip-us.apache.org/repos/asf/oozie/blob/7d434279/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/mapping/GraphNodesToWORKFLOWAPPConverter.java ---------------------------------------------------------------------- diff --git a/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/mapping/GraphNodesToWORKFLOWAPPConverter.java b/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/mapping/GraphNodesToWORKFLOWAPPConverter.java index da4691f..09b82cd 100644 --- a/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/mapping/GraphNodesToWORKFLOWAPPConverter.java +++ b/fluent-job/fluent-job-api/src/main/java/org/apache/oozie/fluentjob/api/mapping/GraphNodesToWORKFLOWAPPConverter.java @@ -182,8 +182,11 @@ public class GraphNodesToWORKFLOWAPPConverter extends DozerConverter<GraphNodes, final Object mappedObject = mapper.map(nodeBase, SOURCE_TARGET_CLASSES.get(sourceClass)); if (nodeBase instanceof ExplicitNode) { - final ACTION errorHandlerAction = addErrorTransition((ExplicitNode) nodeBase, (ACTION) mappedObject, kill); - if (errorHandlerAction != null) { + final ACTION errorHandlerAction = ensureErrorTransition(workflowapp, (ExplicitNode) nodeBase, + (ACTION) mappedObject, + kill + ); + if (errorHandlerAction != null && !workflowapp.getDecisionOrForkOrJoin().contains(errorHandlerAction)) { workflowapp.getDecisionOrForkOrJoin().add(errorHandlerAction); } } @@ -200,7 +203,10 @@ public class GraphNodesToWORKFLOWAPPConverter extends DozerConverter<GraphNodes, return kill; } - private ACTION addErrorTransition(final ExplicitNode node, final ACTION action, final KILL kill) { + private ACTION ensureErrorTransition(final WORKFLOWAPP workflowapp, + final ExplicitNode node, + final ACTION action, + final KILL kill) { final ACTIONTRANSITION error = ensureError(action); final ErrorHandler errorHandler = node.getRealNode().getErrorHandler(); @@ -213,13 +219,32 @@ public class GraphNodesToWORKFLOWAPPConverter extends DozerConverter<GraphNodes, else { final Node handlerNode = errorHandler.getHandlerNode(); - final ACTION handlerAction = createErrorHandlerAction(handlerNode, kill); + final ACTION handlerAction = ensureErrorHandlerAction(workflowapp, handlerNode, kill); error.setTo(handlerAction.getName()); return handlerAction; } } + private ACTION ensureErrorHandlerAction(final WORKFLOWAPP workflowapp, final Node handlerNode, final KILL kill) { + ACTION handlerAction = null; + for (final Object alreadyPresentObject : workflowapp.getDecisionOrForkOrJoin()) { + if (alreadyPresentObject instanceof ACTION) { + final ACTION alreadyPresentAction = (ACTION) alreadyPresentObject; + if (alreadyPresentAction.getName().equals(handlerNode.getName())) { + handlerAction = alreadyPresentAction; + break; + } + } + } + + if (handlerAction == null) { + handlerAction = createErrorHandlerAction(handlerNode, kill); + } + + return handlerAction; + } + private ACTIONTRANSITION ensureError(final ACTION action) { ACTIONTRANSITION error = action.getError(); http://git-wip-us.apache.org/repos/asf/oozie/blob/7d434279/fluent-job/fluent-job-api/src/test/java/org/apache/oozie/fluentjob/api/mapping/TestGraphMapping.java ---------------------------------------------------------------------- diff --git a/fluent-job/fluent-job-api/src/test/java/org/apache/oozie/fluentjob/api/mapping/TestGraphMapping.java b/fluent-job/fluent-job-api/src/test/java/org/apache/oozie/fluentjob/api/mapping/TestGraphMapping.java index 0563ec6..e529e9d 100644 --- a/fluent-job/fluent-job-api/src/test/java/org/apache/oozie/fluentjob/api/mapping/TestGraphMapping.java +++ b/fluent-job/fluent-job-api/src/test/java/org/apache/oozie/fluentjob/api/mapping/TestGraphMapping.java @@ -73,6 +73,7 @@ public class TestGraphMapping { final MapReduceAction mrAction = MapReduceActionBuilder.create() .withName("map-reduce-action") + .withErrorHandler(errorHandler) .build(); final FSAction fsAction = FSActionBuilder.create() .withName("fs-action") @@ -100,11 +101,12 @@ public class TestGraphMapping { final List<Object> actions = expectedWorkflowapp.getDecisionOrForkOrJoin(); final ACTION actionMr = convertEmailActionByHand((ExplicitNode) graph.getNodeByName(mrAction.getName())); + final ACTIONTRANSITION mrErrorTransition = actionMr.getError(); + mrErrorTransition.setTo(errorHandlerName); final ACTION actionFs = convertEmailActionByHand((ExplicitNode) graph.getNodeByName(fsAction.getName())); - - final ACTIONTRANSITION error = actionFs.getError(); - error.setTo(errorHandlerName); + final ACTIONTRANSITION fsErrorTransition = actionFs.getError(); + fsErrorTransition.setTo(errorHandlerName); final Node emailErrorHandlerNode = emailBuilder.build(); final ExplicitNode emailErrorHandlerExplicitNode @@ -120,11 +122,11 @@ public class TestGraphMapping { errorHandlerAction.setError(okAndError); actions.add(kill); - actions.add(actionMr); actions.add(errorHandlerAction); + actions.add(actionMr); actions.add(actionFs); - assertEquals(expectedWorkflowapp, workflowapp); + assertEquals("expected and actual WORKFLOWAPP should look the same", expectedWorkflowapp, workflowapp); } @Test http://git-wip-us.apache.org/repos/asf/oozie/blob/7d434279/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 3f24a84..ac90e18 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 5.1.0 release (trunk - unreleased) +OOZIE-3340 [fluent-job] Create error handler ACTION only if needed (kmarton, andras.piros) OOZIE-3307 amend [core] Limit heap usage of LauncherAM (andras.piros) OOZIE-3343 [build] [tests] Add the first five test errors per module to the report (kmarton via andras.piros) OOZIE-3307 [core] Limit heap usage of LauncherAM (andras.piros)
