diff options
author | 2022-02-15 18:23:05 +0000 | |
---|---|---|
committer | 2022-02-28 15:25:58 +0000 | |
commit | e0643ab5130dde375c229989e216341e623a9c55 (patch) | |
tree | ae0d551c6f904950a1263dd73b2ada099d636b34 /cps-ncmp-service/src | |
parent | 87de1fc8454fb1d93dfda7c5193783f16974cdaf (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')
3 files changed, 40 insertions, 40 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 3c8d8bc3b..aac44e43e 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 657b0b474..aec4517c0 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) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy index 3af4fc00e..3f82f5e0b 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy @@ -50,26 +50,36 @@ class NetworkCmProxyDataServiceImplModelSyncSpec extends Specification { def cmHandle = new CmHandle() def dmiServiceName = 'some service name' cmHandle.cmHandleID = 'cm handle id 1' - cmHandle.dmiProperties = dmiProperties def persistenceCmHandle = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, '' , '', cmHandle) and: 'DMI operations returns some module references' def moduleReferences = [ new ModuleReference(moduleName:'module1',revision:'1'), new ModuleReference(moduleName:'module2',revision:'2') ] mockDmiModelOperations.getModuleReferences(persistenceCmHandle) >> moduleReferences and: 'CPS-Core returns list of existing module resources' - mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> existingModuleResourcesInCps + mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> toModuleReference(existingModuleResourcesInCps) and: 'DMI-Plugin returns resource(s) for "new" module(s)' mockDmiModelOperations.getNewYangResourcesFromDmi(persistenceCmHandle, [new ModuleReference('module1', '1')]) >> yangResourceToContentMap when: 'module sync is triggered' + mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> toModuleReference(identifiedNewModuleReferences) objectUnderTest.syncModulesAndCreateAnchor(persistenceCmHandle) then: 'the CPS module service is called once with the correct parameters' - 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, persistenceCmHandle.getId(), yangResourceToContentMap, expectedKnownModules) + 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, persistenceCmHandle.getId(), yangResourceToContentMap, toModuleReference(expectedKnownModules)) and: 'admin service create anchor method has been called with correct parameters' 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, persistenceCmHandle.getId(), persistenceCmHandle.getId()) where: 'the following parameters are used' - scenario | dmiProperties | existingModuleResourcesInCps | yangResourceToContentMap || expectedKnownModules - 'one unknown module' | ['name1': 'value1'] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')] - 'no add. properties' | [:] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')] - 'no unknown module' | [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | [:] || [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] + scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | yangResourceToContentMap || expectedKnownModules + 'one new module' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source'] || [['module2' : '2']] + 'no add. properties' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source'] || [['module2' : '2']] + 'no new module' | [['module1' : '1'], ['module2' : '2']] | [] | [:] || [['module1' : '1'], ['module2' : '2']] } + + def toModuleReference(moduleReferenceAsMap) { + def moduleReferences = [].withDefault { [:] } + moduleReferenceAsMap.forEach(property -> + property.forEach((moduleName, revision) -> { + moduleReferences.add(new ModuleReference('moduleName' : moduleName, 'revision' : revision)) + })) + return moduleReferences + } + } |