2465fc622e356a6cf973316f499ca6e2ec38aa21
[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     public void setMediatorServerServlet(MsServlet servlet) {
61         this.mediatorServerServlet = servlet;
62     }
63     public void setAboutServlet(AboutHttpServlet aboutServlet) {
64         this.aboutServlet = aboutServlet;
65     }
66     public void init() throws Exception {
67
68         LOG.info("Session Initiated start {}", APPLICATION_NAME);
69
70         // Start RPC Service
71         this.rpcApiService = new DataProviderServiceImpl(rpcProviderService,this.mediatorServerServlet);
72         LOG.info("Session Initiated end. Initialization done");
73     }
74
75     @Override
76     public void close() throws Exception {
77         LOG.info("DeviceManagerImpl closing ...");
78
79         close(dbClient);
80         close(rpcApiService);
81         LOG.info("DeviceManagerImpl closing done");
82     }
83
84     /**
85      * Used to close all Services, that should support AutoCloseable Pattern
86      *
87      * @param toClose
88      * @throws Exception
89      */
90     private void close(AutoCloseable... toCloseList) throws Exception {
91         for (AutoCloseable element : toCloseList) {
92             if (element != null) {
93                 element.close();
94             }
95         }
96     }
97
98     @Override
99     public DataProvider getDataProvider() {
100         return rpcApiService.getDataProvider();
101     }
102
103     @Override
104     public HtDatabaseMaintenance getHtDatabaseMaintenance() {
105         return rpcApiService.getHtDatabaseMaintenance();
106     }
107
108     @Override
109     public IEsConfig getEsConfig() {
110         return rpcApiService.getEsConfig();
111     }
112
113     @Override
114     public NetconfTimeStamp getConverter() {
115         return NetconfTimeStampImpl.getConverter();
116     }
117
118     @Override
119     public void setReadyStatus(boolean status) {
120             ReadyHttpServlet.setStatus(status);
121     }
122
123     @Override
124     public void setStatus(StatusKey key, String value) {
125         if(this.aboutServlet!=null) {
126             if(key==StatusKey.CLUSTER_SIZE) {
127                 this.aboutServlet.setClusterSize(value);
128             }
129         }
130     }
131
132 }