286af7aa3e79494d986cefdcefc99e09eed535f9
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 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.dataprovider.impl;
23
24 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
25 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.AboutHttpServlet;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.ReadyHttpServlet;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
36 import org.opendaylight.mdsal.binding.api.RpcProviderService;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 public class DataProviderImpl implements IEntityDataProvider, AutoCloseable {
41
42     private static final Logger LOG = LoggerFactory.getLogger(DataProviderImpl.class);
43
44     private static final String APPLICATION_NAME = "data-provider";
45     private RpcProviderService rpcProviderService = null;
46     private MsServlet mediatorServerServlet;
47     private DataProviderServiceImpl rpcApiService;
48     private AboutHttpServlet aboutServlet;
49     private HtDatabaseClient dbClient;
50
51     // Blueprint 1
52     public DataProviderImpl() {
53         super();
54         LOG.info("Creating provider for {}", APPLICATION_NAME);
55     }
56
57     public void setRpcProviderService(RpcProviderService rpcProviderService) {
58         this.rpcProviderService = rpcProviderService;
59     }
60
61     public void setMediatorServerServlet(MsServlet servlet) {
62         this.mediatorServerServlet = servlet;
63     }
64
65     public void setAboutServlet(AboutHttpServlet aboutServlet) {
66         this.aboutServlet = aboutServlet;
67     }
68
69     public void init() throws Exception {
70
71         LOG.info("Session Initiated start {}", APPLICATION_NAME);
72
73         // Start RPC Service
74         this.rpcApiService = new DataProviderServiceImpl(rpcProviderService, this.mediatorServerServlet);
75         LOG.info("Session Initiated end. Initialization done");
76     }
77
78     @Override
79     public void close() throws Exception {
80         LOG.info("DeviceManagerImpl closing ...");
81
82         close(dbClient);
83         close(rpcApiService);
84         LOG.info("DeviceManagerImpl closing done");
85     }
86
87     /**
88      * Used to close all Services, that should support AutoCloseable Pattern
89      *
90      * @param toClose
91      * @throws Exception
92      */
93     private void close(AutoCloseable... toCloseList) throws Exception {
94         for (AutoCloseable element : toCloseList) {
95             if (element != null) {
96                 element.close();
97             }
98         }
99     }
100
101     @Override
102     public DataProvider getDataProvider() {
103         return rpcApiService.getDataProvider();
104     }
105
106     @Override
107     public HtDatabaseMaintenance getHtDatabaseMaintenance() {
108         return rpcApiService.getHtDatabaseMaintenance();
109     }
110
111     @Override
112     public IEsConfig getEsConfig() {
113         return rpcApiService.getEsConfig();
114     }
115
116     @Override
117     public NetconfTimeStamp getConverter() {
118         return NetconfTimeStampImpl.getConverter();
119     }
120
121     @Override
122     public void setReadyStatus(boolean status) {
123         ReadyHttpServlet.setStatus(status);
124     }
125
126     @Override
127     public void setStatus(StatusKey key, String value) {
128         if (this.aboutServlet != null) {
129             if (key == StatusKey.CLUSTER_SIZE) {
130                 this.aboutServlet.setClusterSize(value);
131             }
132         }
133     }
134
135 }