6ca61ffbb99127b8cd0ad8d557c06d70ec45ec1e
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs;
23
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.Optional;
27 import org.eclipse.jdt.annotation.NonNull;
28 import org.eclipse.jdt.annotation.Nullable;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
32 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
33 import org.opendaylight.yangtools.yang.common.QName;
34 import org.opendaylight.yangtools.yang.common.QNameModule;
35 import org.opendaylight.yangtools.yang.common.Revision;
36 import org.opendaylight.yangtools.yang.common.XMLNamespace;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
39 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43
44
45 public class OnapSystem extends YangModule {
46
47     private static final Logger LOG = LoggerFactory.getLogger(OnapSystem.class);
48     public static final String NAMESPACE = "urn:onap:system";
49     public static final QNameModule ONAPSYSTEM_2020_10_26 =
50             QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2020-10-26"));
51     public static final QNameModule ONAPSYSTEM_2022_11_04 =
52             QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2022-11-04"));
53     private static final List<QNameModule> MODULES = Arrays.asList(ONAPSYSTEM_2020_10_26, ONAPSYSTEM_2022_11_04);
54
55     private final QName NAME;
56     private final QName WEB_UI;
57     private final QName GEOGRAPHICAL_LOCATION;
58
59     OnapSystem(NetconfDomAccessor netconfDomAccessor, QNameModule module) {
60         super(netconfDomAccessor, module);
61
62         NAME = QName.create(module, "name");
63         WEB_UI = QName.create(module, "web-ui");
64         GEOGRAPHICAL_LOCATION = QName.create(module, "geographical-location");
65     }
66
67     public QName getName() {
68         return NAME;
69     }
70
71     public QName getWebUi() {
72         return WEB_UI;
73     }
74
75     public QName getGeoLocation() {
76         return GEOGRAPHICAL_LOCATION;
77     }
78
79     // Read from device
80     /**
81      * Read system data with GUI cut through information from device if ONAP_SYSTEM YANG is supported.
82      *
83      * @return NormalizedNode data with GUI cut through information or null if not available.
84      */
85     public @Nullable NormalizedNode getOnapSystemData() {
86         LOG.debug("Get System1 for mountpoint {}", netconfDomAccessor.getNodeId().getValue());
87         @NonNull
88         InstanceIdentifierBuilder ietfSystemIID =
89                 YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.IETF_SYSTEM_CONTAINER);
90
91         Optional<NormalizedNode> res =
92                 netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, ietfSystemIID.build());
93         LOG.debug("Result of System1 = {}", res);
94         return res.isPresent() ? res.get() : null;
95
96     }
97
98     /**
99      * Get specific instance, depending on capabilities
100      *
101      * @param capabilities
102      * @return
103      */
104     public static Optional<OnapSystem> getModule(NetconfDomAccessor netconfDomAccessor) {
105         Capabilities capabilities = netconfDomAccessor.getCapabilites();
106         for (QNameModule module : MODULES) {
107             if (capabilities.isSupportingNamespaceAndRevision(module)) {
108                 return Optional.of(new OnapSystem(netconfDomAccessor, module));
109             }
110         }
111         return Optional.empty();
112     }
113
114
115 }