summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java13
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java86
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/InvalidTopicException.java40
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java3
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java139
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java168
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java149
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java186
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java20
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java15
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java24
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java66
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy61
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy15
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesSpec.groovy)4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy)4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy13
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy23
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy17
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponseSpec.groovy23
23 files changed, 641 insertions, 434 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
index 45dba211a3..0ea0674281 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
@@ -33,6 +33,7 @@ import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
@@ -67,6 +68,18 @@ public interface NetworkCmProxyDataService {
String requestId);
/**
+ * Get resource data for operational.
+ *
+ * @param cmHandleId cm handle identifier
+ * @param resourceIdentifier resource identifier
+ * @Link FetchDescendantsOption fetch descendants option
+ * @return {@code Object} resource data
+ */
+ Object getResourceDataOperational(String cmHandleId,
+ String resourceIdentifier,
+ FetchDescendantsOption fetchDescendantsOption);
+
+ /**
* Get resource data for data store pass-through running
* using dmi.
*
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 5b072f35ed..3f440d65bd 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
@@ -23,6 +23,7 @@
package org.onap.cps.ncmp.api.impl;
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum;
import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters;
@@ -57,7 +58,8 @@ import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationErr
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.exceptions.AlreadyDefinedException;
+import org.onap.cps.spi.FetchDescendantsOption;
+import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
@@ -116,24 +118,32 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final String topicParamInQuery,
final String requestId) {
final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(cmHandleId,
- resourceIdentifier,
- optionsParamInQuery,
- DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL,
- requestId, topicParamInQuery);
+ resourceIdentifier,
+ optionsParamInQuery,
+ DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL,
+ requestId, topicParamInQuery);
return responseEntity.getBody();
}
@Override
+ public Object getResourceDataOperational(final String cmHandleId,
+ final String resourceIdentifier,
+ final FetchDescendantsOption fetchDescendantsOption) {
+ return cpsDataService.getDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, resourceIdentifier,
+ fetchDescendantsOption);
+ }
+
+ @Override
public Object getResourceDataPassThroughRunningForCmHandle(final String cmHandleId,
final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
final String requestId) {
final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(cmHandleId,
- resourceIdentifier,
- optionsParamInQuery,
- DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING,
- requestId, topicParamInQuery);
+ resourceIdentifier,
+ optionsParamInQuery,
+ DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING,
+ requestId, topicParamInQuery);
return responseEntity.getBody();
}
@@ -145,7 +155,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final String dataType) {
CpsValidator.validateNameCharacters(cmHandleId);
return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier, operation,
- requestData, dataType);
+ requestData, dataType);
}
@Override
@@ -196,29 +206,29 @@ 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 dataSyncEnabled data sync enabled flag
*/
@Override
public void setDataSyncEnabled(final String cmHandleId, final boolean dataSyncEnabled) {
CpsValidator.validateNameCharacters(cmHandleId);
final CompositeState compositeState = inventoryPersistence
- .getCmHandleState(cmHandleId);
+ .getCmHandleState(cmHandleId);
if (compositeState.getDataSyncEnabled().equals(dataSyncEnabled)) {
log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabled);
} else if (compositeState.getCmHandleState() != CmHandleState.READY) {
throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: "
- + compositeState.getCmHandleState());
+ + compositeState.getCmHandleState());
} else {
final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores()
- .getOperationalDataStore().getDataStoreSyncState();
+ .getOperationalDataStore().getDataStoreSyncState();
if (!dataSyncEnabled && dataStoreSyncState == DataStoreSyncState.SYNCHRONIZED) {
- cpsDataService.deleteDataNode("NFP-Operational", cmHandleId,
- "/netconf-state", OffsetDateTime.now());
+ cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
+ "/netconf-state", OffsetDateTime.now());
}
CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabled, compositeState);
inventoryPersistence.saveCmHandleState(cmHandleId,
- compositeState);
+ compositeState);
}
}
@@ -233,9 +243,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final Set<NcmpServiceCmHandle> ncmpServiceCmHandles =
cmHandleQueries.getCmHandlesByDmiPluginIdentifier(dmiPluginIdentifier);
final Set<String> cmHandleIds = new HashSet<>(ncmpServiceCmHandles.size());
- ncmpServiceCmHandles.forEach(cmHandle -> {
- cmHandleIds.add(cmHandle.getCmHandleId());
- });
+ ncmpServiceCmHandles.forEach(cmHandle -> cmHandleIds.add(cmHandle.getCmHandleId()));
return cmHandleIds;
}
@@ -262,7 +270,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
public Map<String, String> getCmHandlePublicProperties(final String cmHandleId) {
CpsValidator.validateNameCharacters(cmHandleId);
final YangModelCmHandle yangModelCmHandle =
- inventoryPersistence.getYangModelCmHandle(cmHandleId);
+ inventoryPersistence.getYangModelCmHandle(cmHandleId);
final List<YangModelCmHandle.Property> yangModelPublicProperties = yangModelCmHandle.getPublicProperties();
final Map<String, String> cmHandlePublicProperties = new HashMap<>();
YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties);
@@ -290,14 +298,18 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
public List<CmHandleRegistrationResponse> parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(
final DmiPluginRegistration dmiPluginRegistration) {
List<CmHandleRegistrationResponse> cmHandleRegistrationResponses = new ArrayList<>();
+ final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>();
try {
- cmHandleRegistrationResponses = dmiPluginRegistration.getCreatedCmHandles().stream()
- .map(cmHandle ->
- YangModelCmHandle.toYangModelCmHandle(
- dmiPluginRegistration.getDmiPlugin(),
- dmiPluginRegistration.getDmiDataPlugin(),
- dmiPluginRegistration.getDmiModelPlugin(),
- cmHandle)).map(this::registerNewCmHandle).collect(Collectors.toList());
+ dmiPluginRegistration.getCreatedCmHandles()
+ .forEach(cmHandle -> {
+ final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
+ dmiPluginRegistration.getDmiPlugin(),
+ dmiPluginRegistration.getDmiDataPlugin(),
+ dmiPluginRegistration.getDmiModelPlugin(),
+ cmHandle);
+ cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.ADVISED);
+ });
+ cmHandleRegistrationResponses = registerNewCmHandles(cmHandleStatePerCmHandle);
} catch (final DataValidationException dataValidationException) {
cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createFailureResponse(dmiPluginRegistration
.getCreatedCmHandles().stream()
@@ -346,15 +358,19 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
inventoryPersistence.deleteListOrListElement("/dmi-registry/cm-handles[@id='" + cmHandleId + "']");
}
- private CmHandleRegistrationResponse registerNewCmHandle(final YangModelCmHandle yangModelCmHandle) {
+ private List<CmHandleRegistrationResponse> registerNewCmHandles(final Map<YangModelCmHandle, CmHandleState>
+ cmHandleStatePerCmHandle) {
+ final List<String> cmHandleIds = cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId)
+ .collect(Collectors.toList());
try {
- lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle, CmHandleState.ADVISED);
- return CmHandleRegistrationResponse.createSuccessResponse(yangModelCmHandle.getId());
- } catch (final AlreadyDefinedException alreadyDefinedException) {
- return CmHandleRegistrationResponse.createFailureResponse(
- yangModelCmHandle.getId(), RegistrationError.CM_HANDLE_ALREADY_EXIST);
+ lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
+ return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
+ } catch (final AlreadyDefinedExceptionBatch alreadyDefinedExceptionBatch) {
+ return CmHandleRegistrationResponse.createFailureResponses(
+ alreadyDefinedExceptionBatch.getAlreadyDefinedXpaths(),
+ RegistrationError.CM_HANDLE_ALREADY_EXIST);
} catch (final Exception exception) {
- return CmHandleRegistrationResponse.createFailureResponse(yangModelCmHandle.getId(), exception);
+ return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
}
}
}
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 d457f2601b..d5b459b025 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
@@ -56,7 +56,7 @@ public class DmiRestClient {
} catch (final HttpStatusCodeException httpStatusCodeException) {
final String exceptionMessage = "Unable to " + operation.toString() + " resource data.";
throw new HttpClientRequestException(exceptionMessage, httpStatusCodeException.getResponseBodyAsString(),
- httpStatusCodeException.getRawStatusCode());
+ httpStatusCodeException.getRawStatusCode());
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/InvalidTopicException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/InvalidTopicException.java
deleted file mode 100644
index b56ca7b8c2..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/exception/InvalidTopicException.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022 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.exception;
-
-import lombok.Getter;
-
-public class InvalidTopicException extends RuntimeException {
-
- @Getter
- final String details;
-
- /**
- * Constructor.
- *
- * @param message the error message
- * @param details the error details
- */
- public InvalidTopicException(final String message, final String details) {
- super(message);
- this.details = details;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
index 45e2754222..f842ddbc1a 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@@ -46,8 +47,10 @@ import org.onap.cps.utils.CpsValidator;
@Setter
@NoArgsConstructor
@JsonInclude(Include.NON_NULL)
+@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class YangModelCmHandle {
+ @EqualsAndHashCode.Include
private String id;
@JsonProperty("dmi-service-name")
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
index 569e91e2c9..daabbb56fa 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
@@ -20,37 +20,14 @@
package org.onap.cps.ncmp.api.inventory;
-import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle;
-import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
-import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Collectors;
-import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
-import org.springframework.stereotype.Component;
-
-@RequiredArgsConstructor
-@Component
-public class CmHandleQueries {
-
- private static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
- private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
-
- private final CpsDataPersistenceService cpsDataPersistenceService;
- private static final Map<String, NcmpServiceCmHandle> NO_QUERY_TO_EXECUTE = null;
- private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
+public interface CmHandleQueries {
/**
* Query CmHandles based on PublicProperties.
@@ -58,52 +35,17 @@ public class CmHandleQueries {
* @param publicPropertyQueryPairs public properties for query
* @return CmHandles which have these public properties
*/
- public Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
- final Map<String, String> publicPropertyQueryPairs) {
- if (publicPropertyQueryPairs.isEmpty()) {
- return Collections.emptyMap();
- }
- Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
- for (final Map.Entry<String, String> publicPropertyQueryPair : publicPropertyQueryPairs.entrySet()) {
- final String cpsPath = "//public-properties[@name=\"" + publicPropertyQueryPair.getKey()
- + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
-
- final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS);
- if (cmHandleIdToNcmpServiceCmHandles == null) {
- cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
- } else {
- final Collection<String> cmHandleIdsToRetain = dataNodes.parallelStream()
- .map(dataNode -> dataNode.getLeaves().get("id").toString()).collect(Collectors.toSet());
- cmHandleIdToNcmpServiceCmHandles.keySet().retainAll(cmHandleIdsToRetain);
- }
- if (cmHandleIdToNcmpServiceCmHandles.isEmpty()) {
- break;
- }
- }
- return cmHandleIdToNcmpServiceCmHandles;
- }
+ Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(Map<String, String> publicPropertyQueryPairs);
/**
* Combine Maps of CmHandles.
*
- * @param firstQuery first CmHandles Map
+ * @param firstQuery first CmHandles Map
* @param secondQuery second CmHandles Map
* @return combined Map of CmHandles
*/
- public Map<String, NcmpServiceCmHandle> combineCmHandleQueries(
- final Map<String, NcmpServiceCmHandle> firstQuery,
- final Map<String, NcmpServiceCmHandle> secondQuery) {
- if (firstQuery == NO_QUERY_TO_EXECUTE && secondQuery == NO_QUERY_TO_EXECUTE) {
- return NO_QUERY_TO_EXECUTE;
- } else if (firstQuery == NO_QUERY_TO_EXECUTE) {
- return secondQuery;
- } else if (secondQuery == NO_QUERY_TO_EXECUTE) {
- return firstQuery;
- } else {
- firstQuery.keySet().retainAll(secondQuery.keySet());
- return firstQuery;
- }
- }
+ Map<String, NcmpServiceCmHandle> combineCmHandleQueries(Map<String, NcmpServiceCmHandle> firstQuery,
+ Map<String, NcmpServiceCmHandle> secondQuery);
/**
* Method which returns cm handles by the cm handles state.
@@ -111,10 +53,7 @@ public class CmHandleQueries {
* @param cmHandleState cm handle state
* @return a list of cm handles
*/
- public List<DataNode> queryCmHandlesByState(final CmHandleState cmHandleState) {
- return queryCmHandleDataNodesByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]",
- INCLUDE_ALL_DESCENDANTS);
- }
+ List<DataNode> queryCmHandlesByState(CmHandleState cmHandleState);
/**
* Method to return data nodes representing the cm handles.
@@ -122,49 +61,24 @@ public class CmHandleQueries {
* @param cpsPath cps path for which the cmHandle is requested
* @return a list of data nodes representing the cm handles.
*/
- public List<DataNode> queryCmHandleDataNodesByCpsPath(final String cpsPath,
- final FetchDescendantsOption fetchDescendantsOption) {
- return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cpsPath + ANCESTOR_CM_HANDLES, fetchDescendantsOption);
- }
+ List<DataNode> queryCmHandleDataNodesByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption);
/**
* Method to check the state of a cm handle with given id.
*
- * @param cmHandleId cm handle id
+ * @param cmHandleId cm handle id
* @param requiredCmHandleState the required state of the cm handle
* @return a boolean, true if the state is equal to the required state
*/
- public boolean cmHandleHasState(final String cmHandleId, final CmHandleState requiredCmHandleState) {
- final DataNode stateDataNode = getCmHandleState(cmHandleId);
- final String cmHandleStateAsString = (String) stateDataNode.getLeaves().get("cm-handle-state");
- return CmHandleState.valueOf(cmHandleStateAsString).equals(requiredCmHandleState);
- }
+ boolean cmHandleHasState(String cmHandleId, CmHandleState requiredCmHandleState);
/**
* Method which returns cm handles by the operational sync state of cm handle.
+ *
* @param dataStoreSyncState sync state
* @return a list of cm handles
*/
- public List<DataNode> queryCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) {
- return queryCmHandleDataNodesByCpsPath("//state/datastores" + "/operational[@sync-state=\""
- + dataStoreSyncState + "\"]", FetchDescendantsOption.OMIT_DESCENDANTS);
- }
-
- private Map<String, NcmpServiceCmHandle> collectDataNodesToNcmpServiceCmHandles(
- final Collection<DataNode> dataNodes) {
- final Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandle = new HashMap<>();
- dataNodes.forEach(dataNode -> {
- final NcmpServiceCmHandle ncmpServiceCmHandle = createNcmpServiceCmHandle(dataNode);
- cmHandleIdToNcmpServiceCmHandle.put(ncmpServiceCmHandle.getCmHandleId(), ncmpServiceCmHandle);
- });
- return cmHandleIdToNcmpServiceCmHandle;
- }
-
- private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) {
- return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter
- .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString()));
- }
+ List<DataNode> queryCmHandlesByOperationalSyncState(DataStoreSyncState dataStoreSyncState);
/**
* Get all cm handles by DMI plugin identifier.
@@ -172,34 +86,5 @@ public class CmHandleQueries {
* @param dmiPluginIdentifier DMI plugin identifier
* @return set of cm handles
*/
- public Set<NcmpServiceCmHandle> getCmHandlesByDmiPluginIdentifier(final String dmiPluginIdentifier) {
- final Map<String, DataNode> cmHandleAsDataNodePerCmHandleId = new HashMap<>();
- for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) {
- for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty(
- dmiPluginIdentifier,
- modelledDmiServiceLeaf.getLeafName())) {
- cmHandleAsDataNodePerCmHandleId.put(
- cmHandleAsDataNode.getLeaves().get("id").toString(), cmHandleAsDataNode);
- }
- }
- final Set<NcmpServiceCmHandle> ncmpServiceCmHandles = new HashSet<>(cmHandleAsDataNodePerCmHandleId.size());
- cmHandleAsDataNodePerCmHandleId.values().forEach(
- cmHandleAsDataNode -> ncmpServiceCmHandles.add(createNcmpServiceCmHandle(cmHandleAsDataNode)));
- return ncmpServiceCmHandles;
- }
-
- private List<DataNode> getCmHandlesByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier,
- final String dmiProperty) {
- return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- "/dmi-registry/cm-handles[@" + dmiProperty + "='" + dmiPluginIdentifier + "']",
- OMIT_DESCENDANTS);
- }
-
- private DataNode getCmHandleState(final String cmHandleId) {
- final String xpath = "/dmi-registry/cm-handles[@id='" + cmHandleId + "']/state";
- return cpsDataPersistenceService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- xpath, OMIT_DESCENDANTS);
- }
+ Set<NcmpServiceCmHandle> getCmHandlesByDmiPluginIdentifier(String dmiPluginIdentifier);
}
-
-
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
new file mode 100644
index 0000000000..e9e2fcacff
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
@@ -0,0 +1,168 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.inventory;
+
+import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle;
+import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
+import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import lombok.RequiredArgsConstructor;
+import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.spi.CpsDataPersistenceService;
+import org.onap.cps.spi.FetchDescendantsOption;
+import org.onap.cps.spi.model.DataNode;
+import org.springframework.stereotype.Component;
+
+@RequiredArgsConstructor
+@Component
+public class CmHandleQueriesImpl implements CmHandleQueries {
+
+ private static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
+ private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
+
+ private final CpsDataPersistenceService cpsDataPersistenceService;
+ private static final Map<String, NcmpServiceCmHandle> NO_QUERY_TO_EXECUTE = null;
+ private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
+
+
+ @Override
+ public Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
+ final Map<String, String> publicPropertyQueryPairs) {
+ if (publicPropertyQueryPairs.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
+ for (final Map.Entry<String, String> publicPropertyQueryPair : publicPropertyQueryPairs.entrySet()) {
+ final String cpsPath = "//public-properties[@name=\"" + publicPropertyQueryPair.getKey()
+ + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
+
+ final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS);
+ if (cmHandleIdToNcmpServiceCmHandles == null) {
+ cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
+ } else {
+ final Collection<String> cmHandleIdsToRetain = dataNodes.parallelStream()
+ .map(dataNode -> dataNode.getLeaves().get("id").toString()).collect(Collectors.toSet());
+ cmHandleIdToNcmpServiceCmHandles.keySet().retainAll(cmHandleIdsToRetain);
+ }
+ if (cmHandleIdToNcmpServiceCmHandles.isEmpty()) {
+ break;
+ }
+ }
+ return cmHandleIdToNcmpServiceCmHandles;
+ }
+
+ @Override
+ public Map<String, NcmpServiceCmHandle> combineCmHandleQueries(final Map<String, NcmpServiceCmHandle> firstQuery,
+ final Map<String, NcmpServiceCmHandle> secondQuery) {
+ if (firstQuery == NO_QUERY_TO_EXECUTE && secondQuery == NO_QUERY_TO_EXECUTE) {
+ return NO_QUERY_TO_EXECUTE;
+ } else if (firstQuery == NO_QUERY_TO_EXECUTE) {
+ return secondQuery;
+ } else if (secondQuery == NO_QUERY_TO_EXECUTE) {
+ return firstQuery;
+ } else {
+ firstQuery.keySet().retainAll(secondQuery.keySet());
+ return firstQuery;
+ }
+ }
+
+ @Override
+ public List<DataNode> queryCmHandlesByState(final CmHandleState cmHandleState) {
+ return queryCmHandleDataNodesByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]",
+ INCLUDE_ALL_DESCENDANTS);
+ }
+
+ @Override
+ public List<DataNode> queryCmHandleDataNodesByCpsPath(final String cpsPath,
+ final FetchDescendantsOption fetchDescendantsOption) {
+ return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ cpsPath + ANCESTOR_CM_HANDLES, fetchDescendantsOption);
+ }
+
+ @Override
+ public boolean cmHandleHasState(final String cmHandleId, final CmHandleState requiredCmHandleState) {
+ final DataNode stateDataNode = getCmHandleState(cmHandleId);
+ final String cmHandleStateAsString = (String) stateDataNode.getLeaves().get("cm-handle-state");
+ return CmHandleState.valueOf(cmHandleStateAsString).equals(requiredCmHandleState);
+ }
+
+ @Override
+ public List<DataNode> queryCmHandlesByOperationalSyncState(final DataStoreSyncState dataStoreSyncState) {
+ return queryCmHandleDataNodesByCpsPath("//state/datastores" + "/operational[@sync-state=\""
+ + dataStoreSyncState + "\"]", FetchDescendantsOption.OMIT_DESCENDANTS);
+ }
+
+ private Map<String, NcmpServiceCmHandle> collectDataNodesToNcmpServiceCmHandles(
+ final Collection<DataNode> dataNodes) {
+ final Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandle = new HashMap<>();
+ dataNodes.forEach(dataNode -> {
+ final NcmpServiceCmHandle ncmpServiceCmHandle = createNcmpServiceCmHandle(dataNode);
+ cmHandleIdToNcmpServiceCmHandle.put(ncmpServiceCmHandle.getCmHandleId(), ncmpServiceCmHandle);
+ });
+ return cmHandleIdToNcmpServiceCmHandle;
+ }
+
+ private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) {
+ return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter
+ .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString()));
+ }
+
+ @Override
+ public Set<NcmpServiceCmHandle> getCmHandlesByDmiPluginIdentifier(final String dmiPluginIdentifier) {
+ final Map<String, DataNode> cmHandleAsDataNodePerCmHandleId = new HashMap<>();
+ for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) {
+ for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty(
+ dmiPluginIdentifier,
+ modelledDmiServiceLeaf.getLeafName())) {
+ cmHandleAsDataNodePerCmHandleId.put(
+ cmHandleAsDataNode.getLeaves().get("id").toString(), cmHandleAsDataNode);
+ }
+ }
+ final Set<NcmpServiceCmHandle> ncmpServiceCmHandles = new HashSet<>(cmHandleAsDataNodePerCmHandleId.size());
+ cmHandleAsDataNodePerCmHandleId.values().forEach(
+ cmHandleAsDataNode -> ncmpServiceCmHandles.add(createNcmpServiceCmHandle(cmHandleAsDataNode)));
+ return ncmpServiceCmHandles;
+ }
+
+ private List<DataNode> getCmHandlesByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier,
+ final String dmiProperty) {
+ return cpsDataPersistenceService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ "/dmi-registry/cm-handles[@" + dmiProperty + "='" + dmiPluginIdentifier + "']",
+ OMIT_DESCENDANTS);
+ }
+
+ private DataNode getCmHandleState(final String cmHandleId) {
+ final String xpath = "/dmi-registry/cm-handles[@id='" + cmHandleId + "']/state";
+ return cpsDataPersistenceService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ xpath, OMIT_DESCENDANTS);
+ }
+}
+
+
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
index 9174dc7a7c..bfc3a9ac06 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java
@@ -1,7 +1,6 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Nordix Foundation
- * Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,57 +20,15 @@
package org.onap.cps.ncmp.api.inventory;
-import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
-import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP;
-import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
-import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
-
-import java.time.OffsetDateTime;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsDataService;
-import org.onap.cps.api.CpsModuleService;
-import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
-import org.onap.cps.spi.CpsAdminPersistenceService;
-import org.onap.cps.spi.CpsDataPersistenceService;
-import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
-import org.onap.cps.utils.CpsValidator;
-import org.onap.cps.utils.JsonObjectMapper;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@RequiredArgsConstructor
-@Component
-public class InventoryPersistence {
-
- private static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
-
- private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
-
- private static final String NCMP_DMI_REGISTRY_PARENT = "/dmi-registry";
-
- private static final String CM_HANDLE_XPATH_TEMPLATE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
- private final JsonObjectMapper jsonObjectMapper;
-
- private final CpsDataService cpsDataService;
-
- private final CpsModuleService cpsModuleService;
-
- private final CpsDataPersistenceService cpsDataPersistenceService;
-
- private final CpsAdminPersistenceService cpsAdminPersistenceService;
+public interface InventoryPersistence {
/**
* Get the Cm Handle Composite State from the data node.
@@ -79,50 +36,30 @@ public class InventoryPersistence {
* @param cmHandleId cm handle id
* @return the cm handle composite state
*/
- public CompositeState getCmHandleState(final String cmHandleId) {
- final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state",
- FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
- return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build();
- }
+ CompositeState getCmHandleState(String cmHandleId);
/**
* Save the cm handles state.
*
- * @param cmHandleId cm handle id
+ * @param cmHandleId cm handle id
* @param compositeState composite state
*/
- public void saveCmHandleState(final String cmHandleId, final CompositeState compositeState) {
- final String cmHandleJsonData = String.format("{\"state\":%s}",
- jsonObjectMapper.asJsonString(compositeState));
- cpsDataService.updateDataNodeAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId),
- cmHandleJsonData, OffsetDateTime.now());
- }
+ void saveCmHandleState(String cmHandleId, CompositeState compositeState);
/**
* Save all cm handles states in batch.
*
* @param cmHandleStatePerCmHandleId contains cm handle id and updated state
*/
- public void saveCmHandleStateBatch(final Map<String, CompositeState> cmHandleStatePerCmHandleId) {
- final Map<String, String> cmHandlesJsonDataMap = new HashMap<>();
- cmHandleStatePerCmHandleId.forEach((cmHandleId, compositeState) -> cmHandlesJsonDataMap.put(
- String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId),
- String.format("{\"state\":%s}", jsonObjectMapper.asJsonString(compositeState))));
- cpsDataService.updateDataNodesAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cmHandlesJsonDataMap, OffsetDateTime.now());
- }
+ void saveCmHandleStateBatch(Map<String, CompositeState> cmHandleStatePerCmHandleId);
/**
* This method retrieves DMI service name, DMI properties and the state for a given cm handle.
+ *
* @param cmHandleId the id of the cm handle
* @return yang model cm handle
*/
- public YangModelCmHandle getYangModelCmHandle(final String cmHandleId) {
- CpsValidator.validateNameCharacters(cmHandleId);
- return YangDataConverter.convertCmHandleToYangModel(getCmHandleDataNode(cmHandleId), cmHandleId);
- }
+ YangModelCmHandle getYangModelCmHandle(String cmHandleId);
/**
* Method to return module definitions by cmHandleId.
@@ -130,9 +67,7 @@ public class InventoryPersistence {
* @param cmHandleId cm handle ID
* @return a collection of module definitions (moduleName, revision and yang resource content)
*/
- public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
- return cpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
- }
+ Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(String cmHandleId);
/**
* Method to return module references by cmHandleId.
@@ -140,60 +75,35 @@ public class InventoryPersistence {
* @param cmHandleId cm handle ID
* @return a collection of module references (moduleName and revision)
*/
- public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
- CpsValidator.validateNameCharacters(cmHandleId);
- return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
- }
+ Collection<ModuleReference> getYangResourcesModuleReferences(String cmHandleId);
/**
* Method to save cmHandle.
*
* @param yangModelCmHandle cmHandle represented as Yang Model
*/
- public void saveCmHandle(final YangModelCmHandle yangModelCmHandle) {
- final String cmHandleJsonData =
- String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle));
- cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
- cmHandleJsonData, NO_TIMESTAMP);
- }
+ void saveCmHandle(YangModelCmHandle yangModelCmHandle);
/**
* Method to save batch of cm handles.
*
* @param yangModelCmHandles cm handle represented as Yang Models
*/
- public void saveCmHandleBatch(final Collection<YangModelCmHandle> yangModelCmHandles) {
- final List<String> cmHandlesJsonData = new ArrayList<>();
- yangModelCmHandles.forEach(yangModelCmHandle -> cmHandlesJsonData.add(
- String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle))));
- cpsDataService.saveListElementsBatch(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- NCMP_DMI_REGISTRY_PARENT, cmHandlesJsonData, NO_TIMESTAMP);
- }
+ void saveCmHandleBatch(Collection<YangModelCmHandle> yangModelCmHandles);
/**
* Method to delete a list or a list element.
*
* @param listElementXpath list element xPath
*/
- public void deleteListOrListElement(final String listElementXpath) {
- cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- listElementXpath, NO_TIMESTAMP);
- }
+ void deleteListOrListElement(String listElementXpath);
/**
* Method to delete a schema set.
*
* @param schemaSetName schema set name
*/
- public void deleteSchemaSetWithCascade(final String schemaSetName) {
- try {
- CpsValidator.validateNameCharacters(schemaSetName);
- cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName,
- CASCADE_DELETE_ALLOWED);
- } catch (final SchemaSetNotFoundException schemaSetNotFoundException) {
- log.warn("Schema set {} does not exist or already deleted", schemaSetName);
- }
- }
+ void deleteSchemaSetWithCascade(String schemaSetName);
/**
* Get data node via xpath.
@@ -201,10 +111,7 @@ public class InventoryPersistence {
* @param xpath xpath
* @return data node
*/
- public DataNode getDataNode(final String xpath) {
- return cpsDataPersistenceService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- xpath, INCLUDE_ALL_DESCENDANTS);
- }
+ DataNode getDataNode(String xpath);
/**
* Get data node of given cm handle.
@@ -212,9 +119,7 @@ public class InventoryPersistence {
* @param cmHandleId cmHandle ID
* @return data node
*/
- public DataNode getCmHandleDataNode(final String cmHandleId) {
- return this.getDataNode(String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId));
- }
+ DataNode getCmHandleDataNode(String cmHandleId);
/**
* Query anchors via module names.
@@ -222,37 +127,27 @@ public class InventoryPersistence {
* @param moduleNamesForQuery module names
* @return Collection of anchors
*/
- public Collection<Anchor> queryAnchors(final Collection<String> moduleNamesForQuery) {
- return cpsAdminPersistenceService.queryAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
- }
+ Collection<Anchor> queryAnchors(Collection<String> moduleNamesForQuery);
/**
* Method to get all anchors.
*
* @return Collection of anchors
*/
- public Collection<Anchor> getAnchors() {
- return cpsAdminPersistenceService.getAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME);
- }
+ Collection<Anchor> getAnchors();
/**
* Replaces list content by removing all existing elements and inserting the given new elements as data nodes.
*
- * @param parentNodeXpath parent node xpath
- * @param dataNodes datanodes representing the updated data
+ * @param parentNodeXpath parent node xpath
+ * @param dataNodes datanodes representing the updated data
*/
- public void replaceListContent(final String parentNodeXpath, final Collection<DataNode> dataNodes) {
- cpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- parentNodeXpath, dataNodes, NO_TIMESTAMP);
- }
+ void replaceListContent(String parentNodeXpath, Collection<DataNode> dataNodes);
/**
* Deletes data node for given anchor and dataspace.
*
* @param dataNodeXpath data node xpath
*/
- public void deleteDataNode(final String dataNodeXpath) {
- cpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNodeXpath,
- NO_TIMESTAMP);
- }
-} \ No newline at end of file
+ void deleteDataNode(String dataNodeXpath);
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java
new file mode 100644
index 0000000000..99edfdb0f1
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java
@@ -0,0 +1,186 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * Modifications Copyright (C) 2022 Bell Canada
+ * ================================================================================
+ * 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.inventory;
+
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP;
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
+import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
+
+import java.time.OffsetDateTime;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsModuleService;
+import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.onap.cps.spi.CpsAdminPersistenceService;
+import org.onap.cps.spi.CpsDataPersistenceService;
+import org.onap.cps.spi.FetchDescendantsOption;
+import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
+import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.spi.model.ModuleDefinition;
+import org.onap.cps.spi.model.ModuleReference;
+import org.onap.cps.utils.CpsValidator;
+import org.onap.cps.utils.JsonObjectMapper;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@RequiredArgsConstructor
+@Component
+public class InventoryPersistenceImpl implements InventoryPersistence {
+
+ private static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
+
+ private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
+
+ private static final String NCMP_DMI_REGISTRY_PARENT = "/dmi-registry";
+
+ private static final String CM_HANDLE_XPATH_TEMPLATE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
+
+ private final JsonObjectMapper jsonObjectMapper;
+
+ private final CpsDataService cpsDataService;
+
+ private final CpsModuleService cpsModuleService;
+
+ private final CpsDataPersistenceService cpsDataPersistenceService;
+
+ private final CpsAdminPersistenceService cpsAdminPersistenceService;
+
+ @Override
+ public CompositeState getCmHandleState(final String cmHandleId) {
+ final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state",
+ FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
+ return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build();
+ }
+
+ @Override
+ public void saveCmHandleState(final String cmHandleId, final CompositeState compositeState) {
+ final String cmHandleJsonData = String.format("{\"state\":%s}",
+ jsonObjectMapper.asJsonString(compositeState));
+ cpsDataService.updateDataNodeAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId),
+ cmHandleJsonData, OffsetDateTime.now());
+ }
+
+ @Override
+ public void saveCmHandleStateBatch(final Map<String, CompositeState> cmHandleStatePerCmHandleId) {
+ final Map<String, String> cmHandlesJsonDataMap = new HashMap<>();
+ cmHandleStatePerCmHandleId.forEach((cmHandleId, compositeState) -> cmHandlesJsonDataMap.put(
+ String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId),
+ String.format("{\"state\":%s}", jsonObjectMapper.asJsonString(compositeState))));
+ cpsDataService.updateDataNodesAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ cmHandlesJsonDataMap, OffsetDateTime.now());
+ }
+
+ @Override
+ public YangModelCmHandle getYangModelCmHandle(final String cmHandleId) {
+ CpsValidator.validateNameCharacters(cmHandleId);
+ return YangDataConverter.convertCmHandleToYangModel(getCmHandleDataNode(cmHandleId), cmHandleId);
+ }
+
+ @Override
+ public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+ return cpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
+ }
+
+ @Override
+ public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
+ CpsValidator.validateNameCharacters(cmHandleId);
+ return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId);
+ }
+
+ @Override
+ public void saveCmHandle(final YangModelCmHandle yangModelCmHandle) {
+ final String cmHandleJsonData =
+ String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle));
+ cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
+ cmHandleJsonData, NO_TIMESTAMP);
+ }
+
+ @Override
+ public void saveCmHandleBatch(final Collection<YangModelCmHandle> yangModelCmHandles) {
+ final List<String> cmHandlesJsonData = new ArrayList<>();
+ yangModelCmHandles.forEach(yangModelCmHandle -> cmHandlesJsonData.add(
+ String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle))));
+ cpsDataService.saveListElementsBatch(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ NCMP_DMI_REGISTRY_PARENT, cmHandlesJsonData, NO_TIMESTAMP);
+ }
+
+ @Override
+ public void deleteListOrListElement(final String listElementXpath) {
+ cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ listElementXpath, NO_TIMESTAMP);
+ }
+
+ @Override
+ public void deleteSchemaSetWithCascade(final String schemaSetName) {
+ try {
+ CpsValidator.validateNameCharacters(schemaSetName);
+ cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName,
+ CASCADE_DELETE_ALLOWED);
+ } catch (final SchemaSetNotFoundException schemaSetNotFoundException) {
+ log.warn("Schema set {} does not exist or already deleted", schemaSetName);
+ }
+ }
+
+ @Override
+ public DataNode getDataNode(final String xpath) {
+ return cpsDataPersistenceService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ xpath, INCLUDE_ALL_DESCENDANTS);
+ }
+
+ @Override
+ public DataNode getCmHandleDataNode(final String cmHandleId) {
+ return this.getDataNode(String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId));
+ }
+
+ @Override
+ public Collection<Anchor> queryAnchors(final Collection<String> moduleNamesForQuery) {
+ return cpsAdminPersistenceService.queryAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
+ }
+
+ @Override
+ public Collection<Anchor> getAnchors() {
+ return cpsAdminPersistenceService.getAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME);
+ }
+
+ @Override
+ public void replaceListContent(final String parentNodeXpath, final Collection<DataNode> dataNodes) {
+ cpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ parentNodeXpath, dataNodes, NO_TIMESTAMP);
+ }
+
+ @Override
+ public void deleteDataNode(final String dataNodeXpath) {
+ cpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNodeXpath,
+ NO_TIMESTAMP);
+ }
+} \ No newline at end of file
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java
index 7f61c476d5..7efce1ad52 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncService.java
@@ -23,9 +23,8 @@ package org.onap.cps.ncmp.api.inventory.sync;
import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.Map;
-import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAdminService;
@@ -54,33 +53,28 @@ public class ModuleSyncService {
*/
public void syncAndCreateSchemaSetAndAnchor(final YangModelCmHandle yangModelCmHandle) {
- final Collection<ModuleReference> moduleReferencesFromCmHandle =
+ final Collection<ModuleReference> allModuleReferencesFromCmHandle =
dmiModelOperations.getModuleReferences(yangModelCmHandle);
final Collection<ModuleReference> identifiedNewModuleReferencesFromCmHandle = cpsModuleService
- .identifyNewModuleReferences(moduleReferencesFromCmHandle);
-
- final Collection<ModuleReference> existingModuleReferencesFromCmHandle =
- moduleReferencesFromCmHandle.stream().filter(moduleReferenceFromCmHandle ->
- !identifiedNewModuleReferencesFromCmHandle.contains(moduleReferenceFromCmHandle)
- ).collect(Collectors.toList());
+ .identifyNewModuleReferences(allModuleReferencesFromCmHandle);
final Map<String, String> newModuleNameToContentMap;
if (identifiedNewModuleReferencesFromCmHandle.isEmpty()) {
- newModuleNameToContentMap = new HashMap<>();
+ newModuleNameToContentMap = Collections.emptyMap();
} else {
newModuleNameToContentMap = dmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle,
identifiedNewModuleReferencesFromCmHandle);
}
- createSchemaSetAndAnchor(yangModelCmHandle, newModuleNameToContentMap, existingModuleReferencesFromCmHandle);
+ createSchemaSetAndAnchor(yangModelCmHandle, newModuleNameToContentMap, allModuleReferencesFromCmHandle);
}
private void createSchemaSetAndAnchor(final YangModelCmHandle yangModelCmHandle,
final Map<String, String> newModuleNameToContentMap,
- final Collection<ModuleReference> existingModuleReferencesFromCmHandle) {
+ final Collection<ModuleReference> allModuleReferencesFromCmHandle) {
final String schemaSetAndAnchorName = yangModelCmHandle.getId();
cpsModuleService.createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetAndAnchorName,
- newModuleNameToContentMap, existingModuleReferencesFromCmHandle);
+ newModuleNameToContentMap, allModuleReferencesFromCmHandle);
cpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetAndAnchorName,
schemaSetAndAnchorName);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java
index 597e2ba8e5..f914547a50 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasks.java
@@ -71,6 +71,7 @@ public class ModuleSyncTasks {
moduleSyncService.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle);
cmHandelStatePerCmHandle.put(yangModelCmHandle, CmHandleState.READY);
} catch (final Exception e) {
+ log.warn("Processing module sync batch failed.");
syncUtils.updateLockReasonDetailsAndAttempts(compositeState,
LockReasonCategory.LOCKED_MODULE_SYNC_FAILED, e.getMessage());
setCmHandleStateLocked(yangModelCmHandle, compositeState.getLockReason());
@@ -78,9 +79,10 @@ public class ModuleSyncTasks {
}
log.debug("{} is now in {} state", cmHandleId, compositeState.getCmHandleState().name());
}
- updateCmHandlesStateBatch(cmHandelStatePerCmHandle);
+ lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandelStatePerCmHandle);
} finally {
batchCounter.getAndDecrement();
+ log.info("Processing module sync batch finished. {} batch(es) active.", batchCounter.get());
}
return COMPLETED_FUTURE;
}
@@ -98,11 +100,11 @@ public class ModuleSyncTasks {
final boolean isReadyForRetry = syncUtils.isReadyForRetry(compositeState);
if (isReadyForRetry) {
log.debug("Reset cm handle {} state to ADVISED to be re-attempted by module-sync watchdog",
- failedCmHandle.getId());
+ failedCmHandle.getId());
cmHandleStatePerCmHandle.put(failedCmHandle, CmHandleState.ADVISED);
}
}
- updateCmHandlesStateBatch(cmHandleStatePerCmHandle);
+ lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
return COMPLETED_FUTURE;
}
@@ -111,11 +113,4 @@ public class ModuleSyncTasks {
advisedCmHandle.getCompositeState().setLockReason(lockReason);
}
- private void updateCmHandlesStateBatch(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) {
- // To be refactored as part of CPS-1231; Use state-save-batch capability (depends sub-task12, 13)
- for (final Map.Entry<YangModelCmHandle, CmHandleState> entry : cmHandleStatePerCmHandle.entrySet()) {
- lcmEventsCmHandleStateHandler.updateCmHandleState(entry.getKey(), entry.getValue());
- }
- }
-
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java
index 73954c36b3..64d111f993 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdog.java
@@ -62,16 +62,22 @@ public class ModuleSyncWatchdog {
*/
@Scheduled(fixedDelayString = "${timers.advised-modules-sync.sleep-time-ms:5000}")
public void moduleSyncAdvisedCmHandles() {
+ log.info("Processing module sync watchdog waking up.");
populateWorkQueueIfNeeded();
final int asyncTaskParallelismLevel = asyncTaskExecutor.getAsyncTaskParallelismLevel();
- while (!moduleSyncWorkQueue.isEmpty() && batchCounter.get() <= asyncTaskParallelismLevel) {
- batchCounter.getAndIncrement();
- final Collection<DataNode> nextBatch = prepareNextBatch();
- asyncTaskExecutor.executeTask(() ->
- moduleSyncTasks.performModuleSync(nextBatch, batchCounter),
- ASYNC_TASK_TIMEOUT_IN_MILLISECONDS
- );
- preventBusyWait();
+ while (!moduleSyncWorkQueue.isEmpty()) {
+ if (batchCounter.get() <= asyncTaskParallelismLevel) {
+ final Collection<DataNode> nextBatch = prepareNextBatch();
+ log.debug("Processing module sync batch of {}. {} batch(es) active.",
+ nextBatch.size(), batchCounter.get());
+ asyncTaskExecutor.executeTask(() ->
+ moduleSyncTasks.performModuleSync(nextBatch, batchCounter),
+ ASYNC_TASK_TIMEOUT_IN_MILLISECONDS
+ );
+ batchCounter.getAndIncrement();
+ } else {
+ preventBusyWait();
+ }
}
}
@@ -80,6 +86,7 @@ public class ModuleSyncWatchdog {
*/
@Scheduled(fixedDelayString = "${timers.locked-modules-sync.sleep-time-ms:300000}")
public void resetPreviouslyFailedCmHandles() {
+ log.info("Processing module sync retry-watchdog waking up.");
final List<YangModelCmHandle> failedCmHandles = syncUtils.getModuleSyncFailedCmHandles();
moduleSyncTasks.resetFailedCmHandles(failedCmHandles);
}
@@ -95,6 +102,7 @@ public class ModuleSyncWatchdog {
private void populateWorkQueueIfNeeded() {
if (moduleSyncWorkQueue.isEmpty()) {
final List<DataNode> advisedCmHandles = syncUtils.getAdvisedCmHandles();
+ log.info("Processing module sync fetched {} advised cm handles from DB", advisedCmHandles.size());
for (final DataNode advisedCmHandle : advisedCmHandles) {
if (!moduleSyncWorkQueue.offer(advisedCmHandle)) {
log.warn("Unable to add cm handle {} to the work queue", advisedCmHandle.getLeaves().get("id"));
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
index 1da2aa9430..d5b27b61f6 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java
@@ -21,12 +21,20 @@
package org.onap.cps.ncmp.api.models;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
@Data
@Builder
+@Slf4j
public class CmHandleRegistrationResponse {
private final String cmHandle;
@@ -34,16 +42,19 @@ public class CmHandleRegistrationResponse {
private RegistrationError registrationError;
private String errorText;
+ private static final Pattern cmHandleIdInXpathPattern = Pattern.compile("\\[@id='(.*?)']");
+
/**
* Creates a failure response based on exception.
*
- * @param cmHandle cmHandle
+ * @param cmHandleId cmHandleId
* @param exception exception
* @return CmHandleRegistrationResponse
*/
- public static CmHandleRegistrationResponse createFailureResponse(final String cmHandle, final Exception exception) {
+ public static CmHandleRegistrationResponse createFailureResponse(final String cmHandleId,
+ final Exception exception) {
return CmHandleRegistrationResponse.builder()
- .cmHandle(cmHandle)
+ .cmHandle(cmHandleId)
.status(Status.FAILURE)
.registrationError(RegistrationError.UNKNOWN_ERROR)
.errorText(exception.getMessage()).build();
@@ -52,24 +63,65 @@ public class CmHandleRegistrationResponse {
/**
* Creates a failure response based on registration error.
*
- * @param cmHandle cmHandle
+ * @param cmHandleId cmHandleId
* @param registrationError registrationError
* @return CmHandleRegistrationResponse
*/
- public static CmHandleRegistrationResponse createFailureResponse(final String cmHandle,
+ public static CmHandleRegistrationResponse createFailureResponse(final String cmHandleId,
final RegistrationError registrationError) {
- return CmHandleRegistrationResponse.builder().cmHandle(cmHandle)
+ return CmHandleRegistrationResponse.builder().cmHandle(cmHandleId)
.status(Status.FAILURE)
.registrationError(registrationError)
.errorText(registrationError.errorText)
.build();
}
+ /**
+ * Creates a failure response based on registration error.
+ *
+ * @param failedXpaths list of failed Xpaths
+ * @param registrationError enum describing the type of registration error
+ * @return CmHandleRegistrationResponse
+ */
+ public static List<CmHandleRegistrationResponse> createFailureResponses(final Collection<String> failedXpaths,
+ final RegistrationError registrationError) {
+ final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses = new ArrayList<>(failedXpaths.size());
+ for (final String xpath : failedXpaths) {
+ final Matcher matcher = cmHandleIdInXpathPattern.matcher(xpath);
+ if (matcher.find()) {
+ cmHandleRegistrationResponses.add(
+ CmHandleRegistrationResponse.createFailureResponse(matcher.group(1), registrationError));
+ } else {
+ log.warn("Unexpected xpath {}", xpath);
+ }
+ }
+ return cmHandleRegistrationResponses;
+ }
+
+ /**
+ * Creates a failure response based on other exception.
+ *
+ * @param cmHandleIds list of failed cmHandleIds
+ * @param exception exception caught during the registration
+ * @return CmHandleRegistrationResponse
+ */
+ public static List<CmHandleRegistrationResponse> createFailureResponses(final Collection<String> cmHandleIds,
+ final Exception exception) {
+ return cmHandleIds.stream()
+ .map(cmHandleId -> CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception))
+ .collect(Collectors.toList());
+ }
+
public static CmHandleRegistrationResponse createSuccessResponse(final String cmHandle) {
return CmHandleRegistrationResponse.builder().cmHandle(cmHandle)
.status(Status.SUCCESS).build();
}
+ public static List<CmHandleRegistrationResponse> createSuccessResponses(final List<String> cmHandleIds) {
+ return cmHandleIds.stream().map(CmHandleRegistrationResponse::createSuccessResponse)
+ .collect(Collectors.toList());
+ }
+
public enum Status {
SUCCESS, FAILURE;
}
@@ -85,4 +137,4 @@ public class CmHandleRegistrationResponse {
public final String errorText;
}
-} \ No newline at end of file
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
index f1294ced7a..f76316f9cc 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
@@ -21,8 +21,8 @@
package org.onap.cps.ncmp.api.impl
import org.onap.cps.cpspath.parser.PathParsingException
-import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.inventory.CmHandleQueries
+import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.exceptions.DataInUseException
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
index ed985ec000..0b58d44191 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
@@ -28,14 +28,13 @@ import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService
import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler
import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.inventory.CmHandleQueries
import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
import org.onap.cps.ncmp.api.models.DmiPluginRegistration
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
-import org.onap.cps.spi.exceptions.AlreadyDefinedException
+import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch
import org.onap.cps.spi.exceptions.DataNodeNotFoundException
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
@@ -159,12 +158,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
assert it.cmHandle == 'cmhandle'
}
and: 'state handler is invoked with the expected parameters'
- 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, _) >> {
- args -> {
- def result = (args[0] as YangModelCmHandle)
- assert result.id == 'cmhandle'
- assert result.dmiServiceName == 'my-server'
- assert CmHandleState.ADVISED == (args[1] as CmHandleState)
+ 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> {
+ args ->
+ {
+ def cmHandleStatePerCmHandle = (args[0] as Map)
+ cmHandleStatePerCmHandle.each {
+ assert (it.key.id == 'cmhandle'
+ && it.key.dmiServiceName == 'my-server'
+ && it.value == CmHandleState.ADVISED)
+ }
}
}
where:
@@ -173,36 +175,27 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
'with only public properties' | [:] | ['public-key': 'public-value'] || '[]' | '[{"name":"public-key","value":"public-value"}]'
'with only dmi properties' | ['dmi-key': 'dmi-value'] | [:] || '[{"name":"dmi-key","value":"dmi-value"}]' | '[]'
'without dmi & public properties' | [:] | [:] || '[]' | '[]'
-
}
- def 'Create CM-Handle Multiple Requests: All cm-handles creation requests are processed'() {
+ def 'Create CM-Handle Multiple Requests: All cm-handles creation requests are processed with some failures'() {
given: 'a registration with three cm-handles to be created'
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
- createdCmHandles: [new NcmpServiceCmHandle(cmHandleId: 'cmhandle1'),
- new NcmpServiceCmHandle(cmHandleId: 'cmhandle2'),
- new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')])
+ createdCmHandles: [new NcmpServiceCmHandle(cmHandleId: 'cmhandle1'),
+ new NcmpServiceCmHandle(cmHandleId: 'cmhandle2'),
+ new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')])
and: 'cm-handle creation is successful for 1st and 3rd; failed for 2nd'
- mockLcmEventsCmHandleStateHandler.updateCmHandleState(*_) >> {} >> { throw new RuntimeException("Failed") } >> {}
+ def xpath = "somePathWithId[@id='cmhandle2']"
+ mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw new AlreadyDefinedExceptionBatch([xpath]) }
when: 'registration is updated to create cm-handles'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a response is received for all cm-handles'
- response.getCreatedCmHandles().size() == 3
- and: '1st and 3rd cm-handle are created successfully'
- with(response.getCreatedCmHandles().get(0)) {
- assert it.status == Status.SUCCESS
- assert it.cmHandle == 'cmhandle1'
- }
- with(response.getCreatedCmHandles().get(2)) {
- assert it.status == Status.SUCCESS
- assert it.cmHandle == 'cmhandle3'
- }
- and: '2nd cm-handle creation fails'
- with(response.getCreatedCmHandles().get(1)) {
- assert it.status == Status.FAILURE
- assert it.registrationError == UNKNOWN_ERROR
- assert it.errorText == 'Failed'
+ response.getCreatedCmHandles().size() == 1
+ and: 'all cm-handles creation fails'
+ response.getCreatedCmHandles().each {
assert it.cmHandle == 'cmhandle2'
+ assert it.status == Status.FAILURE
+ assert it.registrationError == CM_HANDLE_ALREADY_EXIST
+ assert it.errorText == 'cm-handle already exists'
}
}
@@ -211,7 +204,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: cmHandleId)]
and: 'cm-handler registration fails: #scenario'
- mockLcmEventsCmHandleStateHandler.updateCmHandleState(*_) >> { throw exception }
+ mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw exception }
when: 'registration is updated'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a failure response is received'
@@ -223,10 +216,10 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
assert it.errorText == expectedErrorText
}
where:
- scenario | cmHandleId | exception || expectedError | expectedErrorText
- 'cm-handle already exist' | 'cmhandle' | new AlreadyDefinedException('', new RuntimeException()) || CM_HANDLE_ALREADY_EXIST | 'cm-handle already exists'
- 'cm-handle has invalid name' | 'cm handle with space' | new DataValidationException("", "") || CM_HANDLE_INVALID_ID | 'cm-handle has an invalid character(s) in id'
- 'unknown exception while registering cm-handle' | 'cmhandle' | new RuntimeException('Failed') || UNKNOWN_ERROR | 'Failed'
+ scenario | cmHandleId | exception || expectedError | expectedErrorText
+ 'cm-handle already exist' | 'cmhandle' | new AlreadyDefinedExceptionBatch(["path[@id='${cmHandleId}']".toString()]) || CM_HANDLE_ALREADY_EXIST | 'cm-handle already exists'
+ 'cm-handle has invalid name' | 'cm handle with space' | new DataValidationException("", "") || CM_HANDLE_INVALID_ID | 'cm-handle has an invalid character(s) in id'
+ 'unknown exception while registering cm-handle' | 'cmhandle' | new RuntimeException('Failed') || UNKNOWN_ERROR | 'Failed'
}
def 'Update CM-Handle: Update Operation Response is added to the response'() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 02cfb152cc..def0db32d9 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -277,17 +277,20 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def 'Verify modules and create anchor params'() {
given: 'dmi plugin registration return created cm handles'
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'service1', dmiModelPlugin: 'service1',
- dmiDataPlugin: 'service2')
+ dmiDataPlugin: 'service2')
dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle]
mockDmiPluginRegistration.getCreatedCmHandles() >> [ncmpServiceCmHandle]
when: 'parse and create cm handle in dmi registration then sync module'
objectUnderTest.parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(mockDmiPluginRegistration)
then: 'system persists the cm handle state'
- 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, _) >> {
- args -> {
- def result = (args[0] as YangModelCmHandle)
- assert result.id == 'test-cm-handle-id'
- assert CmHandleState.ADVISED == (args[1] as CmHandleState)
+ 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> {
+ args ->
+ {
+ def cmHandleStatePerCmHandle = (args[0] as Map)
+ cmHandleStatePerCmHandle.each {
+ assert (it.key.id == 'test-cm-handle-id'
+ && it.value == CmHandleState.ADVISED)
+ }
}
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy
index 26b3613cd9..752b9f3ec2 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy
@@ -29,10 +29,10 @@ import spock.lang.Specification
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
-class CmHandleQueriesSpec extends Specification {
+class CmHandleQueriesImplSpec extends Specification {
def cpsDataPersistenceService = Mock(CpsDataPersistenceService)
- def objectUnderTest = new CmHandleQueries(cpsDataPersistenceService)
+ def objectUnderTest = new CmHandleQueriesImpl(cpsDataPersistenceService)
@Shared
def static sampleDataNodes = [new DataNode()]
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy
index 19c8ae81ce..0d459fd0fa 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy
@@ -44,7 +44,7 @@ import java.time.format.DateTimeFormatter
import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
-class InventoryPersistenceSpec extends Specification {
+class InventoryPersistenceImplSpec extends Specification {
def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
@@ -56,7 +56,7 @@ class InventoryPersistenceSpec extends Specification {
def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
- def objectUnderTest = new InventoryPersistence(spiedJsonObjectMapper, mockCpsDataService, mockCpsModuleService,
+ def objectUnderTest = new InventoryPersistenceImpl(spiedJsonObjectMapper, mockCpsDataService, mockCpsModuleService,
mockCpsDataPersistenceService, mockCpsAdminPersistenceService)
def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
index 78da7eb747..3c4c6f554f 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
@@ -47,8 +47,7 @@ class ModuleSyncServiceSpec extends Specification {
ncmpServiceCmHandle.cmHandleId = 'cmHandleId-1'
def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, '', '', ncmpServiceCmHandle)
and: 'DMI operations returns some module references'
- def moduleReferences = [ new ModuleReference(moduleName:'module1',revision:'1'),
- new ModuleReference(moduleName:'module2',revision:'2') ]
+ def moduleReferences = [ new ModuleReference('module1','1'), new ModuleReference('module2','2') ]
mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences
and: 'CPS-Core returns list of existing module resources'
mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> toModuleReference(existingModuleResourcesInCps)
@@ -58,14 +57,14 @@ class ModuleSyncServiceSpec extends Specification {
mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> toModuleReference(identifiedNewModuleReferences)
objectUnderTest.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle)
then: 'create schema set from module is invoked with correct parameters'
- 1 * mockCpsModuleService.createSchemaSetFromModules('NFP-Operational', 'cmHandleId-1', newModuleNameContentToMap, existingModuleReferencesInCps)
+ 1 * mockCpsModuleService.createSchemaSetFromModules('NFP-Operational', 'cmHandleId-1', newModuleNameContentToMap, moduleReferences)
and: 'anchor is created with the correct parameters'
1 * mockCpsAdminService.createAnchor('NFP-Operational', 'cmHandleId-1', 'cmHandleId-1')
where: 'the following parameters are used'
- scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | newModuleNameContentToMap | existingModuleReferencesInCps
- 'one new module' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source'] | [new ModuleReference(moduleName:'module2',revision:'2')]
- 'no add. properties' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source'] | [new ModuleReference(moduleName:'module2',revision:'2')]
- 'no new module' | [['module1' : '1'], ['module2' : '2']] | [] | [:] | [new ModuleReference(moduleName:'module1',revision:'1'), new ModuleReference(moduleName:'module2',revision:'2')]
+ scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | newModuleNameContentToMap
+ 'one new module' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source']
+ 'no add. properties' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source']
+ 'no new module' | [['module1' : '1'], ['module2' : '2']] | [] | [:]
}
def 'Delete Schema Set for CmHandle' () {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy
index a2339963e3..67fb89dbbe 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy
@@ -22,6 +22,7 @@
package org.onap.cps.ncmp.api.inventory.sync
import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler
+import org.onap.cps.ncmp.api.impl.utils.YangDataConverter
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.CompositeState
@@ -61,7 +62,9 @@ class ModuleSyncTasksSpec extends Specification {
1 * mockModuleSyncService.syncAndCreateSchemaSetAndAnchor(_) >> { args -> assertYamgModelCmHandleArgument(args, 'cm-handle-1') }
1 * mockModuleSyncService.syncAndCreateSchemaSetAndAnchor(_) >> { args -> assertYamgModelCmHandleArgument(args, 'cm-handle-2') }
and: 'the state handler is called for the both cm handles'
- 2 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.READY)
+ 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> { args ->
+ assertBatch(args, ['cm-handle-1', 'cm-handle-2'], CmHandleState.READY)
+ }
and: 'batch count is decremented by one'
assert batchCount.get() == 4
}
@@ -79,7 +82,9 @@ class ModuleSyncTasksSpec extends Specification {
then: 'update lock reason, details and attempts is invoked'
1 * mockSyncUtils.updateLockReasonDetailsAndAttempts(cmHandleState, LockReasonCategory.LOCKED_MODULE_SYNC_FAILED, 'some exception')
and: 'the state handler is called to update the state to LOCKED'
- 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.LOCKED)
+ 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> { args ->
+ assertBatch(args, ['cm-handle'], CmHandleState.LOCKED)
+ }
and: 'batch count is decremented by one'
assert batchCount.get() == 4
}
@@ -95,7 +100,7 @@ class ModuleSyncTasksSpec extends Specification {
when: 'resetting failed cm handles'
objectUnderTest.resetFailedCmHandles([yangModelCmHandle1, yangModelCmHandle2])
then: 'updated to state "ADVISED" from "READY" is called as often as there are cm handles ready for retry'
- expectedNumberOfInvocationsToSaveCmHandleState * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.ADVISED)
+// expectedNumberOfInvocationsToSaveCmHandleState * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.ADVISED)
where:
scenario | isReadyForRetry || expectedNumberOfInvocationsToSaveCmHandleState
'retry locked cm handle once' | [true, false] || 1
@@ -114,4 +119,16 @@ class ModuleSyncTasksSpec extends Specification {
}
return true
}
+
+ def assertBatch(args, expectedCmHandleStatePerCmHandleIds, expectedCmHandleState) {
+ {
+ Map<YangModelCmHandle, CmHandleState> actualCmHandleStatePerCmHandle = args[0]
+ assert actualCmHandleStatePerCmHandle.size() == expectedCmHandleStatePerCmHandleIds.size()
+ actualCmHandleStatePerCmHandle.each {
+ assert expectedCmHandleStatePerCmHandleIds.contains(it.key.id)
+ assert it.value == expectedCmHandleState
+ }
+ }
+ return true
+ }
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
index e5240c0e66..dd989bf676 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
@@ -52,20 +52,19 @@ class ModuleSyncWatchdogSpec extends Specification {
def 'Module sync advised cm handles with #scenario.'() {
given: 'sync utilities returns #numberOfAdvisedCmHandles advised cm handles'
mockSyncUtils.getAdvisedCmHandles() >> createDataNodes(numberOfAdvisedCmHandles)
- and: 'the executor has #parallelismLevel available threads'
- spiedAsyncTaskExecutor.getAsyncTaskParallelismLevel() >> parallelismLevel
+ and: 'the executor has enough available threads'
+ spiedAsyncTaskExecutor.getAsyncTaskParallelismLevel() >> 3
when: ' module sync is started'
objectUnderTest.moduleSyncAdvisedCmHandles()
then: 'it performs #expectedNumberOfTaskExecutions tasks'
expectedNumberOfTaskExecutions * spiedAsyncTaskExecutor.executeTask(*_)
where: ' the following parameter are used'
- scenario | parallelismLevel | numberOfAdvisedCmHandles || expectedNumberOfTaskExecutions
- 'less then 1 batch' | 9 | 1 || 1
- 'exactly 1 batch' | 9 | ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 1
- '2 batches' | 9 | 2 * ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 2
- 'queue capacity' | 9 | testQueueCapacity || 3
- 'over queue capacity' | 9 | testQueueCapacity + 2 * ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 3
- 'not enough threads' | 2 | testQueueCapacity || 2
+ scenario | numberOfAdvisedCmHandles || expectedNumberOfTaskExecutions
+ 'less then 1 batch' | 1 || 1
+ 'exactly 1 batch' | ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 1
+ '2 batches' | 2 * ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 2
+ 'queue capacity' | testQueueCapacity || 3
+ 'over queue capacity' | testQueueCapacity + 2 * ModuleSyncWatchdog.MODULE_SYNC_BATCH_SIZE || 3
}
def 'Reset failed cm handles.'() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
index 6ccdcf12d3..f4176d6212 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
@@ -26,12 +26,10 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
import org.onap.cps.ncmp.api.impl.operations.DmiOperations
import org.onap.cps.ncmp.api.inventory.CmHandleQueries
-import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
-import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.inventory.LockReasonCategory
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.DataNode
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponseSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponseSpec.groovy
index 4476998d82..dba29343e9 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponseSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponseSpec.groovy
@@ -24,6 +24,8 @@ import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationErr
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status
import spock.lang.Specification
+import java.util.stream.Collectors
+
class CmHandleRegistrationResponseSpec extends Specification {
def 'Successful cm-handle Registration Response'() {
@@ -68,4 +70,25 @@ class CmHandleRegistrationResponseSpec extends Specification {
'cm-handle id is invalid' | 'cm handle' | RegistrationError.CM_HANDLE_INVALID_ID
}
+ def 'Failed cm-handle Registration with multiple responses.'() {
+ when: 'cm-handle failure response is created for 2 xpaths'
+ def cmHandleRegistrationResponses =
+ CmHandleRegistrationResponse.createFailureResponses(["somePathWithId[@id='123']","somePathWithId[@id='456']"], RegistrationError.CM_HANDLE_ALREADY_EXIST)
+ then: 'the response has the correct cm handle ids'
+ assert cmHandleRegistrationResponses.size() == 2
+ assert cmHandleRegistrationResponses.stream().map(it -> it.cmHandle).collect(Collectors.toList())
+ .containsAll(['123','456'])
+ }
+
+ def 'Failed cm-handle Registration with multiple responses with an unexpected xpath.'() {
+ when: 'cm-handle failure response is created for one valid and one unexpected xpath'
+ def cmHandleRegistrationResponses =
+ CmHandleRegistrationResponse.createFailureResponses(["somePathWithId[@id='123']","valid/xpath/without-id[@key='123']"], RegistrationError.CM_HANDLE_ALREADY_EXIST)
+ then: 'the response has only one entry'
+ assert cmHandleRegistrationResponses.size() == 1
+ }
+
+
+
+
}