/*
* ============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.
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.config.embeddedcache.TrustLevelCacheConfig;
import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
public class DmiPluginWatchDog {
private final DmiRestClient dmiRestClient;
+ private final NetworkCmProxyDataService networkCmProxyDataService;
+ private final TrustLevelManager trustLevelManager;
+
+ @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_DMI_PLUGIN)
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}")
- public void watchDmiPluginTrustLevel() {
- trustLevelPerDmiPlugin.keySet().forEach(dmiKey -> {
- final String dmiHealthStatus = dmiRestClient.getDmiHealthStatus(dmiKey);
+ @Scheduled(fixedDelayString = "${ncmp.timers.trust-level.dmi-availability-watchdog-ms:30000}")
+ 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 {
- trustLevelPerDmiPlugin.put(dmiKey, TrustLevel.NONE);
+ newDmiTrustLevel = TrustLevel.NONE;
+ }
+ if (oldDmiTrustLevel.equals(newDmiTrustLevel)) {
+ log.debug("The Dmi Plugin: {} has already the same trust level: {}", dmiServiceName, newDmiTrustLevel);
+ } else {
+ final Collection<String> cmHandleIds =
+ networkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier(dmiServiceName);
+ trustLevelManager.handleUpdateOfDmiTrustLevel(dmiServiceName, cmHandleIds, newDmiTrustLevel);
}
});
}
+ private String getDmiHealthStatus(final String dmiServiceName) {
+ return dmiRestClient.getDmiHealthStatus(dmiServiceName);
+ }
}