318741dd9f3409b7e1a02644d62e60c82b551494
[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.NetconfBindingAccessor;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
28 import org.opendaylight.mdsal.binding.api.DataBroker;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * @author herbert
35  *
36  */
37 public abstract class ONFCoreNetworkElementBase implements AutoCloseable, ONFCoreNetworkElementRepresentation {
38
39     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElementBase.class);
40
41     protected static final String EMPTY = "";
42
43     private final String mountPointNodeName;
44     private final NodeId nodeId;
45     private final DataBroker netconfNodeDataBroker;
46     private final NetconfBindingAccessor acessor;
47
48     protected ONFCoreNetworkElementBase(NetconfBindingAccessor acessor) {
49         LOG.info("Create ONFCoreNetworkElementBase");
50         this.mountPointNodeName = acessor.getNodeId().getValue();
51         this.nodeId = acessor.getNodeId();
52         this.netconfNodeDataBroker = acessor.getDataBroker();
53         this.acessor = acessor;
54
55     }
56
57     @Override
58     public Optional<NetconfAccessor> getAcessor() {
59         return Optional.of(acessor);
60     }
61
62     @Override
63     public String getMountPointNodeName() {
64         return mountPointNodeName;
65     }
66
67     /**
68      * @return the netconfNodeDataBroker
69      */
70     public DataBroker getNetconfNodeDataBroker() {
71         return netconfNodeDataBroker;
72     }
73
74     @Override
75     public void warmstart() {
76         int problems = removeAllCurrentProblemsOfNode();
77         LOG.debug("Removed all {} problems from database at deregistration for {}", problems, mountPointNodeName);
78     }
79
80     @Override
81     public NodeId getNodeId() {
82         return nodeId;
83     }
84
85     public TransactionUtils getGenericTransactionUtils() {
86         return acessor.getTransactionUtils();
87     }
88
89     /*---------------------------------------------------------------
90      * Getter/ Setter
91      */
92     @Override
93     public String getMountpoint() {
94         return mountPointNodeName;
95     }
96
97     @Override
98     public DataBroker getDataBroker() {
99         return netconfNodeDataBroker;
100     }
101
102 }