diff options
Diffstat (limited to 'a1-policy-management/src')
21 files changed, 448 insertions, 83 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java index 4d1fa331..4d825f85 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java @@ -3,7 +3,7 @@ * ONAP : ccsdk oran * ====================================================================== * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ import org.springframework.context.annotation.Configuration; @Configuration public class BeanFactory { - @Value("${server.http-port}") + @Value("${server.http-port:0}") private int httpPort = 0; @Bean diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java index 204af9c0..6d642a31 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java @@ -3,6 +3,8 @@ * ONAP : ccsdk oran * ====================================================================== * Copyright (C) 2019-2022 Nordix Foundation. All rights reserved. + * Modifications Copyright (C) 2025 OpenInfra Foundation Europe. + * All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +61,12 @@ public class AsyncRestClientFactory { public AsyncRestClientFactory(WebClientConfig clientConfig, SecurityContext securityContext) { if (clientConfig != null) { - this.sslContextFactory = new CachingSslContextFactory(clientConfig); + if (clientConfig.isSslEnabled()) { + this.sslContextFactory = new CachingSslContextFactory(clientConfig); + } else { + this.sslContextFactory = null; + logger.debug("SSL is turned OFF for the web client"); + } this.httpProxyConfig = clientConfig.getHttpProxyConfig(); } else { logger.warn("No configuration for web client defined, HTTPS will not work"); diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java index 6d8d52de..360369c0 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java @@ -3,7 +3,8 @@ * ONAP : ccsdk oran * ====================================================================== * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * Modifications Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved. + * Modifications Copyright (C) 2023-2025 OpenInfra Foundation Europe. + * All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,36 +40,40 @@ import reactor.netty.transport.ProxyProvider; public class ApplicationConfig { @Getter - @Value("${app.filepath}") + @Value("${app.filepath:null}") private String localConfigurationFilePath; @Getter - @Value("${app.config-file-schema-path:}") + @Value("${app.config-file-schema-path:null}") private String configurationFileSchemaPath; @Getter @Value("${app.vardata-directory:null}") private String vardataDirectory; - @Value("${server.ssl.key-store-type}") + @Getter + @Value("${server.ssl.enabled:true}") + private boolean sslEnabled; + + @Value("${server.ssl.key-store-type:null}") private String sslKeyStoreType = ""; - @Value("${server.ssl.key-store-password}") + @Value("${server.ssl.key-store-password:null}") private String sslKeyStorePassword = ""; - @Value("${server.ssl.key-store}") + @Value("${server.ssl.key-store:null}") private String sslKeyStore = ""; - @Value("${server.ssl.key-password}") + @Value("${server.ssl.key-password:null}") private String sslKeyPassword = ""; - @Value("${app.webclient.trust-store-used}") + @Value("${app.webclient.trust-store-used:false}") private boolean sslTrustStoreUsed = false; - @Value("${app.webclient.trust-store-password}") + @Value("${app.webclient.trust-store-password:null}") private String sslTrustStorePassword = ""; - @Value("${app.webclient.trust-store}") + @Value("${app.webclient.trust-store:null}") private String sslTrustStore = ""; @Value("${app.webclient.http.proxy-host:}") @@ -133,17 +138,26 @@ public class ApplicationConfig { .httpProxyPort(this.httpProxyPort) // .httpProxyType(ProxyProvider.Proxy.valueOf(this.httpProxyType)) // .build(); + if (sslEnabled) { + this.webClientConfig = WebClientConfig.builder() // + .sslEnabled(true) + .keyStoreType(this.sslKeyStoreType) // + .keyStorePassword(this.sslKeyStorePassword) // + .keyStore(this.sslKeyStore) // + .keyPassword(this.sslKeyPassword) // + .isTrustStoreUsed(this.sslTrustStoreUsed) // + .trustStore(this.sslTrustStore) // + .trustStorePassword(this.sslTrustStorePassword) // + .httpProxyConfig(httpProxyConfig) // + .build(); + } else { + this.webClientConfig = WebClientConfig.builder() // + .sslEnabled(false) + .isTrustStoreUsed(false) + .httpProxyConfig(httpProxyConfig) // + .build(); + } - this.webClientConfig = WebClientConfig.builder() // - .keyStoreType(this.sslKeyStoreType) // - .keyStorePassword(this.sslKeyStorePassword) // - .keyStore(this.sslKeyStore) // - .keyPassword(this.sslKeyPassword) // - .isTrustStoreUsed(this.sslTrustStoreUsed) // - .trustStore(this.sslTrustStore) // - .trustStorePassword(this.sslTrustStorePassword) // - .httpProxyConfig(httpProxyConfig) // - .build(); } return this.webClientConfig; } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java index f5f0f7e7..24c1d258 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2019-2025 OpenInfra Foundation Europe. All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -148,13 +148,20 @@ public class ApplicationConfigParser { "Configuration error, controller configuration not found: " + controllerName); } - RicConfig ricConfig = RicConfig.builder() // - .ricId(get(ricJsonObj, "name", "id", "ricId").getAsString()) // - .baseUrl(get(ricJsonObj, "baseUrl").getAsString()) // - .managedElementIds(parseManagedElementIds(get(ricJsonObj, "managedElementIds").getAsJsonArray())) // + RicConfig.RicConfigBuilder ricConfigBuilder = RicConfig.builder() + .ricId(get(ricJsonObj, "name", "id", "ricId").getAsString()) + .baseUrl(get(ricJsonObj, "baseUrl").getAsString()) .controllerConfig(controllerConfig) - .customAdapterClass(getString(ricJsonObj, "customAdapterClass", "")) // - .build(); + .customAdapterClass(getString(ricJsonObj, "customAdapterClass", "")); + + if (ricJsonObj.has("managedElementIds")) { + ricConfigBuilder + .managedElementIds(parseManagedElementIds(get(ricJsonObj, "managedElementIds").getAsJsonArray())); + } else { + ricConfigBuilder.managedElementIds(null); + } + + RicConfig ricConfig = ricConfigBuilder.build(); if (!ricConfig.getBaseUrl().isEmpty()) { result.add(ricConfig); } else { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java index ba8e7a1d..194cf8c5 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ import io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSampler; import io.opentelemetry.sdk.trace.samplers.Sampler; import java.time.Duration; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientConfig.java index ab2958c6..1f22d995 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientConfig.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientConfig.java @@ -3,6 +3,8 @@ * ONAP : ccsdk oran * ====================================================================== * Copyright (C) 2020-2023 Nordix Foundation. All rights reserved. + * Modifications Copyright (C) 2025 OpenInfra Foundation Europe. + * All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,13 +25,15 @@ package org.onap.ccsdk.oran.a1policymanagementservice.configuration; import lombok.Builder; import lombok.Getter; import lombok.ToString; - import reactor.netty.transport.ProxyProvider; @Builder @Getter @ToString public class WebClientConfig { + + private boolean sslEnabled; + private String keyStoreType; private String keyStorePassword; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java index 53abcd71..ee3ce6d2 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java @@ -41,9 +41,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; +import java.util.*; @RestController("ricRepositoryControllerV2") @RequiredArgsConstructor @@ -124,9 +122,16 @@ public class RicRepositoryController implements NearRtRicRepositoryApi { } private RicInfo toRicInfo(Ric ric) { - return new RicInfo().ricId(ric.id()) - .managedElementIds((List<String>) ric.getManagedElementIds()) + RicInfo ricInfo = new RicInfo().ricId(ric.id()) .policytypeIds((List<String>) ric.getSupportedPolicyTypeNames()) .state(toRicState(ric.getState())); + + if (ric.getConfig().getManagedElementIds() == null) { + ricInfo.setManagedElementIds(new ArrayList<>()); + } else { + ricInfo.managedElementIds((List<String>) ric.getConfig().getManagedElementIds()); + } + + return ricInfo; } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java index ce2769e6..ff33c7c9 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java @@ -40,8 +40,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; -import java.util.List; -import java.util.Set; +import java.util.*; @RestController("ricRepositoryControllerV3") @RequiredArgsConstructor @@ -93,10 +92,17 @@ public class RicRepositoryControllerV3 implements NearRtRicRepositoryApi { } private RicInfo toRicInfo(Ric ric) { - return new RicInfo().ricId(ric.id()) - .managedElementIds((List<String>) ric.getManagedElementIds()) + RicInfo ricInfo = new RicInfo().ricId(ric.id()) .policyTypeIds((List<String>) ric.getSupportedPolicyTypeNames()) .state(toRicState(ric.getState())); + + if (ric.getConfig().getManagedElementIds() == null) { + ricInfo.setManagedElementIds(new ArrayList<>()); + } else { + ricInfo.managedElementIds((List<String>) ric.getConfig().getManagedElementIds()); + } + + return ricInfo; } private RicInfo.StateEnum toRicState(Ric.RicState state) { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java index d29e37a6..81d864fa 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,7 +67,7 @@ public class ServiceControllerV3 implements ServiceRegistryAndSupervisionApi { } @Override - public Mono<ResponseEntity<Object>> keepAliveService(String serviceId, String accept, Mono<String> body, ServerWebExchange exchange) throws Exception { + public Mono<ResponseEntity<Object>> keepAliveService(String serviceId, String accept, ServerWebExchange exchange) throws Exception { return serviceController.keepAliveService(serviceId, exchange); } diff --git a/a1-policy-management/src/main/resources/logback-json.xml b/a1-policy-management/src/main/resources/logback-json.xml new file mode 100644 index 00000000..3c22aeac --- /dev/null +++ b/a1-policy-management/src/main/resources/logback-json.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2025 OpenInfra Foundation Europe + ================================================================================ + 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. + + SPDX-License-Identifier: Apache-2.0 + ============LICENSE_END========================================================= + --> +<configuration> + <appender name="json" class="ch.qos.logback.core.ConsoleAppender"> + <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> + <providers> + <version> + <fieldName>version</fieldName> + <version>1.2.0</version> + </version> + <timestamp> + <fieldName>timestamp</fieldName> + <pattern>yyyy-MM-dd'T'HH:mm:ss.SSSZ</pattern> + </timestamp> + <pattern> + <omitEmptyFields>true</omitEmptyFields> + <pattern> + { + "service_id": "${SERVICE_ID:-a1pms}", + "message": "%msg", + "facility": "%X{facility}", + "subject": "%X{subject}", + "extra_data": { + "logger": "%logger", + "thread_info": { + "thread_name": "%thread" + }, + "dst": { + "trace_id": "%mdc{traceId}" + }, + "exception": { + "stack_trace": "%xEx" + } + }, + "metadata": { + "application_id": "${APP_ID:-a1pms}" + } + } + </pattern> + </pattern> + </providers> + + </encoder> + </appender> + + <root level="${ROOT_LOG_LEVEL:-INFO}"> + <appender-ref ref="json"/> + </root> + + <logger name="/" level="${ROOT_LOG_LEVEL:-INFO}"/> +</configuration> + diff --git a/a1-policy-management/src/main/resources/logback-plain.xml b/a1-policy-management/src/main/resources/logback-plain.xml index 0340cce8..014a983a 100644 --- a/a1-policy-management/src/main/resources/logback-plain.xml +++ b/a1-policy-management/src/main/resources/logback-plain.xml @@ -19,22 +19,17 @@ ~ --> <configuration> - - <!-- Define a plain text console appender --> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder> - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{55} - <!-- - -->%replace(%X{facility}){'^(.+)$','facility=$1 | '} <!-- - -->%replace(%X{subject}){'^(.+)$','subject=$1 | ' } <!-- - -->%msg%n</pattern> + <pattern> + %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread] %-5level %logger - %msg [facility=%X{facility}, subject=%X{subject}, traceId=%mdc{traceId}] %n%xEx + </pattern> </encoder> </appender> - - - <!-- Configure root logger to use the plain text console appender for all log levels --> - <root level="INFO"> + <root level="${ROOT_LOG_LEVEL:-INFO}"> <appender-ref ref="console"/> </root> + <logger name="/" level="${ROOT_LOG_LEVEL:-INFO}"/> </configuration>
\ No newline at end of file diff --git a/a1-policy-management/src/main/resources/logback-stream.xml b/a1-policy-management/src/main/resources/logback-stream.xml new file mode 100644 index 00000000..9cfb863b --- /dev/null +++ b/a1-policy-management/src/main/resources/logback-stream.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2025 OpenInfra Foundation Europe + ================================================================================ + 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. + + SPDX-License-Identifier: Apache-2.0 + ============LICENSE_END========================================================= + --> +<configuration> + <appender name="json" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> + <destination>localhost:5044</destination> + <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> + <providers> + <version> + <fieldName>version</fieldName> + <version>1.2.0</version> + </version> + <timestamp> + <fieldName>timestamp</fieldName> + <pattern>yyyy-MM-dd'T'HH:mm:ss.SSSZ</pattern> + </timestamp> + <pattern> + <omitEmptyFields>true</omitEmptyFields> + <pattern> + { + "service_id": "${SERVICE_ID:-a1pms}", + "message": "%msg", + "facility": "%X{facility}", + "subject": "%X{subject}", + "extra_data": { + "logger": "%logger", + "thread_info": { + "thread_name": "%thread" + }, + "dst": { + "trace_id": "%mdc{traceId}" + }, + "exception": { + "stack_trace": "%xEx" + } + }, + "metadata": { + "application_id": "${APP_ID:-a1pms}" + } + } + </pattern> + </pattern> + </providers> + + </encoder> + </appender> + + <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern> + %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread] %-5level %logger - %msg [facility=%X{facility}, subject=%X{subject}, traceId=%mdc{traceId}] %n%xEx + </pattern> + </encoder> + </appender> + + <root level="${ROOT_LOG_LEVEL:-INFO}"> + <appender-ref ref="json"/> + <appender-ref ref="console"/> + </root> + + <logger name="/" level="${ROOT_LOG_LEVEL:-INFO}"/> +</configuration> + diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java index 5ed8642a..864a1c53 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java @@ -3,6 +3,8 @@ * ONAP : ccsdk oran * ====================================================================== * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved. + * Modifications Copyright (C) 2025 OpenInfra Foundation Europe. + * All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1170,6 +1172,7 @@ class ApplicationTest { private AsyncRestClient restClient(String baseUrl, boolean useTrustValidation) { WebClientConfig config = this.applicationConfig.getWebClientConfig(); config = WebClientConfig.builder() + .sslEnabled(config.isSslEnabled()) .keyStoreType(config.getKeyStoreType()) .keyStorePassword(config.getKeyStorePassword()) .keyStore(config.getKeyStore()) @@ -1185,8 +1188,12 @@ class ApplicationTest { } - private String baseUrl() { - return "https://localhost:" + port; + public String baseUrl() { + if (applicationConfig.isSslEnabled()) { + return "https://localhost:" + port; + } else { + return "http://localhost:" + port; + } } private AsyncRestClient restClient(boolean useTrustValidation) { diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java index e46b8367..05f82c6d 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java @@ -1,6 +1,8 @@ /*- * ========================LICENSE_START================================= * Copyright (C) 2020-2023 Nordix Foundation. All rights reserved. + * Modifications Copyright (C) 2025 OpenInfra Foundation Europe. + * All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,8 +66,6 @@ import reactor.test.StepVerifier; "app.config-file-schema-path=/application_configuration_schema.json" // }) class ConfigurationControllerTest { - @Autowired - ApplicationContext context; @Autowired ApplicationConfig applicationConfig; @@ -166,19 +166,28 @@ class ConfigurationControllerTest { private AsyncRestClient restClient() { WebClientConfig config = this.applicationConfig.getWebClientConfig(); - config = WebClientConfig.builder() // - .keyStoreType(config.getKeyStoreType()) // - .keyStorePassword(config.getKeyStorePassword()) // - .keyStore(config.getKeyStore()) // - .keyPassword(config.getKeyPassword()) // - .isTrustStoreUsed(false) // - .trustStore(config.getTrustStore()) // - .trustStorePassword(config.getTrustStorePassword()) // - .httpProxyConfig(config.getHttpProxyConfig()) // - .build(); - - AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext("")); - return f.createRestClientNoHttpProxy("https://localhost:" + port); + if (applicationConfig.isSslEnabled()) { + config = WebClientConfig.builder() // + .sslEnabled(applicationConfig.isSslEnabled()) + .keyStoreType(config.getKeyStoreType()) // + .keyStorePassword(config.getKeyStorePassword()) // + .keyStore(config.getKeyStore()) // + .keyPassword(config.getKeyPassword()) // + .isTrustStoreUsed(config.isTrustStoreUsed()) // + .trustStore(config.getTrustStore()) // + .trustStorePassword(config.getTrustStorePassword()) // + .httpProxyConfig(config.getHttpProxyConfig()) // + .build(); + + AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext("")); + return f.createRestClientNoHttpProxy("https://localhost:" + port); + } else { + config = WebClientConfig.builder() + .httpProxyConfig(config.getHttpProxyConfig()) + .build(); + AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext("")); + return f.createRestClientNoHttpProxy("http://localhost:" + port); + } } } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java index d9fa63a9..666b37e0 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * Copyright (C) 2020-2023 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2025 OpenInfra Foundation Europe. All rights reserved. * ====================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,6 +53,10 @@ import static org.hamcrest.CoreMatchers.equalTo; "app.config-file-schema-path=/application_configuration_schema.json" // }) class ConfigurationControllerV3Test { + + @Autowired + private RefreshConfigTask refreshConfigTask; + @Autowired ApplicationContext context; @@ -120,6 +124,46 @@ class ConfigurationControllerV3Test { } @Test + void testPutConfigurationMeNull() throws Exception { + Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().putForEntity("/configuration", + testHelperTest.configAsStringMeNull()); + testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, Objects::isNull); + //put Valid Configuration With New Ric should Update Repository. So, will wait until the ric size is 2 + await().until(rics::size, equalTo(2)); + //test Get Configuration + Mono<ResponseEntity<String>> responseGetConfigMono = testHelperTest.restClientV3().getForEntity("/configuration"); + testHelperTest.testSuccessResponse(responseGetConfigMono, HttpStatus.OK, responseBody -> !responseBody.contains("\"managedElementIds\"")); + + refreshConfigTask.start(); + + Mono<ResponseEntity<String>> responseGetRicsMono = testHelperTest.restClientV3().getForEntity("/rics"); + testHelperTest.testSuccessResponse(responseGetRicsMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]")); + + Mono<ResponseEntity<String>> responseGetRicMono = testHelperTest.restClientV3().getForEntity("/rics/ric1"); + testHelperTest.testSuccessResponse(responseGetRicMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]")); + } + + @Test + void testPutConfigurationMeEmpty() throws Exception { + Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().putForEntity("/configuration", + testHelperTest.configAsStringMeEmpty()); + testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, Objects::isNull); + //put Valid Configuration With New Ric should Update Repository. So, will wait until the ric size is 2 + await().until(rics::size, equalTo(2)); + //test Get Configuration + Mono<ResponseEntity<String>> responseGetConfigMono = testHelperTest.restClientV3().getForEntity("/configuration"); + testHelperTest.testSuccessResponse(responseGetConfigMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]")); + + refreshConfigTask.start(); + + Mono<ResponseEntity<String>> responseGetRicsMono = testHelperTest.restClientV3().getForEntity("/rics"); + testHelperTest.testSuccessResponse(responseGetRicsMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]")); + + Mono<ResponseEntity<String>> responseGetRicMono = testHelperTest.restClientV3().getForEntity("/rics/ric1"); + testHelperTest.testSuccessResponse(responseGetRicMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]")); + } + + @Test void testHealthCheck() { Mono<ResponseEntity<String>> responseHealthCheckMono = testHelperTest.restClientV3().getForEntity("/status"); testHelperTest.testSuccessResponse(responseHealthCheckMono, HttpStatus.OK, responseBody -> responseBody.contains("status")); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java index 2904a069..36e88238 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java @@ -163,7 +163,7 @@ class PolicyControllerV3Test { Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody -> responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}")); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/")); } @@ -179,7 +179,7 @@ class PolicyControllerV3Test { Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody -> responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}")); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/")); } @@ -195,7 +195,7 @@ class PolicyControllerV3Test { Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody -> responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}")); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/")); } @@ -211,7 +211,7 @@ class PolicyControllerV3Test { Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody -> responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}")); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/")); } @Test @@ -237,7 +237,7 @@ class PolicyControllerV3Test { testHelperTest.addPolicyType(policyTypeName, nonRtRicId); String policyBody = testHelperTest.postBadPolicyBody(nonRtRicId, policyTypeName, ""); Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/")); } @Test @@ -250,7 +250,7 @@ class PolicyControllerV3Test { testHelperTest.addPolicyType(policyTypeName, nonRtRicId); String policyBody = testHelperTest.postBadPolicyBody(nonRtRicId, policyTypeName, ""); Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/")); } @Test @@ -262,7 +262,7 @@ class PolicyControllerV3Test { testHelperTest.addPolicyType(policyTypeName, nonRtRicId); String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "1"); Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/1")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/1")); } @Test diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java index 54b9d295..94ab47db 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java @@ -1,3 +1,23 @@ +/*- + * ========================LICENSE_START================================= + * ONAP : ccsdk oran + * ====================================================================== + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ====================================================================== + * 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. + * ========================LICENSE_END=================================== + */ + package org.onap.ccsdk.oran.a1policymanagementservice.utils.v3; import org.junit.jupiter.api.AfterAll; @@ -24,7 +44,6 @@ import java.lang.invoke.MethodHandles; import java.nio.file.Path; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ExtendWith({OutputCaptureExtension.class}) @@ -74,7 +93,7 @@ class ReactiveEntryExitFilterDisableTest { Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody -> responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}")); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/")); assertFalse(capturedOutput.getOut().contains("Request received with path: /a1-policy-management/v1/policies")); assertFalse(capturedOutput.getOut().contains("the Status code of the response: 201 CREATED")); assertFalse(capturedOutput.getOut().contains("the response is:")); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java index 9e0f60ea..0086c1eb 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java @@ -1,3 +1,23 @@ +/*- + * ========================LICENSE_START================================= + * ONAP : ccsdk oran + * ====================================================================== + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ====================================================================== + * 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. + * ========================LICENSE_END=================================== + */ + package org.onap.ccsdk.oran.a1policymanagementservice.utils.v3; import org.junit.jupiter.api.AfterAll; @@ -74,7 +94,7 @@ class ReactiveEntryExitFilterTest { Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody); testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody -> responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}")); - testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/")); + testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/")); assertTrue(capturedOutput.getOut().contains("Request received with path: /a1-policy-management/v1/policies")); assertTrue(capturedOutput.getOut().contains("the Status code of the response: 201 CREATED")); assertTrue(capturedOutput.getOut().contains("the response is:")); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java index c36429c6..a9ff597c 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java @@ -93,6 +93,7 @@ public class TestHelperTest { public AsyncRestClient restClient(String baseUrl, boolean useTrustValidation) { WebClientConfig config = this.applicationConfig.getWebClientConfig(); config = WebClientConfig.builder() + .sslEnabled(config.isSslEnabled()) .keyStoreType(config.getKeyStoreType()) .keyStorePassword(config.getKeyStorePassword()) .keyStore(config.getKeyStore()) @@ -109,7 +110,11 @@ public class TestHelperTest { } public String baseUrl() { - return "https://localhost:" + port; + if (applicationConfig.isSslEnabled()) { + return "https://localhost:" + port; + } else { + return "http://localhost:" + port; + } } public AsyncRestClient restClientV3(boolean useTrustValidation) { @@ -324,4 +329,16 @@ public class TestHelperTest { new File(Objects.requireNonNull(getClass().getClassLoader().getResource("test_application_configuration.json")).getFile()); return FileUtils.readFileToString(configFile, "UTF-8"); } + + public String configAsStringMeNull() throws Exception { + File configFile = + new File(Objects.requireNonNull(getClass().getClassLoader().getResource("test_application_configuration_me_null.json")).getFile()); + return FileUtils.readFileToString(configFile, "UTF-8"); + } + + public String configAsStringMeEmpty() throws Exception { + File configFile = + new File(Objects.requireNonNull(getClass().getClassLoader().getResource("test_application_configuration_me_empty.json")).getFile()); + return FileUtils.readFileToString(configFile, "UTF-8"); + } } diff --git a/a1-policy-management/src/test/resources/test_application_configuration_me_empty.json b/a1-policy-management/src/test/resources/test_application_configuration_me_empty.json new file mode 100644 index 00000000..0bb0985d --- /dev/null +++ b/a1-policy-management/src/test/resources/test_application_configuration_me_empty.json @@ -0,0 +1,32 @@ +{ + "config": { + "description": "Test", + "controller": [ + { + "name": "controller1", + "baseUrl": "http://localhost:8083/", + "userName": "user", + "password": "password" + } + ], + "ric": [ + { + "name": "ric1", + "controller": "controller1", + "baseUrl": "http://localhost:8083/", + "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory", + "managedElementIds": [] + }, + { + "name": "ric2", + "baseUrl": "http://localhost:8085/", + "managedElementIds": [] + }, + { + "name": "ric3_noBaseURL", + "baseUrl": "", + "managedElementIds": [] + } + ] + } +} diff --git a/a1-policy-management/src/test/resources/test_application_configuration_me_null.json b/a1-policy-management/src/test/resources/test_application_configuration_me_null.json new file mode 100644 index 00000000..4fa7ff96 --- /dev/null +++ b/a1-policy-management/src/test/resources/test_application_configuration_me_null.json @@ -0,0 +1,29 @@ +{ + "config": { + "description": "Test", + "controller": [ + { + "name": "controller1", + "baseUrl": "http://localhost:8083/", + "userName": "user", + "password": "password" + } + ], + "ric": [ + { + "name": "ric1", + "controller": "controller1", + "baseUrl": "http://localhost:8083/", + "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory" + }, + { + "name": "ric2", + "baseUrl": "http://localhost:8085/" + }, + { + "name": "ric3_noBaseURL", + "baseUrl": "" + } + ] + } +} |