From 09d43a482fb3e0b6ed904637faf6147695f7c822 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Sun, 14 Apr 2019 19:00:10 -0400 Subject: Do start netty server when grpc server enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7a4154f752bedd32c6c5789c21da82917336c7a6 Issue-ID: CCSDK-1182 Signed-off-by: Alexis de Talhouët --- ms/blueprintsprocessor/application/pom.xml | 5 -- .../blueprintsprocessor/BlueprintHttpServer.java | 34 ------------- .../HttpServerWhenGrpcDisable.java | 37 ++++++++++++++ .../HttpServerWhenGrpcEnable.java | 56 ++++++++++++++++++++++ 4 files changed, 93 insertions(+), 39 deletions(-) delete mode 100644 ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.java create mode 100644 ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcDisable.java create mode 100644 ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcEnable.java (limited to 'ms/blueprintsprocessor/application') diff --git a/ms/blueprintsprocessor/application/pom.xml b/ms/blueprintsprocessor/application/pom.xml index e7af4c852..c079ba990 100755 --- a/ms/blueprintsprocessor/application/pom.xml +++ b/ms/blueprintsprocessor/application/pom.xml @@ -35,11 +35,6 @@ org.onap.ccsdk.cds.controllerblueprints blueprint-core - - org.springframework.boot - spring-boot-devtools - runtime - org.springframework.boot spring-boot-starter-security diff --git a/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.java b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.java deleted file mode 100644 index 85ccd1f43..000000000 --- a/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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 org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; -import org.springframework.stereotype.Component; - -@Component -public class BlueprintHttpServer implements WebServerFactoryCustomizer { - - @Value("${blueprintsprocessor.httpPort}") - private Integer httpPort; - - @Override - public void customize(NettyReactiveWebServerFactory serverFactory) { - serverFactory.setPort(httpPort); - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcDisable.java b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcDisable.java new file mode 100644 index 000000000..c20a324d5 --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcDisable.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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 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 HttpServerWhenGrpcDisable implements WebServerFactoryCustomizer { + + @Value("${blueprintsprocessor.httpPort}") + private Integer httpPort; + + @Override + public void customize(NettyReactiveWebServerFactory serverFactory) { + serverFactory.setPort(httpPort); + } +} \ No newline at end of file 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 index 000000000..e769b9361 --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/HttpServerWhenGrpcEnable.java @@ -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 -- cgit 1.2.3-korg