Author: kamrul
Date: Tue Apr  3 06:12:10 2012
New Revision: 1308715

URL: http://svn.apache.org/viewvc?rev=1308715&view=rev
Log:
OOZIE-741: the size of the workflow definition file (Mohamed via Mohammad)

Modified:
    incubator/oozie/trunk/core/src/main/java/org/apache/oozie/ErrorCode.java
    
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/WorkflowAppService.java
    incubator/oozie/trunk/core/src/main/resources/oozie-default.xml
    
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestLiteWorkflowAppService.java
    incubator/oozie/trunk/release-log.txt

Modified: 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/ErrorCode.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/ErrorCode.java?rev=1308715&r1=1308714&r2=1308715&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/ErrorCode.java 
(original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/ErrorCode.java 
Tue Apr  3 06:12:10 2012
@@ -140,6 +140,7 @@ public enum ErrorCode {
     E0733(XLog.STD, "Fork [{0}] without a join"),
     E0734(XLog.STD, "Invalid transition from node [{0}] to node [{1}] while 
using fork/join"),
     E0735(XLog.STD, "There was an invalid \"error to\" transition to node 
[{1}] while using fork/join"),
+    E0736(XLog.STD, "Workflow definition lenght [{0}] exceeded maximum allowed 
length [{1}]"),
 
     E0800(XLog.STD, "Action it is not running its in [{1}] state, action 
[{0}]"),
     E0801(XLog.STD, "Workflow already running, workflow [{0}]"),

Modified: 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/WorkflowAppService.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/WorkflowAppService.java?rev=1308715&r1=1308714&r2=1308715&view=diff
==============================================================================
--- 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/WorkflowAppService.java
 (original)
+++ 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/WorkflowAppService.java
 Tue Apr  3 06:12:10 2012
@@ -54,7 +54,10 @@ public abstract class WorkflowAppService
 
     public static final String HADOOP_USER = "user.name";
 
+    public static final String CONFG_MAX_WF_LENGTH = CONF_PREFIX + 
"WorkflowDefinitionMaxLength";
+
     private Path systemLibPath;
+    private long maxWFLength;
 
     /**
      * Initialize the workflow application service.
@@ -62,10 +65,14 @@ public abstract class WorkflowAppService
      * @param services services instance.
      */
     public void init(Services services) {
-        String path = services.getConf().get(SYSTEM_LIB_PATH, " ");
+        Configuration conf = services.getConf();
+
+        String path = conf.get(SYSTEM_LIB_PATH, " ");
         if (path.trim().length() > 0) {
             systemLibPath = new Path(path.trim());
         }
+
+        maxWFLength = conf.getInt(CONFG_MAX_WF_LENGTH, 100000);
     }
 
     /**
@@ -107,12 +114,20 @@ public abstract class WorkflowAppService
                 path = new Path(path, "workflow.xml");
             }
 
+            FileStatus fsStatus = fs.getFileStatus(path);
+            if (fsStatus.getLen() > this.maxWFLength) {
+                throw new WorkflowException(ErrorCode.E0736, 
fsStatus.getLen(), this.maxWFLength);
+            }
+
             Reader reader = new InputStreamReader(fs.open(path));
             StringWriter writer = new StringWriter();
             IOUtils.copyCharStream(reader, writer);
             return writer.toString();
 
         }
+        catch (WorkflowException wfe) {
+            throw wfe;
+        }
         catch (IOException ex) {
             throw new WorkflowException(ErrorCode.E0710, ex.getMessage(), ex);
         }

Modified: incubator/oozie/trunk/core/src/main/resources/oozie-default.xml
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/resources/oozie-default.xml?rev=1308715&r1=1308714&r2=1308715&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/resources/oozie-default.xml (original)
+++ incubator/oozie/trunk/core/src/main/resources/oozie-default.xml Tue Apr  3 
06:12:10 2012
@@ -467,6 +467,15 @@
     </property>
 
     <property>
+        
<name>oozie.service.WorkflowAppService.WorkflowDefinitionMaxLength</name>
+        <value>100000</value>
+        <description>
+            The maximum length of the workflow definition in bytes
+            An error will be reported if the length exceeds the given maximum
+        </description>
+    </property>
+
+    <property>
         <name>oozie.service.ELService.ext.functions.workflow</name>
         <value>
         </value>

Modified: 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestLiteWorkflowAppService.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestLiteWorkflowAppService.java?rev=1308715&r1=1308714&r2=1308715&view=diff
==============================================================================
--- 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestLiteWorkflowAppService.java
 (original)
+++ 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestLiteWorkflowAppService.java
 Tue Apr  3 06:12:10 2012
@@ -96,6 +96,36 @@ public class TestLiteWorkflowAppService 
         }
     }
 
+    /**
+     * Making sure an exception is thrown when a WF exceeds the maximum length
+     *
+     * @throws Exception
+     */
+    public void testMaxWfDefinition() throws Exception {
+        setSystemProperty(WorkflowAppService.CONFG_MAX_WF_LENGTH, "100");
+        Services services = new Services();
+        try {
+            services.init();
+
+            Reader reader = IOUtils.getResourceAsReader("wf-schema-valid.xml", 
-1);
+            Writer writer = new FileWriter(getTestCaseDir() + "/workflow.xml");
+            IOUtils.copyCharStream(reader, writer);
+
+            Configuration conf = new XConfiguration();
+
+            WorkflowAppService wps = services.get(WorkflowAppService.class);
+            wps.readDefinition("file://" + getTestCaseDir() + File.separator + 
"workflow.xml", getTestUser(),
+                    "authToken", conf);
+            fail("an exception should be thrown as the definition exceeds the 
given maximum");
+        }
+        catch (WorkflowException wfe) {
+            assertEquals(wfe.getErrorCode(), ErrorCode.E0736);
+        }
+        finally {
+            services.destroy();
+        }
+    }
+
     public void testNoAppPath() throws Exception {
         Services services = new Services();
         services.init();

Modified: incubator/oozie/trunk/release-log.txt
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1308715&r1=1308714&r2=1308715&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Tue Apr  3 06:12:10 2012
@@ -1,5 +1,6 @@
 -- Oozie 3.2.0 release
 
+OOZIE-741: the size of the workflow definition file (Mohamed via Mohammad)
 OOZIE-797 Action retry not reading default error code.(Mona via Mohammad)
 OOZIE-780: XConfiguration parser can't parse XML file with <include> element 
(Virag via Mohammad)
 OOZIE-794: oozie job -info -filter should error out on bundle job and workflow 
job (virag via Mohammad)


Reply via email to