Do start netty server when grpc server enabled 74/85274/4
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Sun, 14 Apr 2019 23:00:10 +0000 (19:00 -0400)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Mon, 15 Apr 2019 12:53:01 +0000 (12:53 +0000)
Change-Id: I7a4154f752bedd32c6c5789c21da82917336c7a6
Issue-ID: CCSDK-1182
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
ms/blueprintsprocessor/application/pom.xml
ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcDisable.java [moved from ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.java with 77% similarity]
ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcEnable.java [new file with mode: 0644]

index e7af4c8..c079ba9 100755 (executable)
             <groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
             <artifactId>blueprint-core</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-devtools</artifactId>
-            <scope>runtime</scope>
-        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-security</artifactId>
 package org.onap.ccsdk.cds.blueprintsprocessor;
 
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
 import org.springframework.boot.web.server.WebServerFactoryCustomizer;
 import org.springframework.stereotype.Component;
 
+// When GRPC disable, no need to create the netty server
+@ConditionalOnProperty(name = "blueprintsprocessor.grpcEnable", havingValue = "false")
 @Component
-public class BlueprintHttpServer implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
+public class HttpServerWhenGrpcDisable implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
 
     @Value("${blueprintsprocessor.httpPort}")
     private Integer httpPort;
diff --git a/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcEnable.java b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcEnable.java
new file mode 100644 (file)
index 0000000..e769b93
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2019 Bell Canada.
+ *
+ * Licensed 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.onap.ccsdk.cds.blueprintsprocessor;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
+import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
+import org.springframework.boot.web.server.WebServer;
+import org.springframework.http.server.reactive.HttpHandler;
+import org.springframework.stereotype.Component;
+
+// When GRPC enable, we need to manually create the netty server
+@ConditionalOnProperty(name = "blueprintsprocessor.grpcEnable", havingValue = "true")
+@Component
+public class HttpServerWhenGrpcEnable {
+
+    @Value("${blueprintsprocessor.httpPort}")
+    private Integer httpPort;
+
+    private final HttpHandler httpHandler;
+    private WebServer http;
+
+    @Autowired
+    public HttpServerWhenGrpcEnable(HttpHandler httpHandler) {
+        this.httpHandler = httpHandler;
+    }
+
+    @PostConstruct
+    public void start() {
+        ReactiveWebServerFactory factory = new NettyReactiveWebServerFactory(httpPort);
+        this.http = factory.getWebServer(this.httpHandler);
+        this.http.start();
+    }
+
+    @PreDestroy
+    public void stop() {
+        this.http.stop();
+    }
+}
\ No newline at end of file