You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2021/06/17 11:13:20 UTC
[incubator-streampipes] branch STREAMPIPES-319 updated:
[STREAMPIPES-383] Add StreamPipesServiceBase to centralize web server
management
This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch STREAMPIPES-319
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
The following commit(s) were added to refs/heads/STREAMPIPES-319 by this push:
new 3821431 [STREAMPIPES-383] Add StreamPipesServiceBase to centralize web server management
3821431 is described below
commit 38214310786a8a8d7a6e5d4a4b20fbae92f368fa
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Thu Jun 17 13:12:58 2021 +0200
[STREAMPIPES-383] Add StreamPipesServiceBase to centralize web server management
---
streampipes-backend/pom.xml | 15 -----
.../backend/StreamPipesBackendApplication.java | 36 ++++-------
streampipes-container-base/pom.xml | 32 ++++-----
.../container/base/StreamPipesServiceBase.java | 75 ++++++++++++++++++++++
4 files changed, 100 insertions(+), 58 deletions(-)
diff --git a/streampipes-backend/pom.xml b/streampipes-backend/pom.xml
index d5b3f9a..e90508f 100644
--- a/streampipes-backend/pom.xml
+++ b/streampipes-backend/pom.xml
@@ -34,12 +34,6 @@
<groupId>org.apache.streampipes</groupId>
<artifactId>streampipes-container-base</artifactId>
<version>0.68.0-SNAPSHOT</version>
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-undertow</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.apache.streampipes</groupId>
@@ -66,21 +60,12 @@
<artifactId>streampipes-platform-services</artifactId>
<version>0.68.0-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.apache.streampipes</groupId>
- <artifactId>streampipes-service-discovery</artifactId>
- <version>0.68.0-SNAPSHOT</version>
- </dependency>
<!-- External dependencies -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
</dependency>
diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java
index 7759c4d..6c2ee97 100644
--- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesBackendApplication.java
@@ -20,7 +20,7 @@ package org.apache.streampipes.backend;
import org.apache.shiro.web.env.EnvironmentLoaderListener;
import org.apache.shiro.web.servlet.OncePerRequestFilter;
import org.apache.shiro.web.servlet.ShiroFilter;
-import org.apache.streampipes.commons.networking.Networking;
+import org.apache.streampipes.container.base.StreamPipesServiceBase;
import org.apache.streampipes.manager.health.PipelineHealthCheck;
import org.apache.streampipes.manager.operations.Operations;
import org.apache.streampipes.model.pipeline.Pipeline;
@@ -28,11 +28,9 @@ import org.apache.streampipes.model.pipeline.PipelineOperationStatus;
import org.apache.streampipes.rest.notifications.NotificationListener;
import org.apache.streampipes.storage.api.IPipelineStorage;
import org.apache.streampipes.storage.management.StorageDispatcher;
-import org.apache.streampipes.svcdiscovery.SpServiceDiscovery;
import org.apache.streampipes.svcdiscovery.SpServiceTags;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
@@ -43,9 +41,8 @@ import org.springframework.context.annotation.Import;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.servlet.ServletContextListener;
-import java.util.HashMap;
-import java.net.UnknownHostException;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
@@ -56,7 +53,7 @@ import java.util.stream.Collectors;
@Configuration
@EnableAutoConfiguration
@Import({StreamPipesResourceConfig.class, WelcomePageController.class})
-public class StreamPipesBackendApplication {
+public class StreamPipesBackendApplication extends StreamPipesServiceBase {
private static final Logger LOG = LoggerFactory.getLogger(StreamPipesBackendApplication.class.getCanonicalName());
@@ -72,22 +69,8 @@ public class StreamPipesBackendApplication {
private Map<String, Integer> failedPipelines = new HashMap<>();
public static void main(String[] args) {
- System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
- try {
- String host = Networking.getHostname();
- Integer port = Networking.getPort(8030);
- SpServiceDiscovery
- .getServiceDiscovery()
- .registerService("core",
- "core",
- host,
- port,
- Arrays.asList(SpServiceTags.CORE, SpServiceTags.CONNECT_MASTER));
-
- SpringApplication.run(StreamPipesBackendApplication.class, args);
- } catch (UnknownHostException e) {
- LOG.error("Could not auto-resolve host address - please manually provide the hostname using the SP_HOST environment variable");
- }
+ StreamPipesBackendApplication application = new StreamPipesBackendApplication();
+ application.startStreamPipesService(StreamPipesBackendApplication.class, "core", "core");
}
@PostConstruct
@@ -241,4 +224,13 @@ public class StreamPipesBackendApplication {
return bean;
}
+ @Override
+ protected Integer getDefaultPort() {
+ return 8030;
+ }
+
+ @Override
+ protected List<String> getServiceTags() {
+ return Arrays.asList(SpServiceTags.CORE, SpServiceTags.CONNECT_MASTER);
+ }
}
diff --git a/streampipes-container-base/pom.xml b/streampipes-container-base/pom.xml
index 09be997..33e3b40 100644
--- a/streampipes-container-base/pom.xml
+++ b/streampipes-container-base/pom.xml
@@ -29,6 +29,16 @@
<dependencies>
<!-- StreamPipes dependencies -->
+ <dependency>
+ <groupId>org.apache.streampipes</groupId>
+ <artifactId>streampipes-commons</artifactId>
+ <version>0.68.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.streampipes</groupId>
+ <artifactId>streampipes-service-discovery</artifactId>
+ <version>0.68.0-SNAPSHOT</version>
+ </dependency>
<!-- External dependencies -->
<dependency>
@@ -44,26 +54,6 @@
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- </dependency>
- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<exclusions>
@@ -92,4 +82,4 @@
<artifactId>wildfly-common</artifactId>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/streampipes-container-base/src/main/java/org/apache/streampipes/container/base/StreamPipesServiceBase.java b/streampipes-container-base/src/main/java/org/apache/streampipes/container/base/StreamPipesServiceBase.java
new file mode 100644
index 0000000..33ab0fd
--- /dev/null
+++ b/streampipes-container-base/src/main/java/org/apache/streampipes/container/base/StreamPipesServiceBase.java
@@ -0,0 +1,75 @@
+/*
+ * 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.streampipes.container.base;
+
+import org.apache.streampipes.commons.networking.Networking;
+import org.apache.streampipes.svcdiscovery.SpServiceDiscovery;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+
+import java.net.UnknownHostException;
+import java.util.Collections;
+import java.util.List;
+
+public abstract class StreamPipesServiceBase {
+
+ private static final Logger LOG = LoggerFactory.getLogger(StreamPipesServiceBase.class);
+
+ protected void startStreamPipesService(Class<?> serviceClass,
+ String serviceGroup,
+ String serviceName) {
+ try {
+ registerService(serviceGroup, serviceName);
+ runApplication(serviceClass);
+ } catch (UnknownHostException e) {
+ LOG.error("Could not auto-resolve host address - please manually provide the hostname using the SP_HOST environment variable");
+ }
+ }
+
+ private void runApplication(Class<?> serviceClass) {
+ SpringApplication app = new SpringApplication(serviceClass);
+ app.setDefaultProperties(Collections.singletonMap("server.port", getPort()));
+ app.run();
+ }
+
+ private void registerService(String serviceGroup,
+ String serviceName) throws UnknownHostException {
+ SpServiceDiscovery
+ .getServiceDiscovery()
+ .registerService(serviceGroup,
+ serviceName,
+ getHostname(),
+ getPort(),
+ getServiceTags());
+ }
+
+ protected String getHostname() throws UnknownHostException {
+ return Networking.getHostname();
+ }
+
+ protected Integer getPort() {
+ return Networking.getPort(getDefaultPort());
+ }
+
+ protected abstract Integer getDefaultPort();
+
+ protected abstract List<String> getServiceTags();
+
+
+}