From 34ec9548babc6180e8fd34818fafe73260ec6042 Mon Sep 17 00:00:00 2001 From: "halil.cakal" Date: Thu, 26 Oct 2023 18:00:24 +0100 Subject: Trust level updates with dmi status change - Change dmi watchdog to store Trustlevel for each DMI - Corrected query algorithm for TrustLevel Queries Issue-ID: CPS-1907 Change-Id: I7ca25db8edfd25b72bcda48e4fde1d9be5c56dc0 Signed-off-by: halil.cakal --- .../api/impl/NetworkCmProxyDataServiceImpl.java | 87 +++++++++++----------- .../NetworkCmProxyDataServicePropertyHandler.java | 4 +- .../cps/ncmp/api/impl/client/DmiRestClient.java | 41 +++++----- .../api/impl/inventory/CmHandleQueriesImpl.java | 25 ++++++- .../cps/ncmp/api/impl/trustlevel/TrustLevel.java | 25 ++++++- .../ncmp/api/impl/trustlevel/TrustLevelFilter.java | 58 --------------- .../dmiavailability/DMiPluginWatchDog.java | 60 --------------- .../dmiavailability/DmiPluginStatus.java | 25 ------- .../dmiavailability/DmiPluginWatchDog.java | 56 ++++++++++++++ 9 files changed, 165 insertions(+), 216 deletions(-) delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelFilter.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDog.java delete mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginStatus.java create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java (limited to 'cps-ncmp-service/src/main/java') 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 1f87a1ef9..db7b12cbc 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 @@ -105,7 +105,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService @Override public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule( - final DmiPluginRegistration dmiPluginRegistration) { + final DmiPluginRegistration dmiPluginRegistration) { dmiPluginRegistration.validateDmiPluginRegistration(); final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse(); @@ -113,23 +113,23 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService if (!dmiPluginRegistration.getRemovedCmHandles().isEmpty()) { dmiPluginRegistrationResponse.setRemovedCmHandles( - parseAndProcessDeletedCmHandlesInRegistration(dmiPluginRegistration.getRemovedCmHandles())); + parseAndProcessDeletedCmHandlesInRegistration(dmiPluginRegistration.getRemovedCmHandles())); } if (!dmiPluginRegistration.getCreatedCmHandles().isEmpty()) { dmiPluginRegistrationResponse.setCreatedCmHandles( - parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration)); + parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration)); populateTrustLevelPerCmHandleCache(dmiPluginRegistration); } if (!dmiPluginRegistration.getUpdatedCmHandles().isEmpty()) { dmiPluginRegistrationResponse.setUpdatedCmHandles( - networkCmProxyDataServicePropertyHandler - .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles())); + networkCmProxyDataServicePropertyHandler + .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles())); } if (dmiPluginRegistration.getUpgradedCmHandles() != null - && !dmiPluginRegistration.getUpgradedCmHandles().getCmHandles().isEmpty()) { + && !dmiPluginRegistration.getUpgradedCmHandles().getCmHandles().isEmpty()) { dmiPluginRegistrationResponse.setUpgradedCmHandles( - parseAndProcessUpgradedCmHandlesInRegistration(dmiPluginRegistration)); + parseAndProcessUpgradedCmHandlesInRegistration(dmiPluginRegistration)); } return dmiPluginRegistrationResponse; @@ -143,10 +143,10 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final String topicParamInQuery, final String requestId) { final ResponseEntity responseEntity = dmiDataOperations.getResourceDataFromDmi(datastoreName, cmHandleId, - resourceIdentifier, - optionsParamInQuery, - topicParamInQuery, - requestId); + resourceIdentifier, + optionsParamInQuery, + topicParamInQuery, + requestId); return responseEntity.getBody(); } @@ -156,13 +156,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final String resourceIdentifier, final FetchDescendantsOption fetchDescendantsOption) { return cpsDataService.getDataNodes(datastoreName, cmHandleId, resourceIdentifier, - fetchDescendantsOption).iterator().next(); + fetchDescendantsOption).iterator().next(); } @Override public void executeDataOperationForCmHandles(final String topicParamInQuery, final DataOperationRequest - dataOperationRequest, + dataOperationRequest, final String requestId) { dmiDataOperations.requestResourceDataFromDmi(topicParamInQuery, dataOperationRequest, requestId); } @@ -174,7 +174,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final String requestData, final String dataType) { return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier, - operationType, requestData, dataType); + operationType, requestData, dataType); } @Override @@ -195,9 +195,9 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public Collection executeCmHandleSearch( - final CmHandleQueryApiParameters cmHandleQueryApiParameters) { + final CmHandleQueryApiParameters cmHandleQueryApiParameters) { final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( - cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); + cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); return networkCmProxyCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters); } @@ -211,7 +211,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService @Override public Collection executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) { final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( - cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); + cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); return networkCmProxyCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters); } @@ -220,7 +220,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService * Set the data sync enabled flag, along with the data sync state * based on the data sync enabled boolean for the cm handle id provided. * - * @param cmHandleId cm handle id + * @param cmHandleId cm handle id * @param dataSyncEnabledTargetValue data sync enabled flag */ @Override @@ -232,18 +232,18 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } if (CmHandleState.READY.equals(compositeState.getCmHandleState())) { final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores() - .getOperationalDataStore().getDataStoreSyncState(); + .getOperationalDataStore().getDataStoreSyncState(); if (Boolean.FALSE.equals(dataSyncEnabledTargetValue) - && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) { + && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) { // TODO : This is hard-coded for onap dmi that need to be addressed cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, - "/netconf-state", OffsetDateTime.now()); + "/netconf-state", OffsetDateTime.now()); } CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabledTargetValue, compositeState); inventoryPersistence.saveCmHandleState(cmHandleId, compositeState); } else { throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: " - + compositeState.getCmHandleState()); + + compositeState.getCmHandleState()); } } @@ -266,7 +266,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public Collection executeCmHandleIdSearchForInventory( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES); return networkCmProxyCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters); } @@ -280,7 +280,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService @Override public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) { return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle( - inventoryPersistence.getYangModelCmHandle(cmHandleId)); + inventoryPersistence.getYangModelCmHandle(cmHandleId)); } /** @@ -316,27 +316,26 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService * @return cm-handle registration response for create cm-handle requests. */ public List parseAndProcessCreatedCmHandlesInRegistration( - final DmiPluginRegistration dmiPluginRegistration) { + final DmiPluginRegistration dmiPluginRegistration) { final Map 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); - }); + 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); } protected List parseAndProcessDeletedCmHandlesInRegistration( - final List tobeRemovedCmHandles) { + final List tobeRemovedCmHandles) { final List cmHandleRegistrationResponses = - new ArrayList<>(tobeRemovedCmHandles.size()); + new ArrayList<>(tobeRemovedCmHandles.size()); final Collection yangModelCmHandles = - inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles); + inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles); updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING); @@ -367,7 +366,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } protected List parseAndProcessUpgradedCmHandlesInRegistration( - final DmiPluginRegistration dmiPluginRegistration) { + final DmiPluginRegistration dmiPluginRegistration) { final List upgradedCmHandleIds = dmiPluginRegistration.getUpgradedCmHandles().getCmHandles(); @@ -446,7 +445,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) { inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId); inventoryPersistence.deleteDataNode(NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId - + "']"); + + "']"); removeDeletedCmHandleFromModuleSyncMap(cmHandleId); } @@ -458,8 +457,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private Collection mapCmHandleIdsToXpaths(final Collection cmHandles) { return cmHandles.stream() - .map(cmHandleId -> NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']") - .collect(Collectors.toSet()); + .map(cmHandleId -> NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']") + .collect(Collectors.toSet()); } // CPS-1239 Robustness cleaning of in progress cache @@ -470,7 +469,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } private List registerNewCmHandles(final Map - cmHandleStatePerCmHandle) { + cmHandleStatePerCmHandle) { final List cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle); try { lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); @@ -495,7 +494,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } private List upgradeCmHandles(final Map - cmHandleStatePerCmHandle) { + cmHandleStatePerCmHandle) { final List cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle); log.info("Moving cm handles : {} into locked (for upgrade) state.", cmHandleIds); try { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java index 25ded162b..be6a40198 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java @@ -74,8 +74,8 @@ public class NetworkCmProxyDataServicePropertyHandler { cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); } catch (final DataNodeNotFoundException e) { log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandleId, e.getMessage()); - cmHandleRegistrationResponses.add(CmHandleRegistrationResponse - .createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND)); + cmHandleRegistrationResponses.add( + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND)); } catch (final DataValidationException e) { log.error("Unable to update cm handle : {}, caused by : {}", cmHandleId, e.getMessage()); cmHandleRegistrationResponses.add( 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 4ef4003cd..b6eb09218 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 @@ -22,12 +22,11 @@ package org.onap.cps.ncmp.api.impl.client; import com.fasterxml.jackson.databind.JsonNode; -import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration.DmiProperties; import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException; import org.onap.cps.ncmp.api.impl.operations.OperationType; -import org.onap.cps.ncmp.api.impl.trustlevel.dmiavailability.DmiPluginStatus; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -37,19 +36,21 @@ import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; @Component -@AllArgsConstructor +@RequiredArgsConstructor @Slf4j public class DmiRestClient { private static final String HEALTH_CHECK_URL_EXTENSION = "/actuator/health"; - private RestTemplate restTemplate; - private DmiProperties dmiProperties; + private static final String EMPTY_STRING = ""; + private final RestTemplate restTemplate; + private final DmiProperties dmiProperties; /** * Sends POST operation to DMI with json body containing module references. - * @param dmiResourceUrl dmi resource url + * + * @param dmiResourceUrl dmi resource url * @param requestBodyAsJsonString json data body - * @param operationType the type of operation being executed (for error reporting only) + * @param operationType the type of operation being executed (for error reporting only) * @return response entity of type String */ public ResponseEntity postOperationWithJsonData(final String dmiResourceUrl, @@ -61,28 +62,28 @@ public class DmiRestClient { } catch (final HttpStatusCodeException httpStatusCodeException) { final String exceptionMessage = "Unable to " + operationType.toString() + " resource data."; throw new HttpClientRequestException(exceptionMessage, httpStatusCodeException.getResponseBodyAsString(), - httpStatusCodeException.getStatusCode().value()); + httpStatusCodeException.getStatusCode().value()); } } /** - * Sends GET operation to DMI plugin's health check URL. + * Get DMI plugin health status. * * @param dmiPluginBaseUrl the base URL of the dmi-plugin - * @return DmiPluginStatus as UP or DOWN + * @return plugin health status ("UP" is all OK, EMPTY_STRING in case of any exception) */ - public DmiPluginStatus getDmiPluginStatus(final String dmiPluginBaseUrl) { + public String getDmiHealthStatus(final String dmiPluginBaseUrl) { + final HttpEntity httpHeaders = new HttpEntity<>(configureHttpHeaders(new HttpHeaders())); try { - final HttpEntity httpHeaders = new HttpEntity<>(configureHttpHeaders(new HttpHeaders())); - final JsonNode dmiPluginHealthStatus = restTemplate - .getForObject(dmiPluginBaseUrl + HEALTH_CHECK_URL_EXTENSION, JsonNode.class, httpHeaders); - if (dmiPluginHealthStatus != null && dmiPluginHealthStatus.get("status").asText().equals("UP")) { - return DmiPluginStatus.UP; - } - } catch (final Exception exception) { - log.warn("Could not send request for health check since {}", exception.getMessage()); + final JsonNode responseHealthStatus = + restTemplate.getForObject(dmiPluginBaseUrl + HEALTH_CHECK_URL_EXTENSION, + JsonNode.class, httpHeaders); + return responseHealthStatus == null ? EMPTY_STRING : + 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 DmiPluginStatus.DOWN; } private HttpHeaders configureHttpHeaders(final HttpHeaders httpHeaders) { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java index 419d0a345..2d7ad698c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImpl.java @@ -36,7 +36,6 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.onap.cps.ncmp.api.impl.inventory.enums.PropertyType; import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelFilter; import org.onap.cps.spi.CpsDataPersistenceService; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; @@ -50,6 +49,7 @@ public class CmHandleQueriesImpl implements CmHandleQueries { private static final String DESCENDANT_PATH = "//"; private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles"; private final CpsDataPersistenceService cpsDataPersistenceService; + private final Map trustLevelPerDmiPlugin; private final Map trustLevelPerCmHandle; private final CpsValidator cpsValidator; @@ -68,8 +68,7 @@ public class CmHandleQueriesImpl implements CmHandleQueries { final String trustLevelProperty = trustLevelPropertyQueryPairs.values().iterator().next(); final TrustLevel targetTrustLevel = TrustLevel.valueOf(trustLevelProperty); - final TrustLevelFilter trustLevelFilter = new TrustLevelFilter(targetTrustLevel, trustLevelPerCmHandle); - return trustLevelFilter.getAllCmHandleIdsByTargetTrustLevel(); + return getCmHandleIdsByTrustLevel(targetTrustLevel); } @Override @@ -117,6 +116,26 @@ public class CmHandleQueriesImpl implements CmHandleQueries { return cmHandleIds; } + private Collection getCmHandleIdsByTrustLevel(final TrustLevel targetTrustLevel) { + final Collection selectedCmHandleIds = new HashSet<>(); + + for (final Map.Entry mapEntry : trustLevelPerDmiPlugin.entrySet()) { + final String dmiPluginIdentifier = mapEntry.getKey(); + final TrustLevel dmiTrustLevel = mapEntry.getValue(); + final Collection candidateCmHandleIds = getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier); + for (final String candidateCmHandleId : candidateCmHandleIds) { + final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandle.get(candidateCmHandleId); + final TrustLevel effectiveTrustlevel = + candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); + if (targetTrustLevel.equals(effectiveTrustlevel)) { + selectedCmHandleIds.add(candidateCmHandleId); + } + } + } + + return selectedCmHandleIds; + } + private Collection collectCmHandleIdsFromDataNodes(final Collection dataNodes) { return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet()); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevel.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevel.java index 8d1f8e90f..f130604a6 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevel.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevel.java @@ -25,11 +25,28 @@ import lombok.Getter; @Getter public enum TrustLevel { NONE(0), COMPLETE(99); + private final int level; - private final int value; + /** + * Creates TrustLevel enum from a numeric value. + * + * @param level numeric value between 0-99 + */ + TrustLevel(final int level) { + this.level = level; + } - TrustLevel(final int value) { - this.value = value; + /** + * Gets the lower trust level (effective) among two. + * + * @param other the trust level compared with this + * @return the lower trust level + */ + public final TrustLevel getEffectiveTrustLevel(final TrustLevel other) { + if (other.level < this.level) { + return other; + } + return this; } -} \ No newline at end of file +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelFilter.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelFilter.java deleted file mode 100644 index 3b704ae4f..000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelFilter.java +++ /dev/null @@ -1,58 +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.trustlevel; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class TrustLevelFilter implements Comparable { - - @EqualsAndHashCode.Include - private final TrustLevel targetTrustLevel; - private final Map trustLevelPerCmHandle; - - @Override - public int compareTo(@NonNull final TrustLevel other) { - return Integer.compare(this.targetTrustLevel.getValue(), other.getValue()); - } - - /** - * This method return cm handles that matches with given trust level. - * - * @return cm handle ids. - */ - public Collection getAllCmHandleIdsByTargetTrustLevel() { - final Collection resultCmHandleIds = new HashSet<>(); - trustLevelPerCmHandle.entrySet().forEach(cmHandleTrustLevelEntrySet -> { - if (compareTo(cmHandleTrustLevelEntrySet.getValue()) == 0) { - resultCmHandleIds.add(cmHandleTrustLevelEntrySet.getKey()); - } - }); - return resultCmHandleIds; - } - -} 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 deleted file mode 100644 index 39f880257..000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDog.java +++ /dev/null @@ -1,60 +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.trustlevel.dmiavailability; - -import java.util.Map; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.impl.client.DmiRestClient; -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - -@Slf4j -@RequiredArgsConstructor -@Service -public class DMiPluginWatchDog { - - private final Map trustLevelPerDmiPlugin; - - private final DmiRestClient dmiRestClient; - - /** - * Monitors the aliveness of DMI plugins by this watchdog. - * This method periodically checks the health and status of each DMI plugin to ensure that - * they are functioning properly. If a plugin is found to be unresponsive or in an - * unhealthy state, the cache will be updated with the latest status. - * The @fixedDelayString is the time interval, in milliseconds, between consecutive aliveness checks. - */ - @Scheduled(fixedDelayString = "${ncmp.timers.trust-evel.dmi-availability-watchdog-ms:30000}") - public void watchDmiPluginAliveness() { - trustLevelPerDmiPlugin.keySet().forEach(dmiPluginName -> { - final DmiPluginStatus dmiPluginStatus = dmiRestClient.getDmiPluginStatus(dmiPluginName); - log.debug("Trust level for dmi-plugin: {} is {}", dmiPluginName, dmiPluginStatus.toString()); - if (DmiPluginStatus.UP.equals(dmiPluginStatus)) { - trustLevelPerDmiPlugin.put(dmiPluginName, TrustLevel.COMPLETE); - } else { - trustLevelPerDmiPlugin.put(dmiPluginName, TrustLevel.NONE); - } - }); - } - -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginStatus.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginStatus.java deleted file mode 100644 index 352d36f94..000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginStatus.java +++ /dev/null @@ -1,25 +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.trustlevel.dmiavailability; - -public enum DmiPluginStatus { - UP, DOWN; -} 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 new file mode 100644 index 000000000..b073f1bc3 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDog.java @@ -0,0 +1,56 @@ +/* + * ============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.dmiavailability; + +import java.util.Map; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.impl.client.DmiRestClient; +import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Slf4j +@RequiredArgsConstructor +@Service +public class DmiPluginWatchDog { + + private final DmiRestClient dmiRestClient; + private final Map 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 @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); + if ("UP".equals(dmiHealthStatus)) { + trustLevelPerDmiPlugin.put(dmiKey, TrustLevel.COMPLETE); + } else { + trustLevelPerDmiPlugin.put(dmiKey, TrustLevel.NONE); + } + }); + } + +} -- cgit 1.2.3-korg