import org.onap.cps.ncmp.api.datajobs.models.WriteOperation;
import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
import org.onap.cps.ncmp.impl.dmi.DmiServiceNameResolver;
-import org.onap.cps.ncmp.impl.inventory.ParameterizedCmHandleQueryService;
+import org.onap.cps.ncmp.impl.inventory.InventoryPersistence;
import org.onap.cps.ncmp.impl.models.RequiredDmiService;
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher;
+import org.onap.cps.ncmp.impl.utils.YangDataConverter;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class WriteRequestExaminer {
+ private static final String PATH_SEPARATOR = "/";
private final AlternateIdMatcher alternateIdMatcher;
- private final ParameterizedCmHandleQueryService parameterizedCmHandleQueryService;
- private static final String PATH_SEPARATOR = "/";
+ private final InventoryPersistence inventoryPersistence;
/**
* Splitting incoming data job write request into Dmi Write Operations by ProducerKey.
public Map<ProducerKey, List<DmiWriteOperation>> splitDmiWriteOperationsFromRequest(
final String dataJobId, final DataJobWriteRequest dataJobWriteRequest) {
final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey = new HashMap<>();
- final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId = getAllNcmpServiceCmHandlesWithoutProperties();
for (final WriteOperation writeOperation : dataJobWriteRequest.data()) {
- examineWriteOperation(dataJobId, dmiWriteOperationsPerProducerKey, writeOperation, cmHandlePerAlternateId);
+ examineWriteOperation(dataJobId, dmiWriteOperationsPerProducerKey, writeOperation);
}
return dmiWriteOperationsPerProducerKey;
}
- private Map<String, NcmpServiceCmHandle> getAllNcmpServiceCmHandlesWithoutProperties() {
- final Map<String, NcmpServiceCmHandle> ncmpServiceCmHandles = new HashMap<>();
- for (final NcmpServiceCmHandle ncmpServiceCmHandle
- : parameterizedCmHandleQueryService.getAllCmHandlesWithoutProperties()) {
- ncmpServiceCmHandles.put(ncmpServiceCmHandle.getAlternateId(), ncmpServiceCmHandle);
- }
- return ncmpServiceCmHandles;
- }
-
private void examineWriteOperation(final String dataJobId,
final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey,
- final WriteOperation writeOperation,
- final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId) {
+ final WriteOperation writeOperation) {
log.debug("data job id for write operation is: {}", dataJobId);
- final NcmpServiceCmHandle ncmpServiceCmHandle = alternateIdMatcher
- .getCmHandleByLongestMatchingAlternateId(writeOperation.path(), PATH_SEPARATOR, cmHandlePerAlternateId);
-
+ final String cmHandleId = alternateIdMatcher
+ .getCmHandleIdByLongestMatchingAlternateId(writeOperation.path(), PATH_SEPARATOR);
+ final NcmpServiceCmHandle ncmpServiceCmHandle = YangDataConverter.toNcmpServiceCmHandle(
+ inventoryPersistence.getYangModelCmHandle(cmHandleId));
final DmiWriteOperation dmiWriteOperation = createDmiWriteOperation(writeOperation, ncmpServiceCmHandle);
final ProducerKey producerKey = createProducerKey(ncmpServiceCmHandle);
package org.onap.cps.ncmp.impl.utils;
import com.hazelcast.map.IMap;
-import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException;
-import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
import org.onap.cps.ncmp.exceptions.NoAlternateIdMatchFoundException;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
*
* @param alternateId alternate ID
* @param separator a string that separates each element from the next.
- * @param cmHandlePerAlternateId all CM-handles by alternate ID
* @return ncmp service cm handle
*/
- public NcmpServiceCmHandle getCmHandleByLongestMatchingAlternateId(
- final String alternateId, final String separator,
- final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId) {
+ public String getCmHandleIdByLongestMatchingAlternateId(
+ final String alternateId, final String separator) {
final String[] splitPath = alternateId.split("#", 2);
String bestMatch = splitPath[0];
while (StringUtils.isNotEmpty(bestMatch)) {
- final NcmpServiceCmHandle ncmpServiceCmHandle = cmHandlePerAlternateId.get(bestMatch);
- if (ncmpServiceCmHandle != null) {
- return ncmpServiceCmHandle;
+ final String cmHandleId = cmHandleIdPerAlternateId.get(bestMatch);
+ if (cmHandleId != null) {
+ return cmHandleId;
}
bestMatch = getParentPath(bestMatch, separator);
}
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation
+ * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest
import org.onap.cps.ncmp.api.datajobs.models.WriteOperation
import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
-import org.onap.cps.ncmp.impl.inventory.ParameterizedCmHandleQueryService
+import org.onap.cps.ncmp.impl.inventory.InventoryPersistence
+import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher
import spock.lang.Specification
class WriteRequestExaminerSpec extends Specification {
def mockAlternateIdMatcher = Mock(AlternateIdMatcher)
- def mockParameterizedCmHandleQueryService = Mock(ParameterizedCmHandleQueryService)
- def objectUnderTest = new WriteRequestExaminer(mockAlternateIdMatcher, mockParameterizedCmHandleQueryService)
+ def mockInventoryPersistence = Mock(InventoryPersistence)
+ def objectUnderTest = new WriteRequestExaminer(mockAlternateIdMatcher, mockInventoryPersistence)
def setup() {
- def ch1 = new NcmpServiceCmHandle(cmHandleId: 'ch1', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn1', dataProducerIdentifier: 'p1')
- def ch2 = new NcmpServiceCmHandle(cmHandleId: 'ch2', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn2', dataProducerIdentifier: 'p1')
- def ch3 = new NcmpServiceCmHandle(cmHandleId: 'ch3', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn3', dataProducerIdentifier: 'p2')
- def ch4 = new NcmpServiceCmHandle(cmHandleId: 'ch4', dmiServiceName: 'dmiB', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn4', dataProducerIdentifier: 'p1')
- def cmHandlePerAlternateId = ['fdn1': ch1, 'fdn2': ch2, 'fdn3': ch3, 'fdn4': ch4]
- mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn1', '/', cmHandlePerAlternateId) >> ch1
- mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn2', '/', cmHandlePerAlternateId) >> ch2
- mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn3', '/', cmHandlePerAlternateId) >> ch3
- mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn4', '/', cmHandlePerAlternateId) >> ch4
- mockParameterizedCmHandleQueryService.getAllCmHandlesWithoutProperties() >> [ch1, ch2, ch3, ch4]
+ def yangModelCmHandle1 = new YangModelCmHandle(id: 'ch1', dmiServiceName: 'dmiA', dmiProperties: [],
+ publicProperties: [], compositeState: null, moduleSetTag: '', alternateId: '', dataProducerIdentifier: 'p1')
+ def yangModelCmHandle2 = new YangModelCmHandle(id: 'ch2', dmiServiceName: 'dmiA', dmiProperties: [],
+ publicProperties: [], compositeState: null, moduleSetTag: '', alternateId: '', dataProducerIdentifier: 'p1')
+ def yangModelCmHandle3 = new YangModelCmHandle(id: 'ch3', dmiServiceName: 'dmiA', dmiProperties: [],
+ publicProperties: [], compositeState: null, moduleSetTag: '', alternateId: '', dataProducerIdentifier: 'p2')
+ def yangModelCmHandle4 = new YangModelCmHandle(id: 'ch4', dmiServiceName: 'dmiB', dmiProperties: [],
+ publicProperties: [], compositeState: null, moduleSetTag: '', alternateId: '', dataProducerIdentifier: 'p1')
+ mockInventoryPersistence.getYangModelCmHandle('ch1') >> yangModelCmHandle1
+ mockInventoryPersistence.getYangModelCmHandle('ch2') >> yangModelCmHandle2
+ mockInventoryPersistence.getYangModelCmHandle('ch3') >> yangModelCmHandle3
+ mockInventoryPersistence.getYangModelCmHandle('ch4') >> yangModelCmHandle4
+ mockAlternateIdMatcher.getCmHandleIdByLongestMatchingAlternateId('fdn1', '/') >> 'ch1'
+ mockAlternateIdMatcher.getCmHandleIdByLongestMatchingAlternateId('fdn2', '/') >> 'ch2'
+ mockAlternateIdMatcher.getCmHandleIdByLongestMatchingAlternateId('fdn3', '/') >> 'ch3'
+ mockAlternateIdMatcher.getCmHandleIdByLongestMatchingAlternateId('fdn4', '/') >> 'ch4'
}
def 'Create a map of dmi write requests per producer key with #scenario.'() {
import com.hazelcast.map.IMap
import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException
-import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
import org.onap.cps.ncmp.exceptions.NoAlternateIdMatchFoundException
import spock.lang.Specification
def objectUnderTest = new AlternateIdMatcher(mockCmHandleIdPerAlternateId)
def 'Finding longest alternate id matches.'() {
- given: 'a cm handle with alternate id /a/b in the cached map of all cm handles'
- def ch1 = new NcmpServiceCmHandle(cmHandleId: 'ch1', alternateId: '/a/b')
- def cmHandlePerAlternateId = ['/a/b': ch1]
+ given:
+ mockCmHandleIdPerAlternateId.get('/a/b') >> 'ch1'
expect: 'querying for alternate id a matching result found'
- assert objectUnderTest.getCmHandleByLongestMatchingAlternateId(targetAlternateId, '/', cmHandlePerAlternateId) != null
+ assert objectUnderTest.getCmHandleIdByLongestMatchingAlternateId(targetAlternateId, '/') != null
where: 'the following parameters are used'
scenario | targetAlternateId
'exact match' | '/a/b'
def 'Attempt to find longest alternate id match without any matches.'() {
when: 'attempt to find alternateId'
- objectUnderTest.getCmHandleByLongestMatchingAlternateId(targetAlternateId, '/', [:])
+ objectUnderTest.getCmHandleIdByLongestMatchingAlternateId(targetAlternateId, '/')
then: 'no alternate id match found exception thrown'
def thrown = thrown(NoAlternateIdMatchFoundException)
and: 'the exception has the relevant details from the error response'