You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by rk...@apache.org on 2013/02/04 18:54:52 UTC

svn commit: r1442203 - in /oozie/branches/branch-3.3: ./ core/src/main/java/org/apache/oozie/command/coord/ core/src/main/java/org/apache/oozie/command/wf/ core/src/main/resources/ core/src/test/java/org/apache/oozie/command/coord/ core/src/test/java/o...

Author: rkanter
Date: Mon Feb  4 17:54:52 2013
New Revision: 1442203

URL: http://svn.apache.org/viewvc?rev=1442203&view=rev
Log:
OOZIE-977 NotificationXCommand (job.notification queue entry) should set a timeout in the HTTP connections it makes (tucu)

Added:
    oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionNotificationXCommand.java
    oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/HangServlet.java
    oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/TestNotificationXCommand.java
Modified:
    oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/coord/CoordActionNotificationXCommand.java
    oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/wf/NotificationXCommand.java
    oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml
    oozie/branches/branch-3.3/release-log.txt

Modified: oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/coord/CoordActionNotificationXCommand.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/coord/CoordActionNotificationXCommand.java?rev=1442203&r1=1442202&r2=1442203&view=diff
==============================================================================
--- oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/coord/CoordActionNotificationXCommand.java (original)
+++ oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/coord/CoordActionNotificationXCommand.java Mon Feb  4 17:54:52 2013
@@ -28,6 +28,8 @@ import org.apache.oozie.ErrorCode;
 import org.apache.oozie.client.OozieClient;
 import org.apache.oozie.command.CommandException;
 import org.apache.oozie.command.PreconditionException;
+import org.apache.oozie.command.wf.NotificationXCommand;
+import org.apache.oozie.service.Services;
 import org.apache.oozie.util.LogUtils;
 import org.apache.oozie.util.ParamChecker;
 import org.apache.oozie.util.XConfiguration;
@@ -42,7 +44,8 @@ public class CoordActionNotificationXCom
     private static final String STATUS_PATTERN = "\\$status";
     private static final String ACTION_ID_PATTERN = "\\$actionId";
 
