Merge "Add withTrustLevel condition to CmHandle Query API"
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / NetworkCmProxyDataServiceImpl.java
1 /*
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
12  *
13  *        http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  *  SPDX-License-Identifier: Apache-2.0
22  *  ============LICENSE_END=========================================================
23  */
24
25 package org.onap.cps.ncmp.api.impl;
26
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;
35
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;
45 import java.util.Map;
46 import java.util.Set;
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;
86
87 @Slf4j
88 @Service
89 @RequiredArgsConstructor
90 public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
91
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> trustLevelPerDmiPlugin;
103
104     @Override
105     public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
106             final DmiPluginRegistration dmiPluginRegistration) {
107         dmiPluginRegistration.validateDmiPluginRegistration();
108         final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse();
109
110         if (!dmiPluginRegistration.getRemovedCmHandles().isEmpty()) {
111             dmiPluginRegistrationResponse.setRemovedCmHandles(
112                     parseAndProcessDeletedCmHandlesInRegistration(dmiPluginRegistration.getRemovedCmHandles()));
113         }
114
115         if (!dmiPluginRegistration.getCreatedCmHandles().isEmpty()) {
116             dmiPluginRegistrationResponse.setCreatedCmHandles(
117                     parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration));
118         }
119         if (!dmiPluginRegistration.getUpdatedCmHandles().isEmpty()) {
120             dmiPluginRegistrationResponse.setUpdatedCmHandles(
121                     networkCmProxyDataServicePropertyHandler
122                             .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles()));
123         }
124         if (dmiPluginRegistration.getUpgradedCmHandles() != null
125                 && !dmiPluginRegistration.getUpgradedCmHandles().getCmHandles().isEmpty()) {
126             dmiPluginRegistrationResponse.setUpgradedCmHandles(
127                     parseAndProcessUpgradedCmHandlesInRegistration(dmiPluginRegistration));
128         }
129
130         setTrustLevelPerDmiPlugin(dmiPluginRegistration);
131
132         return dmiPluginRegistrationResponse;
133     }
134
135     @Override
136     public Object getResourceDataForCmHandle(final String datastoreName,
137                                              final String cmHandleId,
138                                              final String resourceIdentifier,
139                                              final String optionsParamInQuery,
140                                              final String topicParamInQuery,
141                                              final String requestId) {
142         final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(datastoreName, cmHandleId,
143                 resourceIdentifier,
144                 optionsParamInQuery,
145                 topicParamInQuery,
146                 requestId);
147         return responseEntity.getBody();
148     }
149
150     @Override
151     public Object getResourceDataForCmHandle(final String datastoreName,
152                                              final String cmHandleId,
153                                              final String resourceIdentifier,
154                                              final FetchDescendantsOption fetchDescendantsOption) {
155         return cpsDataService.getDataNodes(datastoreName, cmHandleId, resourceIdentifier,
156                 fetchDescendantsOption).iterator().next();
157     }
158
159     @Override
160     public void executeDataOperationForCmHandles(final String topicParamInQuery,
161                                                  final DataOperationRequest
162                                                          dataOperationRequest,
163                                                  final String requestId) {
164         dmiDataOperations.requestResourceDataFromDmi(topicParamInQuery, dataOperationRequest, requestId);
165     }
166
167     @Override
168     public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId,
169                                                                  final String resourceIdentifier,
170                                                                  final OperationType operationType,
171                                                                  final String requestData,
172                                                                  final String dataType) {
173         return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier,
174                 operationType, requestData, dataType);
175     }
176
177     @Override
178     public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
179         return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId);
180     }
181
182     @Override
183     public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
184         return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
185     }
186
187     /**
188      * Retrieve cm handles with details for the given query parameters.
189      *
190      * @param cmHandleQueryApiParameters cm handle query parameters
191      * @return cm handles with details
192      */
193     @Override
194     public Collection<NcmpServiceCmHandle> executeCmHandleSearch(
195             final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
196         final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
197                 cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
198         validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
199         return networkCmProxyCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters);
200     }
201
202     /**
203      * Retrieve cm handle ids for the given query parameters.
204      *
205      * @param cmHandleQueryApiParameters cm handle query parameters
206      * @return cm handle ids
207      */
208     @Override
209     public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
210         final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
211                 cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
212         validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
213         return networkCmProxyCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
214     }
215
216     /**
217      * Set the data sync enabled flag, along with the data sync state
218      * based on the data sync enabled boolean for the cm handle id provided.
219      *
220      * @param cmHandleId      cm handle id
221      * @param dataSyncEnabled data sync enabled flag
222      */
223     @Override
224     public void setDataSyncEnabled(final String cmHandleId, final boolean dataSyncEnabled) {
225         final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
226         if (compositeState.getDataSyncEnabled().equals(dataSyncEnabled)) {
227             log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabled);
228         } else if (compositeState.getCmHandleState() != CmHandleState.READY) {
229             throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: "
230                     + compositeState.getCmHandleState());
231         } else {
232             final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores()
233                     .getOperationalDataStore().getDataStoreSyncState();
234             if (!dataSyncEnabled && dataStoreSyncState == DataStoreSyncState.SYNCHRONIZED) {
235                 cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
236                         "/netconf-state", OffsetDateTime.now());
237             }
238             CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabled, compositeState);
239             inventoryPersistence.saveCmHandleState(cmHandleId,
240                     compositeState);
241         }
242     }
243
244     /**
245      * Get all cm handle IDs by DMI plugin identifier.
246      *
247      * @param dmiPluginIdentifier DMI plugin identifier
248      * @return set of cm handle IDs
249      */
250     @Override
251     public Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
252         return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
253     }
254
255     /**
256      * Get all cm handle IDs by various properties.
257      *
258      * @param cmHandleQueryServiceParameters cm handle query parameters
259      * @return set of cm handle IDs
260      */
261     @Override
262     public Collection<String> executeCmHandleIdSearchForInventory(
263             final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
264         validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
265         return networkCmProxyCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
266     }
267
268     /**
269      * Retrieve cm handle details for a given cm handle.
270      *
271      * @param cmHandleId cm handle identifier
272      * @return cm handle details
273      */
274     @Override
275     public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) {
276         return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(
277                 inventoryPersistence.getYangModelCmHandle(cmHandleId));
278     }
279
280     /**
281      * Get cm handle public properties for a given cm handle id.
282      *
283      * @param cmHandleId cm handle identifier
284      * @return cm handle public properties
285      */
286     @Override
287     public Map<String, String> getCmHandlePublicProperties(final String cmHandleId) {
288         final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
289         final List<YangModelCmHandle.Property> yangModelPublicProperties = yangModelCmHandle.getPublicProperties();
290         final Map<String, String> cmHandlePublicProperties = new HashMap<>();
291         YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties);
292         return cmHandlePublicProperties;
293     }
294
295     /**
296      * Get cm handle composite state for a given cm handle id.
297      *
298      * @param cmHandleId cm handle identifier
299      * @return cm handle state
300      */
301     @Override
302     public CompositeState getCmHandleCompositeState(final String cmHandleId) {
303         return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState();
304     }
305
306     /**
307      * THis method registers a cm handle and initiates modules sync.
308      *
309      * @param dmiPluginRegistration dmi plugin registration information.
310      * @return cm-handle registration response for create cm-handle requests.
311      */
312     public List<CmHandleRegistrationResponse> parseAndProcessCreatedCmHandlesInRegistration(
313             final DmiPluginRegistration dmiPluginRegistration) {
314         final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>();
315         dmiPluginRegistration.getCreatedCmHandles()
316                 .forEach(cmHandle -> {
317                     final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
318                             dmiPluginRegistration.getDmiPlugin(),
319                             dmiPluginRegistration.getDmiDataPlugin(),
320                             dmiPluginRegistration.getDmiModelPlugin(),
321                             cmHandle,
322                             cmHandle.getModuleSetTag());
323                     cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.ADVISED);
324                 });
325         return registerNewCmHandles(cmHandleStatePerCmHandle);
326     }
327
328     protected List<CmHandleRegistrationResponse> parseAndProcessDeletedCmHandlesInRegistration(
329             final List<String> tobeRemovedCmHandles) {
330         final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
331                 new ArrayList<>(tobeRemovedCmHandles.size());
332         final Collection<YangModelCmHandle> yangModelCmHandles =
333                 inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles);
334
335         updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING);
336
337         final Set<String> notDeletedCmHandles = new HashSet<>();
338         for (final List<String> tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandles, DELETE_BATCH_SIZE)) {
339             try {
340                 batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch);
341                 tobeRemovedCmHandleBatch.forEach(cmHandleId ->
342                     cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)));
343
344             } catch (final RuntimeException batchException) {
345                 log.error("Unable to de-register cm-handle batch, retrying on each cm handle");
346                 for (final String cmHandleId : tobeRemovedCmHandleBatch) {
347                     final CmHandleRegistrationResponse cmHandleRegistrationResponse =
348                         deleteCmHandleAndGetCmHandleRegistrationResponse(cmHandleId);
349                     cmHandleRegistrationResponses.add(cmHandleRegistrationResponse);
350                     if (cmHandleRegistrationResponse.getStatus() != CmHandleRegistrationResponse.Status.SUCCESS) {
351                         notDeletedCmHandles.add(cmHandleId);
352                     }
353                 }
354             }
355         }
356
357         yangModelCmHandles.removeIf(yangModelCmHandle -> notDeletedCmHandles.contains(yangModelCmHandle.getId()));
358         updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETED);
359
360         return cmHandleRegistrationResponses;
361     }
362
363     protected List<CmHandleRegistrationResponse> parseAndProcessUpgradedCmHandlesInRegistration(
364             final DmiPluginRegistration dmiPluginRegistration) {
365
366         final UpgradedCmHandles upgradedCmHandles = dmiPluginRegistration.getUpgradedCmHandles();
367         final String moduleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag();
368         final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle =
369                 new HashMap<>(upgradedCmHandles.getCmHandles().size());
370         final Collection<String> notReadyCmHandles = new ArrayList<>(upgradedCmHandles.getCmHandles().size());
371         final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle();
372         final String formattedModuleSetTag = MessageFormat.format("new moduleSetTag: {0}", moduleSetTag);
373
374         upgradedCmHandles.getCmHandles().forEach(cmHandleId -> {
375             if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) {
376                 ncmpServiceCmHandle.setCmHandleId(cmHandleId);
377                 ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder()
378                         .withCmHandleState(CmHandleState.READY)
379                         .withLockReason(MODULE_UPGRADE, formattedModuleSetTag).build());
380                 final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
381                         dmiPluginRegistration.getDmiPlugin(),
382                         dmiPluginRegistration.getDmiDataPlugin(),
383                         dmiPluginRegistration.getDmiModelPlugin(),
384                         ncmpServiceCmHandle,
385                         moduleSetTag);
386                 cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED);
387             } else {
388                 notReadyCmHandles.add(cmHandleId);
389             }
390         });
391
392         final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses
393                 = upgradeCmHandles(cmHandleStatePerCmHandle);
394         cmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponses(notReadyCmHandles,
395                 CM_HANDLES_NOT_READY));
396         return cmHandleRegistrationResponses;
397     }
398
399     private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) {
400         try {
401             deleteCmHandleFromDbAndModuleSyncMap(cmHandleId);
402             return CmHandleRegistrationResponse.createSuccessResponse(cmHandleId);
403         } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
404             log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
405                 cmHandleId, dataNodeNotFoundException.getMessage());
406             return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND);
407         } catch (final DataValidationException dataValidationException) {
408             log.error("Unable to de-register cm-handle id: {}, caused by: {}",
409                 cmHandleId, dataValidationException.getMessage());
410             return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID);
411         } catch (final Exception exception) {
412             log.error("Unable to de-register cm-handle id : {} , caused by : {}", cmHandleId, exception.getMessage());
413             return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception);
414         }
415     }
416
417     private void updateCmHandleStateBatch(final Collection<YangModelCmHandle> yangModelCmHandles,
418                                           final CmHandleState cmHandleState) {
419         final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size());
420         yangModelCmHandles.forEach(yangModelCmHandle -> cmHandleStatePerCmHandle.put(yangModelCmHandle, cmHandleState));
421         lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
422     }
423
424     private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) {
425         inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId);
426         inventoryPersistence.deleteDataNode(NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId
427                 + "']");
428         removeDeletedCmHandleFromModuleSyncMap(cmHandleId);
429     }
430
431     private void batchDeleteCmHandlesFromDbAndModuleSyncMap(final Collection<String> tobeRemovedCmHandles) {
432         inventoryPersistence.deleteSchemaSetsWithCascade(tobeRemovedCmHandles);
433         inventoryPersistence.deleteDataNodes(mapCmHandleIdsToXpaths(tobeRemovedCmHandles));
434         tobeRemovedCmHandles.forEach(this::removeDeletedCmHandleFromModuleSyncMap);
435     }
436
437     private Collection<String> mapCmHandleIdsToXpaths(final Collection<String> cmHandles) {
438         return cmHandles.stream()
439                 .map(cmHandleId -> NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']")
440                 .collect(Collectors.toSet());
441     }
442
443     // CPS-1239 Robustness cleaning of in progress cache
444     private void removeDeletedCmHandleFromModuleSyncMap(final String deletedCmHandleId) {
445         if (moduleSyncStartedOnCmHandles.remove(deletedCmHandleId) != null) {
446             log.debug("{} removed from in progress map", deletedCmHandleId);
447         }
448     }
449
450     private List<CmHandleRegistrationResponse> registerNewCmHandles(final Map<YangModelCmHandle, CmHandleState>
451                                                                             cmHandleStatePerCmHandle) {
452         final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
453         try {
454             lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
455             return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
456         } catch (final AlreadyDefinedException alreadyDefinedException) {
457             return CmHandleRegistrationResponse.createFailureResponses(
458                     alreadyDefinedException.getAlreadyDefinedObjectNames(),
459                     CM_HANDLE_ALREADY_EXIST);
460         } catch (final Exception exception) {
461             return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
462         }
463     }
464
465     private List<CmHandleRegistrationResponse> upgradeCmHandles(final Map<YangModelCmHandle, CmHandleState>
466                                                                         cmHandleStatePerCmHandle) {
467         final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
468         log.info("Moving cm handles : {} into locked (for upgrade) state.", cmHandleIds);
469         try {
470             lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
471             return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
472         } catch (final Exception exception) {
473             return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
474         }
475     }
476
477     private static List<String> getCmHandleIds(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) {
478         return cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId).toList();
479     }
480
481     private void setTrustLevelPerDmiPlugin(final DmiPluginRegistration dmiPluginRegistration) {
482         if (DmiPluginRegistration.isNullEmptyOrBlank(dmiPluginRegistration.getDmiDataPlugin())) {
483             trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiPlugin(), TrustLevel.COMPLETE);
484         } else {
485             trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiDataPlugin(), TrustLevel.COMPLETE);
486         }
487     }
488
489 }