summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2024-02-07 14:55:03 +0000
committermpriyank <priyank.maheshwari@est.tech>2024-02-12 15:33:13 +0000
commit1302ce8ecc2772d258bdd10f32af23e7e9861880 (patch)
treedc41a02b264050786d42cc6d8a8147f0c98d41e2 /cps-ncmp-service/src/main
parentc72a0132b024141716b35550fd7204338b2fc673 (diff)
CmSubscription minor code refactoring
- As per discusstion , refactoring the naming of the classes and caches - Combining the validation service with CmSubscriptionPersistence service - removed dmiCmNotificationScopeFilter class and the attributes are part of Predicates only Issue-ID: CPS-2078 Change-Id: Ic2b3ee28a150f3ae6e0911e88296f01e22604ef5 Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/CmNotificationSubscriptionCacheConfig.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/CmSubscriptionEventCacheConfig.java)16
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmNotificationSubscriptionStatus.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionStatus.java)8
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionPredicate.java34
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/DmiCmNotificationSubscriptionDetails.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionCacheObject.java)6
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/DmiCmNotificationSubscriptionPredicate.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/ScopeFilter.java)6
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionPersistenceService.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionService.java)17
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionPersistenceServiceImpl.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionServiceImpl.java)24
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionValidationService.java34
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionValidationServiceImpl.java43
9 files changed, 52 insertions, 136 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/CmSubscriptionEventCacheConfig.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/CmNotificationSubscriptionCacheConfig.java
index 8b429d44c9..1d6da90a9a 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/CmSubscriptionEventCacheConfig.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/CmNotificationSubscriptionCacheConfig.java
@@ -24,26 +24,26 @@ import com.hazelcast.config.MapConfig;
import com.hazelcast.map.IMap;
import java.util.Map;
import org.onap.cps.cache.HazelcastCacheConfig;
-import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.CmSubscriptionCacheObject;
+import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionDetails;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
-public class CmSubscriptionEventCacheConfig extends HazelcastCacheConfig {
+public class CmNotificationSubscriptionCacheConfig extends HazelcastCacheConfig {
- private static final MapConfig cmSubscriptionEventCacheMapConfig =
- createMapConfig("cmSubscriptionEventCacheMapConfig");
+ private static final MapConfig cmNotificationSubscriptionCacheMapConfig =
+ createMapConfig("cmNotificationSubscriptionCacheMapConfig");
/**
- * Distributed instance of cm subscription information
+ * Distributed instance of cm notification subscription information
* cache that contains subscription id as key
* and incoming event data processed per dmi plugin.
*
* @return configured map of subscription events.
*/
@Bean
- public IMap<String, Map<String, CmSubscriptionCacheObject>> cmSubscriptionEventCache() {
- return createHazelcastInstance("hazelCastInstanceCmSubscriptionEvents",
- cmSubscriptionEventCacheMapConfig).getMap("cmSubscriptionEventCache");
+ public IMap<String, Map<String, DmiCmNotificationSubscriptionDetails>> cmNotificationSubscriptionCache() {
+ return createHazelcastInstance("hazelCastInstanceCmNotificationSubscription",
+ cmNotificationSubscriptionCacheMapConfig).getMap("cmNotificationSubscriptionCache");
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionStatus.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmNotificationSubscriptionStatus.java
index 0bc3cbe93d..68d54fac95 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionStatus.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmNotificationSubscriptionStatus.java
@@ -20,13 +20,13 @@
package org.onap.cps.ncmp.api.impl.events.cmsubscription.model;
-public enum CmSubscriptionStatus {
+public enum CmNotificationSubscriptionStatus {
ACCEPTED("ACCEPTED"), REJECTED("REJECTED"), PENDING("PENDING");
- private final String cmSubscriptionStatusValue;
+ private final String cmNotificationSubscriptionStatusValue;
- CmSubscriptionStatus(final String cmSubscriptionStatusValue) {
- this.cmSubscriptionStatusValue = cmSubscriptionStatusValue;
+ CmNotificationSubscriptionStatus(final String cmNotificationSubscriptionStatusValue) {
+ this.cmNotificationSubscriptionStatusValue = cmNotificationSubscriptionStatusValue;
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionPredicate.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionPredicate.java
deleted file mode 100644
index 262126ef14..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionPredicate.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * 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.
- * 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.cmsubscription.model;
-
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-
-@Getter
-@Setter
-public class CmSubscriptionPredicate {
-
- private List<String> targetFilter;
- private ScopeFilter scopeFilter;
-
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionCacheObject.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/DmiCmNotificationSubscriptionDetails.java
index 2888a6734b..4f6caefce7 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/CmSubscriptionCacheObject.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/DmiCmNotificationSubscriptionDetails.java
@@ -26,8 +26,8 @@ import lombok.Setter;
@Getter
@Setter
-public class CmSubscriptionCacheObject {
+public class DmiCmNotificationSubscriptionDetails {
- private List<CmSubscriptionPredicate> cmSubscriptionPredicates;
- private CmSubscriptionStatus cmSubscriptionStatus;
+ private List<DmiCmNotificationSubscriptionPredicate> dmiCmNotificationSubscriptionPredicates;
+ private CmNotificationSubscriptionStatus cmNotificationSubscriptionStatus;
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/ScopeFilter.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/DmiCmNotificationSubscriptionPredicate.java
index b9ca68761f..65365808d2 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/ScopeFilter.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/model/DmiCmNotificationSubscriptionPredicate.java
@@ -27,8 +27,10 @@ import org.onap.cps.ncmp.api.impl.operations.DatastoreType;
@Getter
@Setter
-public class ScopeFilter {
+public class DmiCmNotificationSubscriptionPredicate {
+ private List<String> targetCmHandleIds;
private DatastoreType datastoreType;
- private List<String> xpathFilters;
+ private List<String> xpaths;
+
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionPersistenceService.java
index 723a3032a5..189fbb53d9 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionPersistenceService.java
@@ -20,9 +20,10 @@
package org.onap.cps.ncmp.api.impl.events.cmsubscription.service;
+import java.util.Collection;
import org.onap.cps.ncmp.api.impl.operations.DatastoreType;
-public interface CmSubscriptionService {
+public interface CmNotificationSubscriptionPersistenceService {
String NCMP_DATASPACE_NAME = "NCMP-Admin";
String CM_SUBSCRIPTIONS_ANCHOR_NAME = "cm-data-subscriptions";
@@ -35,5 +36,17 @@ public interface CmSubscriptionService {
* @param xpath valid xpath
* @return true for ongoing cmsubscription , otherwise false
*/
- boolean isOngoingCmSubscription(final DatastoreType datastoreType, final String cmHandleId, final String xpath);
+ boolean isOngoingCmNotificationSubscription(final DatastoreType datastoreType, final String cmHandleId,
+ final String xpath);
+
+ /**
+ * Get all ongoing cm notification subscription based on the parameters.
+ *
+ * @param datastoreType valid datastore type
+ * @param cmHandleId cmhandle id
+ * @param xpath valid xpath
+ * @return collection of subscription ids of ongoing cm notification subscription
+ */
+ Collection<String> getOngoingCmNotificationSubscriptionIds(final DatastoreType datastoreType,
+ final String cmHandleId, final String xpath);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionPersistenceServiceImpl.java
index 011397adb3..ca9adb36b2 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionPersistenceServiceImpl.java
@@ -21,9 +21,11 @@
package org.onap.cps.ncmp.api.impl.events.cmsubscription.service;
import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsQueryService;
import org.onap.cps.ncmp.api.impl.operations.DatastoreType;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
@@ -32,23 +34,33 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
-public class CmSubscriptionServiceImpl implements CmSubscriptionService {
+public class CmNotificationSubscriptionPersistenceServiceImpl implements CmNotificationSubscriptionPersistenceService {
private static final String IS_ONGOING_CM_SUBSCRIPTION_CPS_PATH_QUERY = """
/datastores/datastore[@name='%s']/cm-handles/cm-handle[@id='%s']/filters/filter[@xpath='%s']""";
- private final CpsDataService cpsDataService;
+ private final CpsQueryService cpsQueryService;
@Override
- public boolean isOngoingCmSubscription(final DatastoreType datastoreType, final String cmHandleId,
+ public boolean isOngoingCmNotificationSubscription(final DatastoreType datastoreType, final String cmHandleId,
final String xpath) {
+ return !getOngoingCmNotificationSubscriptionIds(datastoreType, cmHandleId, xpath).isEmpty();
+ }
+
+ @Override
+ public Collection<String> getOngoingCmNotificationSubscriptionIds(final DatastoreType datastoreType,
+ final String cmHandleId, final String xpath) {
+
final String isOngoingCmSubscriptionCpsPathQuery =
IS_ONGOING_CM_SUBSCRIPTION_CPS_PATH_QUERY.formatted(datastoreType.getDatastoreName(), cmHandleId,
escapeQuotesByDoublingThem(xpath));
final Collection<DataNode> existingNodes =
- cpsDataService.getDataNodes(NCMP_DATASPACE_NAME, CM_SUBSCRIPTIONS_ANCHOR_NAME,
+ cpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, CM_SUBSCRIPTIONS_ANCHOR_NAME,
isOngoingCmSubscriptionCpsPathQuery, FetchDescendantsOption.OMIT_DESCENDANTS);
- return !existingNodes.isEmpty();
+ if (existingNodes.isEmpty()) {
+ return Collections.emptyList();
+ }
+ return (List<String>) existingNodes.iterator().next().getLeaves().get("subscribers");
}
private static String escapeQuotesByDoublingThem(final String inputXpath) {
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionValidationService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionValidationService.java
deleted file mode 100644
index 6bf509349d..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionValidationService.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * 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.
- * 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.cmsubscription.service;
-
-
-public interface CmSubscriptionValidationService {
-
- /**
- * Validate against the allowed datastores.
- *
- * @param incomingDatastore Datastore from the incoming CmSubscription event from client
- * @return true if valid datastore , otherwise false
- */
- boolean isValidDataStore(final String incomingDatastore);
-
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionValidationServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionValidationServiceImpl.java
deleted file mode 100644
index 697366258d..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmSubscriptionValidationServiceImpl.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * 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.
- * 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.cmsubscription.service;
-
-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 java.util.Arrays;
-import java.util.List;
-import org.springframework.stereotype.Service;
-
-@Service
-public class CmSubscriptionValidationServiceImpl implements CmSubscriptionValidationService {
-
- private static final List<String> validDatastores =
- Arrays.asList(PASSTHROUGH_RUNNING.getDatastoreName(), PASSTHROUGH_OPERATIONAL.getDatastoreName());
-
-
- @Override
- public boolean isValidDataStore(final String incomingDatastore) {
- return validDatastores.contains(incomingDatastore);
- }
-
-
-}