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