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
8 * http://www.apache.org/licenses/LICENSE-2.0
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============================================
17 package org.onap.ccsdk.distribution.lighty;
19 import com.google.common.collect.ImmutableSet;
20 import io.lighty.core.controller.api.AbstractLightyModule;
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;
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.
44 public class CcsdkLightyModule extends AbstractLightyModule {
46 private static final Logger LOG = LoggerFactory.getLogger(CcsdkLightyModule.class);
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()
57 private final DataBroker dataBroker;
58 private final NotificationPublishService notificationPublishService;
59 private final RpcProviderRegistry rpcProviderRegistry;
60 private final AAAEncryptionService aaaEncryptionService;
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;
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;
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
82 LOG.debug("Initializing CCSDK Lighty module...");
84 this.dblibModule = new DblibModule(aaaEncryptionService);
85 if (!CcsdkLightyUtils.startLightyModule(dblibModule)) {
86 LOG.error("Unable to start DblibModule in CCSDK Core Lighty module!");
90 this.ccsdkAdaptorsLightyModule = new CcsdkAdaptorsLightyModule(dblibModule.getDbLibService());
91 if (!CcsdkLightyUtils.startLightyModule(ccsdkAdaptorsLightyModule)) {
92 LOG.error("Unable to start CcsdkAdaptorsLightyModule in CCSDK Lighty module!");
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!");
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!");
110 this.sliPluginUtilsModule = new SliPluginUtilsModule();
111 if (!CcsdkLightyUtils.startLightyModule(sliPluginUtilsModule)) {
112 LOG.error("Unable to start SliPluginUtilsModule in CCSDK Core Lighty module!");
116 this.ccsdkPluginsLightyModule = new CcsdkPluginsLightyModule();
117 if (!CcsdkLightyUtils.startLightyModule(ccsdkPluginsLightyModule)) {
118 LOG.error("Unable to start CcsdkPluginsLightyModule in CCSDK Lighty module!");
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!");
130 LOG.debug("CCSDK Lighty module was initialized successfully");
132 } catch (Exception e) {
133 LOG.error("Exception caught!", e);
138 protected boolean stopProcedure() {
139 LOG.debug("Stopping CCSDK Lighty module...");
141 boolean stopSuccessful = true;
143 if (!CcsdkLightyUtils.stopLightyModule(ccsdkPluginsLightyModule)) {
144 stopSuccessful = false;
147 if (!CcsdkLightyUtils.stopLightyModule(ccsdkNorhboundLightyModule)) {
148 stopSuccessful = false;
151 if (!CcsdkLightyUtils.stopLightyModule(ccsdkAdaptorsLightyModule)) {
152 stopSuccessful = false;
155 if (!CcsdkLightyUtils.stopLightyModule(sliPluginUtilsModule)) {
156 stopSuccessful = false;
159 if (!CcsdkLightyUtils.stopLightyModule(sliApiModule)) {
160 stopSuccessful = false;
163 if (!CcsdkLightyUtils.stopLightyModule(sliModule)) {
164 stopSuccessful = false;
167 if (!CcsdkLightyUtils.stopLightyModule(dblibModule)) {
168 stopSuccessful = false;
171 if (stopSuccessful) {
172 LOG.debug("CCSDK Lighty module was stopped successfully");
174 LOG.error("CCSDK Lighty module was not stopped successfully!");
176 return stopSuccessful;
179 public CcsdkAdaptorsLightyModule getCcsdkAdaptorsLightyModule() {
180 return ccsdkAdaptorsLightyModule;
183 public CcsdkNorhboundLightyModule getCcsdkNorhboundLightyModule() {
184 return ccsdkNorhboundLightyModule;
187 public CcsdkPluginsLightyModule getCcsdkPluginsLightyModule() {
188 return ccsdkPluginsLightyModule;
191 public DblibModule getDblibModule() {
195 public SliModule getSliModule() {
199 public SliApiModule getSliApiModule() {
203 public SliPluginUtilsModule getSliPluginUtilsModule() {
204 return sliPluginUtilsModule;