aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/yangspecs/OnapSystem.java
blob: 03ed89111476d1e03bd3a8c7afee5a472e7ef115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * ============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.devicemanager.oran.yangspecs;

import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class OnapSystem extends YangModule {

    private static final Logger LOG = LoggerFactory.getLogger(OnapSystem.class);
    public static final String NAMESPACE = "urn:onap:system";
    public static final QNameModule ONAPSYSTEM_2020_10_26 =
            QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2020-10-26"));
    public static final QNameModule ONAPSYSTEM_2022_11_04 =
            QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2022-11-04"));
    private static final List<QNameModule> MODULES = Arrays.asList(ONAPSYSTEM_2020_10_26, ONAPSYSTEM_2022_11_04);

    private final QName NAME;
    private final QName WEB_UI;
    private final QName GEOGRAPHICAL_LOCATION;

    OnapSystem(NetconfDomAccessor netconfDomAccessor, QNameModule module) {
        super(netconfDomAccessor, module);

        NAME = QName.create(module, "name");
        WEB_UI = QName.create(module, "web-ui");
        GEOGRAPHICAL_LOCATION = QName.create(module, "geographical-location");
    }

    public QName getName() {
        return NAME;
    }

    public QName getWebUi() {
        return WEB_UI;
    }

    public QName getGeoLocation() {
        return GEOGRAPHICAL_LOCATION;
    }

    // Read from device
    /**
     * Read system data with GUI cut through information from device if ONAP_SYSTEM YANG is supported.
     *
     * @return NormalizedNode data with GUI cut through information or null if not available.
     */
    public @Nullable NormalizedNode getOnapSystemData() {
        LOG.debug("Get System1 for mountpoint {}", netconfDomAccessor.getNodeId().getValue());
        @NonNull
        InstanceIdentifierBuilder ietfSystemIID =
                YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.IETF_SYSTEM_CONTAINER);
        @NonNull
        AugmentationIdentifier onapSystemIID = null;
        if (netconfDomAccessor.getCapabilites().isSupportingNamespaceAndRevision(ONAPSYSTEM_2020_10_26))
            onapSystemIID = YangInstanceIdentifier.AugmentationIdentifier.create(Sets.newHashSet(NAME, WEB_UI));
        else if (netconfDomAccessor.getCapabilites().isSupportingNamespaceAndRevision(ONAPSYSTEM_2022_11_04))
            onapSystemIID = YangInstanceIdentifier.AugmentationIdentifier
                    .create(Sets.newHashSet(NAME, WEB_UI, GEOGRAPHICAL_LOCATION));

        InstanceIdentifierBuilder augmentedOnapSystem =
                YangInstanceIdentifier.builder(ietfSystemIID.build()).node(onapSystemIID);

        Optional<NormalizedNode> res =
                netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, augmentedOnapSystem.build());
        LOG.debug("Result of System1 = {}", res);
        return res.isPresent() ? res.get() : null;

    }

    /**
     * Get specific instance, depending on capabilities
     *
     * @param capabilities
     * @return
     */
    public static Optional<OnapSystem> getModule(NetconfDomAccessor netconfDomAccessor) {
        Capabilities capabilities = netconfDomAccessor.getCapabilites();
        for (QNameModule module : MODULES) {
            if (capabilities.isSupportingNamespaceAndRevision(module)) {
                return Optional.of(new OnapSystem(netconfDomAccessor, module));
            }
        }
        return Optional.empty();
    }


}