Merge "Release version 0.6.0"
[ccsdk/distribution.git] / lighty / ccsdk-lighty-module / src / main / java / org / onap / ccsdk / distribution / lighty / CcsdkLightyModule.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.distribution.lighty;
18
19 import com.google.common.collect.ImmutableSet;
20 import io.lighty.core.controller.api.AbstractLightyModule;
21 import java.util.Set;
22 import org.onap.ccsdk.sli.adaptors.lighty.CcsdkAdaptorsLightyModule;
23 import org.onap.ccsdk.sli.core.dblib.lighty.DblibModule;
24 import org.onap.ccsdk.sli.core.lighty.common.CcsdkLightyUtils;
25 import org.onap.ccsdk.sli.core.sli.lighty.SliModule;
26 import org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder;
27 import org.onap.ccsdk.sli.core.sliapi.lighty.SliApiModule;
28 import org.onap.ccsdk.sli.core.slipluginutils.lighty.SliPluginUtilsModule;
29 import org.onap.ccsdk.sli.northbound.lighty.CcsdkNorhboundLightyModule;
30 import org.onap.ccsdk.sli.plugins.lighty.CcsdkPluginsLightyModule;
31 import org.opendaylight.aaa.encrypt.AAAEncryptionService;
32 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
33 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
34 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
35 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 /**
40  * The implementation of the {@link io.lighty.core.controller.api.LightyModule} that groups all other LightyModules
41  * from the CCSDK project so they can be all treated as one component (for example started/stopped at once).
42  * For more information about the lighty.io visit the website https://lighty.io.
43  */
44 public class CcsdkLightyModule extends AbstractLightyModule {
45
46     private static final Logger LOG = LoggerFactory.getLogger(CcsdkLightyModule.class);
47
48     public static final Set<YangModuleInfo> YANG_MODELS = ImmutableSet.of(
49             org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.$YangModuleInfoImpl.getInstance(),
50             org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.$YangModuleInfoImpl.getInstance(),
51             org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.datachange.rev150519.$YangModuleInfoImpl.getInstance(),
52             org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.common.rev170201.$YangModuleInfoImpl.getInstance(),
53             org.opendaylight.yang.gen.v1.http.xmlns.onap.org.asdc.license.model._1._0.rev160427.$YangModuleInfoImpl.getInstance(),
54             org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.$YangModuleInfoImpl.getInstance()
55     );
56
57     private final DataBroker dataBroker;
58     private final NotificationPublishService notificationPublishService;
59     private final RpcProviderRegistry rpcProviderRegistry;
60     private final AAAEncryptionService aaaEncryptionService;
61
62     private CcsdkAdaptorsLightyModule ccsdkAdaptorsLightyModule;
63     private CcsdkNorhboundLightyModule ccsdkNorhboundLightyModule;
64     private CcsdkPluginsLightyModule ccsdkPluginsLightyModule;
65     private DblibModule dblibModule;
66     private SliModule sliModule;
67     private SliApiModule sliApiModule;
68     private SliPluginUtilsModule sliPluginUtilsModule;
69
70     public CcsdkLightyModule(DataBroker dataBroker, NotificationPublishService notificationPublishService,
71             RpcProviderRegistry rpcProviderRegistry, AAAEncryptionService aaaEncryptionService) {
72         this.dataBroker = dataBroker;
73         this.notificationPublishService = notificationPublishService;
74         this.rpcProviderRegistry = rpcProviderRegistry;
75         this.aaaEncryptionService = aaaEncryptionService;
76     }
77
78     protected boolean initProcedure() {
79         // FIXME modules from CcsdkCoreLightyModule need to be started separately (not through CcsdkCoreLightyModule
80         //  itself) because SliApiModule is dependent on the adaptors
81         try {
82             LOG.debug("Initializing CCSDK Lighty module...");
83
84             this.dblibModule = new DblibModule(aaaEncryptionService);
85             if (!CcsdkLightyUtils.startLightyModule(dblibModule)) {
86                 LOG.error("Unable to start DblibModule in CCSDK Core Lighty module!");
87                 return false;
88             }
89
90             this.ccsdkAdaptorsLightyModule = new CcsdkAdaptorsLightyModule(dblibModule.getDbLibService());
91             if (!CcsdkLightyUtils.startLightyModule(ccsdkAdaptorsLightyModule)) {
92                 LOG.error("Unable to start CcsdkAdaptorsLightyModule in CCSDK Lighty module!");
93                 return false;
94             }
95
96             this.sliModule = new SliModule(dblibModule.getDbLibService(),
97                     ccsdkAdaptorsLightyModule.getAaaServiceModule().getAAIService(), new Slf4jRecorder(),
98                     ccsdkAdaptorsLightyModule.getAaaServiceModule().getAAIService(), null);
99             if (!CcsdkLightyUtils.startLightyModule(sliModule)) {
100                 LOG.error("Unable to start SliModule in CCSDK Core Lighty module!");
101                 return false;
102             }
103
104             this.sliApiModule = new SliApiModule(dataBroker, notificationPublishService, rpcProviderRegistry, sliModule.getSvcLogicServiceImpl());
105             if (!CcsdkLightyUtils.startLightyModule(sliApiModule)) {
106                 LOG.error("Unable to start SliApiModule in CCSDK Core Lighty module!");
107                 return false;
108             }
109
110             this.sliPluginUtilsModule = new SliPluginUtilsModule();
111             if (!CcsdkLightyUtils.startLightyModule(sliPluginUtilsModule)) {
112                 LOG.error("Unable to start SliPluginUtilsModule in CCSDK Core Lighty module!");
113                 return false;
114             }
115
116             this.ccsdkPluginsLightyModule = new CcsdkPluginsLightyModule();
117             if (!CcsdkLightyUtils.startLightyModule(ccsdkPluginsLightyModule)) {
118                 LOG.error("Unable to start CcsdkPluginsLightyModule in CCSDK Lighty module!");
119                 return false;
120             }
121
122             this.ccsdkNorhboundLightyModule =
123                     new CcsdkNorhboundLightyModule(sliModule.getSvcLogicServiceImpl(), dataBroker,
124                             notificationPublishService, rpcProviderRegistry);
125             if (!CcsdkLightyUtils.startLightyModule(ccsdkNorhboundLightyModule)) {
126                 LOG.error("Unable to start CcsdkNorhboundLightyModule in CCSDK Lighty module!");
127                 return false;
128             }
129
130             LOG.debug("CCSDK Lighty module was initialized successfully");
131             return true;
132         } catch (Exception e) {
133             LOG.error("Exception caught!", e);
134             throw e;
135         }
136     }
137
138     protected boolean stopProcedure() {
139         LOG.debug("Stopping CCSDK Lighty module...");
140
141         boolean stopSuccessful = true;
142
143         if (!CcsdkLightyUtils.stopLightyModule(ccsdkPluginsLightyModule)) {
144             stopSuccessful = false;
145         }
146
147         if (!CcsdkLightyUtils.stopLightyModule(ccsdkNorhboundLightyModule)) {
148             stopSuccessful = false;
149         }
150
151         if (!CcsdkLightyUtils.stopLightyModule(ccsdkAdaptorsLightyModule)) {
152             stopSuccessful = false;
153         }
154
155         if (!CcsdkLightyUtils.stopLightyModule(sliPluginUtilsModule)) {
156             stopSuccessful = false;
157         }
158
159         if (!CcsdkLightyUtils.stopLightyModule(sliApiModule)) {
160             stopSuccessful = false;
161         }
162
163         if (!CcsdkLightyUtils.stopLightyModule(sliModule)) {
164             stopSuccessful = false;
165         }
166
167         if (!CcsdkLightyUtils.stopLightyModule(dblibModule)) {
168             stopSuccessful = false;
169         }
170
171         if (stopSuccessful) {
172             LOG.debug("CCSDK Lighty module was stopped successfully");
173         } else {
174             LOG.error("CCSDK Lighty module was not stopped successfully!");
175         }
176         return stopSuccessful;
177     }
178
179     public CcsdkAdaptorsLightyModule getCcsdkAdaptorsLightyModule() {
180         return ccsdkAdaptorsLightyModule;
181     }
182
183     public CcsdkNorhboundLightyModule getCcsdkNorhboundLightyModule() {
184         return ccsdkNorhboundLightyModule;
185     }
186
187     public CcsdkPluginsLightyModule getCcsdkPluginsLightyModule() {
188         return ccsdkPluginsLightyModule;
189     }
190
191     public DblibModule getDblibModule() {
192         return dblibModule;
193     }
194
195     public SliModule getSliModule() {
196         return sliModule;
197     }
198
199     public SliApiModule getSliApiModule() {
200         return sliApiModule;
201     }
202
203     public SliPluginUtilsModule getSliPluginUtilsModule() {
204         return sliPluginUtilsModule;
205     }
206 }