diff options
Diffstat (limited to 'sdnr/wt/data-provider/model/src')
7 files changed, 652 insertions, 0 deletions
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/BaseInventoryTreeProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/BaseInventoryTreeProvider.java new file mode 100644 index 000000000..3d7f82ebd --- /dev/null +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/BaseInventoryTreeProvider.java @@ -0,0 +1,206 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property. + * 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. + * 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. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeChildObject; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryEntity; +import org.opendaylight.yangtools.yang.common.Uint32; + +public abstract class BaseInventoryTreeProvider implements InventoryTreeProvider { + + private static final String INVENTORY_PROPERTY_TREELEVEL = "tree-level"; + protected static final String INVENTORY_PROPERTY_NODEID = "node-id"; + protected static final String INVENTORY_PROPERTY_UUID = "uuid"; + protected static final String INVENTORY_PROPERTY_PARENTUUID = "parent-uuid"; + + protected abstract List<String> getAllNodeIds(); + + protected abstract List<InventoryEntity> search(String filter, String sortOrderProperty, SortOrder sortOrder); + + protected abstract List<InventoryEntity> search(String filter, String nodeId, String parentUuid, String uuid, + String sortOrderProperty, SortOrder sortOrder); + + protected abstract List<InventoryEntity> getItemsForNodes(List<String> nodeIds, String sortOrderProperty, + SortOrder sortOrder); + + + @Override + public DataTreeObject readInventoryTree(List<String> tree, String filter) throws IOException { + + //root nodes will be node-information -> below inventory + if (tree == null || tree.size() <= 0) { + return this.readInventoryTreeWithNode(filter); + } + //root node will be inventory on tree-level if sliced treePath + else { + return this.readInventoryTreeForNode(tree.get(0), tree.subList(0, tree.size() - 1), filter); + } + + } + + /** + * Provide inventory list for a node, starting from element described by path + * @param nodeId node + * @param path describing element + * @param filter + * @return Inventory tree + */ + private DataTreeObject readInventoryTreeForNode(String nodeId, List<String> path, String filter) + throws IOException { + DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID); + //get parent uuid of path + final String parentUuid = path.size() > 1 ? path.get(path.size() - 2) : null; + //get uuid of path + final String uuid = path.size() > 0 ? path.get(path.size() - 1) : null; + List<InventoryEntity> matches = + this.search(filter, nodeId, parentUuid, uuid, INVENTORY_PROPERTY_TREELEVEL, SortOrder.ASCENDING); + //tree.a(subtreePath); + List<InventoryEntity> others = + this.search((String) null, nodeId, null, null, INVENTORY_PROPERTY_TREELEVEL, SortOrder.ASCENDING); + if (matches.size() > 0) { + int treeLevelToStart = (path == null || path.size() <= 0) ? 0 : path.size() - 1; + //build tree + //fill root elems + for (InventoryEntity hit : matches) { + if (hit.getTreeLevel().longValue() == treeLevelToStart) { + tree.put(hit.getId(), + new DataTreeChildObject(hit.getUuid(), true) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + for (InventoryEntity hit : others) { + if (hit.getTreeLevel().longValue() == treeLevelToStart) { + tree.putIfNotExists(hit.getId(), + new DataTreeChildObject(hit.getUuid(), false) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + //fill child elems + for (InventoryEntity hit : matches) { + if (hit.getTreeLevel().longValue() > treeLevelToStart) { + tree.put(hit.getTreeLevel().longValue() - treeLevelToStart - 1, hit.getId(), + new DataTreeChildObject(hit.getUuid(), true) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + for (InventoryEntity hit : others) { + if (hit.getTreeLevel().longValue() > treeLevelToStart) { + tree.putIfNotExists(hit.getTreeLevel().longValue() - treeLevelToStart - 1, hit.getId(), + new DataTreeChildObject(hit.getUuid(), false) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + tree.removeUnmatchedPaths(); + } + return tree; + } + + /** + * node will be root elements inventory information below from level-1 + * + * @param filter + * @return + * @throws IOException + */ + private DataTreeObject readInventoryTreeWithNode(String filter) throws IOException { + DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID); + + List<InventoryEntity> matches = this.search(filter, INVENTORY_PROPERTY_TREELEVEL, SortOrder.ASCENDING); + List<InventoryEntity> others = null; + if (matches.size() > 0) { + if (filter != null) { + //find all parents up to tree-level 0 + String nodeId = ""; + List<String> alreadyInList = new ArrayList<>(); + for (InventoryEntity hit : matches) { + nodeId = hit.getNodeId(); + if (alreadyInList.contains(nodeId)) { + continue; + } + alreadyInList.add(nodeId); + tree.put(nodeId, + new DataTreeChildObject(nodeId, false).setProperty(INVENTORY_PROPERTY_UUID, nodeId)); + + } + others = this.getItemsForNodes(alreadyInList, INVENTORY_PROPERTY_TREELEVEL, SortOrder.ASCENDING); + } else { + List<String> nodeIds = this.getAllNodeIds(); + for (String node : nodeIds) { + tree.put(node, new DataTreeChildObject(node, false).setProperty(INVENTORY_PROPERTY_UUID, node)); + } + } + + //build tree + //fill root elems + for (InventoryEntity hit : matches) { + if (hit.getTreeLevel() == Uint32.ZERO) { + tree.put(0, hit.getId(), + new DataTreeChildObject(hit.getUuid(), true) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getNodeId())); + } + } + if (others != null) { + for (InventoryEntity hit : others) { + if (hit.getTreeLevel() == Uint32.ZERO) { + tree.putIfNotExists(0, hit.getId(), + new DataTreeChildObject(hit.getUuid(), false) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getNodeId())); + } + } + } + //fill child elements + for (InventoryEntity hit : matches) { + long treeLevel = hit.getTreeLevel().longValue(); + if (treeLevel > 0) { + tree.put(treeLevel, hit.getId(), + new DataTreeChildObject(hit.getUuid(), true) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + if (others != null) { + for (InventoryEntity hit : others) { + long treeLevel = hit.getTreeLevel().longValue(); + if (treeLevel > 0) { + tree.putIfNotExists(treeLevel, hit.getId(), + new DataTreeChildObject(hit.getUuid(), false) + .setProperty(INVENTORY_PROPERTY_UUID, hit.getUuid()) + .setProperty(INVENTORY_PROPERTY_PARENTUUID, hit.getParentUuid())); + } + } + } + tree.removeUnmatchedPaths(); + } + return tree; + } +} diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DatabaseDataProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DatabaseDataProvider.java new file mode 100644 index 000000000..97b8b0de5 --- /dev/null +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DatabaseDataProvider.java @@ -0,0 +1,141 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. 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. + * 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. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.model; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateNetworkElementConnectionOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMaintenanceInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMaintenanceOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMediatorServerInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteMediatorServerOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteNetworkElementConnectionInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.DeleteNetworkElementConnectionOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultlogListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMaintenanceListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadMediatorServerListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadNetworkElementConnectionListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mDeviceListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata15mLtpListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hDeviceListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadPmdata24hLtpListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadStatusOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMaintenanceInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMaintenanceOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMediatorServerInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateMediatorServerOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionOutputBuilder; + + +public interface DatabaseDataProvider { + + HtDatabaseClient getRawClient(); + + ReadFaultcurrentListOutputBuilder readFaultCurrentList(EntityInput input); + + ReadFaultlogListOutputBuilder readFaultLogList(EntityInput input); + + ReadCmlogListOutputBuilder readCMLogList(EntityInput input); + + ReadMaintenanceListOutputBuilder readMaintenanceList(EntityInput input); + + ReadMediatorServerListOutputBuilder readMediatorServerList(EntityInput input); + + ReadNetworkElementConnectionListOutputBuilder readNetworkElementConnectionList(EntityInput input); + + ReadInventoryListOutputBuilder readInventoryList(EntityInput input); + + ReadConnectionlogListOutputBuilder readConnectionlogList(EntityInput input); + + ReadEventlogListOutputBuilder readEventlogList(EntityInput input) throws IOException; + + ReadPmdata15mListOutputBuilder readPmdata15mList(EntityInput input); + + ReadPmdata24hListOutputBuilder readPmdata24hList(EntityInput input); + + ReadPmdata15mLtpListOutputBuilder readPmdata15mLtpList(EntityInput input) throws IOException; + + ReadPmdata15mDeviceListOutputBuilder readPmdata15mDeviceList(EntityInput input) throws IOException; + + ReadPmdata24hLtpListOutputBuilder readPmdata24hLtpList(EntityInput input) throws IOException; + + ReadPmdata24hDeviceListOutputBuilder readPmdata24hDeviceList(EntityInput input) throws IOException; + + ReadStatusOutputBuilder readStatus(EntityInput input) throws IOException; + + boolean waitForYellowDatabaseStatus(long timeout, TimeUnit unit); + + CreateNetworkElementConnectionOutputBuilder createNetworkElementConnection(NetworkElementConnectionEntity input) + throws IOException; + + UpdateNetworkElementConnectionOutputBuilder updateNetworkElementConnection( + UpdateNetworkElementConnectionInput input) throws IOException; + + DeleteNetworkElementConnectionOutputBuilder deleteNetworkElementConnection( + DeleteNetworkElementConnectionInput input) throws IOException; + + DeleteMediatorServerOutputBuilder deleteMediatorServer(DeleteMediatorServerInput input) throws IOException; + + DeleteMaintenanceOutputBuilder deleteMaintenance(DeleteMaintenanceInput input) throws IOException; + + UpdateMaintenanceOutputBuilder updateMaintenance(UpdateMaintenanceInput input) throws IOException; + + UpdateMediatorServerOutputBuilder updateMediatorServer(UpdateMediatorServerInput input) throws IOException; + + CreateMaintenanceOutputBuilder createMaintenance(CreateMaintenanceInput input) throws IOException; + + CreateMediatorServerOutputBuilder createMediatorServer(CreateMediatorServerInput input) throws IOException; + + ReadGuiCutThroughEntryOutputBuilder readGuiCutThroughEntry(EntityInput input); + + DataProvider getDataProvider(); + + HtDatabaseMaintenance getHtDatabaseMaintenance(); + + HtDatabaseMediatorserver getHtDatabaseMediatorServer(); + + HtUserdataManager getUserManager(); + + InventoryTreeProvider getInventoryTreeProvider(); + + ReadInventoryDeviceListOutputBuilder readInventoryDeviceList(EntityInput input); + +} diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/InventoryTreeProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/InventoryTreeProvider.java new file mode 100644 index 000000000..e9523418a --- /dev/null +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/InventoryTreeProvider.java @@ -0,0 +1,31 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property. + * 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. + * 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. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.model; + +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.DataTreeObject; + +import java.io.IOException; +import java.util.List; + +public interface InventoryTreeProvider { + public DataTreeObject readInventoryTree(List<String> tree, String filter) throws IOException; +} diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeChildObject.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeChildObject.java new file mode 100644 index 000000000..227020505 --- /dev/null +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeChildObject.java @@ -0,0 +1,155 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * 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. + * 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. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import org.json.JSONObject; + +public class DataTreeChildObject { + + private final String label; + private final boolean isSearchMatch; + private final Map<String, DataTreeChildObject> children; + private final Map<String, Object> properties; + + public DataTreeChildObject(String label, boolean isMatch, Map<String, DataTreeChildObject> children, + String ownSeverity, String childrenSeveritySummary) { + this.label = label; + this.isSearchMatch = isMatch; + this.children = children; + this.properties = new HashMap<>(); + } + + public DataTreeChildObject setProperty(String key, Object value) { + this.properties.put(key, value); + return this; + } + + public DataTreeChildObject(String label, boolean isMatch) { + this(label, isMatch, new HashMap<>(), null, null); + } + + public boolean isMatch() { + return this.isSearchMatch; + } + + public Object getProperty(String key, Object defaultValue) { + return this.properties.getOrDefault(key, defaultValue); + } + + public boolean putChild(long treeLevel, String id, DataTreeChildObject data, String parentKey, String childKey) { + Object itemValue; + Object itemValueToMatch = data.getProperty(parentKey, null); + if (itemValueToMatch == null) { + return false; + } + if (treeLevel > 0) { + if (this.children != null) { + for (DataTreeChildObject child : this.children.values()) { + if (child.putChild(treeLevel - 1, id, data, parentKey, childKey)) { + return true; + } + } + } + } else { + itemValue = this.getProperty(childKey, null); + if (itemValue != null && itemValue.equals(itemValueToMatch)) { + this.children.put(id, data); + return true; + } + } + return false; + } + + public boolean putChildIfNotExists(long treeLevel, String id, DataTreeChildObject data, String parentKey, + String childKey) { + Object itemValue; + Object itemValueToMatch = data.getProperty(parentKey, null); + if (itemValueToMatch == null) { + return false; + } + if (treeLevel > 0) { + if (this.children != null) { + for (DataTreeChildObject child : this.children.values()) { + if (child.putChildIfNotExists(treeLevel - 1, id, data, parentKey, childKey)) { + return true; + } + } + } + } else { + itemValue = this.getProperty(childKey, null); + if (itemValue != null && itemValue.equals(itemValueToMatch)) { + if (!this.children.containsKey(id)) { + this.children.put(id, data); + } + } + } + return false; + } + + public JSONObject toJSONObject() { + JSONObject o = new JSONObject(); + o.put("label", this.label); + o.put("isMatch", this.isSearchMatch); + JSONObject c = new JSONObject(); + if (this.children != null) { + for (Entry<String, DataTreeChildObject> entry : this.children.entrySet()) { + c.put(entry.getKey(), entry.getValue().toJSONObject()); + } + } + o.put("children", c); + return o; + } + + public boolean hasChildMatching() { + boolean match = false; + for (DataTreeChildObject child : this.children.values()) { + match = match || child.hasChildMatching() || this.isSearchMatch; + if (match) { + break; + } + } + return match; + } + + public void removeUnmatchedPaths() { + List<String> toRemove = new ArrayList<>(); + for (Entry<String, DataTreeChildObject> entry : this.children.entrySet()) { + if (!(entry.getValue().hasChildMatching() || entry.getValue().isSearchMatch)) { + toRemove.add(entry.getKey()); + } else { + entry.getValue().removeUnmatchedPaths(); + } + } + for (String key : toRemove) { + this.children.remove(key); + } + } + + public boolean hasChildren() { + return this.children != null && !this.children.isEmpty(); + } +} diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeObject.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeObject.java new file mode 100644 index 000000000..c4b2b128d --- /dev/null +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/DataTreeObject.java @@ -0,0 +1,93 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * 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. + * 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. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import org.json.JSONObject; + +public class DataTreeObject extends HashMap<String, DataTreeChildObject> { + + private static final long serialVersionUID = 1L; + private final String parentKey; + private final String childKey; + + public DataTreeObject(String parentKey, String childKey) { + this.parentKey = parentKey; + this.childKey = childKey; + } + + public void put(long treeLevel, String id, DataTreeChildObject data) { + for (DataTreeChildObject entry : this.values()) { + if (entry.putChild(treeLevel, id, data, this.parentKey, this.childKey)) { + break; + } + } + } + + public void putIfNotExists(long treeLevel, String id, DataTreeChildObject data) { + for (DataTreeChildObject entry : this.values()) { + if (entry.putChildIfNotExists(treeLevel, id, data, this.parentKey, this.childKey)) { + break; + } + } + } + + public void putIfNotExists(String id, DataTreeChildObject data) { + if (!this.containsKey(id)) { + this.put(id, data); + } + } + + public String toJSON() { + JSONObject o = new JSONObject(); + for (Entry<String, DataTreeChildObject> entry : this.entrySet()) { + o.put(entry.getKey(), entry.getValue().toJSONObject()); + } + return o.toString(); + } + + public void removeUnmatchedPaths() { + List<String> toRemove = new ArrayList<>(); + for (Entry<String,DataTreeChildObject> entry : this.entrySet()) { + entry.getValue().removeUnmatchedPaths(); + if(!entry.getValue().isMatch() && !entry.getValue().hasChildren()) { + toRemove.add(entry.getKey()); + } + } + for(String toRemoveKey:toRemove) { + this.remove(toRemoveKey); + } + + } + + + public static String[] slice(String[] source, int start) { + String[] r = new String[source.length - start]; + for (int i = 0; i < r.length; i++) { + r[i] = source[i + start]; + } + return r; + + } +} diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/YangHelper2.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/YangHelper2.java index 423ebab0b..d0169ce06 100644 --- a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/YangHelper2.java +++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/YangHelper2.java @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SortOrder; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.Identifier; import org.opendaylight.yangtools.yang.common.Uint16; @@ -113,4 +114,9 @@ public class YangHelper2 { return org.opendaylight.yangtools.yang.binding.ScalarTypeObject.class; } + public static SortOrder getSortOrder(org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder sortOrder){ + return sortOrder== org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING? + SortOrder.Ascending:SortOrder.Descending; + } + } diff --git a/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang b/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang index 72ac45a56..0c89b675b 100644 --- a/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang +++ b/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang @@ -2015,6 +2015,26 @@ module data-provider { } } + rpc read-inventory-device-list { + description + "Get list of mountpoints with inventory data"; + input { + uses entity-input; + } + output { + container pagination { + uses pagination-output-g; + description + "The pagination details used by the provider to filter the data."; + } + leaf-list data { + type string; + description + "The list of found mountpoint names."; + } + } + } + rpc read-status { description "Read status information of controller"; |