deacab8f2b1af9c005f2def737ae0a6d0666f22f
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 /**
19  *
20  */
21 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ne;
22
23 import java.util.Optional;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ONFCoreNetworkElementRepresentation;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
27 import org.opendaylight.mdsal.binding.api.DataBroker;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * @author herbert
34  *
35  */
36 public abstract class ONFCoreNetworkElementBase implements AutoCloseable, ONFCoreNetworkElementRepresentation {
37
38     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementBase.class);
39
40     protected static final String EMPTY = "";
41
42     private final String mountPointNodeName;
43     private final NodeId nodeId;
44     private final DataBroker netconfNodeDataBroker;
45     private final NetconfAccessor acessor;
46
47     protected ONFCoreNetworkElementBase(NetconfAccessor acessor) {
48         LOG.info("Create ONFCoreNetworkElementBase");
49         this.mountPointNodeName = acessor.getNodeId().getValue();
50         this.nodeId = acessor.getNodeId();
51         this.netconfNodeDataBroker = acessor.getDataBroker();
52         this.acessor = acessor;
53
54     }
55
56     @Override
57     public Optional<NetconfAccessor> getAcessor() {
58         return Optional.of(acessor);
59     }
60
61     @Override
62     public String getMountPointNodeName() {
63         return mountPointNodeName;
64     }
65
66     /**
67      * @return the netconfNodeDataBroker
68      */
69     public DataBroker getNetconfNodeDataBroker() {
70         return netconfNodeDataBroker;
71     }
72
73     @Override
74     public void warmstart() {
75         int problems = removeAllCurrentProblemsOfNode();
76         LOG.debug("Removed all {} problems from database at deregistration for {}", problems, mountPointNodeName);
77     }
78
79     @Override
80     public NodeId getNodeId() {
81         return nodeId;
82     }
83
84     public TransactionUtils getGenericTransactionUtils() {
85         return acessor.getTransactionUtils();
86     }
87
88     /*---------------------------------------------------------------
89      * Getter/ Setter
90      */
91     @Override
92     public String getMountpoint() {
93         return mountPointNodeName;
94     }
95
96     @Override
97     public DataBroker getDataBroker() {
98         return netconfNodeDataBroker;
99     }
100
101 }