summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorJosephKeenan <joseph.keenan@est.tech>2022-02-15 18:23:05 +0000
committerJosephKeenan <joseph.keenan@est.tech>2022-02-28 15:25:58 +0000
commite0643ab5130dde375c229989e216341e623a9c55 (patch)
treeae0d551c6f904950a1263dd73b2ada099d636b34 /cps-ncmp-service/src/main
parent87de1fc8454fb1d93dfda7c5193783f16974cdaf (diff)
CPS-887 Decreasing performance of cmHandle registration
- Creating temporary table module references from the node - Query returning new moduleReferences for node to be added to CPS - Modified registration for node to use new implementation (incl. tests) - Refactored some interface to use collection instead of list - Modified SQL statements to use String.format() - Fixed tests Issue-ID: CPS-887 Signed-off-by: JosephKeenan <joseph.keenan@est.tech> Change-Id: I58b17d29e8b9d6f7a644d33bf6cf8bf46f892580
Diffstat (limited to 'cps-ncmp-service/src/main')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java43
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java13
2 files changed, 23 insertions, 33 deletions
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 3c8d8bc3b7..aac44e43ec 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
@@ -32,11 +32,11 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
import com.fasterxml.jackson.core.JsonProcessingException;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAdminService;
@@ -228,38 +228,27 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
private void syncAndCreateSchemaSet(final PersistenceCmHandle persistenceCmHandle) {
- final List<ModuleReference> moduleReferencesFromCmHandle =
+ final Collection<ModuleReference> moduleReferencesFromCmHandle =
dmiModelOperations.getModuleReferences(persistenceCmHandle);
- final List<ModuleReference> existingModuleReferences = new ArrayList<>();
- final List<ModuleReference> unknownModuleReferences = new ArrayList<>();
- prepareModuleSubsets(moduleReferencesFromCmHandle, existingModuleReferences, unknownModuleReferences);
- final Map<String, String> newYangResourcesModuleNameToContentMap;
- if (unknownModuleReferences.isEmpty()) {
- newYangResourcesModuleNameToContentMap = new HashMap<>();
+ final Collection<ModuleReference> identifiedNewModuleReferencesFromCmHandle = cpsModuleService
+ .identifyNewModuleReferences(moduleReferencesFromCmHandle);
+
+ final Collection<ModuleReference> existingModuleReferencesFromCmHandle =
+ moduleReferencesFromCmHandle.stream().filter(moduleReferenceFromCmHandle ->
+ !identifiedNewModuleReferencesFromCmHandle.contains(moduleReferenceFromCmHandle)
+ ).collect(Collectors.toList());
+
+ final Map<String, String> newModuleNameToContentMap;
+ if (identifiedNewModuleReferencesFromCmHandle.isEmpty()) {
+ newModuleNameToContentMap = new HashMap<>();
} else {
- newYangResourcesModuleNameToContentMap = dmiModelOperations.getNewYangResourcesFromDmi(persistenceCmHandle,
- unknownModuleReferences);
+ newModuleNameToContentMap = dmiModelOperations.getNewYangResourcesFromDmi(persistenceCmHandle,
+ identifiedNewModuleReferencesFromCmHandle);
}
cpsModuleService
.createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, persistenceCmHandle.getId(),
- newYangResourcesModuleNameToContentMap, existingModuleReferences);
- }
-
- private void prepareModuleSubsets(final List<ModuleReference> moduleReferencesFromCmHandle,
- final List<ModuleReference> existingModuleReferences,
- final List<ModuleReference> unknownModuleReferences) {
-
- final Collection<ModuleReference> knownModuleReferencesInCps =
- cpsModuleService.getYangResourceModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME);
-
- for (final ModuleReference moduleReferenceFromDmiForCmHandle : moduleReferencesFromCmHandle) {
- if (knownModuleReferencesInCps.contains(moduleReferenceFromDmiForCmHandle)) {
- existingModuleReferences.add(moduleReferenceFromDmiForCmHandle);
- } else {
- unknownModuleReferences.add(moduleReferenceFromDmiForCmHandle);
- }
- }
+ newModuleNameToContentMap, existingModuleReferencesFromCmHandle);
}
private void createAnchor(final PersistenceCmHandle persistenceCmHandle) {
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
index 657b0b4740..aec4517c03 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
@@ -25,6 +25,7 @@ import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -76,13 +77,13 @@ public class DmiModelOperations extends DmiOperations {
* Retrieve yang resources from dmi for any modules that CPS-NCMP hasn't cached before.
*
* @param persistenceCmHandle the persistenceCmHandle
- * @param unknownModuleReferences the unknown module references
+ * @param newModuleReferences the unknown module references
* @return yang resources as map of module name to yang(re)source
*/
public Map<String, String> getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle,
- final List<ModuleReference> unknownModuleReferences) {
+ final Collection<ModuleReference> newModuleReferences) {
final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources(
- unknownModuleReferences, persistenceCmHandle.getDmiProperties());
+ newModuleReferences, persistenceCmHandle.getDmiProperties());
final ResponseEntity<Object> responseEntity = getResourceFromDmiWithJsonData(
persistenceCmHandle.resolveDmiServiceName(MODEL),
jsonWithDataAndDmiProperties,
@@ -108,9 +109,9 @@ public class DmiModelOperations extends DmiOperations {
return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonData, new HttpHeaders());
}
- private static String getRequestBodyToFetchYangResources(final List<ModuleReference> unknownModuleReferences,
+ private static String getRequestBodyToFetchYangResources(final Collection<ModuleReference> newModuleReferences,
final List<PersistenceCmHandle.Property> dmiProperties) {
- final JsonArray moduleReferencesAsJson = getModuleReferencesAsJson(unknownModuleReferences);
+ final JsonArray moduleReferencesAsJson = getModuleReferencesAsJson(newModuleReferences);
final JsonObject data = new JsonObject();
data.add("modules", moduleReferencesAsJson);
final JsonObject jsonRequestObject = new JsonObject();
@@ -119,7 +120,7 @@ public class DmiModelOperations extends DmiOperations {
return jsonRequestObject.toString();
}
- private static JsonArray getModuleReferencesAsJson(final List<ModuleReference> unknownModuleReferences) {
+ private static JsonArray getModuleReferencesAsJson(final Collection<ModuleReference> unknownModuleReferences) {
final JsonArray moduleReferences = new JsonArray();
for (final ModuleReference moduleReference : unknownModuleReferences) {