summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2023-12-04 09:13:57 +0000
committerGerrit Code Review <gerrit@onap.org>2023-12-04 09:13:57 +0000
commitc5e6ada7b5f90f7ab0316257f5ee59b257108de9 (patch)
treefd39b11385253ed872832afb0097904aa7bd37d2 /cps-ncmp-service/src/main
parent0d3d2f5968afa2bd5d8a64a677439d930710abb8 (diff)
parenta36b3f28624a14da75eb5ea1cd0bd677ebce325c (diff)
Merge "Fix the algorithm for device trust level"
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumer.java5
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManager.java87
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java15
3 files changed, 71 insertions, 36 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumer.java
index 45aa631b12..230a370d65 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumer.java
@@ -36,7 +36,6 @@ public class DeviceHeartbeatConsumer {
private static final String CLOUD_EVENT_ID_HEADER_NAME = "ce_id";
private final TrustLevelManager trustLevelManager;
-
/**
* Listening the device heartbeats.
*
@@ -51,8 +50,8 @@ public class DeviceHeartbeatConsumer {
final DeviceTrustLevel deviceTrustLevel =
CloudEventMapper.toTargetEvent(deviceHeartbeatConsumerRecord.value(), DeviceTrustLevel.class);
-
- trustLevelManager.handleUpdateOfTrustLevels(cmHandleId, deviceTrustLevel.getData().getTrustLevel());
+ final TrustLevel newDeviceTrustLevel = TrustLevel.valueOf(deviceTrustLevel.getData().getTrustLevel());
+ trustLevelManager.handleUpdateOfDeviceTrustLevel(cmHandleId, newDeviceTrustLevel);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManager.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManager.java
index 4df6bd237a..22f18cd243 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManager.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManager.java
@@ -20,10 +20,14 @@
package org.onap.cps.ncmp.api.impl.trustlevel;
+import java.util.Collection;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.impl.events.avc.ncmptoclient.AvcEventPublisher;
+import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
+import org.onap.cps.ncmp.api.impl.operations.RequiredDmiService;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.springframework.stereotype.Service;
@Slf4j
@@ -32,10 +36,12 @@ import org.springframework.stereotype.Service;
public class TrustLevelManager {
private final Map<String, TrustLevel> trustLevelPerCmHandle;
- private final AvcEventPublisher avcEventPublisher;
- private static final String NO_OLD_VALUE = null;
- private static final String CHANGED_ATTRIBUTE_NAME = "trustLevel";
+ private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
+ private final InventoryPersistence inventoryPersistence;
+ private final AvcEventPublisher avcEventPublisher;
+ private static final String AVC_CHANGED_ATTRIBUTE_NAME = "trustLevel";
+ private static final String AVC_NO_OLD_VALUE = null;
/**
* Add cmHandles to the cache and publish notification for initial trust level of cmHandles if it is NONE.
@@ -54,37 +60,72 @@ public class TrustLevelManager {
}
trustLevelPerCmHandle.put(cmHandleId, initialTrustLevel);
if (TrustLevel.NONE.equals(initialTrustLevel)) {
- sendAvcNotificationEvent(cmHandleId, NO_OLD_VALUE, initialTrustLevel.name());
+ avcEventPublisher.publishAvcEvent(cmHandleId,
+ AVC_CHANGED_ATTRIBUTE_NAME,
+ AVC_NO_OLD_VALUE,
+ initialTrustLevel.name());
}
}
}
}
-
/**
- * Update a cmHandle in the cache and publish notification if the trust level is different.
+ * Updates trust level of dmi plugin in the cache and publish notification for trust level of cmHandles if it
+ * has changed.
*
- * @param cmHandleId id of the cmHandle being updated
- * @param newTrustLevel new trust level of the cmHandle being updated
+ * @param dmiServiceName dmi service name
+ * @param affectedCmHandleIds cm handle ids belonging to dmi service name
+ * @param newDmiTrustLevel new trust level of the dmi plugin
*/
- public void handleUpdateOfTrustLevels(final String cmHandleId, final String newTrustLevel) {
- final TrustLevel oldTrustLevel = trustLevelPerCmHandle.get(cmHandleId);
- if (newTrustLevel.equals(oldTrustLevel.name())) {
- log.debug("The Cm Handle: {} has already the same trust level: {}", cmHandleId, newTrustLevel);
- } else {
- trustLevelPerCmHandle.put(cmHandleId, TrustLevel.valueOf(newTrustLevel));
- sendAvcNotificationEvent(cmHandleId, oldTrustLevel.name(), newTrustLevel);
- log.info("The new trust level: {} has been updated for Cm Handle: {}", newTrustLevel, cmHandleId);
+ public void handleUpdateOfDmiTrustLevel(final String dmiServiceName,
+ final Collection<String> affectedCmHandleIds,
+ final TrustLevel newDmiTrustLevel) {
+ final TrustLevel oldDmiTrustLevel = trustLevelPerDmiPlugin.get(dmiServiceName);
+ trustLevelPerDmiPlugin.put(dmiServiceName, newDmiTrustLevel);
+ for (final String affectedCmHandleId : affectedCmHandleIds) {
+ final TrustLevel deviceTrustLevel = trustLevelPerCmHandle.get(affectedCmHandleId);
+ final TrustLevel oldEffectiveTrustLevel = deviceTrustLevel.getEffectiveTrustLevel(oldDmiTrustLevel);
+ final TrustLevel newEffectiveTrustLevel = deviceTrustLevel.getEffectiveTrustLevel(newDmiTrustLevel);
+ sendAvcNotificationIfRequired(affectedCmHandleId, oldEffectiveTrustLevel, newEffectiveTrustLevel);
}
}
- private void sendAvcNotificationEvent(final String cmHandleId,
- final String oldTrustLevel,
- final String newTrustLevel) {
- avcEventPublisher.publishAvcEvent(cmHandleId,
- CHANGED_ATTRIBUTE_NAME,
- oldTrustLevel,
- newTrustLevel);
+ /**
+ * Updates trust level of device in the cache and publish notification for trust level of device if it has
+ * changed.
+ *
+ * @param cmHandleId cm handle id
+ * @param newDeviceTrustLevel new trust level of the device
+ */
+ public void handleUpdateOfDeviceTrustLevel(final String cmHandleId,
+ final TrustLevel newDeviceTrustLevel) {
+ final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
+ final String dmiServiceName = yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA);
+
+ final TrustLevel dmiTrustLevel = trustLevelPerDmiPlugin.get(dmiServiceName);
+ final TrustLevel oldDeviceTrustLevel = trustLevelPerCmHandle.get(cmHandleId);
+
+ final TrustLevel oldEffectiveTrustLevel = oldDeviceTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
+ final TrustLevel newEffectiveTrustLevel = newDeviceTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
+
+ trustLevelPerCmHandle.put(cmHandleId, newDeviceTrustLevel);
+ sendAvcNotificationIfRequired(cmHandleId, oldEffectiveTrustLevel, newEffectiveTrustLevel);
+ }
+
+ private void sendAvcNotificationIfRequired(final String notificationCandidateCmHandleId,
+ final TrustLevel oldEffectiveTrustLevel,
+ final TrustLevel newEffectiveTrustLevel) {
+ if (oldEffectiveTrustLevel.equals(newEffectiveTrustLevel)) {
+ log.debug("The Cm Handle: {} has already the same trust level: {}", notificationCandidateCmHandleId,
+ newEffectiveTrustLevel);
+ } else {
+ log.info("The trust level for Cm Handle: {} is now: {} ", notificationCandidateCmHandleId,
+ newEffectiveTrustLevel);
+ avcEventPublisher.publishAvcEvent(notificationCandidateCmHandleId,
+ AVC_CHANGED_ATTRIBUTE_NAME,
+ oldEffectiveTrustLevel.name(),
+ newEffectiveTrustLevel.name());
+ }
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java
index 9fd096daea..6a272f1c66 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java
@@ -38,12 +38,13 @@ public class DmiPluginWatchDog {
private final DmiRestClient dmiRestClient;
private final NetworkCmProxyDataService networkCmProxyDataService;
+
private final TrustLevelManager trustLevelManager;
private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
/**
* This class monitors the trust level of all DMI plugin by checking the health status
- * the resulting trustlevel wil be stored in the relevant cache.
+ * the resulting trust level wil be stored in the relevant cache.
* The @fixedDelayString is the time interval, in milliseconds, between consecutive checks.
*/
@Scheduled(fixedDelayString = "${ncmp.timers.trust-evel.dmi-availability-watchdog-ms:30000}")
@@ -60,18 +61,12 @@ public class DmiPluginWatchDog {
} else {
newDmiTrustLevel = TrustLevel.NONE;
}
-
if (oldDmiTrustLevel.equals(newDmiTrustLevel)) {
- log.debug("The Dmi Plugin: {} has already the same trust level: {}", dmiServiceName,
- newDmiTrustLevel);
+ log.debug("The Dmi Plugin: {} has already the same trust level: {}", dmiServiceName, newDmiTrustLevel);
} else {
- trustLevelPerDmiPlugin.put(dmiServiceName, newDmiTrustLevel);
-
- final Collection<String> notificationCandidateCmHandleIds =
+ final Collection<String> cmHandleIds =
networkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier(dmiServiceName);
- for (final String cmHandleId: notificationCandidateCmHandleIds) {
- trustLevelManager.handleUpdateOfTrustLevels(cmHandleId, newDmiTrustLevel.name());
- }
+ trustLevelManager.handleUpdateOfDmiTrustLevel(dmiServiceName, cmHandleIds, newDmiTrustLevel);
}
});
}