This is an automated email from the ASF dual-hosted git repository.

kmarton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/oozie.git


The following commit(s) were added to refs/heads/master by this push:
     new 4390925  OOZIE-3417 [FS Action] Refactor and optimize 
FsActionExecutor.java decision making part (nobigo via asalamon74, kmarton)
4390925 is described below

commit 439092563e1dc057af781e7fea70576f9cbf7210
Author: Julia Kinga Marton <[email protected]>
AuthorDate: Wed Jan 30 10:55:21 2019 +0100

    OOZIE-3417 [FS Action] Refactor and optimize FsActionExecutor.java decision 
making part (nobigo via asalamon74, kmarton)
---
 .../oozie/action/hadoop/FsActionExecutor.java      | 173 +++++++++++++--------
 release-log.txt                                    |   1 +
 2 files changed, 107 insertions(+), 67 deletions(-)

diff --git 
a/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java 
b/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java
index de55793..634d3b8 100644
--- a/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java
+++ b/core/src/main/java/org/apache/oozie/action/hadoop/FsActionExecutor.java
@@ -62,6 +62,22 @@ public class FsActionExecutor extends ActionExecutor {
 
     public static final String ACTION_TYPE = "fs";
 
+    public static final String FS_OP_MKDIR = "mkdir";
+    public static final String FS_OP_DELETE = "delete";
+    public static final String FS_OP_MOVE = "move";
+    public static final String FS_OP_CHMOD = "chmod";
+    public static final String FS_OP_TOUCHZ = "touchz";
+    public static final String FS_OP_CHGRP = "chgrp";
+    public static final String FS_OP_SETREP = "setrep";
+
+    public static final String FS_TAG_PATH = "path";
+    public static final String FS_TAG_SOURCE = "source";
+    public static final String FS_TAG_TARGET = "target";
+    public static final String FS_TAG_RECURSIVE = "recursive";
+    public static final String FS_TAG_DIRFILES = "dir-files";
+    public static final String FS_TAG_SKIPTRASH = "skip-trash";
+    public static final String FS_TAG_PERMISSIONS = "permissions";
+
     private final int maxGlobCount;
 
     private final XLog LOG = XLog.getLog(getClass());
@@ -182,73 +198,97 @@ public class FsActionExecutor extends ActionExecutor {
 
             for (Element commandElement : (List<Element>) 
element.getChildren()) {
                 String command = commandElement.getName();
-                if (command.equals("mkdir")) {
-                    Path path = getPath(commandElement, "path");
-                    mkdir(context, fsConf, nameNodePath, path);
-                }
-                else {
-                    if (command.equals("delete")) {
-                        Path path = getPath(commandElement, "path");
-                        boolean skipTrash = true;
-                        if (commandElement.getAttributeValue("skip-trash") != 
null &&
-                                
commandElement.getAttributeValue("skip-trash").equals("false")) {
-                            skipTrash = false;
-                        }
-                        delete(context, fsConf, nameNodePath, path, skipTrash);
-                    }
-                    else {
-                        if (command.equals("move")) {
-                            Path source = getPath(commandElement, "source");
-                            Path target = getPath(commandElement, "target");
-                            move(context, fsConf, nameNodePath, source, 
target, recovery);
-                        }
-                        else {
-                            if (command.equals("chmod")) {
-                                Path path = getPath(commandElement, "path");
-                                boolean recursive = 
commandElement.getChild("recursive", commandElement.getNamespace()) != null;
-                                String str = 
commandElement.getAttributeValue("dir-files");
-                                boolean dirFiles = (str == null) || 
Boolean.parseBoolean(str);
-                                String permissionsMask = 
commandElement.getAttributeValue("permissions").trim();
-                                chmod(context, fsConf, nameNodePath, path, 
permissionsMask, dirFiles, recursive);
-                            }
-                            else {
-                                if (command.equals("touchz")) {
-                                    Path path = getPath(commandElement, 
"path");
-                                    touchz(context, fsConf, nameNodePath, 
path);
-                                }
-                                else {
-                                    if (command.equals("chgrp")) {
-                                        Path path = getPath(commandElement, 
"path");
-                                        boolean recursive = 
commandElement.getChild("recursive",
-                                                commandElement.getNamespace()) 
!= null;
-                                        String group = 
commandElement.getAttributeValue("group");
-                                        String str = 
commandElement.getAttributeValue("dir-files");
-                                        boolean dirFiles = (str == null) || 
Boolean.parseBoolean(str);
-                                        chgrp(context, fsConf, nameNodePath, 
path, context.getWorkflow().getUser(),
-                                                group, dirFiles, recursive);
-                                    }
-                                    else {
-                                        if (command.equals("setrep")) {
-                                            Path path = 
getPath(commandElement, "path");
-                                            String replicationFactor =
-                                            
commandElement.getAttributeValue("replication-factor");
-                                            if 
(commandElement.getAttributeValue("replication-factor") != null) {
-                                                setrep(context, path, 
Short.parseShort(replicationFactor));
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
+                switch (command) {
+                    case FS_OP_MKDIR:
+                        doMkdirOperation(context, fsConf, nameNodePath, 
commandElement);
+                        break;
+                    case FS_OP_DELETE:
+                        doDeleteOperation(context, fsConf, nameNodePath, 
commandElement);
+                        break;
+                    case FS_OP_MOVE:
+                        doMoveOperation(context, fsConf, nameNodePath, 
commandElement, recovery);
+                        break;
+                    case FS_OP_CHMOD:
+                        doChmodOperation(context, fsConf, nameNodePath, 
commandElement);
+                        break;
+                    case FS_OP_TOUCHZ:
+                        doTouchzOperation(context, fsConf, nameNodePath, 
commandElement);
+                        break;
+                    case FS_OP_CHGRP:
+                        doChgrpOperation(context, fsConf, nameNodePath, 
commandElement);
+                        break;
+                    case FS_OP_SETREP:
+                        doSetrepOperation(context, commandElement);
+                        break;
+                    default:
+                        LOG.warn("Fs Action don't support [{0}] operation for 
the time being ", command);
                 }
             }
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
             throw convertException(ex);
         }
     }
 
+    private void doMkdirOperation(Context context,  XConfiguration fsConf, 
Path nameNodePath,
+                                  Element commandElement) throws 
ActionExecutorException {
+        Path path = getPath(commandElement, FS_TAG_PATH);
+        mkdir(context, fsConf, nameNodePath, path);
+    }
+
+    private void doDeleteOperation(Context context, XConfiguration fsConf, 
Path nameNodePath,
+                                   Element commandElement) throws 
ActionExecutorException {
+        Path path = getPath(commandElement, FS_TAG_PATH);
+        boolean skipTrash = true;
+        String skipTrashTag = 
commandElement.getAttributeValue(FS_TAG_SKIPTRASH);
+        if (skipTrashTag != null && skipTrashTag.equals("false")) {
+            skipTrash = false;
+        }
+        delete(context, fsConf, nameNodePath, path, skipTrash);
+    }
+
+    private void doMoveOperation(Context context, XConfiguration fsConf, Path 
nameNodePath,
+                                 Element commandElement, boolean recovery) 
throws ActionExecutorException {
+        Path source = getPath(commandElement, FS_TAG_SOURCE);
+        Path target = getPath(commandElement, FS_TAG_TARGET);
+        move(context, fsConf, nameNodePath, source, target, recovery);
+    }
+
+    private void doChmodOperation(Context context, XConfiguration fsConf, Path 
nameNodePath,
+                                  Element commandElement) throws 
ActionExecutorException {
+        Path path = getPath(commandElement, FS_TAG_PATH);
+        String permissionsTag = 
commandElement.getAttributeValue(FS_TAG_PERMISSIONS).trim();
+        String dirFilesTag = commandElement.getAttributeValue(FS_TAG_DIRFILES);
+        boolean dirFiles = (dirFilesTag == null) || 
Boolean.parseBoolean(dirFilesTag);
+        boolean recursive = commandElement.getChild(FS_TAG_RECURSIVE, 
commandElement.getNamespace()) != null;
+        chmod(context, fsConf, nameNodePath, path, permissionsTag, dirFiles, 
recursive);
+    }
+
+    private void doTouchzOperation(Context context, XConfiguration fsConf, 
Path nameNodePath,
+                                   Element commandElement) throws 
ActionExecutorException {
+        Path path = getPath(commandElement, FS_TAG_PATH);
+        touchz(context, fsConf, nameNodePath, path);
+    }
+
+    private void doChgrpOperation(Context context, XConfiguration fsConf, Path 
nameNodePath,
+                                  Element commandElement) throws 
ActionExecutorException {
+        Path path = getPath(commandElement, FS_TAG_PATH);
+        String groupTag = commandElement.getAttributeValue("group");
+        String dirFilesTag = commandElement.getAttributeValue(FS_TAG_DIRFILES);
+        boolean dirFiles = (dirFilesTag == null) || 
Boolean.parseBoolean(dirFilesTag);
+        boolean recursive = commandElement.getChild(FS_TAG_RECURSIVE, 
commandElement.getNamespace()) != null;
+        chgrp(context, fsConf, nameNodePath, path, 
context.getWorkflow().getUser(),
+                groupTag, dirFiles, recursive);
+    }
+
+    private void doSetrepOperation(Context context, Element commandElement)
+            throws ActionExecutorException, HadoopAccessorException {
+        Path path = getPath(commandElement, FS_TAG_PATH);
+        String replicationFactor = 
commandElement.getAttributeValue("replication-factor");
+        if (replicationFactor != null) {
+            setrep(context, path, Short.parseShort(replicationFactor));
+        }
+    }
+
     void chgrp(Context context, XConfiguration fsConf, Path nameNodePath, Path 
path, String user, String group,
             boolean dirFiles, boolean recursive) throws 
ActionExecutorException {
 
@@ -309,12 +349,12 @@ public class FsActionExecutor extends ActionExecutor {
 
     private void doFsOperation(String op, FileSystem fs, Path p, Map<String, 
String> argsMap)
             throws ActionExecutorException, IOException {
-        if (op.equals("chmod")) {
-            String permissions = argsMap.get("permissions");
+        if (op.equals(FS_OP_CHMOD)) {
+            String permissions = argsMap.get(FS_TAG_PERMISSIONS);
             FsPermission newFsPermission = createShortPermission(permissions, 
p);
             fs.setPermission(p, newFsPermission);
         }
-        else if (op.equals("chgrp")) {
+        else if (op.equals(FS_OP_CHGRP)) {
             String user = argsMap.get("user");
             String group = argsMap.get("group");
             fs.setOwner(p, user, group);
@@ -546,7 +586,7 @@ public class FsActionExecutor extends ActionExecutor {
 
         LOG.info("Setting permissions [{0}] on [{1}]. Recursive mode: [{2}]", 
permissions, path, recursive);
         HashMap<String, String> argsMap = new HashMap<String, String>();
-        argsMap.put("permissions", permissions);
+        argsMap.put(FS_TAG_PERMISSIONS, permissions);
         try {
             FileSystem fs = getFileSystemFor(path, context, fsConf);
             path = resolveToFullPath(nameNodePath, path, true);
@@ -557,7 +597,7 @@ public class FsActionExecutor extends ActionExecutor {
             }
             checkGlobMax(pathArr);
             for (Path p : pathArr) {
-                recursiveFsOperation("chmod", fs, nameNodePath, p, argsMap, 
dirFiles, recursive, true);
+                recursiveFsOperation(FS_OP_CHMOD, fs, nameNodePath, p, 
argsMap, dirFiles, recursive, true);
             }
 
         }
@@ -679,7 +719,6 @@ public class FsActionExecutor extends ActionExecutor {
                     "too many globbed files/dirs to do FS operation");
         }
     }
-
     void setrep(Context context, Path path, short replicationFactor)
             throws ActionExecutorException, HadoopAccessorException {
         LOG.info("Setting replication factor: [{0}] for [{1}]", 
replicationFactor, path);
diff --git a/release-log.txt b/release-log.txt
index b5ca0cf..2fd9938 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 5.2.0 release (trunk - unreleased)
 
+OOZIE-3417 [FS Action] Refactor and optimize FsActionExecutor.java decision 
making part (nobigo via asalamon74, kmarton)
 OOZIE-3243 [tests] Flaky test 
TestCoordActionsKillXCommand#testActionKillCommandDate (asalamon74 via kmarton)
 OOZIE-3419 amend [fluent-job] GraphVisualization fails before JDK 1.8.0_u40 
(asalamon74 via kmarton)
 OOZIE-3420 [action] pom.xml fixes (andras.piros via kmarton)

Reply via email to