Author: kamrul
Date: Sun Dec 11 04:05:03 2011
New Revision: 1212964

URL: http://svn.apache.org/viewvc?rev=1212964&view=rev
Log:
OOZIE-629 Oozie server to prevent usage of dataset initial-instance earlier 
than the system-defined default value.(Mona via Mohammad)

Added:
    
incubator/oozie/trunk/core/src/test/resources/coord-dataset-initial-instance.xml
Modified:
    
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
    
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordSubmitXCommand.java
    incubator/oozie/trunk/release-log.txt

Modified: 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java?rev=1212964&r1=1212963&r2=1212964&view=diff
==============================================================================
--- 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
 (original)
+++ 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
 Sun Dec 11 04:05:03 2011
@@ -24,6 +24,8 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -32,6 +34,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TimeZone;
 import java.util.TreeSet;
 
 import javax.xml.transform.stream.StreamSource;
@@ -763,6 +766,7 @@ public class CoordSubmitXCommand extends
                     .toString() : ((TimeUnit) 
evalFreq.getVariable("endOfDuration")).toString());
             val = resolveAttribute("initial-instance", dsElem, evalNofuncs);
             ParamChecker.checkUTC(val, "initial-instance");
+            checkInitialInstance(val);
             val = resolveAttribute("timezone", dsElem, evalNofuncs);
             ParamChecker.checkTimeZone(val, "timezone");
             resolveTagContents("uri-template", dsElem, evalNofuncs);
@@ -1006,6 +1010,26 @@ public class CoordSubmitXCommand extends
         return jobId;
     }
 
+    /*
+     * this method checks if the initial-instance specified for a particular
+       is not a date earlier than the oozie server default Jan 01, 1970 00:00Z 
UTC
+     */
+    private void checkInitialInstance(String val) throws 
CoordinatorJobException, IllegalArgumentException {
+        Date initialInstance, givenInstance;
+        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
+        df.setTimeZone(TimeZone.getTimeZone("UTC"));
+        try {
+            initialInstance = DateUtils.parseDateUTC("1970-01-01T00:00Z");
+            givenInstance = DateUtils.parseDateUTC(val);
+        }
+        catch (Exception e) {
+            throw new IllegalArgumentException("Unable to parse dataset 
initial-instance string '" + val + "' to Date object. ",e);
+        }
+        if(givenInstance.compareTo(initialInstance) < 0) {
+            throw new CoordinatorJobException(ErrorCode.E1021, "Dataset 
initial-instance " + df.format(givenInstance) + " is earlier than the default 
initial instance " + df.format(initialInstance));
+        }
+    }
+
     /* (non-Javadoc)
      * @see org.apache.oozie.command.XCommand#getEntityKey()
      */

Modified: 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordSubmitXCommand.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordSubmitXCommand.java?rev=1212964&r1=1212963&r2=1212964&view=diff
==============================================================================
--- 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordSubmitXCommand.java
 (original)
+++ 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/coord/TestCoordSubmitXCommand.java
 Sun Dec 11 04:05:03 2011
@@ -613,6 +613,33 @@ public class TestCoordSubmitXCommand ext
         }
     }
 
+    /**
+     * Checking that any dataset initial-instance is not set to a date earlier 
than the server default Jan 01, 1970 00:00Z UTC
+     * @throws Exception
+     */
+    public void testSubmitDatasetInitialInstance() throws Exception {
+        Configuration conf = new XConfiguration();
+        String appPath = getTestCaseDir() + File.separator + "coordinator.xml";
+        Reader reader = 
IOUtils.getResourceAsReader("coord-dataset-initial-instance.xml", -1);
+        Writer writer = new FileWriter(appPath);
+        IOUtils.copyCharStream(reader, writer);
+
+        conf.set(OozieClient.COORDINATOR_APP_PATH, appPath);
+        conf.set(OozieClient.USER_NAME, getTestUser());
+        conf.set(OozieClient.GROUP_NAME, "other");
+        CoordSubmitXCommand sc = new CoordSubmitXCommand(conf, "UNIT_TESTING");
+        try {
+            sc.call();
+            fail("Expected to catch errors due to invalid dataset initial 
instance");
+        }
+        catch(CommandException cx) {
+            assertEquals(sc.getJob().getStatus(), Job.Status.FAILED);
+            assertEquals(cx.getErrorCode(), ErrorCode.E1021);
+            if(!(cx.getMessage().contains("earlier than the default initial 
instance"))) {
+                fail("Unexpected failure - " + cx.getMessage());
+            }
+        }
+    }
 
     private void _testConfigDefaults(boolean withDefaults) throws Exception {
         Configuration conf = new XConfiguration();

Added: 
incubator/oozie/trunk/core/src/test/resources/coord-dataset-initial-instance.xml
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/resources/coord-dataset-initial-instance.xml?rev=1212964&view=auto
==============================================================================
--- 
incubator/oozie/trunk/core/src/test/resources/coord-dataset-initial-instance.xml
 (added)
+++ 
incubator/oozie/trunk/core/src/test/resources/coord-dataset-initial-instance.xml
 Sun Dec 11 04:05:03 2011
@@ -0,0 +1,57 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<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>
+  <concurrency>2</concurrency>
+  <execution>LIFO</execution>
+ </controls>
+ <datasets>
+       <!-- Note the initial-instance is set to a date older than the default 
date Jan 01, 1970 00:00Z. -->
+  <dataset name="a" frequency="${coord:days(7)}" 
initial-instance="1960-02-01T01:00Z" timezone="UTC">
+   <uri-template>file:///tmp/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>
+  </dataset>
+ </datasets>
+ <input-events>
+   <data-in name="A" dataset="a">
+     <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>

Modified: incubator/oozie/trunk/release-log.txt
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1212964&r1=1212963&r2=1212964&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Sun Dec 11 04:05:03 2011
@@ -1,5 +1,6 @@
 -- Oozie 3.2.0 release
 
+OOZIE-629 Oozie server to prevent usage of dataset initial-instance earlier 
than the system-defined default value.(Mona via Mohammad)
 OOZIE-621 Option to add timeunit for frequency for coordinator jobs 
filtering.(Kiran via Mohammad)
 OOZIE-627 Handle GZ log retrieval failures gracefully.(Kiran via Mohammad)
 OOZIE-8   Variable not getting replaced with value in workflow rerun.(Mona via 
Mohammad)


Reply via email to