From: ToineSiebelink Date: Tue, 19 Aug 2025 11:43:19 +0000 (+0100) Subject: IntelliJ Code Inspection Updates X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F141877%2F9;p=cps.git IntelliJ Code Inspection Updates - Use Lombok where possible - Removed unused (interface) methods - Removed parameters where method was called with only 1 (always same) value. This lead to so manual refactoring, more specific method names etc. For data job read I logged some details to get over this as the implementation is currently on hold/blocked - Use 'record' (instead of class) where possible - Apply @serial annotation - Fixed unused result from matcher.find() We used to catch exceptions instead which is very bad :-( - Some unused constant/return values needed for consistency, used annotation to ignore thee warning - Removed Enum private value that was identical to Enum itself - Uncheck casting, just added annotation to prevent warning I think they are all safe because we know and control the model - Use {} for logging instead on string concatenation - Use for links in Javadoc - Added missed null-checks - Manually updated groovy test classes that were affected by some of above - Spelling and grammar, original about 200 errors using 'Id' (with uppercase) I was flagged as a grammar issue and I like the idea of consistently using 'id' lower case in descriptions most typos where actually fixed by adding some work to the dictionary like cmhandle, onap, etsi etc. about 10% were genuine errors which also 2 or 3 variables affected which I have corrected now - Security flagged some (http) links with suppress as we cannot change them some dependency issues remaining, need to check with Ger, looks like correct early warning without need for any CIO job or other tools! - CODE ANALYZER ON WHOLE PROJECT only 4 java updates! inserted 2 finals (1 reverted as it was needed for test!), removed unnecessary casting in 2 places incorrectly add = sing in a cert.properties file for socker which I reverted Issue-ID: CPS-2941 Change-Id: I439237422b01d533ae1c9301cbfcedbebf922fd4 Signed-off-by: ToineSiebelink --- diff --git a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java index 4318f44c30..81c2b0a7f6 100644 --- a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java +++ b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada - * Modifications Copyright (c) 2022-2024 Nordix Foundation + * Modifications Copyright (c) 2022-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. @@ -112,7 +112,7 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } - return ResponseEntity.ok(Collections.emptyList()); + return ResponseEntity.ok(Collections.emptyList()); } private ResponseEntity> populateAsyncResponse(final String topicParamInQuery) { diff --git a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/providers/ResourceProviderImpl.java b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/providers/ResourceProviderImpl.java index c0779eb270..f223b4f265 100644 --- a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/providers/ResourceProviderImpl.java +++ b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/java/org/onap/cps/ncmp/rest/stub/providers/ResourceProviderImpl.java @@ -36,7 +36,7 @@ import org.springframework.stereotype.Service; @Service public class ResourceProviderImpl implements ResourceProvider { - private String pathToResponseFiles; + private final String pathToResponseFiles; @Autowired public ResourceProviderImpl(@Value("${stub.path}") final String pathToResponseFiles) { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java index be22752882..32d44f0177 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023-2024 Nordix Foundation + * 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. @@ -25,7 +25,7 @@ import lombok.Getter; @Getter public enum NcmpResponseStatus { - SUCCESS("0", "Successfully applied changes"), + @SuppressWarnings("unused") SUCCESS("0", "Successfully applied changes"), CM_DATA_SUBSCRIPTION_ACCEPTED("1", "ACCEPTED"), CM_HANDLES_NOT_FOUND("100", "cm handle reference(s) not found"), CM_HANDLES_NOT_READY("101", "cm handle(s) not ready"), @@ -35,8 +35,8 @@ public enum NcmpResponseStatus { UNKNOWN_ERROR("108", "Unknown error"), CM_HANDLE_ALREADY_EXIST("109", "cm-handle already exists"), CM_HANDLE_INVALID_ID("110", "cm handle reference has an invalid character(s) in id"), - ALTERNATE_ID_ALREADY_ASSOCIATED("111", "alternate id already associated"), - MESSAGE_TOO_LARGE("112", "message too large"); + @SuppressWarnings("unused") ALTERNATE_ID_ALREADY_ASSOCIATED("111", "alternate id already associated"), + @SuppressWarnings("unused") MESSAGE_TOO_LARGE("112", "message too large"); private final String code; private final String message; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/CmResourceAddress.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/CmResourceAddress.java index 24a9b21bf4..f641f9f022 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/CmResourceAddress.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/CmResourceAddress.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -20,18 +20,10 @@ package org.onap.cps.ncmp.api.data.models; -import lombok.Getter; -import lombok.RequiredArgsConstructor; import org.onap.cps.ncmp.config.CpsApplicationContext; import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher; -@Getter -@RequiredArgsConstructor -public class CmResourceAddress { - - private final String datastoreName; - private final String cmHandleReference; - private final String resourceIdentifier; +public record CmResourceAddress(String datastoreName, String cmHandleReference, String resourceIdentifier) { public String resolveCmHandleReferenceToId() { final AlternateIdMatcher alternateIdMatcher = CpsApplicationContext.getCpsBean(AlternateIdMatcher.class); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobService.java index 255b3847eb..2cba7ed02b 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/DataJobService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -54,4 +54,4 @@ public interface DataJobService { String dataJobId, DataJobMetadata dataJobMetadata, DataJobWriteRequest dataJobWriteRequest); -} \ No newline at end of file +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/ProducerKey.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/ProducerKey.java index ac6b7f8622..7b4f181d36 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/ProducerKey.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/ProducerKey.java @@ -33,4 +33,4 @@ public record ProducerKey(String dmiServiceName, String dataProducerIdentifier) public String toString() { return dmiServiceName + "#" + dataProducerIdentifier; } -} \ No newline at end of file +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/SubJobWriteRequest.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/SubJobWriteRequest.java index a7a6573279..c80da736d1 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/SubJobWriteRequest.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/SubJobWriteRequest.java @@ -32,7 +32,7 @@ import java.util.Collection; * @param dataContentType Define the data request content type. * e.g. "application/3gpp-json-patch+json" etc. * @param dataProducerId Identifier of the data producer. - * @param dataJobId Identifier for the overall Datajob + * @param dataJobId Identifier for the overall data job * @param data A collection of outgoing write operations. */ public record SubJobWriteRequest ( @@ -41,4 +41,4 @@ public record SubJobWriteRequest ( String dataContentType, String dataProducerId, String dataJobId, - Collection data) {} \ No newline at end of file + Collection data) {} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/DmiClientRequestException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/DmiClientRequestException.java index 65ccba8018..01eba4e9d6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/DmiClientRequestException.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/DmiClientRequestException.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2024 Nordix Foundation + * Copyright (C) 2022-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. @@ -20,6 +20,7 @@ package org.onap.cps.ncmp.api.exceptions; +import java.io.Serial; import lombok.Getter; import org.onap.cps.ncmp.api.NcmpResponseStatus; @@ -29,6 +30,7 @@ import org.onap.cps.ncmp.api.NcmpResponseStatus; @Getter public class DmiClientRequestException extends NcmpException { + @Serial private static final long serialVersionUID = 6659897770659834797L; final NcmpResponseStatus ncmpResponseStatus; final String message; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/NcmpException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/NcmpException.java index 3c81d0f536..c27e34a395 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/NcmpException.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/NcmpException.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation + * Copyright (C) 2021-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. @@ -20,6 +20,7 @@ package org.onap.cps.ncmp.api.exceptions; +import java.io.Serial; import lombok.Getter; /** @@ -27,6 +28,7 @@ import lombok.Getter; */ public class NcmpException extends RuntimeException { + @Serial private static final long serialVersionUID = 1482619410918497467L; @Getter diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/PolicyExecutorException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/PolicyExecutorException.java index bb753b85f1..0fa808f42f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/PolicyExecutorException.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/PolicyExecutorException.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -20,6 +20,7 @@ package org.onap.cps.ncmp.api.exceptions; +import java.io.Serial; import lombok.Getter; /** @@ -28,6 +29,7 @@ import lombok.Getter; @Getter public class PolicyExecutorException extends NcmpException { + @Serial private static final long serialVersionUID = 6659897770659834798L; /** diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CmHandleRegistrationResponse.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CmHandleRegistrationResponse.java index 7523f77af2..b5c096d061 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CmHandleRegistrationResponse.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CmHandleRegistrationResponse.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada - * Modifications Copyright (C) 2022-2024 Nordix Foundation + * Modifications Copyright (C) 2022--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. @@ -88,12 +88,13 @@ public class CmHandleRegistrationResponse { final Collection failedXpaths, final NcmpResponseStatus ncmpResponseStatus) { final List cmHandleRegistrationResponses = new ArrayList<>(failedXpaths.size()); for (final String xpath : failedXpaths) { - try { - final String cmHandleId = YangDataConverter.extractCmHandleIdFromXpath(xpath); - cmHandleRegistrationResponses - .add(CmHandleRegistrationResponse.createFailureResponse(cmHandleId, ncmpResponseStatus)); - } catch (IllegalArgumentException | IllegalStateException e) { - log.warn("Unexpected xpath {}", xpath); + final String cmHandleId = YangDataConverter.extractCmHandleIdFromXpath(xpath); + if (cmHandleId == null) { + log.warn("Unexpected xpath (no id found) {}", xpath); + } else { + final CmHandleRegistrationResponse cmHandleRegistrationResponse = + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, ncmpResponseStatus); + cmHandleRegistrationResponses.add(cmHandleRegistrationResponse); } } return cmHandleRegistrationResponses; @@ -142,6 +143,6 @@ public class CmHandleRegistrationResponse { } public enum Status { - SUCCESS, FAILURE; + SUCCESS, FAILURE } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CompositeState.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CompositeState.java index d873f66ff5..e02be318d2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CompositeState.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/models/CompositeState.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation + * Copyright (C) 2022-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. @@ -114,18 +114,6 @@ public class CompositeState { private String lastSyncTime; } - @Data - @Builder - @JsonInclude(JsonInclude.Include.NON_NULL) - public static class Running { - - @JsonProperty("sync-state") - private String syncState; - - @JsonProperty("last-sync-time") - private String lastSyncTime; - } - /** * The date and time format used for the cm handle sync state. * diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/CpsApplicationContext.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/CpsApplicationContext.java index fbc31adcf3..32e0305b33 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/CpsApplicationContext.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/CpsApplicationContext.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * 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. @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.config; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; @Component @@ -36,12 +37,12 @@ public class CpsApplicationContext implements ApplicationContextAware { * @param cpsBeanClass cps class type * @return requested bean instance */ - public static T getCpsBean(final Class cpsBeanClass) { + public static T getCpsBean(final Class cpsBeanClass) { return applicationContext.getBean(cpsBeanClass); } @Override - public void setApplicationContext(final ApplicationContext cpsApplicationContext) { + public void setApplicationContext(@NonNull final ApplicationContext cpsApplicationContext) { setCpsApplicationContext(cpsApplicationContext); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/OpenTelemetryConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/OpenTelemetryConfig.java index a6a82b7936..d8094eed62 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/OpenTelemetryConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/OpenTelemetryConfig.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -52,9 +52,11 @@ public class OpenTelemetryConfig { @Value("${spring.application.name:cps-application}") private String serviceId; + @SuppressWarnings("HttpUrlsUsage") @Value("${cps.tracing.exporter.endpoint:http://onap-otel-collector:4317}") private String tracingExporterEndpointUrl; + @SuppressWarnings("HttpUrlsUsage") @Value("${cps.tracing.sampler.jaeger_remote.endpoint:http://onap-otel-collector:14250}") private String jaegerRemoteSamplerUrl; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/TimedCustom.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/TimedCustom.java index 7219147538..d39bddf5b2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/TimedCustom.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/TimedCustom.java @@ -28,6 +28,7 @@ import java.lang.annotation.Target; /** * Custom annotation to enable metric scraping. */ +@SuppressWarnings("UnusedReturnValue") @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface TimedCustom { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/exceptions/NcmpStartUpException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/exceptions/NcmpStartUpException.java deleted file mode 100644 index 7ffbe2e5cb..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/exceptions/NcmpStartUpException.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation - * ================================================================================ - * 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========================================================= - */ - -package org.onap.cps.ncmp.exceptions; - -import org.onap.cps.ncmp.api.exceptions.NcmpException; - -/** - * NCMP start up exception. - */ -public class NcmpStartUpException extends NcmpException { - - /** - * Constructor. - * - * @param message the error message - * @param details the error details - */ - public NcmpStartUpException(final String message, final String details) { - super(message, details); - } -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/AdminCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/AdminCacheConfig.java index fe933d766f..05f96c87cc 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/AdminCacheConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/AdminCacheConfig.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2025 Nordix Foundation + * 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. @@ -28,7 +28,7 @@ import org.springframework.context.annotation.Configuration; @Configuration public class AdminCacheConfig extends HazelcastCacheConfig { - private static final MapConfig cmHandleStateCacheMapConfig = createMapConfig("cmHandleStateCacheMapConfig"); + private static final MapConfig cmHandleStateCacheMapConfig = createGenericMapConfig("cmHandleStateCacheMapConfig"); /** * Distributed instance admin cache map for cm handles by state for use of gauge metrics. diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/AlternateIdCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/AlternateIdCacheConfig.java index 14936c81d7..b31bceb5f0 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/AlternateIdCacheConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/AlternateIdCacheConfig.java @@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration; public class AlternateIdCacheConfig extends HazelcastCacheConfig { private static final MapConfig cmHandleIdPerAlternateIdMapConfig = - createMapConfig("cmHandleIdPerAlternateIdMapConfig"); + createGenericMapConfig("cmHandleIdPerAlternateIdMapConfig"); /** * Distributed instance used for mapping alternate id to cm handle id. diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/CpsAndNcmpLockConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/CpsAndNcmpLockConfig.java index 61cf939a51..294768df4e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/CpsAndNcmpLockConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/CpsAndNcmpLockConfig.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================== - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -31,7 +31,7 @@ public class CpsAndNcmpLockConfig extends HazelcastCacheConfig { // Lock names for different use cases ( to be used as cpsAndNcmpLock keys) public static final String MODULE_SYNC_WORK_QUEUE_LOCK_NAME = "workQueueLock"; - private static final MapConfig cpsAndNcmpLockMapConfig = createMapConfig("cpsAndNcmpLockConfig"); + private static final MapConfig cpsAndNcmpLockMapConfig = createGenericMapConfig("cpsAndNcmpLockConfig"); /** * Distributed instance used for locking purpose for various use cases in cps-and-ncmp. diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java index 1a7ef758d8..69e31e9415 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfig.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================== - * Copyright (C) 2023-2025 Nordix Foundation + * 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. @@ -23,7 +23,6 @@ package org.onap.cps.ncmp.impl.cache; import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.config.NamedConfig; -import com.hazelcast.config.NearCacheConfig; import com.hazelcast.config.QueueConfig; import com.hazelcast.config.SetConfig; import com.hazelcast.core.Hazelcast; @@ -78,35 +77,19 @@ public class HazelcastCacheConfig { private Config getHazelcastInstanceConfig(final String instanceConfigName) { final HazelcastInstance hazelcastInstance = Hazelcast.getHazelcastInstanceByName(instanceConfigName); - Config config = null; - if (hazelcastInstance != null) { - config = hazelcastInstance.getConfig(); - } else { - config = new Config(instanceConfigName); + if (hazelcastInstance == null) { + return new Config(instanceConfigName); } - return config; + return hazelcastInstance.getConfig(); } - protected static MapConfig createMapConfig(final String configName) { + protected static MapConfig createGenericMapConfig(final String configName) { final MapConfig mapConfig = new MapConfig(configName); mapConfig.setBackupCount(1); return mapConfig; } - protected static MapConfig createMapConfigWithTimeToLiveInSeconds(final String configName, - final int timeToLiveInSeconds) { - final MapConfig mapConfig = new MapConfig(configName); - mapConfig.setBackupCount(1); - mapConfig.setTimeToLiveSeconds(timeToLiveInSeconds); - return mapConfig; - } - protected static MapConfig createNearCacheMapConfig(final String configName) { - final MapConfig mapConfig = new MapConfig(configName); - mapConfig.setBackupCount(1); - mapConfig.setNearCacheConfig(new NearCacheConfig(configName)); - return mapConfig; - } protected static QueueConfig createQueueConfig(final String configName) { final QueueConfig commonQueueConfig = new QueueConfig(configName); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java index cb5102063e..37213c96ed 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/CmSubscriptionConfig.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -32,7 +32,7 @@ import org.springframework.context.annotation.Configuration; public class CmSubscriptionConfig extends HazelcastCacheConfig { private static final MapConfig cmNotificationSubscriptionCacheMapConfig = - createMapConfig("cmNotificationSubscriptionCacheMapConfig"); + createGenericMapConfig("cmNotificationSubscriptionCacheMapConfig"); /** * Distributed instance of cm notification subscription information diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/DmiCacheHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/DmiCacheHandler.java index b0b1cc5226..9d87690531 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/DmiCacheHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cache/DmiCacheHandler.java @@ -129,7 +129,7 @@ public class DmiCacheHandler { /** * Update status in map of subscription details per DMI. * - * @param subscriptionId String of subscription Id + * @param subscriptionId String of subscription id * @param dmiServiceName String of dmiServiceName * @param status String of status * @@ -145,7 +145,7 @@ public class DmiCacheHandler { /** * Persist map of subscription details per DMI. * - * @param subscriptionId String of subscription Id + * @param subscriptionId String of subscription id * @param dmiServiceName String of dmiServiceName * */ diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cmavc/CmAvcEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cmavc/CmAvcEventConsumer.java index f504207e3f..b18c7f9a1a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cmavc/CmAvcEventConsumer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cmavc/CmAvcEventConsumer.java @@ -83,7 +83,9 @@ public class CmAvcEventConsumer { if (Boolean.TRUE.equals(dataSyncEnabled)) { final AvcEvent cmAvcEvent = toTargetEvent(cmAvcEventAsConsumerRecord.value(), AvcEvent.class); log.debug("Event to be processed to update the cache with cmHandleId : {}", cmHandleId); - cmAvcEventService.processCmAvcEvent(cmHandleId, cmAvcEvent); + if (cmAvcEvent != null) { + cmAvcEventService.processCmAvcEvent(cmHandleId, cmAvcEvent); + } } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cmavc/CmAvcEventService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cmavc/CmAvcEventService.java index 061fe56c8a..1bfc038eef 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cmavc/CmAvcEventService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/cmavc/CmAvcEventService.java @@ -139,7 +139,7 @@ public class CmAvcEventService { } private String getCpsPath(final String cmHandleId, final String restConfStylePath) { - log.debug("Getting cps path from the restconfpath : {}", restConfStylePath); + log.debug("Getting cps path from the rest config path : {}", restConfStylePath); final Anchor anchor = cpsAnchorService.getAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId); return yangParser.getCpsPathFromRestConfStylePath(anchor, restConfStylePath); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventMapper.java index 04fe6d1480..ed5d657026 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventMapper.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventMapper.java @@ -87,8 +87,8 @@ public class DmiInEventMapper { final CmHandle cmHandle = new CmHandle(); final Map cmHandleAdditionalProperties = new LinkedHashMap<>(); yangModelCmHandle.getAdditionalProperties() - .forEach(additionalProperty -> cmHandleAdditionalProperties.put(additionalProperty.getName(), - additionalProperty.getValue())); + .forEach(additionalProperty -> cmHandleAdditionalProperties.put(additionalProperty.name(), + additionalProperty.value())); cmHandle.setCmhandleId(yangModelCmHandle.getId()); cmHandle.setPrivateProperties(cmHandleAdditionalProperties); cmSubscriptionCmHandles.add(cmHandle); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventProducer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventProducer.java index baa9926a40..3b1fb95610 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventProducer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventProducer.java @@ -45,8 +45,8 @@ public class DmiInEventProducer { /** * Send the event to the provided dmi plugin with key as subscription id and the event is in Cloud Event format. * - * @param subscriptionId Cm Subscription Id - * @param dmiPluginName Dmi Plugin Name + * @param subscriptionId CM subscription id + * @param dmiPluginName Dmi plugin Name * @param eventType Type of event * @param dmiInEvent Cm Notification Subscription event for Dmi */ diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/models/CmSubscriptionStatus.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/models/CmSubscriptionStatus.java index 5b7c46ed00..1763f24f46 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/models/CmSubscriptionStatus.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/models/CmSubscriptionStatus.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -22,11 +22,6 @@ package org.onap.cps.ncmp.impl.cmnotificationsubscription.models; public enum CmSubscriptionStatus { - ACCEPTED("ACCEPTED"), REJECTED("REJECTED"), PENDING("PENDING"); + ACCEPTED(), REJECTED(), PENDING() - private final String cmNotificationSubscriptionStatusValue; - - CmSubscriptionStatus(final String cmNotificationSubscriptionStatusValue) { - this.cmNotificationSubscriptionStatusValue = cmNotificationSubscriptionStatusValue; - } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/models/DmiCmSubscriptionTuple.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/models/DmiCmSubscriptionTuple.java index cd4a15af47..5be75776a0 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/models/DmiCmSubscriptionTuple.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/models/DmiCmSubscriptionTuple.java @@ -24,7 +24,7 @@ import java.util.Collection; import java.util.Map; /** - * Tuple to be used during for to delete usecase. + * Tuple to be used during for to delete use case. * * @param lastRemainingSubscriptionsPerDmi subscriptions that are used by only one subscriber grouped per dmi * @param overlappingSubscriptionsPerDmi subscriptions that are shared by multiple subscribers grouped per dmi diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImpl.java index d0285e1dbe..a82b5beaa8 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImpl.java @@ -198,6 +198,7 @@ public class CmSubscriptionHandlerImpl implements CmSubscriptionHandler { final DmiCmSubscriptionKey dmiCmSubscriptionKey = extractCmSubscriptionKey(subscriptionNode.getXpath()); final String dmiServiceName = inventoryPersistence.getYangModelCmHandle( dmiCmSubscriptionKey.cmHandleId()).getDmiServiceName(); + @SuppressWarnings("unchecked") final List subscribers = (List) subscriptionNode.getLeaves().get("subscriptionIds"); populateDmiCmSubscriptionTuple(subscribers, overlappingSubscriptionsPerDmi, lastRemainingSubscriptionsPerDmi, dmiServiceName, dmiCmSubscriptionKey); @@ -228,4 +229,4 @@ public class CmSubscriptionHandlerImpl implements CmSubscriptionHandler { throw new IllegalArgumentException("DataNode xpath does not represent a subscription key"); } -} \ No newline at end of file +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpInEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpInEventConsumer.java index 17b1de6d08..b3fb133432 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpInEventConsumer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpInEventConsumer.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -50,22 +50,23 @@ public class NcmpInEventConsumer { containerFactory = "cloudEventConcurrentKafkaListenerContainerFactory") public void consumeSubscriptionEvent(final ConsumerRecord ncmpInEventAsConsumerRecord) { final CloudEvent cloudEvent = ncmpInEventAsConsumerRecord.value(); - final NcmpInEvent ncmpInEvent = - toTargetEvent(cloudEvent, NcmpInEvent.class); - log.info("Subscription with name {} to be mapped to hazelcast object...", + final NcmpInEvent ncmpInEvent = toTargetEvent(cloudEvent, NcmpInEvent.class); + if (ncmpInEvent != null) { + log.info("Subscription with name {} to be mapped to hazelcast object...", ncmpInEvent.getData().getSubscriptionId()); - final String subscriptionId = ncmpInEvent.getData().getSubscriptionId(); - final List predicates = ncmpInEvent.getData().getPredicates(); - if ("subscriptionCreateRequest".equals(cloudEvent.getType())) { - log.info("Subscription create request for source {} with subscription id {} ...", + final String subscriptionId = ncmpInEvent.getData().getSubscriptionId(); + final List predicates = ncmpInEvent.getData().getPredicates(); + if ("subscriptionCreateRequest".equals(cloudEvent.getType())) { + log.info("Subscription create request for source {} with subscription id {} ...", cloudEvent.getSource(), subscriptionId); - cmSubscriptionHandler.processSubscriptionCreateRequest(subscriptionId, predicates); - } - if ("subscriptionDeleteRequest".equals(cloudEvent.getType())) { - log.info("Subscription delete request for source {} with subscription id {} ...", + cmSubscriptionHandler.processSubscriptionCreateRequest(subscriptionId, predicates); + } + if ("subscriptionDeleteRequest".equals(cloudEvent.getType())) { + log.info("Subscription delete request for source {} with subscription id {} ...", cloudEvent.getSource(), subscriptionId); - cmSubscriptionHandler.processSubscriptionDeleteRequest(subscriptionId); + cmSubscriptionHandler.processSubscriptionDeleteRequest(subscriptionId); + } } } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventMapper.java index afff9d1298..9f59b1a344 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventMapper.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventMapper.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -40,7 +40,7 @@ public class NcmpOutEventMapper { /** * Mapper to form a response for the client for the Cm Notification Subscription. * - * @param subscriptionId Cm Notification Subscription Id + * @param subscriptionId CM notification subscription id * @param dmiSubscriptionsPerDmi contains CmNotificationSubscriptionDetails per dmi plugin * @return CmNotificationSubscriptionNcmpOutEvent to sent back to the client */ diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducer.java index 639fb65296..a5b9ae60c6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducer.java @@ -62,7 +62,7 @@ public class NcmpOutEventProducer { * Send the event to the client who requested the subscription with key as subscription id and event is Cloud * Event compliant. * - * @param subscriptionId Cm Subscription Id + * @param subscriptionId CM subscription id * @param eventType Type of event * @param ncmpOutEvent Cm Notification Subscription Event for the * client diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/utils/CmDataJobSubscriptionPersistenceService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/utils/CmDataJobSubscriptionPersistenceService.java index 5c53f3d53b..b761f84257 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/utils/CmDataJobSubscriptionPersistenceService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/utils/CmDataJobSubscriptionPersistenceService.java @@ -27,7 +27,6 @@ import java.io.Serializable; import java.time.OffsetDateTime; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -85,6 +84,7 @@ public class CmDataJobSubscriptionPersistenceService { * @param alternateId the alternate id target of the data job subscription * @return collection of subscription ids of ongoing cm notification subscription */ + @SuppressWarnings("unchecked") public Collection getSubscriptionIds(final String dataType, final String alternateId) { final String query = CPS_PATH_TEMPLATE_FOR_SUBSCRIPTION_WITH_ALTERNATE_ID_AND_DATATYPE.formatted( alternateId, dataType); @@ -94,7 +94,7 @@ public class CmDataJobSubscriptionPersistenceService { if (existingNodes.isEmpty()) { return Collections.emptyList(); } - return (List) existingNodes.iterator().next().getLeaves().get("dataJobId"); + return (Collection) existingNodes.iterator().next().getLeaves().get("dataJobId"); } /** @@ -105,8 +105,7 @@ public class CmDataJobSubscriptionPersistenceService { * @param subscriptionId data job subscription id to be added */ public void addSubscription(final String dataType, final String alternateId, final String subscriptionId) { - final Collection subscriptionIds = - getSubscriptionIds(dataType, alternateId); + final Collection subscriptionIds = getSubscriptionIds(dataType, alternateId); if (subscriptionIds.isEmpty()) { addNewSubscriptionDetails(dataType, alternateId, subscriptionId); } else { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java index b64d4569e3..9b0dc9f88e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java @@ -102,7 +102,7 @@ public class DmiDataOperations { validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState); final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle); final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters(cmResourceAddress - .getDatastoreName(), yangModelCmHandle, cmResourceAddress.getResourceIdentifier(), options, topic); + .datastoreName(), yangModelCmHandle, cmResourceAddress.resourceIdentifier(), options, topic); return dmiRestClient.asynchronousPostOperationWithJsonData(DATA, urlTemplateParameters, jsonRequestBody, READ, authorization); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java index 5b2fedefcf..85456c8644 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java @@ -66,20 +66,18 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle final String authorization) { final FetchDescendantsOption fetchDescendantsOption = FetchDescendantsOption.getFetchDescendantsOption(includeDescendants); - - final Map dataNodes = cpsFacade.getDataNodesByAnchorV3(resolveDatastoreName(cmResourceAddress), - cmResourceAddress.resolveCmHandleReferenceToId(), cmResourceAddress.getResourceIdentifier(), + validateDatastore(cmResourceAddress.datastoreName()); + final Map dataNodes = cpsFacade.getDataNodesByAnchorV3(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, + cmResourceAddress.resolveCmHandleReferenceToId(), cmResourceAddress.resourceIdentifier(), fetchDescendantsOption); return Mono.justOrEmpty(dataNodes); } - private String resolveDatastoreName(final CmResourceAddress cmResourceAddress) { - final String datastoreName = cmResourceAddress.getDatastoreName(); - if (datastoreName.equals(OPERATIONAL.getDatastoreName())) { - return NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME; - } - throw new IllegalArgumentException( + private void validateDatastore(final String datastoreName) { + if (!datastoreName.equals(OPERATIONAL.getDatastoreName())) { + throw new IllegalArgumentException( "Unsupported datastore name provided to fetch the cached data: " + datastoreName); + } } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java index 8920839cd5..276b56c2dd 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpPassthroughResourceRequestHandler.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2024 Nordix Foundation + * Copyright (C) 2022-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. @@ -52,7 +52,7 @@ public class NcmpPassthroughResourceRequestHandler extends NcmpDatastoreRequestH * @param topic the topic param in query * @param dataOperationRequest data operation request details for resource data * @param authorization contents of Authorization header, or null if not present - * @return a map with one entry of request Id for success or status and error when async feature is disabled + * @return a map with one entry of request id for success or status and error when async feature is disabled */ public Map executeAsynchronousRequest(final String topic, final DataOperationRequest dataOperationRequest, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java index ab20fa10c7..73bd1e7e34 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021 highstreet technologies GmbH - * Modifications Copyright (C) 2021-2024 Nordix Foundation + * Modifications Copyright (C) 2021-2025 OpenInfra Foundation Europe. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021-2022 Bell Canada * Modifications Copyright (C) 2023 TechMahindra Ltd. @@ -67,7 +67,7 @@ public class NetworkCmProxyFacade { final String authorization) { final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler - = getNcmpDatastoreRequestHandler(cmResourceAddress.getDatastoreName()); + = getNcmpDatastoreRequestHandler(cmResourceAddress.datastoreName()); return ncmpDatastoreRequestHandler.executeRequest(cmResourceAddress, optionsParamInQuery, topicParamInQuery, includeDescendants, authorization); } @@ -78,7 +78,7 @@ public class NetworkCmProxyFacade { * @param topic the topic param in query * @param dataOperationRequest data operation request details for resource data * @param authorization contents of Authorization header, or null if not present - * @return a map with one entry of request Id for success or status and error when async feature is disabled + * @return a map with one entry of request id for success or status and error when async feature is disabled */ public Object executeDataOperationForCmHandles(final String topic, final DataOperationRequest dataOperationRequest, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/async/RecordFilterStrategies.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/async/RecordFilterStrategies.java index 2615672374..cb15bca60d 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/async/RecordFilterStrategies.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/async/RecordFilterStrategies.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * 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. @@ -47,8 +47,7 @@ public class RecordFilterStrategies { */ @Bean public RecordFilterStrategy includeDataOperationEventsOnly() { - return consumerRecord -> - isNotCloudEventOfType(consumerRecord.headers(), "DataOperationEvent"); + return consumerRecord -> isNotCloudDataOperationEvent(consumerRecord.headers()); } /** @@ -66,12 +65,12 @@ public class RecordFilterStrategies { return headers.lastHeader("ce_type") != null; } - private boolean isNotCloudEventOfType(final Headers headers, final String requiredEventType) { + private boolean isNotCloudDataOperationEvent(final Headers headers) { final String eventTypeHeaderValue = KafkaHeaders.getParsedKafkaHeader(headers, "ce_type"); if (eventTypeHeaderValue == null) { log.trace("No ce_type header found, possibly a legacy event (ignored)"); return EXCLUDE_EVENT; } - return !(eventTypeHeaderValue.contains(requiredEventType)); + return !(eventTypeHeaderValue.contains("DataOperationEvent")); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutor.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutor.java index 6e69a5c473..e9d83aaa47 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutor.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/policyexecutor/PolicyExecutor.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * 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. @@ -60,6 +60,7 @@ public class PolicyExecutor { @Value("${ncmp.policy-executor.defaultDecision:deny}") private String defaultDecision; + @SuppressWarnings("HttpUrlsUsage") @Value("${ncmp.policy-executor.server.address:http://policy-executor}") private String serverAddress; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java index 0946eaeb74..6fddd9ed6a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java @@ -141,6 +141,7 @@ public class DmiDataOperationsHelper { if (!cmHandleIdsPerResponseCodesPerOperation.isEmpty()) { final CloudEvent dataOperationCloudEvent = DataOperationEventCreator.createDataOperationEvent(clientTopic, requestId, cmHandleIdsPerResponseCodesPerOperation); + @SuppressWarnings("unchecked") final EventsProducer eventsProducer = CpsApplicationContext.getCpsBean(EventsProducer.class); log.warn("sending error message to client topic: {} ,requestId: {}, data operation cloud event id: {}", clientTopic, requestId, dataOperationCloudEvent.getId()); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java index 56352c1c81..d4ffadac39 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImpl.java @@ -48,7 +48,9 @@ public class DataJobServiceImpl implements DataJobService { final String dataJobId, final DataJobMetadata dataJobMetadata, final DataJobReadRequest dataJobReadRequest) { - log.info("data job id for read operation is: {}", dataJobId); + logJobIdAndSize(dataJobId, dataJobReadRequest.data().size()); + log.info("Destination: {}", dataJobMetadata.destination()); + log.info("authorization: {}", authorization); } @Override @@ -56,8 +58,7 @@ public class DataJobServiceImpl implements DataJobService { final String dataJobId, final DataJobMetadata dataJobMetadata, final DataJobWriteRequest dataJobWriteRequest) { - - log.info("Data Job ID: {} - Total operations received: {}", dataJobId, dataJobWriteRequest.data().size()); + logJobIdAndSize(dataJobId, dataJobWriteRequest.data().size()); logJsonRepresentation("Initiating WRITE operation for Data Job ID: " + dataJobId, dataJobWriteRequest); final Map> dmiWriteOperationsPerProducerKey = @@ -71,10 +72,15 @@ public class DataJobServiceImpl implements DataJobService { return subJobWriteResponses; } + private void logJobIdAndSize(final String dataJobId, final int numberOfOperations) { + log.info("Data Job ID: {} - Total operations received: {}", dataJobId, numberOfOperations); + } + private void logJsonRepresentation(final String description, final Object object) { if (log.isDebugEnabled()) { final String objectAsJsonString = jsonObjectMapper.asJsonString(object); log.debug("{} (JSON): {}", description, objectAsJsonString); } } + } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java index 5a62667fb2..a8edbd1b0e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024-2025 Nordix Foundation + * 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. @@ -79,6 +79,7 @@ public class DmiSubJobRequestHandler { jsonObjectMapper.asJsonString(subJobWriteRequest), OperationType.CREATE, authorization); + @SuppressWarnings("unchecked") final Map responseAsKeyValuePairs = jsonObjectMapper .convertToValueType(responseEntity.getBody(), Map.class); final String subJobId = responseAsKeyValuePairs.get("subJobId"); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiServiceNameOrganizer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiServiceNameOrganizer.java index 6d35f372e8..868bedde8b 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiServiceNameOrganizer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/dmi/DmiServiceNameOrganizer.java @@ -61,6 +61,6 @@ public class DmiServiceNameOrganizer { private static Map additionalPropertiesAsMap( final List additionalProperties) { return additionalProperties.stream().collect( - Collectors.toMap(YangModelCmHandle.Property::getName, YangModelCmHandle.Property::getValue)); + Collectors.toMap(YangModelCmHandle.Property::name, YangModelCmHandle.Property::value)); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java index c441d4d90e..af9d51264c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java @@ -75,24 +75,6 @@ public interface CmHandleQueryService { */ Collection queryCmHandleAncestorsByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption); - /** - * Method to return data nodes representing the cm handles. - * - * @param cpsPath cps path for which the cmHandle is requested - * @return a list of data nodes representing the cm handles. - */ - Collection queryNcmpRegistryByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption); - - /** - * Method to return data nodes representing the cm handles. - * - * @param cpsPath cps path for which the cmHandle is requested - * @param queryResultLimit the maximum number of data nodes to return; if less than 1, returns all matching nodes - * @return a list of data nodes representing the cm handles. - */ - Collection queryNcmpRegistryByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption, - int queryResultLimit); - /** * Method to check the state of a cm handle with given id. * diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java index dae2f45b03..b624eb8fd2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java @@ -99,20 +99,6 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { .toList(); } - @Override - public Collection queryNcmpRegistryByCpsPath(final String cpsPath, - final FetchDescendantsOption fetchDescendantsOption) { - return queryNcmpRegistryByCpsPath(cpsPath, fetchDescendantsOption, NO_LIMIT); - } - - @Override - public Collection queryNcmpRegistryByCpsPath(final String cpsPath, - final FetchDescendantsOption fetchDescendantsOption, - final int queryResultLimit) { - return cpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, - fetchDescendantsOption, queryResultLimit); - } - @Override public Collection queryCmHandleAncestorsByCpsPath(final String cpsPath, final FetchDescendantsOption fetchDescendantsOption) { @@ -267,4 +253,11 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { return cpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, OMIT_DESCENDANTS).iterator().next(); } + + private Collection queryNcmpRegistryByCpsPath(final String cpsPath, + final FetchDescendantsOption fetchDescendantsOption) { + return cpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, + fetchDescendantsOption, NO_LIMIT); + } + } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java index d380668657..391fd6a797 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java @@ -124,8 +124,7 @@ public class CmHandleRegistrationService { if (CmHandleState.READY.equals(compositeState.getCmHandleState())) { final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores() .getOperationalDataStore().getDataStoreSyncState(); - if (Boolean.FALSE.equals(dataSyncEnabledTargetValue) - && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) { + if (!dataSyncEnabledTargetValue && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) { // TODO : This is hard-coded for onap dmi that need to be addressed cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, "/netconf-state", OffsetDateTime.now()); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java index ecf27a3aaa..7bd7c8ee1e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java @@ -133,16 +133,6 @@ public interface InventoryPersistence extends NcmpPersistence { Collection getCmHandleDataNodeByCmHandleId(String cmHandleId, FetchDescendantsOption fetchDescendantsOption); - /** - * Get collection of data nodes of given cm handles. - * - * @param cmHandleIds collection of cmHandle IDs - * @param fetchDescendantsOption fetch descendants option - * @return collection of data nodes - */ - Collection getCmHandleDataNodes(Collection cmHandleIds, - FetchDescendantsOption fetchDescendantsOption); - /** * get CM handles that has given module names. * diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java index e06a46e856..d024072776 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java @@ -58,7 +58,7 @@ import org.springframework.stereotype.Component; @Component public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements InventoryPersistence { - private static final int CMHANDLE_BATCH_SIZE = 300; + private static final int CM_HANDLE_BATCH_SIZE = 300; private final CpsModuleService cpsModuleService; private final CpsValidator cpsValidator; @@ -154,7 +154,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv @Override public void saveCmHandleBatch(final List yangModelCmHandles) { for (final List yangModelCmHandleBatch : - Lists.partition(yangModelCmHandles, CMHANDLE_BATCH_SIZE)) { + Lists.partition(yangModelCmHandles, CM_HANDLE_BATCH_SIZE)) { final String cmHandlesJsonData = createCmHandlesJsonData(yangModelCmHandleBatch); cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT, cmHandlesJsonData, NO_TIMESTAMP, ContentType.JSON); @@ -167,14 +167,6 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv return this.getDataNode(getXPathForCmHandleById(cmHandleId), fetchDescendantsOption); } - @Override - public Collection getCmHandleDataNodes(final Collection cmHandleIds, - final FetchDescendantsOption fetchDescendantsOption) { - final Collection xpaths = new ArrayList<>(cmHandleIds.size()); - cmHandleIds.forEach(cmHandleId -> xpaths.add(getXPathForCmHandleById(cmHandleId))); - return this.getDataNodes(xpaths, fetchDescendantsOption); - } - @Override public Collection getCmHandleReferencesWithGivenModules(final Collection moduleNamesForQuery, final boolean outputAlternateId) { @@ -233,4 +225,11 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv return YangDataConverter.toYangModelCmHandles(getCmHandleDataNodes(validCmHandleIds, fetchDescendantsOption)); } + private Collection getCmHandleDataNodes(final Collection cmHandleIds, + final FetchDescendantsOption fetchDescendantsOption) { + final Collection xpaths = new ArrayList<>(cmHandleIds.size()); + cmHandleIds.forEach(cmHandleId -> xpaths.add(getXPathForCmHandleById(cmHandleId))); + return this.getDataNodes(xpaths, fetchDescendantsOption); + } + } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/NcmpPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/NcmpPersistence.java index f327edab17..f9b9dccc7e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/NcmpPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/NcmpPersistence.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2025 Nordix Foundation + * Copyright (C) 2022-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. @@ -57,29 +57,11 @@ public interface NcmpPersistence { */ Collection getDataNode(String xpath, FetchDescendantsOption fetchDescendantsOption); - /** - * Get collection of data nodes via xpaths. - * - * @param xpaths collection of xpaths - * @return collection of data nodes - */ - Collection getDataNodes(Collection xpaths); - - /** - * Get collection of data nodes via xpaths. - * - * @param xpaths collection of xpaths - * @param fetchDescendantsOption fetch descendants option - * @return collection of data nodes - */ - Collection getDataNodes(Collection xpaths, - FetchDescendantsOption fetchDescendantsOption); - /** * Replaces list content by removing all existing elements and inserting the given new elements as data nodes. * * @param parentNodeXpath parent node xpath - * @param dataNodes datanodes representing the updated data + * @param dataNodes data nodes representing the updated data */ void replaceListContent(String parentNodeXpath, Collection dataNodes); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/NcmpPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/NcmpPersistenceImpl.java index 2232d7ce12..97112bae63 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/NcmpPersistenceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/NcmpPersistenceImpl.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023-2025 Nordix Foundation + * 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. @@ -61,12 +61,6 @@ public class NcmpPersistenceImpl implements NcmpPersistence { fetchDescendantsOption); } - @Override - public Collection getDataNodes(final Collection xpaths) { - return getDataNodes(xpaths, INCLUDE_ALL_DESCENDANTS); - } - - @Override public Collection getDataNodes(final Collection xpaths, final FetchDescendantsOption fetchDescendantsOption) { return cpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpaths, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java index 68d97fbbad..a34a89f568 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java @@ -225,18 +225,19 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan } private Collection getNcmpServiceCmHandleBatch(final Collection cmHandleIds) { - final Collection yangModelcmHandles + final Collection yangModelCmHandles = inventoryPersistence.getYangModelCmHandles(cmHandleIds); - final Collection ncmpServiceCmHandles = new ArrayList<>(yangModelcmHandles.size()); + final Collection ncmpServiceCmHandles = new ArrayList<>(yangModelCmHandles.size()); - yangModelcmHandles.forEach(yangModelcmHandle -> + yangModelCmHandles.forEach(yangModelcmHandle -> ncmpServiceCmHandles.add(YangDataConverter.toNcmpServiceCmHandle(yangModelcmHandle)) ); trustLevelManager.applyEffectiveTrustLevels(ncmpServiceCmHandles); return ncmpServiceCmHandles; } + @SafeVarargs private Collection executeQueries(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId, final BiFunction lcmEventHeadersMap = jsonObjectMapper.convertToValueType(lcmEventHeader, Map.class); eventsProducer.sendEvent(topicName, cmHandleId, lcmEventHeadersMap, lcmEvent); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumer.java index 44befab574..9622a8ff6d 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumer.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * 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. @@ -53,8 +53,10 @@ public class DeviceTrustLevelMessageConsumer { final DeviceTrustLevel deviceTrustLevel = CloudEventMapper.toTargetEvent(consumerRecord.value(), DeviceTrustLevel.class); - final String trustLevelAsString = deviceTrustLevel.getData().getTrustLevel(); - trustLevelManager.updateCmHandleTrustLevel(cmHandleId, TrustLevel.valueOf(trustLevelAsString)); + if (deviceTrustLevel != null) { + final String trustLevelAsString = deviceTrustLevel.getData().getTrustLevel(); + trustLevelManager.updateCmHandleTrustLevel(cmHandleId, TrustLevel.valueOf(trustLevelAsString)); + } } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java index 779024bf9f..3fc4b051fa 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfig.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================== - * Copyright (C) 2023-2024 Nordix Foundation + * 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. @@ -21,6 +21,7 @@ package org.onap.cps.ncmp.impl.inventory.trustlevel; import com.hazelcast.config.MapConfig; +import com.hazelcast.config.NearCacheConfig; import com.hazelcast.map.IMap; import org.onap.cps.ncmp.api.inventory.models.TrustLevel; import org.onap.cps.ncmp.impl.cache.HazelcastCacheConfig; @@ -34,10 +35,10 @@ public class TrustLevelCacheConfig extends HazelcastCacheConfig { public static final String TRUST_LEVEL_PER_CM_HANDLE = "trustLevelPerCmHandle"; private static final MapConfig trustLevelPerCmHandleIdNearCacheConfig = - createNearCacheMapConfig("trustLevelPerCmHandleCacheConfig"); + createMapConfigsWithNearCache(); private static final MapConfig trustLevelPerDmiPluginCacheConfig = - createMapConfig("trustLevelPerDmiPluginCacheConfig"); + createGenericMapConfig("trustLevelPerDmiPluginCacheConfig"); /** * Distributed instance of trust level cache containing the trust level per cm handle. @@ -60,4 +61,10 @@ public class TrustLevelCacheConfig extends HazelcastCacheConfig { trustLevelPerDmiPluginCacheConfig).getMap(TRUST_LEVEL_PER_DMI_PLUGIN); } + private static MapConfig createMapConfigsWithNearCache() { + final MapConfig mapConfig = createGenericMapConfig("trustLevelPerCmHandleCacheConfig"); + mapConfig.setNearCacheConfig(new NearCacheConfig("trustLevelPerCmHandleCacheConfig")); + return mapConfig; + } + } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/models/DmiRequestBody.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/models/DmiRequestBody.java index 2989b3d35f..0e88d42bd8 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/models/DmiRequestBody.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/models/DmiRequestBody.java @@ -55,7 +55,7 @@ public class DmiRequestBody { final List yangModelCmHandleProperties) { additionalProperties = new LinkedHashMap<>(); for (final YangModelCmHandle.Property additionalProperty : yangModelCmHandleProperties) { - additionalProperties.put(additionalProperty.getName(), additionalProperty.getValue()); + additionalProperties.put(additionalProperty.name(), additionalProperty.value()); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/models/RequiredDmiService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/models/RequiredDmiService.java index c0c4f73f2a..cb85205f87 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/models/RequiredDmiService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/models/RequiredDmiService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation + * Copyright (C) 2021-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. @@ -21,7 +21,7 @@ package org.onap.cps.ncmp.impl.models; /** - * Enmm to determine if the required service is for a data or model operation. + * Enum to determine if the required service is for a data or model operation. */ public enum RequiredDmiService { DATA, MODEL diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java index e2b39e5797..f9707aa1af 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java @@ -117,7 +117,7 @@ public class AlternateIdMatcher { } /** - * Get cm handle Id from given cmHandleReference. + * Get cm handle id from given cmHandleReference. * * @param cmHandleReference cm handle or alternate identifier * @return cm handle id string diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java index 07945d9fe0..8d7ac9f9a6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java @@ -72,7 +72,7 @@ public class YangDataConverter { public static Map toPropertiesMap(final List properties) { final Map propertiesMap = new LinkedHashMap<>(properties.size()); for (final YangModelCmHandle.Property property : properties) { - propertiesMap.put(property.getName(), property.getValue()); + propertiesMap.put(property.name(), property.value()); } return propertiesMap; } @@ -111,12 +111,11 @@ public class YangDataConverter { /** * This method extracts cm handle id from xpath of data node. * @param xpath for data node of the cm handle - * @return cm handle Id + * @return cm handle id or null if no id can be found */ public static String extractCmHandleIdFromXpath(final String xpath) { final Matcher matcher = cmHandleIdInXpathPattern.matcher(xpath); - matcher.find(); - return matcher.group(1); + return matcher.find() ? matcher.group(1) : null; } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/RestServiceUrlTemplateBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/RestServiceUrlTemplateBuilder.java index 32d4257382..659dcf5fe6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/RestServiceUrlTemplateBuilder.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/RestServiceUrlTemplateBuilder.java @@ -91,7 +91,7 @@ public class RestServiceUrlTemplateBuilder { /** * Constructs a URL template with variables based on the accumulated path segments and query parameters. * - * @param serviceBaseUrl the base URL of the service, e.g., "http://dmi-service.com". + * @param serviceBaseUrl the base URL of the service, e.g., "...". * @param basePath the base path of the service * @return a UrlTemplateParameters instance containing the complete URL template and URL variables */ @@ -120,7 +120,7 @@ public class RestServiceUrlTemplateBuilder { /** * Constructs a URL for a spring actuator health check based on the given base URL. * - * @param serviceBaseUrl the base URL of the service, e.g., "http://dmi-service.com". + * @param serviceBaseUrl the base URL of the service, e.g., "...". * @return a {@link UrlTemplateParameters} instance containing the complete URL template and empty URL variables, * suitable for DMI health check. */ diff --git a/cps-ncmp-service/src/main/resources/models/dmi-registry@2024-02-23.yang b/cps-ncmp-service/src/main/resources/models/dmi-registry@2024-02-23.yang index 8daf82f336..c70e30e35d 100644 --- a/cps-ncmp-service/src/main/resources/models/dmi-registry@2024-02-23.yang +++ b/cps-ncmp-service/src/main/resources/models/dmi-registry@2024-02-23.yang @@ -25,7 +25,7 @@ module dmi-registry { revision "2022-05-10" { description - "Added data-sync-enabled, sync-state with state, last-sync-time, data-store-sync-state with operational and running syncstate"; + "Added data-sync-enabled, sync-state with state, last-sync-time, data-store-sync-state with operational and running sync-state"; } revision "2022-02-10" { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/models/CmHandleRegistrationResponseSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/models/CmHandleRegistrationResponseSpec.groovy index c49af0f01b..2a98592378 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/models/CmHandleRegistrationResponseSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/models/CmHandleRegistrationResponseSpec.groovy @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada - * Modifications Copyright (C) 2023-2025 Nordix Foundation + * Modifications Copyright (C) 2023-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. @@ -46,10 +46,9 @@ class CmHandleRegistrationResponseSpec extends Specification { def 'Failed cm-handle Registration Response: for unexpected exception'() { when: 'cm-handle response is created for an unexpected exception' - def cmHandleRegistrationResponse = - CmHandleRegistrationResponse.createFailureResponse('cmHandle', new Exception('unexpected error')) + def result = CmHandleRegistrationResponse.createFailureResponse('cmHandle', new Exception('unexpected error')) then: 'the response is created with expected value' - with(cmHandleRegistrationResponse) { + with(result) { assert it.ncmpResponseStatus == UNKNOWN_ERROR assert it.cmHandle == 'cmHandle' assert errorText == 'unexpected error' @@ -58,44 +57,39 @@ class CmHandleRegistrationResponseSpec extends Specification { def 'Failed cm-handle Registration Response'() { when: 'cm-handle failure response is created' - def cmHandleRegistrationResponse = - CmHandleRegistrationResponse.createFailureResponse('cmHandle', CM_HANDLE_ALREADY_EXIST) + def result = CmHandleRegistrationResponse.createFailureResponse('cmHandle', CM_HANDLE_ALREADY_EXIST) then: 'the response is created with expected value' - with(cmHandleRegistrationResponse) { - assert it.ncmpResponseStatus == CM_HANDLE_ALREADY_EXIST - assert it.cmHandle == 'cmHandle' - assert it.status == Status.FAILURE - assert errorText == CM_HANDLE_ALREADY_EXIST.message - } + with(result) { + assert it.ncmpResponseStatus == CM_HANDLE_ALREADY_EXIST + assert it.cmHandle == 'cmHandle' + assert it.status == Status.FAILURE + assert errorText == CM_HANDLE_ALREADY_EXIST.message + } } def 'Failed cm-handle Registration with multiple responses.'() { when: 'cm-handle failure response is created for 2 xpaths' - def cmHandleRegistrationResponses = - CmHandleRegistrationResponse.createFailureResponsesFromXpaths(["somePathWithId[@id='123']", "somePathWithId[@id='456']"], CM_HANDLE_ALREADY_EXIST) + def result = CmHandleRegistrationResponse.createFailureResponsesFromXpaths(["somePathWithId[@id='123']", "somePathWithId[@id='456']"], CM_HANDLE_ALREADY_EXIST) then: 'the response has the correct cm handle ids' - assert cmHandleRegistrationResponses.size() == 2 - assert cmHandleRegistrationResponses.stream().map(it -> it.cmHandle).collect(Collectors.toList()) - .containsAll(['123','456']) + assert result.size() == 2 + assert result.stream().map(it -> it.cmHandle).collect(Collectors.toList()).containsAll(['123','456']) } def 'Failed cm-handle Registration with multiple responses with an unexpected xpath.'() { when: 'cm-handle failure response is created for one valid and one unexpected xpath' - def cmHandleRegistrationResponses = - CmHandleRegistrationResponse.createFailureResponsesFromXpaths(["somePathWithId[@id='123']", "valid/xpath/without-id[@key='123']"], CM_HANDLE_ALREADY_EXIST) + def result = CmHandleRegistrationResponse.createFailureResponsesFromXpaths(["somePathWithId[@id='123']", "valid/xpath/without-id[@key='123']"], CM_HANDLE_ALREADY_EXIST) then: 'the response has only one entry' - assert cmHandleRegistrationResponses.size() == 1 + assert result.size() == 1 } def 'Failed cm-handle registration based on cm handle id and registration error'() { when: 'the failure response is created with "cm-handle already exists" error code for 1 cm handle' - def cmHandleRegistrationResponses = - CmHandleRegistrationResponse.createFailureResponses(['ch 1'], CM_HANDLE_ALREADY_EXIST) + def result = CmHandleRegistrationResponse.createFailureResponses(['ch 1'], CM_HANDLE_ALREADY_EXIST) then: 'the response with expected values' - assert cmHandleRegistrationResponses[0].cmHandle == 'ch 1' - assert cmHandleRegistrationResponses[0].status == Status.FAILURE - assert cmHandleRegistrationResponses[0].ncmpResponseStatus == CM_HANDLE_ALREADY_EXIST - assert cmHandleRegistrationResponses[0].errorText == 'cm-handle already exists' + assert result[0].cmHandle == 'ch 1' + assert result[0].status == Status.FAILURE + assert result[0].ncmpResponseStatus == CM_HANDLE_ALREADY_EXIST + assert result[0].errorText == 'cm-handle already exists' } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfigSpec.groovy index 0026d7c4e6..f021930d27 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfigSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cache/HazelcastCacheConfigSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023-2025 Nordix Foundation + * 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. @@ -20,7 +20,6 @@ package org.onap.cps.ncmp.impl.cache - import com.hazelcast.core.Hazelcast import spock.lang.Specification @@ -54,7 +53,7 @@ class HazelcastCacheConfigSpec extends Specification { } where: 'the following configs are used' scenario | config || expectMapConfig | expectQueueConfig | expectSetConfig - 'Map Config' | HazelcastCacheConfig.createMapConfig('my map config') || true | false | false + 'Map Config' | HazelcastCacheConfig.createGenericMapConfig('my map config') || true | false | false 'Queue Config' | HazelcastCacheConfig.createQueueConfig('my queue config') || false | true | false 'Set Config' | HazelcastCacheConfig.createSetConfig('my set config') || false | false | true } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpInEventConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpInEventConsumerSpec.groovy index 9c24e2b005..3b8fb0f756 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpInEventConsumerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpInEventConsumerSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (c) 2024 Nordix Foundation. + * 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. @@ -59,10 +59,10 @@ class NcmpInEventConsumerSpec extends MessagingBaseSpec { } - def 'Consume valid CmNotificationSubscriptionNcmpInEvent create message'() { + def 'Consume valid CmNotificationSubscriptionNcmpInEvent create message.'() { given: 'a cmNotificationSubscription event' def jsonData = TestUtils.getResourceFileContent('cmSubscription/cmNotificationSubscriptionNcmpInEvent.json') - def testEventSent = jsonObjectMapper.convertJsonString(jsonData, NcmpInEvent.class) + def testEventSent = jsonObjectMapper.convertJsonString(jsonData, NcmpInEvent) def testCloudEventSent = CloudEventBuilder.v1() .withData(objectMapper.writeValueAsBytes(testEventSent)) .withId('subscriptionCreated') @@ -81,10 +81,10 @@ class NcmpInEventConsumerSpec extends MessagingBaseSpec { 1 * mockCmSubscriptionHandler.processSubscriptionCreateRequest('test-id',_) } - def 'Consume valid CmNotificationSubscriptionNcmpInEvent delete message'() { + def 'Consume valid CmNotificationSubscriptionNcmpInEvent delete message.'() { given: 'a cmNotificationSubscription event' def jsonData = TestUtils.getResourceFileContent('cmSubscription/cmNotificationSubscriptionNcmpInEvent.json') - def testEventSent = jsonObjectMapper.convertJsonString(jsonData, NcmpInEvent.class) + def testEventSent = jsonObjectMapper.convertJsonString(jsonData, NcmpInEvent) def testCloudEventSent = CloudEventBuilder.v1() .withData(objectMapper.writeValueAsBytes(testEventSent)) .withId('sub-id') @@ -103,6 +103,21 @@ class NcmpInEventConsumerSpec extends MessagingBaseSpec { 1 * mockCmSubscriptionHandler.processSubscriptionDeleteRequest('test-id') } + def 'Attempt to consume unsupported Event.'() { + given: 'a unsupported event with a valid supported type' + def unsupportedEvent = Mock(CloudEvent) + def cloudEventWithUnsupportedEvent = CloudEventBuilder.v1() + .withId('some id') + .withType('subscriptionCreateRequest') // this is valid but does not match the event object + .withSource(URI.create('some-resource')) + .withData(objectMapper.writeValueAsBytes(unsupportedEvent)).build() + def consumerRecord = new ConsumerRecord('some topic', 0, 0, 'some key', cloudEventWithUnsupportedEvent) + when: 'attempt to consume the unsupported event' + objectUnderTest.consumeSubscriptionEvent(consumerRecord) + then: 'the subscription handler service is not called at all' + 0 * mockCmSubscriptionHandler.processSubscriptionDeleteRequest(*_) + 0 * mockCmSubscriptionHandler.processSubscriptionCreateRequest(*_) + } def getLoggingEvent() { return logger.list[1] diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/async/RecordFilterStrategiesSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/async/RecordFilterStrategiesSpec.groovy index 5ff2a3b55d..af6dabfc85 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/async/RecordFilterStrategiesSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/async/RecordFilterStrategiesSpec.groovy @@ -1,3 +1,23 @@ +/* + * ============LICENSE_START======================================================== + * 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. + * 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========================================================= + */ + package org.onap.cps.ncmp.impl.data.async import org.apache.kafka.common.header.Header @@ -24,18 +44,18 @@ class RecordFilterStrategiesSpec extends Specification { 'non-cloud event' | 'other' || false } - def 'Excluding cloud event of given type only with #scenario.'() { + def 'Excluding cloud event with header #scenario.'() { given: 'headers contain a header for key: #key and value: #value' header.value() >> value.getBytes(Charset.defaultCharset()) headers.lastHeader(key) >> header expect: 'the event would (not) be excluded: #expectedToBeExcluded' - assert objectUnderTest.isNotCloudEventOfType(headers,'requiredType') == expectedToBeExcluded + assert objectUnderTest.isNotCloudDataOperationEvent(headers) == expectedToBeExcluded where: 'the following headers are defined' - scenario | key | value || expectedToBeExcluded - 'required type' | 'ce_type' | 'requiredType' || false - 'contains requiredType' | 'ce_type' | 'Contains requiredType and more' || false - 'other type' | 'ce_type' | 'other' || true - 'no ce_type header' | 'other' | 'irrelevant' || true + scenario | key | value || expectedToBeExcluded + 'DataOperationEvent' | 'ce_type' | 'DataOperationEvent' || false + 'contains DataOperationEvent' | 'ce_type' | 'Contains DataOperationEvent and more' || false + 'other type' | 'ce_type' | 'other' || true + 'no ce_type header' | 'other' | 'irrelevant' || true } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy index 9f0e134466..dcad514c30 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DataJobServiceImplSpec.groovy @@ -61,7 +61,7 @@ class DataJobServiceImplSpec extends Specification { then: 'the data job id is correctly logged' def loggingEvent = logger.list[0] assert loggingEvent.level == Level.INFO - assert loggingEvent.formattedMessage.contains('data job id for read operation is: my-job-id') + assert loggingEvent.formattedMessage.contains('Data Job ID: my-job-id') } def 'Write data-job request and verify logging when info enabled.'() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy index c7d0616bb2..ff52483239 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * 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. diff --git a/cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java index b4966e117a..46ab5d15a9 100755 --- a/cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java @@ -356,8 +356,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ DuplicatedYangResourceException duplicatedYangResourceException = null; final Throwable cause = originalException.getCause(); - if (cause instanceof ConstraintViolationException) { - final ConstraintViolationException constraintException = (ConstraintViolationException) cause; + if (cause instanceof final ConstraintViolationException constraintException) { if (YANG_RESOURCE_CHECKSUM_CONSTRAINT_NAME.equals(constraintException.getConstraintName())) { // Db constraint related to yang resource checksum uniqueness is not respected final String checksumInError = getDuplicatedChecksumFromException(constraintException); diff --git a/policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java b/policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java index aef27a6389..0eb7b37800 100644 --- a/policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java +++ b/policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java @@ -44,6 +44,7 @@ public class PolicyExecutorStubController implements OperationPermissionApi { private final Sleeper sleeper; private static final Pattern ERROR_CODE_PATTERN = Pattern.compile("(\\d{3})"); private int decisionCounter = 0; + // Do NOT change below to final as it needs to be set during test private static int slowResponseTimeInSeconds = 40; @Override