summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ForwardedSubscriptionEventCacheConfig.java52
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionPersistence.java50
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionPersistenceImpl.java199
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionStatus.java49
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionDmiOutEventConsumer.java104
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionDmiOutEventToYangModelSubscriptionEventMapper.java56
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionEventToCmSubscriptionNcmpOutEventMapper.java105
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventConsumer.java96
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventForwarder.java204
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventMapper.java52
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventToCmSubscriptionDmiInEventMapper.java35
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpOutEventPublisher.java146
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/ResponseTimeoutTask.java52
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmSubscriptionEventCloudMapper.java63
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java64
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelSubscriptionEvent.java100
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmSubscriptionEvent.java50
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmSubscriptionStatus.java45
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/SubscriptionEventResponse.java42
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java43
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java8
22 files changed, 34 insertions, 1585 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ForwardedSubscriptionEventCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ForwardedSubscriptionEventCacheConfig.java
deleted file mode 100644
index 306d103a8f..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ForwardedSubscriptionEventCacheConfig.java
+++ /dev/null
@@ -1,52 +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.api.impl.config.embeddedcache;
-
-import com.hazelcast.config.MapConfig;
-import com.hazelcast.map.IMap;
-import java.util.Set;
-import org.onap.cps.cache.HazelcastCacheConfig;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Core infrastructure of the hazelcast distributed cache for subscription forward config use cases.
- */
-@Configuration
-public class ForwardedSubscriptionEventCacheConfig extends HazelcastCacheConfig {
-
- public static final int SUBSCRIPTION_FORWARD_STARTED_TTL_SECS = 600;
-
- private static final MapConfig forwardedSubscriptionEventCacheMapConfig =
- createMapConfig("forwardedSubscriptionEventCacheMapConfig");
-
- /**
- * Distributed instance of forwarded subscription information cache that contains subscription event
- * id by dmi names as properties.
- *
- * @return configured map of subscription event ids as keys to sets of dmi names for values
- */
- @Bean
- public IMap<String, Set<String>> forwardedSubscriptionEventCache() {
- return createHazelcastInstance("hazelCastInstanceSubscriptionEvents",
- forwardedSubscriptionEventCacheMapConfig).getMap("forwardedSubscriptionEventCache");
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionPersistence.java
deleted file mode 100644
index 7aa073d356..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionPersistence.java
+++ /dev/null
@@ -1,50 +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.api.impl.deprecated.subscriptions;
-
-import java.util.Collection;
-import org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence;
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
-import org.onap.cps.spi.model.DataNode;
-
-public interface SubscriptionPersistence extends NcmpPersistence {
-
- /**
- * Save subscription Event.
- *
- * @param yangModelSubscriptionEvent subscription Event as Yang Model.
- */
- void saveSubscriptionEvent(YangModelSubscriptionEvent yangModelSubscriptionEvent);
-
- /**
- * Get data nodes.
- *
- * @return the DataNode as collection.
- */
- Collection<DataNode> getDataNodesForSubscriptionEvent();
-
- /**
- * Get data nodes by xpath.
- *
- * @return the DataNode as collection.
- */
- Collection<DataNode> getCmHandlesForSubscriptionEvent(String clientId, String subscriptionName);
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionPersistenceImpl.java
deleted file mode 100644
index 29b7c7d044..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionPersistenceImpl.java
+++ /dev/null
@@ -1,199 +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.api.impl.deprecated.subscriptions;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsDataService;
-import org.onap.cps.api.CpsModuleService;
-import org.onap.cps.ncmp.api.impl.inventory.NcmpPersistenceImpl;
-import org.onap.cps.ncmp.api.impl.utils.DataNodeHelper;
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
-import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.model.DataNode;
-import org.onap.cps.spi.utils.CpsValidator;
-import org.onap.cps.utils.JsonObjectMapper;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-public class SubscriptionPersistenceImpl extends NcmpPersistenceImpl implements SubscriptionPersistence {
-
- private static final String SUBSCRIPTION_ANCHOR_NAME = "AVC-Subscriptions";
- private static final String SUBSCRIPTION_REGISTRY_PARENT = "/subscription-registry";
-
- public SubscriptionPersistenceImpl(final JsonObjectMapper jsonObjectMapper, final CpsDataService cpsDataService,
- final CpsModuleService cpsModuleService, final CpsValidator cpsValidator) {
- super(jsonObjectMapper, cpsDataService, cpsModuleService, cpsValidator);
- }
-
-
- @Override
- public void saveSubscriptionEvent(final YangModelSubscriptionEvent yangModelSubscriptionEvent) {
- final String clientId = yangModelSubscriptionEvent.getClientId();
- final String subscriptionName = yangModelSubscriptionEvent.getSubscriptionName();
-
- final Collection<DataNode> dataNodes = cpsDataService.getDataNodes(NCMP_DATASPACE_NAME,
- SUBSCRIPTION_ANCHOR_NAME, SUBSCRIPTION_REGISTRY_PARENT, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
-
- if (isSubscriptionRegistryEmptyOrNonExist(dataNodes, clientId, subscriptionName)) {
- saveSubscriptionEventYangModel(createSubscriptionEventJsonData(
- jsonObjectMapper.asJsonString(yangModelSubscriptionEvent)));
- } else {
- findDeltaCmHandlesAddOrUpdateInDatabase(yangModelSubscriptionEvent, clientId, subscriptionName, dataNodes);
- }
- }
-
- private void findDeltaCmHandlesAddOrUpdateInDatabase(final YangModelSubscriptionEvent yangModelSubscriptionEvent,
- final String clientId, final String subscriptionName,
- final Collection<DataNode> dataNodes) {
- final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMapNew =
- extractCmHandleFromYangModelAsMap(yangModelSubscriptionEvent);
- final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMapOriginal =
- DataNodeHelper.cmHandleIdToStatusAndDetailsAsMapFromDataNode(dataNodes);
-
- final Map<String, Map<String, String>> newTargetCmHandles = mapDifference(cmHandleIdToStatusAndDetailsAsMapNew,
- cmHandleIdToStatusAndDetailsAsMapOriginal);
- traverseCmHandleList(newTargetCmHandles, clientId, subscriptionName, true);
-
- final Map<String, Map<String, String>> existingTargetCmHandles =
- mapDifference(cmHandleIdToStatusAndDetailsAsMapNew, newTargetCmHandles);
- traverseCmHandleList(existingTargetCmHandles, clientId, subscriptionName, false);
- }
-
- private static Map<String, Map<String, String>> extractCmHandleFromYangModelAsMap(
- final YangModelSubscriptionEvent yangModelSubscriptionEvent) {
- return yangModelSubscriptionEvent.getPredicates().getTargetCmHandles()
- .stream().collect(
- HashMap::new,
- (result, cmHandle) -> {
- final String cmHandleId = cmHandle.getCmHandleId();
- final SubscriptionStatus status = cmHandle.getStatus();
- final String details = cmHandle.getDetails();
-
- if (cmHandleId != null && status != null) {
- result.put(cmHandleId, new HashMap<>());
- result.get(cmHandleId).put("status", status.toString());
- result.get(cmHandleId).put("details", details == null ? "" : details);
- }
- },
- HashMap::putAll
- );
- }
-
- private void traverseCmHandleList(final Map<String, Map<String, String>> cmHandleMap,
- final String clientId,
- final String subscriptionName,
- final boolean isAddListElementOperation) {
- final List<YangModelSubscriptionEvent.TargetCmHandle> cmHandleList = targetCmHandlesAsList(cmHandleMap);
- for (final YangModelSubscriptionEvent.TargetCmHandle targetCmHandle : cmHandleList) {
- final String targetCmHandleAsJson =
- createTargetCmHandleJsonData(jsonObjectMapper.asJsonString(targetCmHandle));
- addOrReplaceCmHandlePredicateListElement(targetCmHandleAsJson, clientId, subscriptionName,
- isAddListElementOperation);
- }
- }
-
- private boolean isSubscriptionRegistryEmptyOrNonExist(final Collection<DataNode> dataNodes,
- final String clientId, final String subscriptionName) {
- final Optional<DataNode> dataNodeFirst = dataNodes.stream().findFirst();
- return ((dataNodeFirst.isPresent() && dataNodeFirst.get().getChildDataNodes().isEmpty())
- || getCmHandlesForSubscriptionEvent(clientId, subscriptionName).isEmpty());
- }
-
- private void addOrReplaceCmHandlePredicateListElement(final String targetCmHandleAsJson,
- final String clientId,
- final String subscriptionName,
- final boolean isAddListElementOperation) {
- if (isAddListElementOperation) {
- log.info("targetCmHandleAsJson to be added into DB {}", targetCmHandleAsJson);
- cpsDataService.saveListElements(NCMP_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
- createCmHandleXpathPredicates(clientId, subscriptionName), targetCmHandleAsJson, NO_TIMESTAMP);
- } else {
- log.info("targetCmHandleAsJson to be updated into DB {}", targetCmHandleAsJson);
- cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
- createCmHandleXpathPredicates(clientId, subscriptionName), targetCmHandleAsJson, NO_TIMESTAMP);
- }
- }
-
- private void saveSubscriptionEventYangModel(final String subscriptionEventJsonData) {
- log.info("SubscriptionEventJsonData to be saved into DB {}", subscriptionEventJsonData);
- cpsDataService.saveListElements(NCMP_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
- SUBSCRIPTION_REGISTRY_PARENT, subscriptionEventJsonData, NO_TIMESTAMP);
- }
-
- @Override
- public Collection<DataNode> getDataNodesForSubscriptionEvent() {
- return cpsDataService.getDataNodes(NCMP_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
- SUBSCRIPTION_REGISTRY_PARENT, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
- }
-
- @Override
- public Collection<DataNode> getCmHandlesForSubscriptionEvent(final String clientId, final String subscriptionName) {
- return cpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
- List.of(createCmHandleXpath(clientId, subscriptionName)),
- FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
- }
-
- private static List<YangModelSubscriptionEvent.TargetCmHandle> targetCmHandlesAsList(
- final Map<String, Map<String, String>> newCmHandles) {
- return newCmHandles.entrySet().stream().map(entry -> {
- final String cmHandleId = entry.getKey();
- final Map<String, String> statusAndDetailsMap = entry.getValue();
- final String status = statusAndDetailsMap.get("status");
- final String details = statusAndDetailsMap.get("details");
- return new YangModelSubscriptionEvent.TargetCmHandle(cmHandleId, SubscriptionStatus.fromString(status),
- details);
- }).collect(Collectors.toList());
- }
-
- private static String createSubscriptionEventJsonData(final String yangModelSubscriptionAsJson) {
- return "{\"subscription\":[" + yangModelSubscriptionAsJson + "]}";
- }
-
- private static String createTargetCmHandleJsonData(final String targetCmHandleAsJson) {
- return "{\"targetCmHandles\":[" + targetCmHandleAsJson + "]}";
- }
-
- private static String createCmHandleXpathPredicates(final String clientId, final String subscriptionName) {
- return "/subscription-registry/subscription[@clientID='" + clientId
- + "' and @subscriptionName='" + subscriptionName + "']/predicates";
- }
-
- private static String createCmHandleXpath(final String clientId, final String subscriptionName) {
- return "/subscription-registry/subscription[@clientID='" + clientId
- + "' and @subscriptionName='" + subscriptionName + "']";
- }
-
- private static <K, L, M> Map<K, Map<L, M>> mapDifference(final Map<K, Map<L, M>> left,
- final Map<K, Map<L, M>> right) {
- final Map<K, Map<L, M>> difference = new HashMap<>();
- difference.putAll(left);
- difference.putAll(right);
- difference.entrySet().removeAll(right.entrySet());
- return difference;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionStatus.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionStatus.java
deleted file mode 100644
index 023e8de527..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/deprecated/subscriptions/SubscriptionStatus.java
+++ /dev/null
@@ -1,49 +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.api.impl.deprecated.subscriptions;
-
-
-public enum SubscriptionStatus {
- ACCEPTED("ACCEPTED"),
- REJECTED("REJECTED"),
- PENDING("PENDING");
-
- private final String subscriptionStatusValue;
-
- SubscriptionStatus(final String subscriptionStatusValue) {
- this.subscriptionStatusValue = subscriptionStatusValue;
- }
-
- /**
- * Finds the value of the given enum.
- *
- * @param statusValue value of the enum
- * @return a SubscriptionStatus
- */
- public static SubscriptionStatus fromString(final String statusValue) {
- for (final SubscriptionStatus subscriptionStatusType : SubscriptionStatus.values()) {
- if (subscriptionStatusType.subscriptionStatusValue.equalsIgnoreCase(statusValue)) {
- return subscriptionStatusType;
- }
- }
- return null;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionDmiOutEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionDmiOutEventConsumer.java
deleted file mode 100644
index 307940c19e..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionDmiOutEventConsumer.java
+++ /dev/null
@@ -1,104 +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.api.impl.events.deprecated.cmsubscription;
-
-import static org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper.toTargetEvent;
-
-import com.hazelcast.map.IMap;
-import io.cloudevents.CloudEvent;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.kafka.clients.consumer.ConsumerRecord;
-import org.onap.cps.ncmp.api.impl.config.embeddedcache.ForwardedSubscriptionEventCacheConfig;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionPersistence;
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
-import org.onap.cps.ncmp.api.models.CmSubscriptionEvent;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.dmi_to_ncmp.CmSubscriptionDmiOutEvent;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.kafka.annotation.KafkaListener;
-import org.springframework.stereotype.Component;
-
-@Component
-@Slf4j
-@RequiredArgsConstructor
-public class CmSubscriptionDmiOutEventConsumer {
-
- private final IMap<String, Set<String>> forwardedSubscriptionEventCache;
- private final SubscriptionPersistence subscriptionPersistence;
- private final CmSubscriptionDmiOutEventToYangModelSubscriptionEventMapper
- cmSubscriptionDmiOutEventToYangModelSubscriptionEventMapper;
- private final CmSubscriptionNcmpOutEventPublisher cmSubscriptionNcmpOutEventPublisher;
-
- @Value("${notification.enabled:true}")
- private boolean notificationFeatureEnabled;
-
- @Value("${ncmp.model-loader.subscription:false}")
- private boolean subscriptionModelLoaderEnabled;
-
- /**
- * Consume subscription response event.
- *
- * @param cmSubscriptionDmiOutConsumerRecord the event to be consumed
- */
- @KafkaListener(topics = "${app.ncmp.avc.subscription-response-topic}",
- containerFactory = "cloudEventConcurrentKafkaListenerContainerFactory")
- public void consumeDmiOutEvent(
- final ConsumerRecord<String, CloudEvent> cmSubscriptionDmiOutConsumerRecord) {
- final CloudEvent cloudEvent = cmSubscriptionDmiOutConsumerRecord.value();
- final String eventType = cmSubscriptionDmiOutConsumerRecord.value().getType();
- final CmSubscriptionDmiOutEvent cmSubscriptionDmiOutEvent =
- toTargetEvent(cloudEvent, CmSubscriptionDmiOutEvent.class);
- final String clientId = cmSubscriptionDmiOutEvent.getData().getClientId();
- log.info("subscription event response of clientId: {} is received.", clientId);
- final String subscriptionName = cmSubscriptionDmiOutEvent.getData().getSubscriptionName();
- final String subscriptionEventId = clientId + subscriptionName;
- boolean createOutcomeResponse = true;
- if (forwardedSubscriptionEventCache.containsKey(subscriptionEventId)) {
- final Set<String> dmiNames = forwardedSubscriptionEventCache.get(subscriptionEventId);
- dmiNames.remove(cmSubscriptionDmiOutEvent.getData().getDmiName());
- forwardedSubscriptionEventCache.put(subscriptionEventId, dmiNames,
- ForwardedSubscriptionEventCacheConfig.SUBSCRIPTION_FORWARD_STARTED_TTL_SECS, TimeUnit.SECONDS);
- createOutcomeResponse = forwardedSubscriptionEventCache.get(subscriptionEventId).isEmpty();
- }
- if (subscriptionModelLoaderEnabled) {
- updateSubscriptionEvent(cmSubscriptionDmiOutEvent);
- }
- if (createOutcomeResponse
- && notificationFeatureEnabled) {
-
- final CmSubscriptionEvent cmSubscriptionEvent = new CmSubscriptionEvent();
- cmSubscriptionEvent.setClientId(cmSubscriptionDmiOutEvent.getData().getClientId());
- cmSubscriptionEvent.setSubscriptionName(cmSubscriptionDmiOutEvent.getData().getSubscriptionName());
-
- cmSubscriptionNcmpOutEventPublisher.sendResponse(cmSubscriptionEvent, eventType);
- forwardedSubscriptionEventCache.remove(subscriptionEventId);
- }
- }
-
- private void updateSubscriptionEvent(final CmSubscriptionDmiOutEvent cmSubscriptionDmiOutEvent) {
- final YangModelSubscriptionEvent yangModelSubscriptionEvent =
- cmSubscriptionDmiOutEventToYangModelSubscriptionEventMapper
- .toYangModelSubscriptionEvent(cmSubscriptionDmiOutEvent);
- subscriptionPersistence.saveSubscriptionEvent(yangModelSubscriptionEvent);
- }
-} \ No newline at end of file
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionDmiOutEventToYangModelSubscriptionEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionDmiOutEventToYangModelSubscriptionEventMapper.java
deleted file mode 100644
index e2999950e5..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionDmiOutEventToYangModelSubscriptionEventMapper.java
+++ /dev/null
@@ -1,56 +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.api.impl.events.deprecated.cmsubscription;
-
-import java.util.List;
-import java.util.stream.Collectors;
-import org.mapstruct.Mapper;
-import org.mapstruct.Mapping;
-import org.mapstruct.Named;
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.dmi_to_ncmp.CmSubscriptionDmiOutEvent;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.dmi_to_ncmp.SubscriptionStatus;
-
-@Mapper(componentModel = "spring")
-public interface CmSubscriptionDmiOutEventToYangModelSubscriptionEventMapper {
-
- @Mapping(source = "data.clientId", target = "clientId")
- @Mapping(source = "data.subscriptionName", target = "subscriptionName")
- @Mapping(source = "data.subscriptionStatus", target = "predicates.targetCmHandles",
- qualifiedByName = "mapSubscriptionStatusToCmHandleTargets")
- YangModelSubscriptionEvent toYangModelSubscriptionEvent(
- CmSubscriptionDmiOutEvent cmSubscriptionDmiOutEvent);
-
- /**
- * Maps SubscriptionStatus to list of TargetCmHandle.
- *
- * @param subscriptionStatus as a list
- * @return TargetCmHandle list
- */
- @Named("mapSubscriptionStatusToCmHandleTargets")
- default List<YangModelSubscriptionEvent.TargetCmHandle> mapSubscriptionStatusToCmHandleTargets(
- List<SubscriptionStatus> subscriptionStatus) {
- return subscriptionStatus.stream().map(status -> new YangModelSubscriptionEvent.TargetCmHandle(status.getId(),
- org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus.fromString(
- status.getStatus().value()),
- status.getDetails())).collect(Collectors.toList());
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionEventToCmSubscriptionNcmpOutEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionEventToCmSubscriptionNcmpOutEventMapper.java
deleted file mode 100644
index 0de04ade7b..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionEventToCmSubscriptionNcmpOutEventMapper.java
+++ /dev/null
@@ -1,105 +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.api.impl.events.deprecated.cmsubscription;
-
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import org.mapstruct.Mapper;
-import org.mapstruct.Mapping;
-import org.mapstruct.Named;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus;
-import org.onap.cps.ncmp.api.models.CmSubscriptionEvent;
-import org.onap.cps.ncmp.api.models.CmSubscriptionStatus;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_client.AdditionalInfo;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_client.AdditionalInfoDetail;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_client.CmSubscriptionNcmpOutEvent;
-import org.onap.cps.spi.exceptions.DataValidationException;
-
-@Mapper(componentModel = "spring")
-public interface CmSubscriptionEventToCmSubscriptionNcmpOutEventMapper {
-
- @Mapping(source = "cmSubscriptionStatus", target = "data.additionalInfo",
- qualifiedByName = "mapCmSubscriptionStatusToAdditionalInfo")
- CmSubscriptionNcmpOutEvent toCmSubscriptionNcmpOutEvent(CmSubscriptionEvent cmSubscriptionEvent);
-
- /**
- * Maps list of SubscriptionStatus to an AdditionalInfo.
- *
- * @param cmSubscriptionStatusList containing details
- * @return an AdditionalInfo
- */
- @Named("mapCmSubscriptionStatusToAdditionalInfo")
- default AdditionalInfo mapCmSubscriptionStatusToAdditionalInfo(
- final List<CmSubscriptionStatus> cmSubscriptionStatusList) {
- if (cmSubscriptionStatusList == null || cmSubscriptionStatusList.isEmpty()) {
- throw new DataValidationException("Invalid cmSubscriptionStatusList",
- "CmSubscriptionStatus list cannot be null or empty");
- }
-
- final Map<String, List<CmSubscriptionStatus>> rejectedSubscriptionsPerDetails =
- getSubscriptionsPerDetails(cmSubscriptionStatusList, SubscriptionStatus.REJECTED);
- final Map<String, List<String>> rejectedCmHandlesPerDetails =
- getCmHandlesPerDetails(rejectedSubscriptionsPerDetails);
- final List<AdditionalInfoDetail> rejectedCmHandles = getAdditionalInfoDetailList(rejectedCmHandlesPerDetails);
-
- final Map<String, List<CmSubscriptionStatus>> pendingSubscriptionsPerDetails =
- getSubscriptionsPerDetails(cmSubscriptionStatusList, SubscriptionStatus.PENDING);
- final Map<String, List<String>> pendingCmHandlesPerDetails =
- getCmHandlesPerDetails(pendingSubscriptionsPerDetails);
- final List<AdditionalInfoDetail> pendingCmHandles = getAdditionalInfoDetailList(pendingCmHandlesPerDetails);
-
- final AdditionalInfo additionalInfo = new AdditionalInfo();
- additionalInfo.setRejected(rejectedCmHandles);
- additionalInfo.setPending(pendingCmHandles);
-
- return additionalInfo;
- }
-
- private static Map<String, List<CmSubscriptionStatus>> getSubscriptionsPerDetails(
- final List<CmSubscriptionStatus> cmSubscriptionStatusList, final SubscriptionStatus status) {
- return cmSubscriptionStatusList.stream()
- .filter(subscriptionStatus -> subscriptionStatus.getStatus() == status)
- .collect(Collectors.groupingBy(CmSubscriptionStatus::getDetails));
- }
-
- private static Map<String, List<String>> getCmHandlesPerDetails(
- final Map<String, List<CmSubscriptionStatus>> cmSubscriptionsPerDetails) {
- return cmSubscriptionsPerDetails.entrySet().stream()
- .collect(Collectors.toMap(
- Map.Entry::getKey,
- entry -> entry.getValue().stream()
- .map(CmSubscriptionStatus::getId)
- .collect(Collectors.toList())
- ));
- }
-
- private static List<AdditionalInfoDetail> getAdditionalInfoDetailList(
- final Map<String, List<String>> cmHandlesPerDetails) {
- return cmHandlesPerDetails.entrySet().stream()
- .map(entry -> {
- final AdditionalInfoDetail detail = new AdditionalInfoDetail();
- detail.setDetails(entry.getKey());
- detail.setTargets(entry.getValue());
- return detail;
- }).collect(Collectors.toList());
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventConsumer.java
deleted file mode 100644
index 7227af91a6..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventConsumer.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-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.api.impl.events.deprecated.cmsubscription;
-
-import static org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper.toTargetEvent;
-import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL;
-import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING;
-
-import io.cloudevents.CloudEvent;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.kafka.clients.consumer.ConsumerRecord;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionPersistence;
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.client_to_ncmp.CmSubscriptionNcmpInEvent;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.kafka.annotation.KafkaListener;
-import org.springframework.stereotype.Component;
-
-
-@Component
-@Slf4j
-@RequiredArgsConstructor
-public class CmSubscriptionNcmpInEventConsumer {
-
- private final CmSubscriptionNcmpInEventForwarder cmSubscriptionNcmpInEventForwarder;
- private final CmSubscriptionNcmpInEventMapper cmSubscriptionNcmpInEventMapper;
- private final SubscriptionPersistence subscriptionPersistence;
-
- @Value("${notification.enabled:true}")
- private boolean notificationFeatureEnabled;
-
- @Value("${ncmp.model-loader.subscription:false}")
- private boolean subscriptionModelLoaderEnabled;
-
- /**
- * Consume the specified event.
- *
- * @param subscriptionEventConsumerRecord the event to be consumed
- */
- @KafkaListener(topics = "${app.ncmp.avc.subscription-topic}",
- containerFactory = "cloudEventConcurrentKafkaListenerContainerFactory")
- public void consumeSubscriptionEvent(final ConsumerRecord<String, CloudEvent> subscriptionEventConsumerRecord) {
- final CloudEvent cloudEvent = subscriptionEventConsumerRecord.value();
- final String eventType = subscriptionEventConsumerRecord.value().getType();
- final CmSubscriptionNcmpInEvent cmSubscriptionNcmpInEvent =
- toTargetEvent(cloudEvent, CmSubscriptionNcmpInEvent.class);
- final String eventDatastore = cmSubscriptionNcmpInEvent.getData().getPredicates().getDatastore();
- if (!eventDatastore.equals(PASSTHROUGH_RUNNING.getDatastoreName()) || eventDatastore.equals(
- PASSTHROUGH_OPERATIONAL.getDatastoreName())) {
- throw new UnsupportedOperationException(
- "passthrough datastores are currently only supported for event subscriptions");
- }
- if ("CM".equals(cmSubscriptionNcmpInEvent.getData().getDataType().getDataCategory())) {
- if (subscriptionModelLoaderEnabled) {
- persistSubscriptionEvent(cmSubscriptionNcmpInEvent);
- }
- if ("subscriptionCreated".equals(cloudEvent.getType())) {
- log.info("Subscription for ClientID {} with name {} ...",
- cmSubscriptionNcmpInEvent.getData().getSubscription().getClientID(),
- cmSubscriptionNcmpInEvent.getData().getSubscription().getName());
- if (notificationFeatureEnabled) {
- cmSubscriptionNcmpInEventForwarder.forwardCreateSubscriptionEvent(cmSubscriptionNcmpInEvent,
- eventType);
- }
- }
- } else {
- log.trace("Non-CM subscription event ignored");
- }
- }
-
- private void persistSubscriptionEvent(final CmSubscriptionNcmpInEvent cmSubscriptionNcmpInEvent) {
- final YangModelSubscriptionEvent yangModelSubscriptionEvent =
- cmSubscriptionNcmpInEventMapper.toYangModelSubscriptionEvent(cmSubscriptionNcmpInEvent);
- subscriptionPersistence.saveSubscriptionEvent(yangModelSubscriptionEvent);
- }
-
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventForwarder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventForwarder.java
deleted file mode 100644
index ae192c439d..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventForwarder.java
+++ /dev/null
@@ -1,204 +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.api.impl.events.deprecated.cmsubscription;
-
-import com.hazelcast.map.IMap;
-import io.cloudevents.CloudEvent;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.impl.config.embeddedcache.ForwardedSubscriptionEventCacheConfig;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionPersistence;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus;
-import org.onap.cps.ncmp.api.impl.events.EventsPublisher;
-import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
-import org.onap.cps.ncmp.api.impl.utils.CmSubscriptionEventCloudMapper;
-import org.onap.cps.ncmp.api.impl.utils.DmiServiceNameOrganizer;
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
-import org.onap.cps.ncmp.api.models.CmSubscriptionEvent;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.client_to_ncmp.CmSubscriptionNcmpInEvent;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_dmi.CmHandle;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_dmi.CmSubscriptionDmiInEvent;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-
-@Component
-@Slf4j
-@RequiredArgsConstructor
-public class CmSubscriptionNcmpInEventForwarder {
-
- private static final Pattern REGEX_TO_EXTRACT_DOMAIN_FROM_URL_EXCLUDING_PORT =
- Pattern.compile("http[s]?:\\/\\/(?:www\\.)?([^\\/:]+):{0,1}[0-9]{0,5}");
-
- private final InventoryPersistence inventoryPersistence;
- private final EventsPublisher<CloudEvent> eventsPublisher;
- private final IMap<String, Set<String>> forwardedSubscriptionEventCache;
- private final CmSubscriptionNcmpOutEventPublisher cmSubscriptionNcmpOutEventPublisher;
- private final CmSubscriptionNcmpInEventMapper cmSubscriptionNcmpInEventMapper;
- private final CmSubscriptionEventCloudMapper cmSubscriptionEventCloudMapper;
- private final CmSubscriptionNcmpInEventToCmSubscriptionDmiInEventMapper
- cmSubscriptionNcmpInEventToCmSubscriptionDmiInEventMapper;
- private final SubscriptionPersistence subscriptionPersistence;
- private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
- @Value("${app.ncmp.avc.subscription-forward-topic-prefix}")
- private String dmiAvcSubscriptionTopicPrefix;
-
- @Value("${ncmp.timers.subscription-forwarding.dmi-response-timeout-ms:30000}")
- private int dmiResponseTimeoutInMs;
-
- /**
- * Forward subscription event.
- *
- * @param cmSubscriptionNcmpInEvent the event to be forwarded
- */
- public void forwardCreateSubscriptionEvent(final CmSubscriptionNcmpInEvent cmSubscriptionNcmpInEvent,
- final String eventType) {
- final List<String> cmHandleTargets = cmSubscriptionNcmpInEvent.getData().getPredicates().getTargets();
- if (cmHandleTargets == null || cmHandleTargets.isEmpty() || cmHandleTargets.stream()
- .anyMatch(id -> (id).contains("*"))) {
- throw new UnsupportedOperationException(
- "CMHandle targets are required. \"Wildcard\" operations are not yet supported");
- }
- final Collection<YangModelCmHandle> yangModelCmHandles =
- inventoryPersistence.getYangModelCmHandles(cmHandleTargets);
- final Map<String, Map<String, Map<String, String>>> dmiPropertiesPerCmHandleIdPerServiceName =
- DmiServiceNameOrganizer.getDmiPropertiesPerCmHandleIdPerServiceName(yangModelCmHandles);
- findDmisAndRespond(cmSubscriptionNcmpInEvent, eventType, cmHandleTargets,
- dmiPropertiesPerCmHandleIdPerServiceName);
- }
-
- private void findDmisAndRespond(final CmSubscriptionNcmpInEvent cmSubscriptionNcmpInEvent, final String eventType,
- final List<String> cmHandleTargetsAsStrings,
- final Map<String, Map<String, Map<String, String>>> dmiPropertiesPerCmHandleIdPerServiceName) {
-
- final CmSubscriptionEvent cmSubscriptionEvent = new CmSubscriptionEvent();
- cmSubscriptionEvent.setSubscriptionName(cmSubscriptionNcmpInEvent.getData().getSubscription().getName());
- cmSubscriptionEvent.setClientId(cmSubscriptionNcmpInEvent.getData().getSubscription().getClientID());
-
- final List<String> cmHandlesThatExistsInDb =
- dmiPropertiesPerCmHandleIdPerServiceName.entrySet().stream().map(Map.Entry::getValue).map(Map::keySet)
- .flatMap(Set::stream).collect(Collectors.toList());
-
- final List<String> targetCmHandlesDoesNotExistInDb = new ArrayList<>(cmHandleTargetsAsStrings);
- targetCmHandlesDoesNotExistInDb.removeAll(cmHandlesThatExistsInDb);
-
- final Set<String> dmisToRespond = new HashSet<>(dmiPropertiesPerCmHandleIdPerServiceName.keySet());
-
- if (dmisToRespond.isEmpty() || !targetCmHandlesDoesNotExistInDb.isEmpty()) {
- updatesCmHandlesToRejectedAndPersistSubscriptionEvent(cmSubscriptionNcmpInEvent,
- targetCmHandlesDoesNotExistInDb);
- }
- if (dmisToRespond.isEmpty()) {
- cmSubscriptionNcmpOutEventPublisher.sendResponse(cmSubscriptionEvent,
- "subscriptionCreatedStatus");
- } else {
- startResponseTimeout(cmSubscriptionEvent, dmisToRespond);
- final CmSubscriptionDmiInEvent cmSubscriptionDmiInEvent =
- cmSubscriptionNcmpInEventToCmSubscriptionDmiInEventMapper.toCmSubscriptionDmiInEvent(
- cmSubscriptionNcmpInEvent);
- forwardEventToDmis(dmiPropertiesPerCmHandleIdPerServiceName, cmSubscriptionDmiInEvent, eventType);
- }
- }
-
- private void startResponseTimeout(final CmSubscriptionEvent cmSubscriptionEvent,
- final Set<String> dmisToRespond) {
- final String subscriptionClientId = cmSubscriptionEvent.getClientId();
- final String subscriptionName = cmSubscriptionEvent.getSubscriptionName();
- final String subscriptionEventId = subscriptionClientId + subscriptionName;
-
- forwardedSubscriptionEventCache.put(subscriptionEventId, dmisToRespond,
- ForwardedSubscriptionEventCacheConfig.SUBSCRIPTION_FORWARD_STARTED_TTL_SECS, TimeUnit.SECONDS);
- final ResponseTimeoutTask responseTimeoutTask =
- new ResponseTimeoutTask(forwardedSubscriptionEventCache, cmSubscriptionNcmpOutEventPublisher,
- cmSubscriptionEvent);
-
- executorService.schedule(responseTimeoutTask, dmiResponseTimeoutInMs, TimeUnit.MILLISECONDS);
- }
-
- private void forwardEventToDmis(final Map<String, Map<String, Map<String, String>>> dmiNameCmHandleMap,
- final CmSubscriptionDmiInEvent cmSubscriptionDmiInEvent, final String eventType) {
- dmiNameCmHandleMap.forEach((dmiName, cmHandlePropertiesMap) -> {
- final List<CmHandle> cmHandleTargets = cmHandlePropertiesMap.entrySet().stream().map(
- cmHandleAndProperties -> {
- final CmHandle cmHandle = new CmHandle();
- cmHandle.setId(cmHandleAndProperties.getKey());
- cmHandle.setAdditionalProperties(cmHandleAndProperties.getValue());
- return cmHandle;
- }).collect(Collectors.toList());
-
- cmSubscriptionDmiInEvent.getData().getPredicates().setTargets(cmHandleTargets);
- final String dmiNameSuffix = toValidTopicSuffix(dmiName);
- final String eventKey = createEventKey(cmSubscriptionDmiInEvent, dmiNameSuffix);
- final String dmiAvcSubscriptionTopic = dmiAvcSubscriptionTopicPrefix + dmiNameSuffix;
-
- final CloudEvent cmSubscriptionDmiInCloudEvent =
- cmSubscriptionEventCloudMapper.toCloudEvent(cmSubscriptionDmiInEvent, eventKey, eventType);
- eventsPublisher.publishCloudEvent(dmiAvcSubscriptionTopic, eventKey, cmSubscriptionDmiInCloudEvent);
- });
- }
-
- private String createEventKey(final CmSubscriptionDmiInEvent cmSubscriptionDmiInEvent, final String dmiName) {
- return cmSubscriptionDmiInEvent.getData().getSubscription().getClientID() + "-"
- + cmSubscriptionDmiInEvent.getData().getSubscription().getName() + "-" + dmiName;
- }
-
- private void updatesCmHandlesToRejectedAndPersistSubscriptionEvent(
- final CmSubscriptionNcmpInEvent cmSubscriptionNcmpInEvent,
- final List<String> targetCmHandlesDoesNotExistInDb) {
- final YangModelSubscriptionEvent yangModelSubscriptionEvent =
- cmSubscriptionNcmpInEventMapper.toYangModelSubscriptionEvent(cmSubscriptionNcmpInEvent);
- yangModelSubscriptionEvent.getPredicates()
- .setTargetCmHandles(findRejectedCmHandles(targetCmHandlesDoesNotExistInDb, yangModelSubscriptionEvent));
- subscriptionPersistence.saveSubscriptionEvent(yangModelSubscriptionEvent);
- }
-
- private static List<YangModelSubscriptionEvent.TargetCmHandle> findRejectedCmHandles(
- final List<String> targetCmHandlesDoesNotExistInDb,
- final YangModelSubscriptionEvent yangModelSubscriptionEvent) {
- return yangModelSubscriptionEvent.getPredicates().getTargetCmHandles().stream()
- .filter(targetCmHandle -> targetCmHandlesDoesNotExistInDb.contains(targetCmHandle.getCmHandleId()))
- .map(target -> new YangModelSubscriptionEvent.TargetCmHandle(target.getCmHandleId(),
- SubscriptionStatus.REJECTED, "Targets not found"))
- .collect(Collectors.toList());
- }
-
- /*
- CPS-1979 : DmiName can be a URL , which is not a valid topic name.
- Hence just taking the domain name(excluding port) information to be part of the topic name.
- */
- private String toValidTopicSuffix(final String dmiName) {
- final Matcher matcher = REGEX_TO_EXTRACT_DOMAIN_FROM_URL_EXCLUDING_PORT.matcher(dmiName);
- return matcher.find() ? matcher.group(1) : dmiName;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventMapper.java
deleted file mode 100644
index 852d5510c4..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventMapper.java
+++ /dev/null
@@ -1,52 +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.api.impl.events.deprecated.cmsubscription;
-
-import java.util.List;
-import java.util.stream.Collectors;
-import org.mapstruct.Mapper;
-import org.mapstruct.Mapping;
-import org.mapstruct.Named;
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.client_to_ncmp.CmSubscriptionNcmpInEvent;
-
-@Mapper(componentModel = "spring")
-public interface CmSubscriptionNcmpInEventMapper {
-
- @Mapping(source = "data.subscription.clientID", target = "clientId")
- @Mapping(source = "data.subscription.name", target = "subscriptionName")
- @Mapping(source = "data.predicates.targets", target = "predicates.targetCmHandles",
- qualifiedByName = "mapTargetsToCmHandleTargets")
- @Mapping(source = "data.predicates.datastore", target = "predicates.datastore")
- YangModelSubscriptionEvent toYangModelSubscriptionEvent(CmSubscriptionNcmpInEvent cmSubscriptionNcmpInEvent);
-
- /**
- * Maps list of Targets to list of TargetCmHandle.
- *
- * @param targets list of objects
- * @return TargetCmHandle list
- */
- @Named("mapTargetsToCmHandleTargets")
- default List<YangModelSubscriptionEvent.TargetCmHandle> mapTargetsToCmHandleTargets(List<String> targets) {
- return targets.stream().map(YangModelSubscriptionEvent.TargetCmHandle::new)
- .collect(Collectors.toList());
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventToCmSubscriptionDmiInEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventToCmSubscriptionDmiInEventMapper.java
deleted file mode 100644
index a87508ce54..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpInEventToCmSubscriptionDmiInEventMapper.java
+++ /dev/null
@@ -1,35 +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.api.impl.events.deprecated.cmsubscription;
-
-import org.mapstruct.Mapper;
-import org.mapstruct.Mapping;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.client_to_ncmp.CmSubscriptionNcmpInEvent;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_dmi.CmSubscriptionDmiInEvent;
-
-@Mapper(componentModel = "spring")
-public interface CmSubscriptionNcmpInEventToCmSubscriptionDmiInEventMapper {
-
- @Mapping(target = "data.predicates.targets", ignore = true)
- CmSubscriptionDmiInEvent toCmSubscriptionDmiInEvent(
- CmSubscriptionNcmpInEvent cmSubscriptionNcmpInEvent);
-
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpOutEventPublisher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpOutEventPublisher.java
deleted file mode 100644
index 8a3c44da4f..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/CmSubscriptionNcmpOutEventPublisher.java
+++ /dev/null
@@ -1,146 +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.api.impl.events.deprecated.cmsubscription;
-
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.PARTIALLY_APPLIED_SUBSCRIPTION;
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.SUBSCRIPTION_NOT_APPLICABLE;
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.SUBSCRIPTION_PENDING;
-import static org.onap.cps.ncmp.api.NcmpResponseStatus.SUCCESSFULLY_APPLIED_SUBSCRIPTION;
-import static org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus.ACCEPTED;
-import static org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus.PENDING;
-import static org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus.REJECTED;
-
-import io.cloudevents.CloudEvent;
-import java.util.List;
-import java.util.Map;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.NcmpResponseStatus;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionPersistence;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus;
-import org.onap.cps.ncmp.api.impl.events.EventsPublisher;
-import org.onap.cps.ncmp.api.impl.utils.DataNodeHelper;
-import org.onap.cps.ncmp.api.impl.utils.SubscriptionOutcomeCloudMapper;
-import org.onap.cps.ncmp.api.models.CmSubscriptionEvent;
-import org.onap.cps.ncmp.api.models.CmSubscriptionStatus;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_client.CmSubscriptionNcmpOutEvent;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-@Component
-@Slf4j
-@RequiredArgsConstructor
-public class CmSubscriptionNcmpOutEventPublisher {
-
- private final SubscriptionPersistence subscriptionPersistence;
-
- private final EventsPublisher<CloudEvent> outcomeEventsPublisher;
-
- private final CmSubscriptionEventToCmSubscriptionNcmpOutEventMapper
- cmSubscriptionEventToCmSubscriptionNcmpOutEventMapper;
-
- private final SubscriptionOutcomeCloudMapper subscriptionOutcomeCloudMapper;
-
- @Value("${app.ncmp.avc.subscription-outcome-topic:subscription-response}")
- private String subscriptionOutcomeEventTopic;
-
- /**
- * This is for construction of outcome message to be published for client apps.
- *
- * @param cmSubscriptionEvent event produced by Dmi Plugin
- */
- public void sendResponse(final CmSubscriptionEvent cmSubscriptionEvent, final String eventType) {
- final CmSubscriptionNcmpOutEvent cmSubscriptionNcmpOutEvent =
- formCmSubscriptionNcmpOutEvent(cmSubscriptionEvent);
- final String subscriptionClientId = cmSubscriptionEvent.getClientId();
- final String subscriptionName = cmSubscriptionEvent.getSubscriptionName();
- final String subscriptionEventId = subscriptionClientId + subscriptionName;
- final CloudEvent subscriptionOutcomeCloudEvent =
- subscriptionOutcomeCloudMapper.toCloudEvent(cmSubscriptionNcmpOutEvent,
- subscriptionEventId, eventType);
- outcomeEventsPublisher.publishCloudEvent(subscriptionOutcomeEventTopic,
- subscriptionEventId, subscriptionOutcomeCloudEvent);
- }
-
- private CmSubscriptionNcmpOutEvent formCmSubscriptionNcmpOutEvent(
- final CmSubscriptionEvent cmSubscriptionEvent) {
- final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMap =
- DataNodeHelper.cmHandleIdToStatusAndDetailsAsMapFromDataNode(
- subscriptionPersistence.getCmHandlesForSubscriptionEvent(
- cmSubscriptionEvent.getClientId(),
- cmSubscriptionEvent.getSubscriptionName()));
- final List<CmSubscriptionStatus> cmSubscriptionStatusList =
- mapCmHandleIdStatusDetailsMapToSubscriptionStatusList(cmHandleIdToStatusAndDetailsAsMap);
- cmSubscriptionEvent.setCmSubscriptionStatus(cmSubscriptionStatusList);
- return fromCmSubscriptionEvent(cmSubscriptionEvent,
- decideOnNcmpEventResponseCodeForSubscription(cmHandleIdToStatusAndDetailsAsMap));
- }
-
- private static List<CmSubscriptionStatus> mapCmHandleIdStatusDetailsMapToSubscriptionStatusList(
- final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMap) {
- return cmHandleIdToStatusAndDetailsAsMap.entrySet()
- .stream().map(entryset -> {
- final CmSubscriptionStatus cmSubscriptionStatus = new CmSubscriptionStatus();
- final String cmHandleId = entryset.getKey();
- final Map<String, String> statusAndDetailsMap = entryset.getValue();
- final String status = statusAndDetailsMap.get("status");
- final String details = statusAndDetailsMap.get("details");
- cmSubscriptionStatus.setId(cmHandleId);
- cmSubscriptionStatus.setStatus(SubscriptionStatus.fromString(status));
- cmSubscriptionStatus.setDetails(details);
- return cmSubscriptionStatus;
- }).toList();
- }
-
- private NcmpResponseStatus decideOnNcmpEventResponseCodeForSubscription(
- final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMap) {
-
- if (allTargetsHaveStatus(cmHandleIdToStatusAndDetailsAsMap, ACCEPTED)) {
- return SUCCESSFULLY_APPLIED_SUBSCRIPTION;
- }
- if (allTargetsHaveStatus(cmHandleIdToStatusAndDetailsAsMap, REJECTED)) {
- return SUBSCRIPTION_NOT_APPLICABLE;
- }
- if (allTargetsHaveStatus(cmHandleIdToStatusAndDetailsAsMap, PENDING)) {
- return SUBSCRIPTION_PENDING;
- }
- return PARTIALLY_APPLIED_SUBSCRIPTION;
- }
-
- private boolean allTargetsHaveStatus(final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMap,
- final SubscriptionStatus subscriptionStatus) {
- return cmHandleIdToStatusAndDetailsAsMap.values().stream()
- .allMatch(entryset -> entryset.containsValue(subscriptionStatus.toString()));
- }
-
- private CmSubscriptionNcmpOutEvent fromCmSubscriptionEvent(
- final CmSubscriptionEvent cmSubscriptionEvent,
- final NcmpResponseStatus ncmpResponseStatus) {
-
- final CmSubscriptionNcmpOutEvent cmSubscriptionNcmpOutEvent =
- cmSubscriptionEventToCmSubscriptionNcmpOutEventMapper.toCmSubscriptionNcmpOutEvent(
- cmSubscriptionEvent);
- cmSubscriptionNcmpOutEvent.getData().setStatusCode(Integer.parseInt(ncmpResponseStatus.getCode()));
- cmSubscriptionNcmpOutEvent.getData().setStatusMessage(ncmpResponseStatus.getMessage());
-
- return cmSubscriptionNcmpOutEvent;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/ResponseTimeoutTask.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/ResponseTimeoutTask.java
deleted file mode 100644
index 8832ca3d04..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/deprecated/cmsubscription/ResponseTimeoutTask.java
+++ /dev/null
@@ -1,52 +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.api.impl.events.deprecated.cmsubscription;
-
-import com.hazelcast.map.IMap;
-import java.util.Set;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.models.CmSubscriptionEvent;
-
-@Slf4j
-@RequiredArgsConstructor
-public class ResponseTimeoutTask implements Runnable {
-
- private final IMap<String, Set<String>> forwardedSubscriptionEventCache;
- private final CmSubscriptionNcmpOutEventPublisher cmSubscriptionNcmpOutEventPublisher;
- private final CmSubscriptionEvent cmSubscriptionEvent;
-
- @Override
- public void run() {
- generateTimeoutResponse();
- }
-
- private void generateTimeoutResponse() {
- final String subscriptionClientId = cmSubscriptionEvent.getClientId();
- final String subscriptionName = cmSubscriptionEvent.getSubscriptionName();
- final String subscriptionEventId = subscriptionClientId + subscriptionName;
- if (forwardedSubscriptionEventCache.containsKey(subscriptionEventId)) {
- cmSubscriptionNcmpOutEventPublisher.sendResponse(cmSubscriptionEvent,
- "subscriptionCreatedStatus");
- forwardedSubscriptionEventCache.remove(subscriptionEventId);
- }
- }
-} \ No newline at end of file
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmSubscriptionEventCloudMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmSubscriptionEventCloudMapper.java
deleted file mode 100644
index 8e565d2200..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmSubscriptionEventCloudMapper.java
+++ /dev/null
@@ -1,63 +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.api.impl.utils;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.cloudevents.CloudEvent;
-import io.cloudevents.core.builder.CloudEventBuilder;
-import java.net.URI;
-import java.util.UUID;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_dmi.CmSubscriptionDmiInEvent;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class CmSubscriptionEventCloudMapper {
-
- private final ObjectMapper objectMapper;
-
- private static String randomId = UUID.randomUUID().toString();
-
- /**
- * Maps CmSubscriptionDmiInEvent to a CloudEvent.
- *
- * @param cmSubscriptionDmiInEvent object.
- * @param eventKey as String.
- * @return CloudEvent built.
- */
- public CloudEvent toCloudEvent(final CmSubscriptionDmiInEvent cmSubscriptionDmiInEvent, final String eventKey,
- final String eventType) {
- try {
- return CloudEventBuilder.v1().withId(randomId)
- .withSource(URI.create(cmSubscriptionDmiInEvent.getData().getSubscription().getClientID()))
- .withType(eventType).withExtension("correlationid", eventKey)
- .withDataSchema(URI.create("urn:cps:" + CmSubscriptionDmiInEvent.class.getName() + ":1.0.0"))
- .withData(objectMapper.writeValueAsBytes(cmSubscriptionDmiInEvent)).build();
- } catch (final JsonProcessingException jsonProcessingException) {
- log.error("The Cloud Event could not be constructed", jsonProcessingException);
- }
- return null;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java
deleted file mode 100644
index af629a6bd1..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java
+++ /dev/null
@@ -1,64 +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.api.impl.utils;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.cloudevents.CloudEvent;
-import io.cloudevents.core.builder.CloudEventBuilder;
-import java.net.URI;
-import java.util.UUID;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.events.cmsubscription1_0_0.ncmp_to_client.CmSubscriptionNcmpOutEvent;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class SubscriptionOutcomeCloudMapper {
-
- private final ObjectMapper objectMapper;
-
- private static String randomId = UUID.randomUUID().toString();
-
- /**
- * Maps CmSubscriptionNcmpOutEvent to a CloudEvent.
- *
- * @param cmSubscriptionNcmpOutEvent object
- * @return CloudEvent
- */
- public CloudEvent toCloudEvent(final CmSubscriptionNcmpOutEvent cmSubscriptionNcmpOutEvent,
- final String eventKey, final String eventType) {
- try {
- return CloudEventBuilder.v1()
- .withId(randomId)
- .withSource(URI.create("NCMP"))
- .withType(eventType)
- .withExtension("correlationid", eventKey)
- .withDataSchema(URI.create("urn:cps:" + CmSubscriptionNcmpOutEvent.class.getName() + ":1.0.0"))
- .withData(objectMapper.writeValueAsBytes(cmSubscriptionNcmpOutEvent)).build();
- } catch (final JsonProcessingException jsonProcessingException) {
- log.error("The Cloud Event could not be constructed", jsonProcessingException);
- }
- return null;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelSubscriptionEvent.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelSubscriptionEvent.java
deleted file mode 100644
index a6cfa7bb73..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelSubscriptionEvent.java
+++ /dev/null
@@ -1,100 +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.api.impl.yangmodels;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.List;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus;
-
-/**
- * Subscription event model to persist data into DB.
- * Yang model subscription event
- */
-@Getter
-@Setter
-@NoArgsConstructor
-@JsonInclude(Include.NON_NULL)
-@EqualsAndHashCode(onlyExplicitlyIncluded = true)
-public class YangModelSubscriptionEvent {
-
- @EqualsAndHashCode.Include
- @JsonProperty("clientID")
- private String clientId;
-
- @EqualsAndHashCode.Include
- @JsonProperty("subscriptionName")
- private String subscriptionName;
-
- private String topic;
-
- @JsonProperty("isTagged")
- private boolean isTagged;
-
- private Predicates predicates;
-
-
- @Data
- @JsonInclude(JsonInclude.Include.NON_NULL)
- public static class Predicates {
-
- private String datastore;
-
- private List<TargetCmHandle> targetCmHandles;
-
- }
-
- @AllArgsConstructor
- @Data
- @JsonInclude(JsonInclude.Include.NON_NULL)
- public static class TargetCmHandle {
-
- @JsonProperty()
- private final String cmHandleId;
-
- @JsonProperty()
- private final SubscriptionStatus status;
-
- @JsonProperty()
- private final String details;
-
- /**
- * Constructor with single parameter for TargetCmHandle.
- *
- * @param cmHandleId as cm handle id
- */
- public TargetCmHandle(final String cmHandleId) {
- this.cmHandleId = cmHandleId;
- this.status = SubscriptionStatus.PENDING;
- this.details = "Subscription forwarded to dmi plugin";
- }
- }
-}
-
-
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmSubscriptionEvent.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmSubscriptionEvent.java
deleted file mode 100644
index c20696a8b6..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmSubscriptionEvent.java
+++ /dev/null
@@ -1,50 +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.api.models;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import jakarta.validation.Valid;
-import jakarta.validation.constraints.NotNull;
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@Getter
-@Setter
-public class CmSubscriptionEvent {
-
- @JsonProperty("clientId")
- @NotNull
- private String clientId;
-
- @JsonProperty("subscriptionName")
- @NotNull
- private String subscriptionName;
-
- @JsonProperty("cmSubscriptionStatus")
- @Valid
- @NotNull
- private List<CmSubscriptionStatus> cmSubscriptionStatus = new ArrayList<>();
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmSubscriptionStatus.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmSubscriptionStatus.java
deleted file mode 100644
index c56912376f..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmSubscriptionStatus.java
+++ /dev/null
@@ -1,45 +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.api.models;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import jakarta.validation.constraints.NotNull;
-import lombok.Getter;
-import lombok.Setter;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus;
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@Getter
-@Setter
-public class CmSubscriptionStatus {
-
- @JsonProperty("id")
- @NotNull
- private String id;
-
- @JsonProperty("status")
- @NotNull
- private SubscriptionStatus status;
-
- @JsonProperty("details")
- private String details;
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/SubscriptionEventResponse.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/SubscriptionEventResponse.java
deleted file mode 100644
index cabd8683ff..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/SubscriptionEventResponse.java
+++ /dev/null
@@ -1,42 +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.api.models;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-import org.onap.cps.ncmp.api.impl.deprecated.subscriptions.SubscriptionStatus;
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@Getter
-@Setter
-public class SubscriptionEventResponse {
- @JsonProperty("clientId")
- private String clientId;
- @JsonProperty("subscriptionName")
- private String subscriptionName;
- @JsonProperty("dmiName")
- private String dmiName;
- @JsonProperty("cmHandleIdToStatus")
- private Map<String, SubscriptionStatus> cmHandleIdToStatus;
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
index bd8dec4dc8..a3ebec3c54 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation
+ * Copyright (C) 2023-2024 Nordix Foundation
* ================================================================================
* 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,8 @@ abstract class AbstractModelLoader implements ModelLoader {
private final CpsDataspaceService cpsDataspaceService;
private final CpsModuleService cpsModuleService;
- private final CpsDataService cpsDataService;
private final CpsAnchorService cpsAnchorService;
+ protected final CpsDataService cpsDataService;
private static final int EXIT_CODE_ON_ERROR = 1;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java
index c0f0279ad4..88ba5e91be 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation
+ * Copyright (C) 2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +21,16 @@
package org.onap.cps.ncmp.init;
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME;
+import static org.onap.cps.utils.ContentType.JSON;
+import java.time.OffsetDateTime;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsDataspaceService;
import org.onap.cps.api.CpsModuleService;
+import org.onap.cps.ncmp.api.impl.exception.NcmpStartUpException;
+import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -38,19 +42,14 @@ public class CmDataSubscriptionModelLoader extends AbstractModelLoader {
private static final String SCHEMASET_NAME = "cm-data-subscriptions";
private static final String ANCHOR_NAME = "cm-data-subscriptions";
private static final String REGISTRY_DATANODE_NAME = "datastores";
-
- private static final String DEPRECATED_MODEL_FILENAME = "subscription.yang";
- private static final String DEPRECATED_ANCHOR_NAME = "AVC-Subscriptions";
- private static final String DEPRECATED_SCHEMASET_NAME = "subscriptions";
- private static final String DEPRECATED_REGISTRY_DATANODE_NAME = "subscription-registry";
-
-
+ private static final String DATASTORE_PASSTHROUGH_OPERATIONAL = "ncmp-datastores:passthrough-operational";
+ private static final String DATASTORE_PASSTHROUGH_RUNNING = "ncmp-datastores:passthrough-running";
public CmDataSubscriptionModelLoader(final CpsDataspaceService cpsDataspaceService,
final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService,
- final CpsAnchorService cpsAnchorService) {
- super(cpsDataspaceService, cpsModuleService, cpsDataService, cpsAnchorService);
+ final CpsAnchorService cpsAnchorService,
+ final CpsDataService cpsDataService) {
+ super(cpsDataspaceService, cpsModuleService, cpsAnchorService, cpsDataService);
}
@Value("${ncmp.model-loader.subscription:true}")
@@ -68,12 +67,26 @@ public class CmDataSubscriptionModelLoader extends AbstractModelLoader {
}
private void onboardSubscriptionModels() {
- createSchemaSet(NCMP_DATASPACE_NAME, DEPRECATED_SCHEMASET_NAME, DEPRECATED_MODEL_FILENAME);
- createAnchor(NCMP_DATASPACE_NAME, DEPRECATED_SCHEMASET_NAME, DEPRECATED_ANCHOR_NAME);
- createTopLevelDataNode(NCMP_DATASPACE_NAME, DEPRECATED_ANCHOR_NAME, DEPRECATED_REGISTRY_DATANODE_NAME);
-
createSchemaSet(NCMP_DATASPACE_NAME, SCHEMASET_NAME, MODEL_FILENAME);
createAnchor(NCMP_DATASPACE_NAME, SCHEMASET_NAME, ANCHOR_NAME);
createTopLevelDataNode(NCMP_DATASPACE_NAME, ANCHOR_NAME, REGISTRY_DATANODE_NAME);
+ createDatastore(DATASTORE_PASSTHROUGH_OPERATIONAL, DATASTORE_PASSTHROUGH_RUNNING);
}
+
+ private void createDatastore(final String... datastoreNames) {
+ for (final String datastoreName : datastoreNames) {
+ final String nodeData = "{\"datastore\":[{\"name\":\"" + datastoreName + "\",\"cm-handles\":{}}]}";
+ try {
+ cpsDataService.saveData(NCMP_DATASPACE_NAME, ANCHOR_NAME, "/" + REGISTRY_DATANODE_NAME, nodeData,
+ OffsetDateTime.now(), JSON);
+ } catch (final AlreadyDefinedException exception) {
+ log.info("Creating new child data node '{}' for data node '{}' failed as data node already exists",
+ datastoreName, REGISTRY_DATANODE_NAME);
+ } catch (final Exception exception) {
+ log.error("Creating data node failed: {}", exception.getMessage());
+ throw new NcmpStartUpException("Creating data node failed", exception.getMessage());
+ }
+ }
+ }
+
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java
index 0e562cdd8b..01bfc2b5d4 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation
+ * Copyright (C) 2023-2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,9 +39,9 @@ public class InventoryModelLoader extends AbstractModelLoader {
public InventoryModelLoader(final CpsDataspaceService cpsDataspaceService,
final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService,
- final CpsAnchorService cpsAnchorService) {
- super(cpsDataspaceService, cpsModuleService, cpsDataService, cpsAnchorService);
+ final CpsAnchorService cpsAnchorService,
+ final CpsDataService cpsDataService) {
+ super(cpsDataspaceService, cpsModuleService, cpsAnchorService, cpsDataService);
}
@Override