Reorganization of devicemanager directory structure
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / openroadm / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / openroadm / impl / DeviceManagerOpenroadmImpl.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 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.openroadm.impl;
23
24 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * @author Shabnam Sultana
32  *
33  *         Class to initialize the OpenRoadm Device Manager
34  **/
35 public class DeviceManagerOpenroadmImpl implements AutoCloseable {
36
37     // variables
38     private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerOpenroadmImpl.class);
39     private static final String APPLICATION_NAME = "DeviceManagerOpenRoadm";
40     @SuppressWarnings("unused")
41     private static final String CONFIGURATIONFILE = "etc/devicemanager-opeenroadm.properties";
42     private NetconfNetworkElementService netconfNetworkElementService;
43     private HtDatabaseClient htDatabaseClient;
44     private Boolean devicemanagerInitializationOk = false;
45     private FactoryRegistration<OpenroadmNetworkElementFactory> resOpenRoadm;
46     // end of variables
47
48     // Blueprint begin
49     // constructors
50     public DeviceManagerOpenroadmImpl() {
51         LOG.info("Creating provider for {}", APPLICATION_NAME);
52         resOpenRoadm = null;
53     }
54     // end of constructors
55
56     // public methods
57     public void setNetconfNetworkElementService(NetconfNetworkElementService netconfNetworkElementService) {
58         this.netconfNetworkElementService = netconfNetworkElementService;
59     }
60
61     public void init() throws Exception {
62
63         LOG.info("Session Initiated start {}", APPLICATION_NAME);
64
65         resOpenRoadm = netconfNetworkElementService.registerBindingNetworkElementFactory(new OpenroadmNetworkElementFactory());
66
67
68         netconfNetworkElementService.writeToEventLog(APPLICATION_NAME, "startup", "done");
69         this.devicemanagerInitializationOk = true;
70
71         LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
72     }
73     // Blueprint end
74
75     @Override
76     public void close() throws Exception {
77         LOG.info("closing ...");
78         close(htDatabaseClient);
79         close(resOpenRoadm);
80         LOG.info("closing done");
81     }
82     // end of public methods
83
84     // private methods
85     /**
86      * Used to close all Services, that should support AutoCloseable Pattern
87      *
88      * @param toClose
89      * @throws Exception
90      */
91     private void close(AutoCloseable... toCloseList) {
92         for (AutoCloseable element : toCloseList) {
93             if (element != null) {
94                 try {
95                     element.close();
96                 } catch (Exception e) {
97                     LOG.warn("Fail during close: ", e);
98                 }
99             }
100         }
101     }
102     // end of private methods
103 }