ce907bd95392da8f18461bbbdb872401ff1a3375
[ccsdk/sli/northbound.git] /
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.northbound.lighty;
18
19 import io.lighty.core.controller.api.AbstractLightyModule;
20 import org.onap.ccsdk.sli.core.lighty.common.CcsdkLightyUtils;
21 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
22 import org.onap.ccsdk.sli.northbound.asdcapi.lighty.AsdcApiModule;
23 import org.onap.ccsdk.sli.northbound.dataChange.lighty.DataChangeModule;
24 import org.onap.ccsdk.sli.northbound.lcm.lighty.LcmModule;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
27 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * The implementation of the {@link io.lighty.core.controller.api.LightyModule} that groups all other LightyModules
33  * from the ccsdk-sli-northbound repository so they can be all treated as one component (for example started/stopped at once).
34  * For more information about the lighty.io visit the website https://lighty.io.
35  */
36 public class CcsdkNorhboundLightyModule extends AbstractLightyModule {
37
38     private static final Logger LOG = LoggerFactory.getLogger(CcsdkNorhboundLightyModule.class);
39
40     private final SvcLogicService svcLogicService;
41     private final DataBroker dataBroker;
42     private final NotificationPublishService publishService;
43     private final RpcProviderRegistry rpcProviderRegistry;
44
45     private AsdcApiModule asdcApiModule;
46     private DataChangeModule dataChangeModule;
47     private LcmModule lcmModule;
48
49     public CcsdkNorhboundLightyModule(SvcLogicService svcLogicService, DataBroker dataBroker,
50             NotificationPublishService publishService, RpcProviderRegistry rpcProviderRegistry) {
51
52         this.svcLogicService = svcLogicService;
53         this.dataBroker = dataBroker;
54         this.publishService = publishService;
55         this.rpcProviderRegistry = rpcProviderRegistry;
56     }
57
58     protected boolean initProcedure() {
59         LOG.debug("Initializing CCSDK Northbound Lighty module...");
60
61         this.asdcApiModule = new AsdcApiModule(svcLogicService, dataBroker, publishService, rpcProviderRegistry);
62         if (!CcsdkLightyUtils.startLightyModule(asdcApiModule)) {
63             LOG.error("Unable to start AsdcApiModule in CCSDK Northbound Lighty module!");
64             return false;
65         }
66
67         this.dataChangeModule = new DataChangeModule(svcLogicService, dataBroker, publishService, rpcProviderRegistry);
68         if (!CcsdkLightyUtils.startLightyModule(dataChangeModule)) {
69             LOG.error("Unable to start DataChangeModule in CCSDK Northbound Lighty module!");
70             return false;
71         }
72
73         this.lcmModule = new LcmModule(svcLogicService, dataBroker, publishService, rpcProviderRegistry);
74         if (!CcsdkLightyUtils.startLightyModule(lcmModule)) {
75             LOG.error("Unable to start LcmModule in CCSDK Northbound Lighty module!");
76             return false;
77         }
78
79         LOG.debug("CCSDK Northbound Lighty module was initialized successfully");
80         return true;
81     }
82
83     protected boolean stopProcedure() {
84         LOG.debug("Stopping CCSDK Northbound Lighty module...");
85
86         boolean stopSuccessful = true;
87
88         if (!CcsdkLightyUtils.stopLightyModule(lcmModule)) {
89             stopSuccessful = false;
90         }
91
92         if (!CcsdkLightyUtils.stopLightyModule(dataChangeModule)) {
93             stopSuccessful = false;
94         }
95
96         if (!CcsdkLightyUtils.stopLightyModule(asdcApiModule)) {
97             stopSuccessful = false;
98         }
99
100         if (stopSuccessful) {
101             LOG.debug("CCSDK Northbound Lighty module was stopped successfully");
102         } else {
103             LOG.error("CCSDK Northbound Lighty module was not stopped successfully!");
104         }
105         return stopSuccessful;
106     }
107
108     public AsdcApiModule getAsdcApiModule() {
109         return asdcApiModule;
110     }
111
112     public DataChangeModule getDataChangeModule() {
113         return dataChangeModule;
114     }
115
116     public LcmModule getLcmModule() {
117         return lcmModule;
118     }
119 }