2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 highstreet technologies GmbH
4 * Modifications Copyright (C) 2021-2023 Nordix Foundation
5 * Modifications Copyright (C) 2021 Pantheon.tech
6 * Modifications Copyright (C) 2021-2022 Bell Canada
7 * Modifications Copyright (C) 2023 TechMahindra Ltd.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * SPDX-License-Identifier: Apache-2.0
22 * ============LICENSE_END=========================================================
25 package org.onap.cps.ncmp.api.impl;
27 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND;
28 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_READY;
29 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST;
30 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID;
31 import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE;
32 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT;
33 import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
34 import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters;
36 import com.google.common.collect.Lists;
37 import com.hazelcast.map.IMap;
38 import java.text.MessageFormat;
39 import java.time.OffsetDateTime;
40 import java.util.ArrayList;
41 import java.util.Collection;
42 import java.util.HashMap;
43 import java.util.HashSet;
44 import java.util.List;
47 import java.util.stream.Collectors;
48 import lombok.RequiredArgsConstructor;
49 import lombok.extern.slf4j.Slf4j;
50 import org.onap.cps.api.CpsDataService;
51 import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService;
52 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
53 import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler;
54 import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
55 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState;
56 import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
57 import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder;
58 import org.onap.cps.ncmp.api.impl.inventory.CompositeStateUtils;
59 import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState;
60 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
61 import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
62 import org.onap.cps.ncmp.api.impl.operations.OperationType;
63 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
64 import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
65 import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
66 import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
67 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
68 import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
69 import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
70 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
71 import org.onap.cps.ncmp.api.models.DataOperationRequest;
72 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
73 import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
74 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
75 import org.onap.cps.ncmp.api.models.UpgradedCmHandles;
76 import org.onap.cps.spi.FetchDescendantsOption;
77 import org.onap.cps.spi.exceptions.AlreadyDefinedException;
78 import org.onap.cps.spi.exceptions.CpsException;
79 import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
80 import org.onap.cps.spi.exceptions.DataValidationException;
81 import org.onap.cps.spi.model.ModuleDefinition;
82 import org.onap.cps.spi.model.ModuleReference;
83 import org.onap.cps.utils.JsonObjectMapper;
84 import org.springframework.http.ResponseEntity;
85 import org.springframework.stereotype.Service;
89 @RequiredArgsConstructor
90 public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
92 private static final int DELETE_BATCH_SIZE = 100;
93 private final JsonObjectMapper jsonObjectMapper;
94 private final DmiDataOperations dmiDataOperations;
95 private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler;
96 private final InventoryPersistence inventoryPersistence;
97 private final CmHandleQueries cmHandleQueries;
98 private final NetworkCmProxyCmHandleQueryService networkCmProxyCmHandleQueryService;
99 private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler;
100 private final CpsDataService cpsDataService;
101 private final IMap<String, Object> moduleSyncStartedOnCmHandles;
102 private final Map<String, TrustLevel> trustLevelPerCmHandle;
105 public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
106 final DmiPluginRegistration dmiPluginRegistration) {
107 dmiPluginRegistration.validateDmiPluginRegistration();
108 final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse();
110 if (!dmiPluginRegistration.getRemovedCmHandles().isEmpty()) {
111 dmiPluginRegistrationResponse.setRemovedCmHandles(
112 parseAndProcessDeletedCmHandlesInRegistration(dmiPluginRegistration.getRemovedCmHandles()));
115 if (!dmiPluginRegistration.getCreatedCmHandles().isEmpty()) {
116 populateTrustLevelPerCmHandleCache(dmiPluginRegistration);
117 dmiPluginRegistrationResponse.setCreatedCmHandles(
118 parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration));
120 if (!dmiPluginRegistration.getUpdatedCmHandles().isEmpty()) {
121 dmiPluginRegistrationResponse.setUpdatedCmHandles(
122 networkCmProxyDataServicePropertyHandler
123 .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles()));
125 if (dmiPluginRegistration.getUpgradedCmHandles() != null
126 && !dmiPluginRegistration.getUpgradedCmHandles().getCmHandles().isEmpty()) {
127 dmiPluginRegistrationResponse.setUpgradedCmHandles(
128 parseAndProcessUpgradedCmHandlesInRegistration(dmiPluginRegistration));
131 return dmiPluginRegistrationResponse;
135 public Object getResourceDataForCmHandle(final String datastoreName,
136 final String cmHandleId,
137 final String resourceIdentifier,
138 final String optionsParamInQuery,
139 final String topicParamInQuery,
140 final String requestId) {
141 final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(datastoreName, cmHandleId,
146 return responseEntity.getBody();
150 public Object getResourceDataForCmHandle(final String datastoreName,
151 final String cmHandleId,
152 final String resourceIdentifier,
153 final FetchDescendantsOption fetchDescendantsOption) {
154 return cpsDataService.getDataNodes(datastoreName, cmHandleId, resourceIdentifier,
155 fetchDescendantsOption).iterator().next();
159 public void executeDataOperationForCmHandles(final String topicParamInQuery,
160 final DataOperationRequest
161 dataOperationRequest,
162 final String requestId) {
163 dmiDataOperations.requestResourceDataFromDmi(topicParamInQuery, dataOperationRequest, requestId);
167 public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId,
168 final String resourceIdentifier,
169 final OperationType operationType,
170 final String requestData,
171 final String dataType) {
172 return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier,
173 operationType, requestData, dataType);
177 public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
178 return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId);
182 public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
183 return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
187 * Retrieve cm handles with details for the given query parameters.
189 * @param cmHandleQueryApiParameters cm handle query parameters
190 * @return cm handles with details
193 public Collection<NcmpServiceCmHandle> executeCmHandleSearch(
194 final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
195 final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
196 cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
197 validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
198 return networkCmProxyCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters);
202 * Retrieve cm handle ids for the given query parameters.
204 * @param cmHandleQueryApiParameters cm handle query parameters
205 * @return cm handle ids
208 public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
209 final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
210 cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
211 validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
212 return networkCmProxyCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
216 * Set the data sync enabled flag, along with the data sync state
217 * based on the data sync enabled boolean for the cm handle id provided.
219 * @param cmHandleId cm handle id
220 * @param dataSyncEnabledTargetValue data sync enabled flag
223 public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) {
224 final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
225 if (dataSyncEnabledTargetValue.equals(compositeState.getDataSyncEnabled())) {
226 log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabledTargetValue);
229 if (CmHandleState.READY.equals(compositeState.getCmHandleState())) {
230 final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores()
231 .getOperationalDataStore().getDataStoreSyncState();
232 if (Boolean.FALSE.equals(dataSyncEnabledTargetValue)
233 && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) {
234 // TODO : This is hard-coded for onap dmi that need to be addressed
235 cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
236 "/netconf-state", OffsetDateTime.now());
238 CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabledTargetValue, compositeState);
239 inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
241 throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: "
242 + compositeState.getCmHandleState());
247 * Get all cm handle IDs by DMI plugin identifier.
249 * @param dmiPluginIdentifier DMI plugin identifier
250 * @return set of cm handle IDs
253 public Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
254 return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
258 * Get all cm handle IDs by various properties.
260 * @param cmHandleQueryServiceParameters cm handle query parameters
261 * @return set of cm handle IDs
264 public Collection<String> executeCmHandleIdSearchForInventory(
265 final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
266 validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
267 return networkCmProxyCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
271 * Retrieve cm handle details for a given cm handle.
273 * @param cmHandleId cm handle identifier
274 * @return cm handle details
277 public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) {
278 return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(
279 inventoryPersistence.getYangModelCmHandle(cmHandleId));
283 * Get cm handle public properties for a given cm handle id.
285 * @param cmHandleId cm handle identifier
286 * @return cm handle public properties
289 public Map<String, String> getCmHandlePublicProperties(final String cmHandleId) {
290 final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
291 final List<YangModelCmHandle.Property> yangModelPublicProperties = yangModelCmHandle.getPublicProperties();
292 final Map<String, String> cmHandlePublicProperties = new HashMap<>();
293 YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties);
294 return cmHandlePublicProperties;
298 * Get cm handle composite state for a given cm handle id.
300 * @param cmHandleId cm handle identifier
301 * @return cm handle state
304 public CompositeState getCmHandleCompositeState(final String cmHandleId) {
305 return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState();
309 * THis method registers a cm handle and initiates modules sync.
311 * @param dmiPluginRegistration dmi plugin registration information.
312 * @return cm-handle registration response for create cm-handle requests.
314 public List<CmHandleRegistrationResponse> parseAndProcessCreatedCmHandlesInRegistration(
315 final DmiPluginRegistration dmiPluginRegistration) {
316 final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>();
317 dmiPluginRegistration.getCreatedCmHandles()
318 .forEach(cmHandle -> {
319 final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
320 dmiPluginRegistration.getDmiPlugin(),
321 dmiPluginRegistration.getDmiDataPlugin(),
322 dmiPluginRegistration.getDmiModelPlugin(),
324 cmHandle.getModuleSetTag());
325 cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.ADVISED);
327 return registerNewCmHandles(cmHandleStatePerCmHandle);
330 protected List<CmHandleRegistrationResponse> parseAndProcessDeletedCmHandlesInRegistration(
331 final List<String> tobeRemovedCmHandles) {
332 final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
333 new ArrayList<>(tobeRemovedCmHandles.size());
334 final Collection<YangModelCmHandle> yangModelCmHandles =
335 inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles);
337 updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING);
339 final Set<String> notDeletedCmHandles = new HashSet<>();
340 for (final List<String> tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandles, DELETE_BATCH_SIZE)) {
342 batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch);
343 tobeRemovedCmHandleBatch.forEach(cmHandleId ->
344 cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)));
346 } catch (final RuntimeException batchException) {
347 log.error("Unable to de-register cm-handle batch, retrying on each cm handle");
348 for (final String cmHandleId : tobeRemovedCmHandleBatch) {
349 final CmHandleRegistrationResponse cmHandleRegistrationResponse =
350 deleteCmHandleAndGetCmHandleRegistrationResponse(cmHandleId);
351 cmHandleRegistrationResponses.add(cmHandleRegistrationResponse);
352 if (cmHandleRegistrationResponse.getStatus() != CmHandleRegistrationResponse.Status.SUCCESS) {
353 notDeletedCmHandles.add(cmHandleId);
359 yangModelCmHandles.removeIf(yangModelCmHandle -> notDeletedCmHandles.contains(yangModelCmHandle.getId()));
360 updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETED);
362 return cmHandleRegistrationResponses;
365 protected List<CmHandleRegistrationResponse> parseAndProcessUpgradedCmHandlesInRegistration(
366 final DmiPluginRegistration dmiPluginRegistration) {
368 final UpgradedCmHandles upgradedCmHandles = dmiPluginRegistration.getUpgradedCmHandles();
369 final String moduleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag();
370 final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle =
371 new HashMap<>(upgradedCmHandles.getCmHandles().size());
372 final Collection<String> notReadyCmHandles = new ArrayList<>(upgradedCmHandles.getCmHandles().size());
373 final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle();
374 final String formattedModuleSetTag = MessageFormat.format("new moduleSetTag: {0}", moduleSetTag);
376 upgradedCmHandles.getCmHandles().forEach(cmHandleId -> {
377 if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) {
378 ncmpServiceCmHandle.setCmHandleId(cmHandleId);
379 ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder()
380 .withCmHandleState(CmHandleState.READY)
381 .withLockReason(MODULE_UPGRADE, formattedModuleSetTag).build());
382 final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
383 dmiPluginRegistration.getDmiPlugin(),
384 dmiPluginRegistration.getDmiDataPlugin(),
385 dmiPluginRegistration.getDmiModelPlugin(),
388 cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED);
390 notReadyCmHandles.add(cmHandleId);
394 return prepareAndGetCmHandleUpgradeResponses(cmHandleStatePerCmHandle, notReadyCmHandles);
397 private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) {
399 deleteCmHandleFromDbAndModuleSyncMap(cmHandleId);
400 return CmHandleRegistrationResponse.createSuccessResponse(cmHandleId);
401 } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
402 log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
403 cmHandleId, dataNodeNotFoundException.getMessage());
404 return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND);
405 } catch (final DataValidationException dataValidationException) {
406 log.error("Unable to de-register cm-handle id: {}, caused by: {}",
407 cmHandleId, dataValidationException.getMessage());
408 return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID);
409 } catch (final Exception exception) {
410 log.error("Unable to de-register cm-handle id : {} , caused by : {}", cmHandleId, exception.getMessage());
411 return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception);
415 private void updateCmHandleStateBatch(final Collection<YangModelCmHandle> yangModelCmHandles,
416 final CmHandleState cmHandleState) {
417 final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size());
418 yangModelCmHandles.forEach(yangModelCmHandle -> cmHandleStatePerCmHandle.put(yangModelCmHandle, cmHandleState));
419 lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
422 private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) {
423 inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId);
424 inventoryPersistence.deleteDataNode(NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId
426 removeDeletedCmHandleFromModuleSyncMap(cmHandleId);
429 private void batchDeleteCmHandlesFromDbAndModuleSyncMap(final Collection<String> tobeRemovedCmHandles) {
430 inventoryPersistence.deleteSchemaSetsWithCascade(tobeRemovedCmHandles);
431 inventoryPersistence.deleteDataNodes(mapCmHandleIdsToXpaths(tobeRemovedCmHandles));
432 tobeRemovedCmHandles.forEach(this::removeDeletedCmHandleFromModuleSyncMap);
435 private Collection<String> mapCmHandleIdsToXpaths(final Collection<String> cmHandles) {
436 return cmHandles.stream()
437 .map(cmHandleId -> NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']")
438 .collect(Collectors.toSet());
441 // CPS-1239 Robustness cleaning of in progress cache
442 private void removeDeletedCmHandleFromModuleSyncMap(final String deletedCmHandleId) {
443 if (moduleSyncStartedOnCmHandles.remove(deletedCmHandleId) != null) {
444 log.debug("{} removed from in progress map", deletedCmHandleId);
448 private List<CmHandleRegistrationResponse> registerNewCmHandles(final Map<YangModelCmHandle, CmHandleState>
449 cmHandleStatePerCmHandle) {
450 final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
452 lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
453 return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
454 } catch (final AlreadyDefinedException alreadyDefinedException) {
455 return CmHandleRegistrationResponse.createFailureResponses(
456 alreadyDefinedException.getAlreadyDefinedObjectNames(),
457 CM_HANDLE_ALREADY_EXIST);
458 } catch (final Exception exception) {
459 return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
463 private List<CmHandleRegistrationResponse> prepareAndGetCmHandleUpgradeResponses(final Map<YangModelCmHandle,
464 CmHandleState> cmHandleStatePerCmHandle, final Collection<String> notReadyCmHandles) {
465 final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses
466 = upgradeCmHandles(cmHandleStatePerCmHandle);
467 final List<CmHandleRegistrationResponse> failedCmHandleRegistrationResponses
468 = CmHandleRegistrationResponse.createFailureResponses(notReadyCmHandles, CM_HANDLES_NOT_READY);
469 failedCmHandleRegistrationResponses.forEach(cmHandleRegistrationResponses::add);
470 return cmHandleRegistrationResponses;
473 private List<CmHandleRegistrationResponse> upgradeCmHandles(final Map<YangModelCmHandle, CmHandleState>
474 cmHandleStatePerCmHandle) {
475 final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
476 log.info("Moving cm handles : {} into locked (for upgrade) state.", cmHandleIds);
478 lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
479 return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
480 } catch (final Exception exception) {
481 return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
485 private static List<String> getCmHandleIds(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) {
486 return cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId).toList();
489 private void populateTrustLevelPerCmHandleCache(final DmiPluginRegistration dmiPluginRegistration) {
490 for (final NcmpServiceCmHandle cmHandle: dmiPluginRegistration.getCreatedCmHandles()) {
491 if (cmHandle.getRegistrationTrustLevel() == null) {
492 if (trustLevelPerCmHandle.containsKey(cmHandle.getCmHandleId())) {
493 log.warn("CmHandle : {}, Already exists, Initial trustLevel ignored.", cmHandle.getCmHandleId());
495 trustLevelPerCmHandle.put(cmHandle.getCmHandleId(), TrustLevel.COMPLETE);
498 trustLevelPerCmHandle.put(cmHandle.getCmHandleId(), cmHandle.getRegistrationTrustLevel());