ba6e9997501127bdc70f624f6e282b4d853d2f91
[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.ReadyHttpServlet;
22 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
23 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider;
24 import org.opendaylight.mdsal.binding.api.RpcProviderService;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class DataProviderImpl implements IEntityDataProvider, AutoCloseable {
29
30     private static final Logger LOG = LoggerFactory.getLogger(DataProviderImpl.class);
31
32     private static final String APPLICATION_NAME = null;
33     private RpcProviderService rpcProviderService = null;
34     private DataProviderServiceImpl rpcApiService;
35         private ReadyHttpServlet readyServlet;
36     private HtDatabaseClient dbClient;
37
38
39     // Blueprint 1
40     public DataProviderImpl() {
41         LOG.info("Creating provider for {}", APPLICATION_NAME);
42     }
43
44     public void setRpcProviderService(RpcProviderService rpcProviderService) {
45         this.rpcProviderService = rpcProviderService;
46     }
47     public void setReadyServlet(ReadyHttpServlet readyServlet) {
48         this.readyServlet = readyServlet;
49     }
50     public void init() throws Exception {
51
52         LOG.info("Session Initiated start {}", APPLICATION_NAME);
53
54         // Start RPC Service
55         this.rpcApiService = new DataProviderServiceImpl(rpcProviderService);
56         // Get configuration
57
58         LOG.info("Session Initiated end. Initialization done");
59     }
60
61     @Override
62     public void close() throws Exception {
63         LOG.info("DeviceManagerImpl closing ...");
64
65         close(dbClient);
66         close(rpcApiService);
67         LOG.info("DeviceManagerImpl closing done");
68     }
69
70     /**
71      * Used to close all Services, that should support AutoCloseable Pattern
72      *
73      * @param toClose
74      * @throws Exception
75      */
76     private void close(AutoCloseable... toCloseList) throws Exception {
77         for (AutoCloseable element : toCloseList) {
78             if (element != null) {
79                 element.close();
80             }
81         }
82     }
83
84     @Override
85     public DataProvider getDataProvider() {
86         return rpcApiService.getDataProvider();
87     }
88
89         @Override
90         public void setReadyStatus(boolean status) {
91                 if(this.readyServlet!=null) {
92                         this.readyServlet.setStatus(status);
93                 }
94         }
95 }