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')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java54
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java10
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisher.java82
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java7
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java10
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumer.java19
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManager.java90
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java36
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java2
9 files changed, 256 insertions, 54 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index db7b12cbc8..2714c1dafb 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -63,6 +63,7 @@ import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
import org.onap.cps.ncmp.api.impl.operations.OperationType;
import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager;
import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
@@ -100,8 +101,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler;
private final CpsDataService cpsDataService;
private final IMap<String, Object> moduleSyncStartedOnCmHandles;
- private final Map<String, TrustLevel> trustLevelPerCmHandle;
private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
+ private final TrustLevelManager trustLevelManager;
@Override
public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
@@ -119,7 +120,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
if (!dmiPluginRegistration.getCreatedCmHandles().isEmpty()) {
dmiPluginRegistrationResponse.setCreatedCmHandles(
parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration));
- populateTrustLevelPerCmHandleCache(dmiPluginRegistration);
}
if (!dmiPluginRegistration.getUpdatedCmHandles().isEmpty()) {
dmiPluginRegistrationResponse.setUpdatedCmHandles(
@@ -317,17 +317,21 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
*/
public List<CmHandleRegistrationResponse> parseAndProcessCreatedCmHandlesInRegistration(
final DmiPluginRegistration dmiPluginRegistration) {
- final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>();
- dmiPluginRegistration.getCreatedCmHandles().forEach(cmHandle -> {
- final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
- dmiPluginRegistration.getDmiPlugin(),
- dmiPluginRegistration.getDmiDataPlugin(),
- dmiPluginRegistration.getDmiModelPlugin(),
- cmHandle,
- cmHandle.getModuleSetTag());
- cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.ADVISED);
- });
- return registerNewCmHandles(cmHandleStatePerCmHandle);
+ final List<NcmpServiceCmHandle> cmHandlesToBeCreated = dmiPluginRegistration.getCreatedCmHandles();
+ final Map<String, TrustLevel> initialTrustLevelPerCmHandleId = new HashMap<>(cmHandlesToBeCreated.size());
+ final List<YangModelCmHandle> yangModelCmHandles = new ArrayList<>(cmHandlesToBeCreated.size());
+ cmHandlesToBeCreated
+ .forEach(cmHandle -> {
+ final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
+ dmiPluginRegistration.getDmiPlugin(),
+ dmiPluginRegistration.getDmiDataPlugin(),
+ dmiPluginRegistration.getDmiModelPlugin(),
+ cmHandle,
+ cmHandle.getModuleSetTag());
+ yangModelCmHandles.add(yangModelCmHandle);
+ initialTrustLevelPerCmHandleId.put(cmHandle.getCmHandleId(), cmHandle.getRegistrationTrustLevel());
+ });
+ return registerNewCmHandles(yangModelCmHandles, initialTrustLevelPerCmHandleId);
}
protected List<CmHandleRegistrationResponse> parseAndProcessDeletedCmHandlesInRegistration(
@@ -468,11 +472,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
}
- private List<CmHandleRegistrationResponse> registerNewCmHandles(final Map<YangModelCmHandle, CmHandleState>
- cmHandleStatePerCmHandle) {
- final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
+ private List<CmHandleRegistrationResponse> registerNewCmHandles(final List<YangModelCmHandle> yangModelCmHandles,
+ final Map<String, TrustLevel>
+ initialTrustLevelPerCmHandleId) {
+ final Set<String> cmHandleIds = initialTrustLevelPerCmHandleId.keySet();
try {
- lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
+ lcmEventsCmHandleStateHandler.initiateStateAdvised(yangModelCmHandles);
+ trustLevelManager.handleInitialRegistrationOfTrustLevels(initialTrustLevelPerCmHandleId);
return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
} catch (final AlreadyDefinedException alreadyDefinedException) {
return CmHandleRegistrationResponse.createFailureResponses(
@@ -510,20 +516,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId).toList();
}
- private void populateTrustLevelPerCmHandleCache(final DmiPluginRegistration dmiPluginRegistration) {
- for (final NcmpServiceCmHandle cmHandle: dmiPluginRegistration.getCreatedCmHandles()) {
- if (cmHandle.getRegistrationTrustLevel() == null) {
- if (trustLevelPerCmHandle.containsKey(cmHandle.getCmHandleId())) {
- log.warn("CmHandle : {}, Already exists, Initial trustLevel ignored.", cmHandle.getCmHandleId());
- } else {
- trustLevelPerCmHandle.put(cmHandle.getCmHandleId(), TrustLevel.COMPLETE);
- }
- } else {
- trustLevelPerCmHandle.put(cmHandle.getCmHandleId(), cmHandle.getRegistrationTrustLevel());
- }
- }
- }
-
private void setTrustLevelPerDmiPlugin(final DmiPluginRegistration dmiPluginRegistration) {
if (DmiPluginRegistration.isNullEmptyOrBlank(dmiPluginRegistration.getDmiDataPlugin())) {
trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiPlugin(), TrustLevel.COMPLETE);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
index b6eb092182..5b93eb4853 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
@@ -41,7 +41,7 @@ import org.springframework.web.client.RestTemplate;
public class DmiRestClient {
private static final String HEALTH_CHECK_URL_EXTENSION = "/actuator/health";
- private static final String EMPTY_STRING = "";
+ private static final String NOT_SPECIFIED = "";
private final RestTemplate restTemplate;
private final DmiProperties dmiProperties;
@@ -70,19 +70,19 @@ public class DmiRestClient {
* Get DMI plugin health status.
*
* @param dmiPluginBaseUrl the base URL of the dmi-plugin
- * @return plugin health status ("UP" is all OK, EMPTY_STRING in case of any exception)
+ * @return plugin health status ("UP" is all OK, "" (not-specified) in case of any exception)
*/
public String getDmiHealthStatus(final String dmiPluginBaseUrl) {
final HttpEntity<Object> httpHeaders = new HttpEntity<>(configureHttpHeaders(new HttpHeaders()));
try {
final JsonNode responseHealthStatus =
restTemplate.getForObject(dmiPluginBaseUrl + HEALTH_CHECK_URL_EXTENSION,
- JsonNode.class, httpHeaders);
- return responseHealthStatus == null ? EMPTY_STRING :
+ JsonNode.class, httpHeaders);
+ return responseHealthStatus == null ? NOT_SPECIFIED :
responseHealthStatus.get("status").asText();
} catch (final Exception e) {
log.warn("Failed to retrieve health status from {}. Error Message: {}", dmiPluginBaseUrl, e.getMessage());
- return EMPTY_STRING;
+ return NOT_SPECIFIED;
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisher.java
new file mode 100644
index 0000000000..cba1f76ff7
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisher.java
@@ -0,0 +1,82 @@
+/*
+ * ============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.avc.ncmptoclient;
+
+import io.cloudevents.CloudEvent;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import org.onap.cps.ncmp.api.impl.events.EventsPublisher;
+import org.onap.cps.ncmp.api.impl.events.NcmpCloudEventBuilder;
+import org.onap.cps.ncmp.events.avc.ncmp_to_client.Avc;
+import org.onap.cps.ncmp.events.avc.ncmp_to_client.AvcEvent;
+import org.onap.cps.ncmp.events.avc.ncmp_to_client.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+@Service
+@RequiredArgsConstructor
+public class AvcEventPublisher {
+
+ private final EventsPublisher<CloudEvent> eventsPublisher;
+
+ @Value("${app.ncmp.avc.cm-events-topic}")
+ private String avcTopic;
+
+ /**
+ * Publish attribute value change event.
+ *
+ * @param eventKey id of the cmHandle being registered
+ */
+ public void publishAvcEvent(final String eventKey, final String attributeName,
+ final String oldAttributeValue, final String newAttributeValue) {
+ final AvcEvent avcEvent = buildAvcEvent(attributeName, oldAttributeValue, newAttributeValue);
+
+ final Map<String, String> extensions = createAvcEventExtensions(eventKey);
+ final CloudEvent avcCloudEvent =
+ NcmpCloudEventBuilder.builder().type(AvcEvent.class.getTypeName())
+ .event(avcEvent).extensions(extensions).setCloudEvent().build();
+
+ eventsPublisher.publishCloudEvent(avcTopic, eventKey, avcCloudEvent);
+ }
+
+ private AvcEvent buildAvcEvent(final String attributeName,
+ final String oldAttributeValue,
+ final String newAttributeValue) {
+ final Avc avc = new Avc();
+ avc.setAttributeName(attributeName);
+ avc.setOldAttributeValue(oldAttributeValue);
+ avc.setNewAttributeValue(newAttributeValue);
+
+ final Data payload = new Data();
+ payload.setAttributeValueChange(Collections.singletonList(avc));
+ final AvcEvent avcEvent = new AvcEvent();
+ avcEvent.setData(payload);
+ return avcEvent;
+ }
+
+ private Map<String, String> createAvcEventExtensions(final String eventKey) {
+ final Map<String, String> extensions = new HashMap<>();
+ extensions.put("correlationid", eventKey);
+ return extensions;
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java
index fdee28e337..8274772d2c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java
@@ -20,6 +20,7 @@
package org.onap.cps.ncmp.api.impl.events.lcm;
+import java.util.Collection;
import java.util.Map;
import org.onap.cps.ncmp.api.impl.inventory.CmHandleState;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
@@ -45,4 +46,10 @@ public interface LcmEventsCmHandleStateHandler {
*/
void updateCmHandleStateBatch(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle);
+ /**
+ * Sets the initial state of cmHandles to ADVISED.
+ *
+ * @param yangModelCmHandles List of Yang Model Cm Handle.
+ */
+ void initiateStateAdvised(Collection<YangModelCmHandle> yangModelCmHandles);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java
index 02368b8574..a31332f094 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java
@@ -28,6 +28,7 @@ import static org.onap.cps.ncmp.api.impl.inventory.CmHandleState.READY;
import io.micrometer.core.annotation.Timed;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -82,6 +83,15 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState
lcmEventsCmHandleStateHandlerAsyncHelper.publishLcmEventBatchAsynchronously(cmHandleTransitionPairs);
}
+ @Override
+ public void initiateStateAdvised(final Collection<YangModelCmHandle> yangModelCmHandles) {
+ final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size());
+ for (final YangModelCmHandle yangModelCmHandle : yangModelCmHandles) {
+ cmHandleStatePerCmHandle.put(yangModelCmHandle, ADVISED);
+ }
+ updateCmHandleStateBatch(cmHandleStatePerCmHandle);
+ }
+
private Collection<CmHandleTransitionPair> prepareCmHandleTransitionBatch(
final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) {
final List<CmHandleTransitionPair> cmHandleTransitionPairs = new ArrayList<>(cmHandleStatePerCmHandle.size());
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 b6d74d980f..45aa631b12 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
@@ -22,22 +22,20 @@ package org.onap.cps.ncmp.api.impl.trustlevel;
import io.cloudevents.CloudEvent;
import io.cloudevents.kafka.impl.KafkaHeaders;
-import java.util.Map;
import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper;
import org.onap.cps.ncmp.events.trustlevel.DeviceTrustLevel;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
-@Slf4j
@Component
@RequiredArgsConstructor
public class DeviceHeartbeatConsumer {
private static final String CLOUD_EVENT_ID_HEADER_NAME = "ce_id";
- private final Map<String, TrustLevel> trustLevelPerCmHandle;
+ private final TrustLevelManager trustLevelManager;
+
/**
* Listening the device heartbeats.
@@ -45,20 +43,17 @@ public class DeviceHeartbeatConsumer {
* @param deviceHeartbeatConsumerRecord Device Heartbeat record.
*/
@KafkaListener(topics = "${app.dmi.device-heartbeat.topic}",
- containerFactory = "cloudEventConcurrentKafkaListenerContainerFactory")
+ containerFactory = "cloudEventConcurrentKafkaListenerContainerFactory")
public void heartbeatListener(final ConsumerRecord<String, CloudEvent> deviceHeartbeatConsumerRecord) {
final String cmHandleId = KafkaHeaders.getParsedKafkaHeader(deviceHeartbeatConsumerRecord.headers(),
- CLOUD_EVENT_ID_HEADER_NAME);
+ CLOUD_EVENT_ID_HEADER_NAME);
final DeviceTrustLevel deviceTrustLevel =
- CloudEventMapper.toTargetEvent(deviceHeartbeatConsumerRecord.value(), DeviceTrustLevel.class);
+ CloudEventMapper.toTargetEvent(deviceHeartbeatConsumerRecord.value(), DeviceTrustLevel.class);
+
+ trustLevelManager.handleUpdateOfTrustLevels(cmHandleId, deviceTrustLevel.getData().getTrustLevel());
- if (cmHandleId != null && deviceTrustLevel != null) {
- final String trustLevel = deviceTrustLevel.getData().getTrustLevel();
- trustLevelPerCmHandle.put(cmHandleId, TrustLevel.valueOf(trustLevel));
- log.debug("Added cmHandleId to trustLevelPerCmHandle map as {}:{}", cmHandleId, trustLevel);
- }
}
}
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
new file mode 100644
index 0000000000..4df6bd237a
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManager.java
@@ -0,0 +1,90 @@
+/*
+ * ============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.trustlevel;
+
+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.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+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";
+
+
+ /**
+ * Add cmHandles to the cache and publish notification for initial trust level of cmHandles if it is NONE.
+ *
+ * @param cmHandlesToBeCreated a list of cmHandles being created
+ */
+ public void handleInitialRegistrationOfTrustLevels(final Map<String, TrustLevel> cmHandlesToBeCreated) {
+ for (final Map.Entry<String, TrustLevel> entry : cmHandlesToBeCreated.entrySet()) {
+ final String cmHandleId = entry.getKey();
+ if (trustLevelPerCmHandle.containsKey(cmHandleId)) {
+ log.warn("Cm handle: {} already registered", cmHandleId);
+ } else {
+ TrustLevel initialTrustLevel = entry.getValue();
+ if (initialTrustLevel == null) {
+ initialTrustLevel = TrustLevel.COMPLETE;
+ }
+ trustLevelPerCmHandle.put(cmHandleId, initialTrustLevel);
+ if (TrustLevel.NONE.equals(initialTrustLevel)) {
+ sendAvcNotificationEvent(cmHandleId, NO_OLD_VALUE, initialTrustLevel.name());
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Update a cmHandle in the cache and publish notification if the trust level is different.
+ *
+ * @param cmHandleId id of the cmHandle being updated
+ * @param newTrustLevel new trust level of the cmHandle being updated
+ */
+ 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);
+ }
+ }
+
+ private void sendAvcNotificationEvent(final String cmHandleId,
+ final String oldTrustLevel,
+ final String newTrustLevel) {
+ avcEventPublisher.publishAvcEvent(cmHandleId,
+ CHANGED_ATTRIBUTE_NAME,
+ oldTrustLevel,
+ newTrustLevel);
+ }
+
+}
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 b073f1bc3a..9fd096daea 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
@@ -20,11 +20,14 @@
package org.onap.cps.ncmp.api.impl.trustlevel.dmiavailability;
+import java.util.Collection;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.api.impl.client.DmiRestClient;
import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@@ -34,6 +37,8 @@ import org.springframework.stereotype.Service;
public class DmiPluginWatchDog {
private final DmiRestClient dmiRestClient;
+ private final NetworkCmProxyDataService networkCmProxyDataService;
+ private final TrustLevelManager trustLevelManager;
private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
/**
@@ -42,15 +47,36 @@ public class DmiPluginWatchDog {
* The @fixedDelayString is the time interval, in milliseconds, between consecutive checks.
*/
@Scheduled(fixedDelayString = "${ncmp.timers.trust-evel.dmi-availability-watchdog-ms:30000}")
- public void watchDmiPluginTrustLevel() {
- trustLevelPerDmiPlugin.keySet().forEach(dmiKey -> {
- final String dmiHealthStatus = dmiRestClient.getDmiHealthStatus(dmiKey);
+ public void checkDmiAvailability() {
+ trustLevelPerDmiPlugin.entrySet().forEach(entry -> {
+ final TrustLevel newDmiTrustLevel;
+ final TrustLevel oldDmiTrustLevel = entry.getValue();
+ final String dmiServiceName = entry.getKey();
+ final String dmiHealthStatus = getDmiHealthStatus(dmiServiceName);
+ log.debug("The health status for dmi-plugin: {} is {}", dmiServiceName, dmiHealthStatus);
+
if ("UP".equals(dmiHealthStatus)) {
- trustLevelPerDmiPlugin.put(dmiKey, TrustLevel.COMPLETE);
+ newDmiTrustLevel = TrustLevel.COMPLETE;
+ } else {
+ newDmiTrustLevel = TrustLevel.NONE;
+ }
+
+ if (oldDmiTrustLevel.equals(newDmiTrustLevel)) {
+ log.debug("The Dmi Plugin: {} has already the same trust level: {}", dmiServiceName,
+ newDmiTrustLevel);
} else {
- trustLevelPerDmiPlugin.put(dmiKey, TrustLevel.NONE);
+ trustLevelPerDmiPlugin.put(dmiServiceName, newDmiTrustLevel);
+
+ final Collection<String> notificationCandidateCmHandleIds =
+ networkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier(dmiServiceName);
+ for (final String cmHandleId: notificationCandidateCmHandleIds) {
+ trustLevelManager.handleUpdateOfTrustLevels(cmHandleId, newDmiTrustLevel.name());
+ }
}
});
}
+ private String getDmiHealthStatus(final String dmiServiceName) {
+ return dmiRestClient.getDmiHealthStatus(dmiServiceName);
+ }
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
index b0aed57630..82283228a1 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
@@ -116,7 +116,7 @@ public class CmHandleRegistrationResponse {
.status(Status.SUCCESS).build();
}
- public static List<CmHandleRegistrationResponse> createSuccessResponses(final List<String> cmHandleIds) {
+ public static List<CmHandleRegistrationResponse> createSuccessResponses(final Collection<String> cmHandleIds) {
return cmHandleIds.stream().map(CmHandleRegistrationResponse::createSuccessResponse)
.collect(Collectors.toList());
}