From c0218ada67784a7d5c3a488303bcbab2b3dce5b5 Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Mon, 28 Nov 2022 09:40:36 +0100 Subject: A1-PMS, graceful shutdown Support for granceful shutdown via signal "SIGTERM" and via calling REST POST /actuator/shutdown Issue-ID: CCSDK-3830 Signed-off-by: PatrikBuhr Change-Id: Ibc71cd8a2c9f44ec844ab49c8f225ae128549776 --- .../oran/a1policymanagementservice/Application.java | 17 ++++++++++++++++- .../oran/a1policymanagementservice/SwaggerConfig.java | 11 ++++++++--- .../a1policymanagementservice/aspect/LogAspect.java | 4 +++- .../clients/A1ClientFactory.java | 3 ++- .../configuration/ConfigurationFile.java | 3 ++- .../datastore/S3ObjectStore.java | 3 ++- .../dmaap/DmaapMessageConsumer.java | 3 ++- .../dmaap/DmaapMessageHandler.java | 4 +++- .../exceptions/GlobalExceptionHandler.java | 4 +++- .../oran/a1policymanagementservice/repository/Lock.java | 3 ++- .../oran/a1policymanagementservice/repository/Ric.java | 3 ++- .../a1policymanagementservice/repository/Services.java | 3 ++- .../tasks/RefreshConfigTask.java | 3 ++- .../a1policymanagementservice/tasks/RicSupervision.java | 3 ++- .../tasks/RicSynchronizationTask.java | 3 ++- .../tasks/ServiceSupervision.java | 3 ++- 16 files changed, 55 insertions(+), 18 deletions(-) (limited to 'a1-policy-management/src/main/java') diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java index ae114f67..259a5ba9 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java @@ -20,13 +20,18 @@ package org.onap.ccsdk.oran.a1policymanagementservice; +import java.lang.invoke.MethodHandles; + import org.onap.ccsdk.oran.a1policymanagementservice.dmaap.DmaapMessageConsumer; import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RefreshConfigTask; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; @SpringBootApplication @@ -38,8 +43,18 @@ public class Application { @Autowired private DmaapMessageConsumer dmaapMessageConsumer; + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + public static void main(String[] args) { - SpringApplication.run(Application.class); + ConfigurableApplicationContext context = SpringApplication.run(Application.class); + + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + logger.warn("Shutting down, received signal SIGTERM"); + SpringApplication.exit(context); + } + }); } /** diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/SwaggerConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/SwaggerConfig.java index 4c3a0c79..b6d3a076 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/SwaggerConfig.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/SwaggerConfig.java @@ -43,7 +43,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.StatusContro version = SwaggerConfig.VERSION, // description = SwaggerConfig.DESCRIPTION, // license = @License( - name = "Copyright (C) 2020-2022 Nordix Foundation. Licensed under the Apache License.", // + name = "Copyright (C) 2020-2023 Nordix Foundation. Licensed under the Apache License.", // url = "http://www.apache.org/licenses/LICENSE-2.0")) // ) public class SwaggerConfig { @@ -83,10 +83,15 @@ public class SwaggerConfig { + H3 + StatusController.API_NAME + H3_END + // "

API used for supervision of the PMS component.

" + // H3 + ServiceController.API_NAME + H3_END + // - "

" + "API used for registering services that uses PMS." + "

" // + + "API used for registering services that uses PMS." + " Each A1 policy is optionally owned by a service. PMS can supervise each registered service by a heart-beat supervision and will automatically remove policies for unavailable services." + " Note that a service does not need to be registered in order to create A1 Policies. This is a feature that is optional to use." - + "

"; + + "

" + // + H3 + "Spring Boot Actuator" + H3_END + // + "

" // + + "Provides generic functions used to monitor and manage the Spring web application." + // + "

"; public static final String VERSION = "1.1.0"; } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/aspect/LogAspect.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/aspect/LogAspect.java index 16f4a7f8..1c40f04f 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/aspect/LogAspect.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/aspect/LogAspect.java @@ -20,6 +20,8 @@ package org.onap.ccsdk.oran.a1policymanagementservice.aspect; +import java.lang.invoke.MethodHandles; + import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; @@ -36,7 +38,7 @@ import org.springframework.util.StopWatch; @Component public class LogAspect { - private static final Logger logger = LoggerFactory.getLogger(LogAspect.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @Around("execution(* org.onap.ccsdk.oran.a1policymanagementservice..*(..)))") public void executimeTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java index 45c0bc42..0956aa13 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java @@ -20,6 +20,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.clients; +import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType; @@ -38,7 +39,7 @@ import reactor.core.publisher.Mono; */ public class A1ClientFactory { - private static final Logger logger = LoggerFactory.getLogger(A1ClientFactory.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final ApplicationConfig appConfig; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java index 4af39c92..9db66202 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java @@ -30,6 +30,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.invoke.MethodHandles; import java.util.Optional; import javax.validation.constraints.NotNull; @@ -41,7 +42,7 @@ import org.springframework.stereotype.Component; @Component public class ConfigurationFile { - private static final Logger logger = LoggerFactory.getLogger(ConfigurationFile.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); final ApplicationConfig appConfig; final Gson gson = new Gson(); diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStore.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStore.java index 4c7c3c3e..5b81f756 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStore.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStore.java @@ -20,6 +20,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.datastore; +import java.lang.invoke.MethodHandles; import java.net.URI; import java.util.concurrent.CompletableFuture; @@ -53,7 +54,7 @@ import software.amazon.awssdk.services.s3.model.PutObjectResponse; import software.amazon.awssdk.services.s3.model.S3Object; class S3ObjectStore implements DataStore { - private static final Logger logger = LoggerFactory.getLogger(S3ObjectStore.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final ApplicationConfig applicationConfig; private static S3AsyncClient s3AsynchClient; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java index 47c73506..94888c38 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java @@ -26,6 +26,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonParser; +import java.lang.invoke.MethodHandles; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -63,7 +64,7 @@ public class DmaapMessageConsumer { protected static final Duration TIME_BETWEEN_DMAAP_RETRIES = Duration.ofSeconds(10); - private static final Logger logger = LoggerFactory.getLogger(DmaapMessageConsumer.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final ApplicationConfig applicationConfig; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandler.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandler.java index d0354174..022dec05 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandler.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandler.java @@ -24,6 +24,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; +import java.lang.invoke.MethodHandles; + import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient; import org.onap.ccsdk.oran.a1policymanagementservice.dmaap.DmaapRequestMessage.Operation; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; @@ -42,7 +44,7 @@ import reactor.core.publisher.Mono; * response though DMAAP */ public class DmaapMessageHandler { - private static final Logger logger = LoggerFactory.getLogger(DmaapMessageHandler.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static Gson gson = new GsonBuilder().create(); private final AsyncRestClient dmaapClient; private final AsyncRestClient pmsClient; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/GlobalExceptionHandler.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/GlobalExceptionHandler.java index 547cd6b0..77d01969 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/GlobalExceptionHandler.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/GlobalExceptionHandler.java @@ -20,6 +20,8 @@ package org.onap.ccsdk.oran.a1policymanagementservice.exceptions; +import java.lang.invoke.MethodHandles; + import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.ErrorResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +35,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep @ControllerAdvice(annotations = RestController.class) public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { - private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @ExceptionHandler(ServiceException.class) public final ResponseEntity handleServiceException(ServiceException ex) { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java index 46033a4a..c40bf504 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java @@ -20,6 +20,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.repository; +import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -39,7 +40,7 @@ import reactor.core.publisher.MonoSink; * resource (for shared usage). */ public class Lock { - private static final Logger logger = LoggerFactory.getLogger(Lock.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); boolean isExclusive = false; private int lockCounter = 0; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java index 2971feb2..290b109b 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java @@ -20,6 +20,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.repository; +import java.lang.invoke.MethodHandles; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -37,7 +38,7 @@ import org.slf4j.LoggerFactory; * Holds information about a Near-RT RIC. */ public class Ric { - private static final Logger logger = LoggerFactory.getLogger(Ric.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @Setter private RicConfig ricConfig; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Services.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Services.java index 9c2846a9..d8a902e9 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Services.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Services.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.repository; import com.google.gson.Gson; +import java.lang.invoke.MethodHandles; import java.util.HashMap; import java.util.Map; import java.util.Vector; @@ -37,7 +38,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; public class Services { - private static final Logger logger = LoggerFactory.getLogger(Services.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static Gson gson = Service.createGson(); private final DataStore dataStore; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java index 978ae1c0..b3023f84 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks; import com.google.gson.JsonObject; +import java.lang.invoke.MethodHandles; import java.time.Duration; import java.util.Optional; import java.util.Properties; @@ -59,7 +60,7 @@ import reactor.util.annotation.Nullable; @SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally public class RefreshConfigTask { - private static final Logger logger = LoggerFactory.getLogger(RefreshConfigTask.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @Value("#{systemEnvironment}") public Properties systemEnvironment; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java index 1f612e42..3f0d3a0c 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java @@ -20,6 +20,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks; +import java.lang.invoke.MethodHandles; import java.util.Collection; import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client; @@ -53,7 +54,7 @@ import reactor.core.publisher.Mono; @EnableScheduling @SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally public class RicSupervision { - private static final Logger logger = LoggerFactory.getLogger(RicSupervision.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final int CONCURRENCY = 50; // Number of RIC checked in paralell private final Rics rics; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java index d1bd433b..c07cf2cd 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks; import static org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric.RicState; +import java.lang.invoke.MethodHandles; import java.util.Set; import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client; @@ -58,7 +59,7 @@ import reactor.core.publisher.SignalType; @SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally public class RicSynchronizationTask { - private static final Logger logger = LoggerFactory.getLogger(RicSynchronizationTask.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static final int CONCURRENCY_RIC = 1; // How many paralell requests that is sent to one NearRT RIC private final A1ClientFactory a1ClientFactory; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervision.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervision.java index e40634e2..f9853af9 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervision.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervision.java @@ -20,6 +20,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks; +import java.lang.invoke.MethodHandles; import java.time.Duration; import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory; @@ -49,7 +50,7 @@ import reactor.core.publisher.Mono; @EnableScheduling @SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally public class ServiceSupervision { - private static final Logger logger = LoggerFactory.getLogger(ServiceSupervision.class); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static final int CONCURRENCY_RIC = 1; // How may paralell requests that is sent private final Services services; private final Policies policies; -- cgit 1.2.3-korg