OOZIE-2850 Fix default callback notifications (asasvari via gezapeti)
Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/ce7eb312 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/ce7eb312 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/ce7eb312 Branch: refs/heads/oya Commit: ce7eb312b34d32841c85dde01cd24cf3e934fad4 Parents: f110c33 Author: Gezapeti Cseh <[email protected]> Authored: Wed Apr 5 15:25:29 2017 +0200 Committer: Gezapeti Cseh <[email protected]> Committed: Wed Apr 5 15:25:29 2017 +0200 ---------------------------------------------------------------------- core/src/main/resources/oozie-default.xml | 2 +- .../oozie/service/TestConfigurationService.java | 4 +- release-log.txt | 1 + .../oozie/server/EmbeddedOozieServer.java | 20 +++++- .../ConstraintSecurityHandlerProvider.java | 15 ++++- .../oozie/server/TestEmbeddedOozieServer.java | 2 + .../TestConstraintSecurityHandlerProvider.java | 66 ++++++++++++++++++++ 7 files changed, 104 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/ce7eb312/core/src/main/resources/oozie-default.xml ---------------------------------------------------------------------- diff --git a/core/src/main/resources/oozie-default.xml b/core/src/main/resources/oozie-default.xml index c2f874f..fe095ca 100644 --- a/core/src/main/resources/oozie-default.xml +++ b/core/src/main/resources/oozie-default.xml @@ -102,7 +102,7 @@ <property> <name>oozie.base.url</name> - <value>http://localhost:8080/oozie</value> + <value>http://${oozie.http.hostname}:${oozie.http.port}/oozie</value> <description> Base Oozie URL. </description> http://git-wip-us.apache.org/repos/asf/oozie/blob/ce7eb312/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java b/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java index 42ffdbe..2a3d3d3 100644 --- a/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java +++ b/core/src/test/java/org/apache/oozie/service/TestConfigurationService.java @@ -173,7 +173,7 @@ public class TestConfigurationService extends XTestCase { assertEquals("oozie-conf", ConfigurationService.get("test.nonexist")); assertEquals(ConfigUtils.STRING_DEFAULT, ConfigurationService.get(testConf, "test.nonexist")); - assertEquals("http://localhost:8080/oozie/callback", ConfigurationService.get(CallbackService.CONF_BASE_URL)); + assertEquals("http://0.0.0.0:11000/oozie/callback", ConfigurationService.get(CallbackService.CONF_BASE_URL)); assertEquals(5, ConfigurationService.getInt(CallbackService.CONF_EARLY_REQUEUE_MAX_RETRIES)); assertEquals("gz", ConfigurationService.get(CodecFactory.COMPRESSION_OUTPUT_CODEC)); assertEquals(4096, ConfigurationService.getInt(XLogStreamingService.STREAM_BUFFER_LEN)); @@ -208,7 +208,7 @@ public class TestConfigurationService extends XTestCase { assertEquals("10", ConfigurationService.get(JPAService.CONF_VALIDATE_DB_CONN_EVICTION_NUM).trim()); assertEquals(2048, ConfigurationService.getInt(LauncherMapper.CONF_OOZIE_ACTION_MAX_OUTPUT_DATA)); - assertEquals("http://localhost:8080/oozie?job=", ConfigurationService.get(JobXCommand.CONF_CONSOLE_URL)); + assertEquals("http://0.0.0.0:11000/oozie?job=", ConfigurationService.get(JobXCommand.CONF_CONSOLE_URL)); assertEquals(true, ConfigurationService.getBoolean(JavaActionExecutor.CONF_HADOOP_YARN_UBER_MODE)); assertEquals(false, ConfigurationService.getBoolean( "oozie.action.shell.launcher." + JavaActionExecutor.HADOOP_YARN_UBER_MODE)); http://git-wip-us.apache.org/repos/asf/oozie/blob/ce7eb312/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index faa30b7..4ccc9e5 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 4.4.0 release (trunk - unreleased) +OOZIE-2850 Fix default callback notifications (asasvari via gezapeti) OOZIE-1283 Remove the old ssh documentation (Jan Hentschel via rkanter) OOZIE-2845 Replace reflection-based code which sets variable in HiveConf (pbacsko via abhishekbafna) OOZIE-2831 Update maven-project-info-reports-plugin to 2.9 (asasvari via gezapeti) http://git-wip-us.apache.org/repos/asf/oozie/blob/ce7eb312/server/src/main/java/org/apache/oozie/server/EmbeddedOozieServer.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/oozie/server/EmbeddedOozieServer.java b/server/src/main/java/org/apache/oozie/server/EmbeddedOozieServer.java index b7918b7..ab0d7ea 100644 --- a/server/src/main/java/org/apache/oozie/server/EmbeddedOozieServer.java +++ b/server/src/main/java/org/apache/oozie/server/EmbeddedOozieServer.java @@ -49,6 +49,7 @@ import java.net.URISyntaxException; */ public class EmbeddedOozieServer { private static final Logger LOG = LoggerFactory.getLogger(EmbeddedOozieServer.class); + private static String contextPath; protected Server server; private int httpPort; private int httpsPort; @@ -106,7 +107,7 @@ public class EmbeddedOozieServer { */ public void setup() throws URISyntaxException, IOException, ServiceException { conf = serviceController.get(ConfigurationService.class).getConf(); - + setContextPath(conf); httpPort = getConfigPort(ConfigUtils.OOZIE_HTTP_PORT); HttpConfiguration httpConfiguration = new HttpConfigurationWrapper(conf).getDefaultHttpConfiguration(); @@ -128,7 +129,7 @@ public class EmbeddedOozieServer { server.setConnectors(new Connector[]{connector}); } - servletContextHandler.setContextPath("/oozie/"); + servletContextHandler.setContextPath(contextPath); oozieServletMapper.mapOozieServlets(); oozieFilterMapper.addFilters(); @@ -168,6 +169,21 @@ public class EmbeddedOozieServer { return isSSLEnabled != null && Boolean.valueOf(isSSLEnabled); } + public static void setContextPath(Configuration oozieConfiguration) { + String baseUrl = oozieConfiguration.get("oozie.base.url"); + String contextPath = baseUrl.substring(baseUrl.lastIndexOf("/")); + LOG.info("Server started with contextPath = " + contextPath); + EmbeddedOozieServer.contextPath = contextPath; + } + + public static String getContextPath(Configuration oozieConfiguration) { + if (contextPath != null) { + return contextPath; + } + + setContextPath(oozieConfiguration); + return EmbeddedOozieServer.contextPath; + } public void start() throws Exception { server.start(); http://git-wip-us.apache.org/repos/asf/oozie/blob/ce7eb312/server/src/main/java/org/apache/oozie/server/guice/ConstraintSecurityHandlerProvider.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/oozie/server/guice/ConstraintSecurityHandlerProvider.java b/server/src/main/java/org/apache/oozie/server/guice/ConstraintSecurityHandlerProvider.java index 6c313fe..48cc469 100644 --- a/server/src/main/java/org/apache/oozie/server/guice/ConstraintSecurityHandlerProvider.java +++ b/server/src/main/java/org/apache/oozie/server/guice/ConstraintSecurityHandlerProvider.java @@ -18,7 +18,12 @@ package org.apache.oozie.server.guice; +import com.google.inject.Inject; import com.google.inject.Provider; +import org.apache.hadoop.conf.Configuration; +import org.apache.oozie.server.EmbeddedOozieServer; +import org.apache.oozie.service.ConfigurationService; +import org.apache.oozie.service.Services; import org.eclipse.jetty.security.ConstraintMapping; import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.util.security.Constraint; @@ -26,10 +31,18 @@ import org.eclipse.jetty.util.security.Constraint; import java.util.Arrays; class ConstraintSecurityHandlerProvider implements Provider<ConstraintSecurityHandler> { + private final Configuration oozieConfiguration; + + @Inject + public ConstraintSecurityHandlerProvider(final Services oozieServices) { + oozieConfiguration = oozieServices.get(ConfigurationService.class).getConf(); + } + @Override public ConstraintSecurityHandler get() { + String contextPath = EmbeddedOozieServer.getContextPath(oozieConfiguration); ConstraintMapping callbackConstraintMapping = new ConstraintMapping(); - callbackConstraintMapping.setPathSpec("/callback/*"); + callbackConstraintMapping.setPathSpec(String.format("%s/callback/*", contextPath)); Constraint unsecureConstraint = new Constraint(); unsecureConstraint.setDataConstraint(Constraint.DC_NONE); callbackConstraintMapping.setConstraint(unsecureConstraint); http://git-wip-us.apache.org/repos/asf/oozie/blob/ce7eb312/server/src/test/java/org/apache/oozie/server/TestEmbeddedOozieServer.java ---------------------------------------------------------------------- diff --git a/server/src/test/java/org/apache/oozie/server/TestEmbeddedOozieServer.java b/server/src/test/java/org/apache/oozie/server/TestEmbeddedOozieServer.java index 0f36e8c..f073256 100644 --- a/server/src/test/java/org/apache/oozie/server/TestEmbeddedOozieServer.java +++ b/server/src/test/java/org/apache/oozie/server/TestEmbeddedOozieServer.java @@ -74,6 +74,7 @@ public class TestEmbeddedOozieServer { doReturn("65536").when(mockConfiguration).get("oozie.http.request.header.size"); doReturn("65536").when(mockConfiguration).get("oozie.http.response.header.size"); doReturn("42").when(mockConfiguration).get("oozie.server.threadpool.max.threads"); + doReturn("https://localhost:11443/oozie").when(mockConfiguration).get("oozie.base.url"); doReturn(mockConfiguration).when(mockConfigService).getConf(); doReturn(mockConfigService).when(mockServices).get(ConfigurationService.class); } @@ -91,6 +92,7 @@ public class TestEmbeddedOozieServer { @Test public void testServerSetup() throws Exception { doReturn("false").when(mockConfiguration).get("oozie.https.enabled"); + embeddedOozieServer.setup(); verify(mockJspHandler).setupWebAppContext(isA(WebAppContext.class)); } http://git-wip-us.apache.org/repos/asf/oozie/blob/ce7eb312/server/src/test/java/org/apache/oozie/server/guice/TestConstraintSecurityHandlerProvider.java ---------------------------------------------------------------------- diff --git a/server/src/test/java/org/apache/oozie/server/guice/TestConstraintSecurityHandlerProvider.java b/server/src/test/java/org/apache/oozie/server/guice/TestConstraintSecurityHandlerProvider.java new file mode 100644 index 0000000..d5f72f7 --- /dev/null +++ b/server/src/test/java/org/apache/oozie/server/guice/TestConstraintSecurityHandlerProvider.java @@ -0,0 +1,66 @@ +/** + * 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.server.guice; + +import org.apache.hadoop.conf.Configuration; +import org.apache.oozie.server.EmbeddedOozieServer; +import org.apache.oozie.service.ConfigurationService; +import org.apache.oozie.service.Services; +import org.eclipse.jetty.security.ConstraintMapping; +import org.eclipse.jetty.security.ConstraintSecurityHandler; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.util.ArrayList; +import java.util.List; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class TestConstraintSecurityHandlerProvider { + @Mock Services mockServices; + @Mock ConfigurationService mockCfgService; + @Mock Configuration mockConfig; + + @Test + public void constraintHandlersCanBeSet() { + Configuration config = new Configuration(false); + config.set("oozie.base.url", "https://localhost:11443/oozie"); + when(mockCfgService.getConf()).thenReturn(config); + when(mockServices.get(ConfigurationService.class)).thenReturn(mockCfgService); + + ConstraintSecurityHandlerProvider constraintSecurityHandlerProvider = new ConstraintSecurityHandlerProvider( + mockServices); + ConstraintSecurityHandler actConstraintSecurityHandler = constraintSecurityHandlerProvider.get(); + List<ConstraintMapping> actConstraintMappings = actConstraintSecurityHandler.getConstraintMappings(); + assertEquals(actConstraintMappings.size(), 2); + + List<String> actPathSpecs = new ArrayList<>(); + for (ConstraintMapping sm : actConstraintMappings) { + actPathSpecs.add(sm.getPathSpec()); + } + + assertTrue(actPathSpecs.contains(String.format("%s/callback/*", EmbeddedOozieServer.getContextPath(config)))); + assertTrue(actPathSpecs.contains("/*")); + } +}
