Roll versions
[ccsdk/sli/adaptors.git] / netbox-client / lighty / src / main / java / org / onap / ccsdk / sli / adaptors / netbox / lighty / NetboxClientModule.java
1 /*
2  * ============LICENSE_START==========================================
3  * Copyright (c) 2019 PANTHEON.tech s.r.o.
4  * ===================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
12  * OF ANY KIND, either express or implied. See the License for the specific language governing permissions and
13  * limitations under the License.
14  * ============LICENSE_END============================================
15  *
16  */
17 package org.onap.ccsdk.sli.adaptors.netbox.lighty;
18
19 import io.lighty.core.controller.api.AbstractLightyModule;
20 import java.io.IOException;
21 import org.onap.ccsdk.sli.adaptors.netbox.api.NetboxClient;
22 import org.onap.ccsdk.sli.adaptors.netbox.impl.NetboxClientImplLighty;
23 import org.onap.ccsdk.sli.adaptors.netbox.impl.NetboxHttpClientLighty;
24 import org.onap.ccsdk.sli.adaptors.netbox.property.NetboxPropertiesLighty;
25 import org.onap.ccsdk.sli.core.dblib.DbLibService;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * The implementation of the {@link io.lighty.core.controller.api.LightyModule} that manages and provides services from
31  * the netbox-client-provider artifact.
32  */
33 public class NetboxClientModule extends AbstractLightyModule {
34
35     private static final Logger LOG = LoggerFactory.getLogger(NetboxClientModule.class);
36
37     private final DbLibService dbLibService;
38
39     private NetboxPropertiesLighty netboxProperties;
40     private NetboxHttpClientLighty netboxHttpClient;
41     private NetboxClientImplLighty netboxClient;
42
43     public NetboxClientModule(DbLibService dbLibService) {
44         this.dbLibService = dbLibService;
45     }
46
47     @Override
48     protected boolean initProcedure() {
49         this.netboxProperties = new NetboxPropertiesLighty();
50         this.netboxHttpClient = new NetboxHttpClientLighty(netboxProperties);
51         this.netboxClient = new NetboxClientImplLighty(netboxHttpClient, dbLibService);
52         return true;
53     }
54
55     @Override
56     protected boolean stopProcedure() {
57         try {
58             netboxHttpClient.close();
59         } catch (IOException e) {
60             LOG.error("Exception thrown while closing {}!", netboxHttpClient.getClass(), e);
61             return false;
62         }
63         return true;
64     }
65
66     public NetboxClient getNetboxClient() {
67         return netboxClient;
68     }
69
70 }