aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/org')
-rw-r--r--common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java12
-rw-r--r--common/src/main/java/org/onap/so/spring/GracefulShutdown.java41
-rw-r--r--common/src/main/java/org/onap/so/spring/GracefulShutdownBeans.java20
3 files changed, 73 insertions, 0 deletions
diff --git a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
index b82d73bbbf..6211b76561 100644
--- a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
+++ b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
@@ -143,6 +143,18 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
final HttpEntity<?> request = new HttpEntity<>(getHttpHeaders());
return restTemplate.exchange(url, HttpMethod.DELETE, request, clazz);
+ } catch (final HttpStatusCodeException httpStatusCodeException) {
+ final String message = "Unable to invoke HTTP " + HttpMethod.DELETE + " using url: " + url + ", Response: "
+ + httpStatusCodeException.getRawStatusCode();
+ LOGGER.error(message, httpStatusCodeException);
+ final int rawStatusCode = httpStatusCodeException.getRawStatusCode();
+ if (rawStatusCode == HttpStatus.BAD_REQUEST.value()) {
+ throw new InvalidRestRequestException("No result found for given url: " + url);
+ } else if (rawStatusCode == HttpStatus.NOT_FOUND.value()) {
+ throw new HttpResouceNotFoundException("No result found for given url: " + url);
+ }
+ throw new RestProcessingException("Unable to invoke HTTP " + HttpMethod.DELETE + " using URL: " + url,
+ httpStatusCodeException, rawStatusCode);
} catch (final RestClientException restClientException) {
LOGGER.error("Unable to invoke HTTP DELETE using url: " + url, restClientException);
throw new InvalidRestRequestException("Unable to invoke HTTP DELETE using URL: " + url,
diff --git a/common/src/main/java/org/onap/so/spring/GracefulShutdown.java b/common/src/main/java/org/onap/so/spring/GracefulShutdown.java
new file mode 100644
index 0000000000..60f5b076cd
--- /dev/null
+++ b/common/src/main/java/org/onap/so/spring/GracefulShutdown.java
@@ -0,0 +1,41 @@
+package org.onap.so.spring;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import org.apache.catalina.connector.Connector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
+import org.springframework.context.event.ContextClosedEvent;
+import org.springframework.context.event.EventListener;
+
+public class GracefulShutdown implements TomcatConnectorCustomizer {
+
+ private static final Logger logger = LoggerFactory.getLogger(GracefulShutdown.class);
+
+ private volatile Connector connector;
+
+ @Override
+ public void customize(Connector connector) {
+ this.connector = connector;
+ }
+
+ @EventListener
+ public void handleClosedEvent(ContextClosedEvent event) {
+ this.connector.pause();
+ Executor executor = this.connector.getProtocolHandler().getExecutor();
+ if (executor instanceof ThreadPoolExecutor) {
+ try {
+ ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
+ threadPoolExecutor.shutdown();
+ if (!threadPoolExecutor.awaitTermination(30, TimeUnit.SECONDS)) {
+ logger.warn("Tomcat thread pool did not shut down gracefully within "
+ + "30 seconds. Proceeding with forceful shutdown");
+ }
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+}
diff --git a/common/src/main/java/org/onap/so/spring/GracefulShutdownBeans.java b/common/src/main/java/org/onap/so/spring/GracefulShutdownBeans.java
new file mode 100644
index 0000000000..219c82fb19
--- /dev/null
+++ b/common/src/main/java/org/onap/so/spring/GracefulShutdownBeans.java
@@ -0,0 +1,20 @@
+package org.onap.so.spring;
+
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
+import org.springframework.context.annotation.Bean;
+
+public class GracefulShutdownBeans {
+
+ @Bean
+ public GracefulShutdown gracefulShutdown() {
+ return new GracefulShutdown();
+ }
+
+ @Bean
+ public ConfigurableServletWebServerFactory webServerFactory(final GracefulShutdown gracefulShutdown) {
+ TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
+ factory.addConnectorCustomizers(gracefulShutdown);
+ return factory;
+ }
+}