-    private int retries = 0;
+    //this variable is package private only for test purposes
+    int retries = 0;
 
     public CoordActionNotificationXCommand(CoordinatorActionBean actionBean) {
         super("coord_action_notification", "coord_action_notification", 0);
@@ -70,8 +73,13 @@ public class CoordActionNotificationXCom
             url = url.replaceAll(STATUS_PATTERN, actionBean.getStatus().toString());
             LOG.debug("Notification URL :" + url);
             try {
+                int timeout = Services.get().getConf().getInt(
+                    NotificationXCommand.NOTIFICATION_URL_CONNECTION_TIMEOUT_KEY,
+                    NotificationXCommand.NOTIFICATION_URL_CONNECTION_TIMEOUT_DEFAULT);
                 URL urlObj = new URL(url);
                 HttpURLConnection urlConn = (HttpURLConnection) urlObj.openConnection();
+                urlConn.setConnectTimeout(timeout);
+                urlConn.setReadTimeout(timeout);
                 if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                     handleRetry(url);
                 }

Modified: oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/wf/NotificationXCommand.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/wf/NotificationXCommand.java?rev=1442203&r1=1442202&r2=1442203&view=diff
==============================================================================
--- oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/wf/NotificationXCommand.java (original)
+++ oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/command/wf/NotificationXCommand.java Mon Feb  4 17:54:52 2013
@@ -22,6 +22,7 @@ import org.apache.oozie.WorkflowActionBe
 import org.apache.oozie.WorkflowJobBean;
 import org.apache.oozie.command.CommandException;
 import org.apache.oozie.command.PreconditionException;
+import org.apache.oozie.service.Services;
 import org.apache.oozie.util.LogUtils;
 import org.apache.oozie.util.ParamChecker;
 import org.apache.oozie.util.XLog;
@@ -32,12 +33,17 @@ import java.net.URL;
 
 public class NotificationXCommand extends WorkflowXCommand<Void> {
 
+    public static final String NOTIFICATION_URL_CONNECTION_TIMEOUT_KEY = "oozie.notification.url.connection.timeout";
+    public static final int NOTIFICATION_URL_CONNECTION_TIMEOUT_DEFAULT = 10 * 1000; // 10 seconds
+
     private static final String STATUS_PATTERN = "\\$status";
     private static final String JOB_ID_PATTERN = "\\$jobId";
     private static final String NODE_NAME_PATTERN = "\\$nodeName";
 
     private String url;
-    private int retries = 0;
+
+    //this variable is package private only for test purposes
+    int retries = 0;
 
     public NotificationXCommand(WorkflowJobBean workflow) {
         super("job.notification", "job.notification", 0);
@@ -92,9 +98,13 @@ public class NotificationXCommand extend
         //if command is requeue, the logInfo has to set to thread local Info object again
         LogUtils.setLogInfo(logInfo);
         if (url != null) {
+            int timeout = Services.get().getConf().getInt(NOTIFICATION_URL_CONNECTION_TIMEOUT_KEY,
+                                                          NOTIFICATION_URL_CONNECTION_TIMEOUT_DEFAULT);
             try {
                 URL url = new URL(this.url);
                 HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
+                urlConn.setConnectTimeout(timeout);
+                urlConn.setReadTimeout(timeout);
                 if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                     handleRetry();
                 }

Modified: oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml?rev=1442203&r1=1442202&r2=1442203&view=diff
==============================================================================
--- oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml (original)
+++ oozie/branches/branch-3.3/core/src/main/resources/oozie-default.xml Mon Feb  4 17:54:52 2013
@@ -1660,6 +1660,20 @@
 		</description>
 	</property>
 
+    <!-- Oozie HTTP Notifications -->
+    
+    <property>
+        <name>oozie.notification.url.connection.timeout</name>
+        <value>10000</value>
+        <description>
+            Defines the timeout, in milliseconds, for Oozie HTTP notification callbacks. Oozie does
+            HTTP notifications for workflow jobs which set the 'oozie.wf.action.notification.url',
+            'oozie.wf.worklfow.notification.url' and/or 'oozie.coord.action.notification.url'
+            properties in their job.properties. Refer to section '5 Oozie Notifications' in the
+            Workflow specification for details.
+        </description>
+    </property>
+
     <!-- Enable Distributed Cache workaround for Hadoop 2.0.2-alpha (MAPREDUCE-4820) -->
     <property>
         <name>oozie.hadoop-2.0.2-alpha.workaround.for.distributed.cache</name>
@@ -1673,4 +1687,5 @@
             job from the launcher.
         </description>
     </property>
+
 </configuration>

Added: oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionNotificationXCommand.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionNotificationXCommand.java?rev=1442203&view=auto
==============================================================================
--- oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionNotificationXCommand.java (added)
+++ oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/coord/TestCoordActionNotificationXCommand.java Mon Feb  4 17:54:52 2013
@@ -0,0 +1,60 @@
+package org.apache.oozie.command.coord;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.OozieClient;
+import org.apache.oozie.command.wf.HangServlet;
+import org.apache.oozie.command.wf.NotificationXCommand;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.EmbeddedServletContainer;
+import org.apache.oozie.test.XTestCase;
+import org.apache.oozie.util.XConfiguration;
+import org.junit.Assert;
+import org.mockito.Mockito;
+
+public class TestCoordActionNotificationXCommand extends XTestCase {
+    private EmbeddedServletContainer container;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        setSystemProperty(NotificationXCommand.NOTIFICATION_URL_CONNECTION_TIMEOUT_KEY, "50");
+        Services services = new Services();
+        services.init();
+        container = new EmbeddedServletContainer("blah");
+        container.addServletEndpoint("/hang/*", HangServlet.class);
+        container.start();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        try {
+            container.stop();
+        }
+        catch (Exception ex) {
+        }
+        try {
+            Services.get().destroy();
+        }
+        catch (Exception ex) {
+        }
+        super.tearDown();
+    }
+
+    public void testCoordNotificationTimeout() throws Exception {
+        XConfiguration conf = new XConfiguration();
+        conf.set(OozieClient.COORD_ACTION_NOTIFICATION_URL, container.getServletURL("/hang/*"));
+        String runConf = conf.toXmlString(false);
+        CoordinatorActionBean coord = Mockito.mock(CoordinatorActionBean.class);
+        Mockito.when(coord.getId()).thenReturn("1");
+        Mockito.when(coord.getStatus()).thenReturn(CoordinatorAction.Status.SUCCEEDED);
+        Mockito.when(coord.getRunConf()).thenReturn(runConf);
+        CoordActionNotificationXCommand command = new CoordActionNotificationXCommand(coord);
+        command.retries = 3;
+        long start = System.currentTimeMillis();
+        command.call();
+        long end = System.currentTimeMillis();
+        Assert.assertTrue(end - start >= 50);
+        Assert.assertTrue(end - start <= 100);
+    }
+}

Added: oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/HangServlet.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/HangServlet.java?rev=1442203&view=auto
==============================================================================
--- oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/HangServlet.java (added)
+++ oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/HangServlet.java Mon Feb  4 17:54:52 2013
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+package org.apache.oozie.command.wf;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Servlet that 'hangs' for 200 ms. Used by TestNotificationXCommand
+ */
+public class HangServlet extends HttpServlet {
+
+    protected void doGet(HttpServletRequest request, HttpServletResponse response)
+        throws ServletException, IOException {
+        try {
+            Thread.sleep(200);
+        }
+        catch (Exception ex) {
+            //NOP
+        }
+    }
+
+}

Added: oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/TestNotificationXCommand.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/TestNotificationXCommand.java?rev=1442203&view=auto
==============================================================================
--- oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/TestNotificationXCommand.java (added)
+++ oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/command/wf/TestNotificationXCommand.java Mon Feb  4 17:54:52 2013
@@ -0,0 +1,60 @@
+package org.apache.oozie.command.wf;
+
+import org.apache.oozie.WorkflowJobBean;
+import org.apache.oozie.client.OozieClient;
+import org.apache.oozie.client.WorkflowJob;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.EmbeddedServletContainer;
+import org.apache.oozie.test.XTestCase;
+import org.apache.oozie.util.XConfiguration;
+import org.apache.oozie.workflow.WorkflowInstance;
+import org.junit.Assert;
+import org.mockito.Mockito;
+
+public class TestNotificationXCommand extends XTestCase {
+    private EmbeddedServletContainer container;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        setSystemProperty(NotificationXCommand.NOTIFICATION_URL_CONNECTION_TIMEOUT_KEY, "50");
+        Services services = new Services();
+        services.init();
+        container = new EmbeddedServletContainer("blah");
+        container.addServletEndpoint("/hang/*", HangServlet.class);
+        container.start();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        try {
+            container.stop();
+        }
+        catch (Exception ex) {
+        }
+        try {
+            Services.get().destroy();
+        }
+        catch (Exception ex) {
+        }
+        super.tearDown();
+    }
+
+    public void testWFNotificationTimeout() throws Exception {
+        XConfiguration conf = new XConfiguration();
+        conf.set(OozieClient.WORKFLOW_NOTIFICATION_URL, container.getServletURL("/hang/*"));
+        WorkflowInstance wfi = Mockito.mock(WorkflowInstance.class);
+        Mockito.when(wfi.getConf()).thenReturn(conf);
+        WorkflowJobBean workflow = Mockito.mock(WorkflowJobBean.class);
+        Mockito.when(workflow.getId()).thenReturn("1");
+        Mockito.when(workflow.getStatus()).thenReturn(WorkflowJob.Status.SUCCEEDED);
+        Mockito.when(workflow.getWorkflowInstance()).thenReturn(wfi);
+        NotificationXCommand command = new NotificationXCommand(workflow);
+        command.retries = 3;
+        long start = System.currentTimeMillis();
+        command.call();
+        long end = System.currentTimeMillis();
+        Assert.assertTrue(end - start >= 50);
+        Assert.assertTrue(end - start <= 100);
+    }
+}

Modified: oozie/branches/branch-3.3/release-log.txt
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/release-log.txt?rev=1442203&r1=1442202&r2=1442203&view=diff
==============================================================================
--- oozie/branches/branch-3.3/release-log.txt (original)
+++ oozie/branches/branch-3.3/release-log.txt Mon Feb  4 17:54:52 2013
@@ -1,5 +1,6 @@
 -- Oozie 3.3.2 (unreleased)
 
+OOZIE-977 NotificationXCommand (job.notification queue entry) should set a timeout in the HTTP connections it makes (tucu)
 OOZIE-654 Provide a way to use 'uber' jars with Oozie MR actions (rkanter via tucu)
 OOZIE-1186 Image load for Job DAG visualization should handle resources better (mona)