diff options
Diffstat (limited to 'cps-ncmp-service/src/main/java')
4 files changed, 105 insertions, 7 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 3295a6e2b4..45dba211a3 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 @@ -162,4 +162,12 @@ public interface NetworkCmProxyDataService { * @param dataSyncEnabled data sync enabled flag */ void setDataSyncEnabled(String cmHandleId, boolean dataSyncEnabled); + + /** + * Get all cm handle IDs by DMI plugin identifier. + * + * @param dmiPluginIdentifier DMI plugin identifier + * @return set of cm handle IDs + */ + Set<String> getAllCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier); } 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 0fdecde077..5b072f35ed 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 @@ -30,6 +30,7 @@ import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -44,6 +45,7 @@ import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations; import org.onap.cps.ncmp.api.impl.operations.DmiOperations; 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.CmHandleQueries; import org.onap.cps.ncmp.api.inventory.CmHandleState; import org.onap.cps.ncmp.api.inventory.CompositeState; import org.onap.cps.ncmp.api.inventory.CompositeStateUtils; @@ -80,6 +82,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private final InventoryPersistence inventoryPersistence; + private final CmHandleQueries cmHandleQueries; + private final NetworkCmProxyCmHandlerQueryService networkCmProxyCmHandlerQueryService; private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler; @@ -219,6 +223,23 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } /** + * Get all cm handle IDs by DMI plugin identifier. + * + * @param dmiPluginIdentifier DMI plugin identifier + * @return set of cm handle IDs + */ + @Override + public Set<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) { + final Set<NcmpServiceCmHandle> ncmpServiceCmHandles = + cmHandleQueries.getCmHandlesByDmiPluginIdentifier(dmiPluginIdentifier); + final Set<String> cmHandleIds = new HashSet<>(ncmpServiceCmHandles.size()); + ncmpServiceCmHandles.forEach(cmHandle -> { + cmHandleIds.add(cmHandle.getCmHandleId()); + }); + return cmHandleIds; + } + + /** * Retrieve cm handle details for a given cm handle. * * @param cmHandleId cm handle identifier 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 9655612e70..569e91e2c9 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 @@ -27,8 +27,10 @@ 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; @@ -57,21 +59,21 @@ public class CmHandleQueries { * @return CmHandles which have these public properties */ public Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties( - final Map<String, String> publicPropertyQueryPairs) { + 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() + "\"]"; + + "\" 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()); + .map(dataNode -> dataNode.getLeaves().get("id").toString()).collect(Collectors.toSet()); cmHandleIdToNcmpServiceCmHandles.keySet().retainAll(cmHandleIdsToRetain); } if (cmHandleIdToNcmpServiceCmHandles.isEmpty()) { @@ -89,8 +91,8 @@ public class CmHandleQueries { * @return combined Map of CmHandles */ public Map<String, NcmpServiceCmHandle> combineCmHandleQueries( - final Map<String, NcmpServiceCmHandle> firstQuery, - final Map<String, NcmpServiceCmHandle> secondQuery) { + 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) { @@ -150,7 +152,7 @@ public class CmHandleQueries { } private Map<String, NcmpServiceCmHandle> collectDataNodesToNcmpServiceCmHandles( - final Collection<DataNode> dataNodes) { + final Collection<DataNode> dataNodes) { final Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandle = new HashMap<>(); dataNodes.forEach(dataNode -> { final NcmpServiceCmHandle ncmpServiceCmHandle = createNcmpServiceCmHandle(dataNode); @@ -161,7 +163,36 @@ public class CmHandleQueries { private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) { return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter - .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString())); + .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString())); + } + + /** + * Get all cm handles by DMI plugin identifier. + * + * @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) { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/ModelledDmiServiceLeaves.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/ModelledDmiServiceLeaves.java new file mode 100644 index 0000000000..0546c388bf --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/ModelledDmiServiceLeaves.java @@ -0,0 +1,38 @@ +/* + * ============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; + +public enum ModelledDmiServiceLeaves { + DMI_SERVICE_NAME("dmi-service-name"), + DMI_DATA_SERVICE_NAME("dmi-data-service-name"), + DMI_MODEL_SERVICE_NAME("dmi-model-service-name"); + + private String leafName; + + ModelledDmiServiceLeaves(final String dmiPluginIdentifierKey) { + this.leafName = dmiPluginIdentifierKey; + } + + public String getLeafName() { + return leafName; + } + +} |