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.EnumMap;
43 import java.util.HashMap;
44 import java.util.HashSet;
45 import java.util.List;
48 import java.util.stream.Collectors;
49 import lombok.RequiredArgsConstructor;
50 import lombok.extern.slf4j.Slf4j;
51 import org.onap.cps.api.CpsDataService;
52 import org.onap.cps.ncmp.api.NcmpResponseStatus;
53 import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService;
54 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
55 import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler;
56 import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
57 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState;
58 import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
59 import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder;
60 import org.onap.cps.ncmp.api.impl.inventory.CompositeStateUtils;
61 import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState;
62 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
63 import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleOperationsUtils;
64 import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
65 import org.onap.cps.ncmp.api.impl.operations.OperationType;
66 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
67 import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
68 import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
69 import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
70 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
71 import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
72 import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
73 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
74 import org.onap.cps.ncmp.api.models.DataOperationRequest;
75 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
76 import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
77 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
78 import org.onap.cps.spi.FetchDescendantsOption;
79 import org.onap.cps.spi.exceptions.AlreadyDefinedException;
80 import org.onap.cps.spi.exceptions.CpsException;
81 import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
82 import org.onap.cps.spi.exceptions.DataValidationException;
83 import org.onap.cps.spi.model.ModuleDefinition;
84 import org.onap.cps.spi.model.ModuleReference;
85 import org.onap.cps.utils.JsonObjectMapper;
86 import org.springframework.http.ResponseEntity;
87 import org.springframework.stereotype.Service;
91 @RequiredArgsConstructor
92 public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
94 private static final int DELETE_BATCH_SIZE = 100;
95 private final JsonObjectMapper jsonObjectMapper;
96 private final DmiDataOperations dmiDataOperations;
97 private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler;
98 private final InventoryPersistence inventoryPersistence;
99 private final CmHandleQueries cmHandleQueries;
100 private final NetworkCmProxyCmHandleQueryService networkCmProxyCmHandleQueryService;
101 private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler;
102 private final CpsDataService cpsDataService;
103 private final IMap<String, Object> moduleSyncStartedOnCmHandles;
104 private final Map<String, TrustLevel> trustLevelPerCmHandle;
105 private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
108 public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
109 final DmiPluginRegistration dmiPluginRegistration) {
110 dmiPluginRegistration.validateDmiPluginRegistration();
111 final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse();
113 setTrustLevelPerDmiPlugin(dmiPluginRegistration);
115 if (!dmiPluginRegistration.getRemovedCmHandles().isEmpty()) {
116 dmiPluginRegistrationResponse.setRemovedCmHandles(
117 parseAndProcessDeletedCmHandlesInRegistration(dmiPluginRegistration.getRemovedCmHandles()));
120 if (!dmiPluginRegistration.getCreatedCmHandles().isEmpty()) {
121 dmiPluginRegistrationResponse.setCreatedCmHandles(
122 parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration));
123 populateTrustLevelPerCmHandleCache(dmiPluginRegistration);
125 if (!dmiPluginRegistration.getUpdatedCmHandles().isEmpty()) {
126 dmiPluginRegistrationResponse.setUpdatedCmHandles(
127 networkCmProxyDataServicePropertyHandler
128 .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles()));
130 if (dmiPluginRegistration.getUpgradedCmHandles() != null
131 && !dmiPluginRegistration.getUpgradedCmHandles().getCmHandles().isEmpty()) {
132 dmiPluginRegistrationResponse.setUpgradedCmHandles(
133 parseAndProcessUpgradedCmHandlesInRegistration(dmiPluginRegistration));
136 return dmiPluginRegistrationResponse;
140 public Object getResourceDataForCmHandle(final String datastoreName,
141 final String cmHandleId,
142 final String resourceIdentifier,
143 final String optionsParamInQuery,
144 final String topicParamInQuery,
145 final String requestId) {
146 final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(datastoreName, cmHandleId,
151 return responseEntity.getBody();
155 public Object getResourceDataForCmHandle(final String datastoreName,
156 final String cmHandleId,
157 final String resourceIdentifier,
158 final FetchDescendantsOption fetchDescendantsOption) {
159 return cpsDataService.getDataNodes(datastoreName, cmHandleId, resourceIdentifier,
160 fetchDescendantsOption).iterator().next();
164 public void executeDataOperationForCmHandles(final String topicParamInQuery,
165 final DataOperationRequest
166 dataOperationRequest,
167 final String requestId) {
168 dmiDataOperations.requestResourceDataFromDmi(topicParamInQuery, dataOperationRequest, requestId);
172 public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId,
173 final String resourceIdentifier,
174 final OperationType operationType,
175 final String requestData,
176 final String dataType) {
177 return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier,
178 operationType, requestData, dataType);
182 public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
183 return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId);
187 public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
188 return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
192 * Retrieve cm handles with details for the given query parameters.
194 * @param cmHandleQueryApiParameters cm handle query parameters
195 * @return cm handles with details
198 public Collection<NcmpServiceCmHandle> executeCmHandleSearch(
199 final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
200 final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
201 cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
202 validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
203 return networkCmProxyCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters);
207 * Retrieve cm handle ids for the given query parameters.
209 * @param cmHandleQueryApiParameters cm handle query parameters
210 * @return cm handle ids
213 public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
214 final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
215 cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
216 validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
217 return networkCmProxyCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
221 * Set the data sync enabled flag, along with the data sync state
222 * based on the data sync enabled boolean for the cm handle id provided.
224 * @param cmHandleId cm handle id
225 * @param dataSyncEnabledTargetValue data sync enabled flag
228 public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) {
229 final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
230 if (dataSyncEnabledTargetValue.equals(compositeState.getDataSyncEnabled())) {
231 log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabledTargetValue);
234 if (CmHandleState.READY.equals(compositeState.getCmHandleState())) {
235 final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores()
236 .getOperationalDataStore().getDataStoreSyncState();
237 if (Boolean.FALSE.equals(dataSyncEnabledTargetValue)
238 && DataStoreSyncState.SYNCHRONIZED.equals(dataStoreSyncState)) {
239 // TODO : This is hard-coded for onap dmi that need to be addressed
240 cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
241 "/netconf-state", OffsetDateTime.now());
243 CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabledTargetValue, compositeState);
244 inventoryPersistence.saveCmHandleState(cmHandleId, compositeState);
246 throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: "
247 + compositeState.getCmHandleState());
252 * Get all cm handle IDs by DMI plugin identifier.
254 * @param dmiPluginIdentifier DMI plugin identifier
255 * @return set of cm handle IDs
258 public Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
259 return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
263 * Get all cm handle IDs by various properties.
265 * @param cmHandleQueryServiceParameters cm handle query parameters
266 * @return set of cm handle IDs
269 public Collection<String> executeCmHandleIdSearchForInventory(
270 final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
271 validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
272 return networkCmProxyCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
276 * Retrieve cm handle details for a given cm handle.
278 * @param cmHandleId cm handle identifier
279 * @return cm handle details
282 public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) {
283 return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(
284 inventoryPersistence.getYangModelCmHandle(cmHandleId));
288 * Get cm handle public properties for a given cm handle id.
290 * @param cmHandleId cm handle identifier
291 * @return cm handle public properties
294 public Map<String, String> getCmHandlePublicProperties(final String cmHandleId) {
295 final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
296 final List<YangModelCmHandle.Property> yangModelPublicProperties = yangModelCmHandle.getPublicProperties();
297 final Map<String, String> cmHandlePublicProperties = new HashMap<>();
298 YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties);
299 return cmHandlePublicProperties;
303 * Get cm handle composite state for a given cm handle id.
305 * @param cmHandleId cm handle identifier
306 * @return cm handle state
309 public CompositeState getCmHandleCompositeState(final String cmHandleId) {
310 return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState();
314 * THis method registers a cm handle and initiates modules sync.
316 * @param dmiPluginRegistration dmi plugin registration information.
317 * @return cm-handle registration response for create cm-handle requests.
319 public List<CmHandleRegistrationResponse> parseAndProcessCreatedCmHandlesInRegistration(
320 final DmiPluginRegistration dmiPluginRegistration) {
321 final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>();
322 dmiPluginRegistration.getCreatedCmHandles().forEach(cmHandle -> {
323 final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
324 dmiPluginRegistration.getDmiPlugin(),
325 dmiPluginRegistration.getDmiDataPlugin(),
326 dmiPluginRegistration.getDmiModelPlugin(),
328 cmHandle.getModuleSetTag());
329 cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.ADVISED);
331 return registerNewCmHandles(cmHandleStatePerCmHandle);
334 protected List<CmHandleRegistrationResponse> parseAndProcessDeletedCmHandlesInRegistration(
335 final List<String> tobeRemovedCmHandles) {
336 final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
337 new ArrayList<>(tobeRemovedCmHandles.size());
338 final Collection<YangModelCmHandle> yangModelCmHandles =
339 inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles);
341 updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING);
343 final Set<String> notDeletedCmHandles = new HashSet<>();
344 for (final List<String> tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandles, DELETE_BATCH_SIZE)) {
346 batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch);
347 tobeRemovedCmHandleBatch.forEach(cmHandleId ->
348 cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)));
350 } catch (final RuntimeException batchException) {
351 log.error("Unable to de-register cm-handle batch, retrying on each cm handle");
352 for (final String cmHandleId : tobeRemovedCmHandleBatch) {
353 final CmHandleRegistrationResponse cmHandleRegistrationResponse =
354 deleteCmHandleAndGetCmHandleRegistrationResponse(cmHandleId);
355 cmHandleRegistrationResponses.add(cmHandleRegistrationResponse);
356 if (cmHandleRegistrationResponse.getStatus() != CmHandleRegistrationResponse.Status.SUCCESS) {
357 notDeletedCmHandles.add(cmHandleId);
363 yangModelCmHandles.removeIf(yangModelCmHandle -> notDeletedCmHandles.contains(yangModelCmHandle.getId()));
364 updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETED);
366 return cmHandleRegistrationResponses;
369 protected List<CmHandleRegistrationResponse> parseAndProcessUpgradedCmHandlesInRegistration(
370 final DmiPluginRegistration dmiPluginRegistration) {
372 final List<String> upgradedCmHandleIds = dmiPluginRegistration.getUpgradedCmHandles().getCmHandles();
374 final Map<YangModelCmHandle, CmHandleState> acceptedCmHandleStatePerCmHandle
375 = new HashMap<>(upgradedCmHandleIds.size());
377 final Map<NcmpResponseStatus, List<String>> failedCmHandlesPerResponseStatus
378 = new EnumMap<>(NcmpResponseStatus.class);
379 final List<String> nonExistingCmHandleIds = new ArrayList<>();
380 final List<String> nonReadyCmHandleIds = new ArrayList<>();
381 final List<String> invalidCmHandleIds = new ArrayList<>();
383 upgradedCmHandleIds.forEach(cmHandleId -> {
385 if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) {
386 final YangModelCmHandle yangModelCmHandleWithUpgradeDetails
387 = createYangModelCmHandle(dmiPluginRegistration, cmHandleId);
388 acceptedCmHandleStatePerCmHandle.put(yangModelCmHandleWithUpgradeDetails, CmHandleState.LOCKED);
390 nonReadyCmHandleIds.add(cmHandleId);
392 } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
393 log.error("Unable to find data node for cm handle id : {} , caused by : {}",
394 cmHandleId, dataNodeNotFoundException.getMessage());
395 nonExistingCmHandleIds.add(cmHandleId);
396 } catch (final DataValidationException dataValidationException) {
397 log.error("Unable to upgrade cm handle id: {}, caused by : {}",
398 cmHandleId, dataValidationException.getMessage());
399 invalidCmHandleIds.add(cmHandleId);
402 failedCmHandlesPerResponseStatus.put(CM_HANDLES_NOT_READY, nonReadyCmHandleIds);
403 failedCmHandlesPerResponseStatus.put(CM_HANDLES_NOT_FOUND, nonExistingCmHandleIds);
404 failedCmHandlesPerResponseStatus.put(CM_HANDLE_INVALID_ID, invalidCmHandleIds);
405 return mergeAllCmHandleResponses(acceptedCmHandleStatePerCmHandle, failedCmHandlesPerResponseStatus);
408 private static YangModelCmHandle createYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration,
409 final String cmHandleId) {
410 final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle();
411 ncmpServiceCmHandle.setCmHandleId(cmHandleId);
412 final String moduleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag();
413 final String lockReasonWithModuleSetTag = MessageFormat.format(
414 ModuleOperationsUtils.MODULE_SET_TAG_MESSAGE_FORMAT, moduleSetTag);
415 ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.READY)
416 .withLockReason(MODULE_UPGRADE, lockReasonWithModuleSetTag).build());
417 return YangModelCmHandle.toYangModelCmHandle(dmiPluginRegistration.getDmiPlugin(),
418 dmiPluginRegistration.getDmiDataPlugin(), dmiPluginRegistration.getDmiModelPlugin(),
419 ncmpServiceCmHandle, moduleSetTag);
422 private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) {
424 deleteCmHandleFromDbAndModuleSyncMap(cmHandleId);
425 return CmHandleRegistrationResponse.createSuccessResponse(cmHandleId);
426 } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
427 log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
428 cmHandleId, dataNodeNotFoundException.getMessage());
429 return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND);
430 } catch (final DataValidationException dataValidationException) {
431 log.error("Unable to de-register cm-handle id: {}, caused by: {}",
432 cmHandleId, dataValidationException.getMessage());
433 return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID);
434 } catch (final Exception exception) {
435 log.error("Unable to de-register cm-handle id : {} , caused by : {}", cmHandleId, exception.getMessage());
436 return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception);
440 private void updateCmHandleStateBatch(final Collection<YangModelCmHandle> yangModelCmHandles,
441 final CmHandleState cmHandleState) {
442 final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size());
443 yangModelCmHandles.forEach(yangModelCmHandle -> cmHandleStatePerCmHandle.put(yangModelCmHandle, cmHandleState));
444 lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
447 private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) {
448 inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId);
449 inventoryPersistence.deleteDataNode(NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId
451 removeDeletedCmHandleFromModuleSyncMap(cmHandleId);
454 private void batchDeleteCmHandlesFromDbAndModuleSyncMap(final Collection<String> tobeRemovedCmHandles) {
455 inventoryPersistence.deleteSchemaSetsWithCascade(tobeRemovedCmHandles);
456 inventoryPersistence.deleteDataNodes(mapCmHandleIdsToXpaths(tobeRemovedCmHandles));
457 tobeRemovedCmHandles.forEach(this::removeDeletedCmHandleFromModuleSyncMap);
460 private Collection<String> mapCmHandleIdsToXpaths(final Collection<String> cmHandles) {
461 return cmHandles.stream()
462 .map(cmHandleId -> NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']")
463 .collect(Collectors.toSet());
466 // CPS-1239 Robustness cleaning of in progress cache
467 private void removeDeletedCmHandleFromModuleSyncMap(final String deletedCmHandleId) {
468 if (moduleSyncStartedOnCmHandles.remove(deletedCmHandleId) != null) {
469 log.debug("{} removed from in progress map", deletedCmHandleId);
473 private List<CmHandleRegistrationResponse> registerNewCmHandles(final Map<YangModelCmHandle, CmHandleState>
474 cmHandleStatePerCmHandle) {
475 final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
477 lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
478 return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
479 } catch (final AlreadyDefinedException alreadyDefinedException) {
480 return CmHandleRegistrationResponse.createFailureResponses(
481 alreadyDefinedException.getAlreadyDefinedObjectNames(), CM_HANDLE_ALREADY_EXIST);
482 } catch (final Exception exception) {
483 return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
487 private List<CmHandleRegistrationResponse> mergeAllCmHandleResponses(
488 final Map<YangModelCmHandle, CmHandleState> acceptedCmHandleStatePerCmHandle,
489 final Map<NcmpResponseStatus, List<String>> failedCmHandlesPerResponseStatus) {
490 final List<CmHandleRegistrationResponse> cmHandleUpgradeResponses
491 = upgradeCmHandles(acceptedCmHandleStatePerCmHandle);
492 failedCmHandlesPerResponseStatus.forEach((ncmpResponseStatus, cmHandleIds) ->
493 cmHandleIds.forEach(cmHandleId -> cmHandleUpgradeResponses.add(CmHandleRegistrationResponse
494 .createFailureResponse(cmHandleId, ncmpResponseStatus))));
495 return cmHandleUpgradeResponses;
498 private List<CmHandleRegistrationResponse> upgradeCmHandles(final Map<YangModelCmHandle, CmHandleState>
499 cmHandleStatePerCmHandle) {
500 final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
501 log.info("Moving cm handles : {} into locked (for upgrade) state.", cmHandleIds);
503 lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
504 return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
505 } catch (final Exception e) {
506 log.error("Unable to update cmHandleIds : {} , caused by : {}", cmHandleIds, e.getMessage());
507 return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, e);
511 private static List<String> getCmHandleIds(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) {
512 return cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId).toList();
515 private void populateTrustLevelPerCmHandleCache(final DmiPluginRegistration dmiPluginRegistration) {
516 for (final NcmpServiceCmHandle cmHandle: dmiPluginRegistration.getCreatedCmHandles()) {
517 if (cmHandle.getRegistrationTrustLevel() == null) {
518 if (trustLevelPerCmHandle.containsKey(cmHandle.getCmHandleId())) {
519 log.warn("CmHandle : {}, Already exists, Initial trustLevel ignored.", cmHandle.getCmHandleId());
521 trustLevelPerCmHandle.put(cmHandle.getCmHandleId(), TrustLevel.COMPLETE);
524 trustLevelPerCmHandle.put(cmHandle.getCmHandleId(), cmHandle.getRegistrationTrustLevel());
529 private void setTrustLevelPerDmiPlugin(final DmiPluginRegistration dmiPluginRegistration) {
530 if (DmiPluginRegistration.isNullEmptyOrBlank(dmiPluginRegistration.getDmiDataPlugin())) {
531 trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiPlugin(), TrustLevel.COMPLETE);
533 trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiDataPlugin(), TrustLevel.COMPLETE);