/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 highstreet technologies GmbH
- * Modifications Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2021-2022 Bell Canada
* ================================================================================
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum;
import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters;
+import com.google.common.collect.Lists;
import com.hazelcast.map.IMap;
import java.time.OffsetDateTime;
import java.util.ArrayList;
@RequiredArgsConstructor
public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
+ private static final int DELETE_BATCH_SIZE = 100;
private final JsonObjectMapper jsonObjectMapper;
private final DmiDataOperations dmiDataOperations;
private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler;
.collect(Collectors.toList());
updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING);
- for (final String cmHandleId : tobeRemovedCmHandles) {
+ for (final List<String> tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandles, DELETE_BATCH_SIZE)) {
try {
- deleteCmHandleFromDbAndModuleSyncMap(cmHandleId);
- cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId));
- } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
- log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
- cmHandleId, dataNodeNotFoundException.getMessage());
- cmHandleRegistrationResponses.add(CmHandleRegistrationResponse
- .createFailureResponse(cmHandleId, RegistrationError.CM_HANDLE_DOES_NOT_EXIST));
- } catch (final DataValidationException dataValidationException) {
- log.error("Unable to de-register cm-handle id: {}, caused by: {}",
- cmHandleId, dataValidationException.getMessage());
- cmHandleRegistrationResponses.add(CmHandleRegistrationResponse
- .createFailureResponse(cmHandleId, RegistrationError.CM_HANDLE_INVALID_ID));
- } catch (final Exception exception) {
- log.error("Unable to de-register cm-handle id : {} , caused by : {}",
- cmHandleId, exception.getMessage());
- cmHandleRegistrationResponses.add(
- CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception));
+ batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch);
+ tobeRemovedCmHandleBatch.forEach(cmHandleId ->
+ cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)));
+
+ } catch (final Exception batchException) {
+ log.error("Unable to de-register cm-handle batch, retrying on each cm handle");
+ for (final String cmHandleId : tobeRemovedCmHandleBatch) {
+ final CmHandleRegistrationResponse cmHandleRegistrationResponse =
+ deleteCmHandleAndGetCmHandleRegistrationResponse(cmHandleId);
+ cmHandleRegistrationResponses.add(cmHandleRegistrationResponse);
+ }
}
}
return cmHandleRegistrationResponses;
}
+ private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) {
+ try {
+ deleteCmHandleFromDbAndModuleSyncMap(cmHandleId);
+ return CmHandleRegistrationResponse.createSuccessResponse(cmHandleId);
+ } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
+ log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
+ cmHandleId, dataNodeNotFoundException.getMessage());
+ return CmHandleRegistrationResponse.createFailureResponse(cmHandleId,
+ RegistrationError.CM_HANDLE_DOES_NOT_EXIST);
+ } catch (final DataValidationException dataValidationException) {
+ log.error("Unable to de-register cm-handle id: {}, caused by: {}",
+ cmHandleId, dataValidationException.getMessage());
+ return CmHandleRegistrationResponse.createFailureResponse(cmHandleId,
+ RegistrationError.CM_HANDLE_INVALID_ID);
+ } catch (final Exception exception) {
+ log.error("Unable to de-register cm-handle id : {} , caused by : {}", cmHandleId, exception.getMessage());
+ return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception);
+ }
+ }
+
private void updateCmHandleStateBatch(final List<YangModelCmHandle> yangModelCmHandles,
final CmHandleState cmHandleState) {
final Map<YangModelCmHandle, CmHandleState> cmHandleIdsToBeRemoved = new HashMap<>();
private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) {
inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId);
- inventoryPersistence.deleteListOrListElement("/dmi-registry/cm-handles[@id='" + cmHandleId + "']");
+ inventoryPersistence.deleteDataNode("/dmi-registry/cm-handles[@id='" + cmHandleId + "']");
removeDeletedCmHandleFromModuleSyncMap(cmHandleId);
}
+ private void batchDeleteCmHandlesFromDbAndModuleSyncMap(final Collection<String> tobeRemovedCmHandles) {
+ tobeRemovedCmHandles.forEach(inventoryPersistence::deleteSchemaSetWithCascade);
+ inventoryPersistence.deleteDataNodes(mapCmHandleIdsToXpaths(tobeRemovedCmHandles));
+ tobeRemovedCmHandles.forEach(this::removeDeletedCmHandleFromModuleSyncMap);
+ }
+
+ private Collection<String> mapCmHandleIdsToXpaths(final Collection<String> cmHandles) {
+ return cmHandles.stream()
+ .map(cmHandleId -> "/dmi-registry/cm-handles[@id='" + cmHandleId + "']")
+ .collect(Collectors.toSet());
+ }
+
// CPS-1239 Robustness cleaning of in progress cache
private void removeDeletedCmHandleFromModuleSyncMap(final String deletedCmHandleId) {
if (moduleSyncStartedOnCmHandles.remove(deletedCmHandleId) != null) {
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation
+ * Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
and: 'method to delete relevant schema set is called once'
1 * mockInventoryPersistence.deleteSchemaSetWithCascade(_)
and: 'method to delete relevant list/list element is called once'
- 1 * mockInventoryPersistence.deleteListOrListElement(_)
+ 1 * mockInventoryPersistence.deleteDataNodes(_)
and: 'successful response is received'
assert response.getRemovedCmHandles().size() == 1
with(response.getRemovedCmHandles().get(0)) {
given: 'a registration with three cm-handles to be deleted'
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
removedCmHandles: ['cmhandle1', 'cmhandle2', 'cmhandle3'])
+ and: 'cm-handle deletion fails on batch'
+ mockInventoryPersistence.deleteDataNodes(_) >> { throw new RuntimeException("Failed") }
and: 'cm-handle deletion is successful for 1st and 3rd; failed for 2nd'
- mockInventoryPersistence.deleteListOrListElement(_) >> {} >> { throw new RuntimeException("Failed") } >> {}
+ mockInventoryPersistence.deleteDataNode(_) >> {} >> { throw new RuntimeException("Failed") } >> {}
when: 'registration is updated to delete cmhandles'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a response is received for all cm-handles'
then: 'no exception is thrown'
noExceptionThrown()
and: 'cm-handle is not deleted'
- 0 * mockInventoryPersistence.deleteListOrListElement(_)
+ 0 * mockInventoryPersistence.deleteDataNodes(_)
and: 'the cmHandle state is not updated to "DELETED"'
0 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.DELETED)
and: 'a failure response is received'
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
removedCmHandles: ['cmhandle'])
and: 'cm-handle deletion throws exception'
- mockInventoryPersistence.deleteListOrListElement(_) >> { throw deleteListElementException }
+ mockInventoryPersistence.deleteDataNodes(_) >> { throw deleteListElementException }
+ mockInventoryPersistence.deleteDataNode(_) >> { throw deleteListElementException }
when: 'registration is updated to delete cmhandle'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a failure response is received'