102c01c7fd618afe1cd427ac173e5c4f6cc392b2
[ccsdk/sli/adaptors.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.adaptors.lighty;
18
19 import io.lighty.core.controller.api.AbstractLightyModule;
20 import org.onap.ccsdk.sli.adaptors.aai.lighty.AaaServiceModule;
21 import org.onap.ccsdk.sli.adaptors.ansible.lighty.AnsibleAdapterModule;
22 import org.onap.ccsdk.sli.adaptors.netbox.lighty.NetboxClientModule;
23 import org.onap.ccsdk.sli.adaptors.resource.lighty.ResourceModule;
24 import org.onap.ccsdk.sli.adaptors.resource.mdsal.lighty.MdsalResourceModule;
25 import org.onap.ccsdk.sli.adaptors.resource.sql.lighty.SqlModule;
26 import org.onap.ccsdk.sli.adaptors.saltstack.lighty.SaltstackAdapterModule;
27 import org.onap.ccsdk.sli.core.dblib.DbLibService;
28 import org.onap.ccsdk.sli.core.lighty.common.CcsdkLightyUtils;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * The implementation of the {@link io.lighty.core.controller.api.LightyModule} that groups all other LightyModules
34  * from the ccsdk-sli-adaptors repository so they can be all treated as one component (for example started/stopped
35  * at once).
36  * For more information about the lighty.io visit the website https://lighty.io.
37  */
38 public class CcsdkAdaptorsLightyModule extends AbstractLightyModule {
39
40     private static final Logger LOG = LoggerFactory.getLogger(CcsdkAdaptorsLightyModule.class);
41
42     private DbLibService dbLibService;
43
44     private AaaServiceModule aaaServiceModule;
45     private AnsibleAdapterModule ansibleAdapterModule;
46     private MdsalResourceModule mdsalResourceModule;
47     private NetboxClientModule netboxClientModule;
48     private ResourceModule resourceModule;
49     private SaltstackAdapterModule saltstackAdapterModule;
50     private SqlModule sqlModule;
51
52     public CcsdkAdaptorsLightyModule(DbLibService dbLibService) {
53         this.dbLibService = dbLibService;
54     }
55
56     @Override
57     protected boolean initProcedure() {
58         LOG.debug("Initializing CCSDK Adaptors Lighty module...");
59
60         this.aaaServiceModule = new AaaServiceModule();
61         if (!CcsdkLightyUtils.startLightyModule(aaaServiceModule)) {
62             LOG.error("Unable to start AaaServiceModule in CCSDK Adaptors Lighty module!");
63             return false;
64         }
65
66         this.ansibleAdapterModule = new AnsibleAdapterModule();
67         if (!CcsdkLightyUtils.startLightyModule(ansibleAdapterModule)) {
68             LOG.error("Unable to start AnsibleAdapterModule in CCSDK Adaptors Lighty module!");
69             return false;
70         }
71
72         this.mdsalResourceModule = new MdsalResourceModule();
73         if (!CcsdkLightyUtils.startLightyModule(mdsalResourceModule)) {
74             LOG.error("Unable to start MdsalResourceModule in CCSDK Adaptors Lighty module!");
75             return false;
76         }
77
78         this.netboxClientModule = new NetboxClientModule(dbLibService);
79         if (!CcsdkLightyUtils.startLightyModule(netboxClientModule)) {
80             LOG.error("Unable to start NetboxClientModule in CCSDK Adaptors Lighty module!");
81             return false;
82         }
83
84         this.resourceModule = new ResourceModule(dbLibService);
85         if (!CcsdkLightyUtils.startLightyModule(resourceModule)) {
86             LOG.error("Unable to start ResourceModule in CCSDK Adaptors Lighty module!");
87             return false;
88         }
89
90         this.saltstackAdapterModule = new SaltstackAdapterModule();
91         if (!CcsdkLightyUtils.startLightyModule(saltstackAdapterModule)) {
92             LOG.error("Unable to start SaltstackAdapterModule in CCSDK Adaptors Lighty module!");
93             return false;
94         }
95
96         this.sqlModule = new SqlModule(dbLibService);
97         if (!CcsdkLightyUtils.startLightyModule(sqlModule)) {
98             LOG.error("Unable to start SqlModule in CCSDK Adaptors Lighty module!");
99             return false;
100         }
101
102         LOG.debug("CCSDK Adaptors Lighty module was initialized successfully");
103         return true;
104     }
105
106     @Override
107     protected boolean stopProcedure() {
108         LOG.debug("Stopping CCSDK Adaptors Lighty module...");
109
110         boolean stopSuccessful = true;
111
112         if (!CcsdkLightyUtils.stopLightyModule(sqlModule)) {
113             stopSuccessful = false;
114         }
115
116         if (!CcsdkLightyUtils.stopLightyModule(saltstackAdapterModule)) {
117             stopSuccessful = false;
118         }
119
120         if (!CcsdkLightyUtils.stopLightyModule(resourceModule)) {
121             stopSuccessful = false;
122         }
123
124         if (!CcsdkLightyUtils.stopLightyModule(netboxClientModule)) {
125             stopSuccessful = false;
126         }
127
128         if (!CcsdkLightyUtils.stopLightyModule(mdsalResourceModule)) {
129             stopSuccessful = false;
130         }
131
132         if (!CcsdkLightyUtils.stopLightyModule(ansibleAdapterModule)) {
133             stopSuccessful = false;
134         }
135
136         if (!CcsdkLightyUtils.stopLightyModule(aaaServiceModule)) {
137             stopSuccessful = false;
138         }
139
140         if (stopSuccessful) {
141             LOG.debug("CCSDK Adaptors Lighty module was stopped successfully");
142         } else {
143             LOG.error("CCSDK Adaptors Lighty module was not stopped successfully!");
144         }
145         return stopSuccessful;
146     }
147
148     public AaaServiceModule getAaaServiceModule() {
149         return aaaServiceModule;
150     }
151
152     public AnsibleAdapterModule getAnsibleAdapterModule() {
153         return ansibleAdapterModule;
154     }
155
156     public MdsalResourceModule getMdsalResourceModule() {
157         return mdsalResourceModule;
158     }
159
160     public NetboxClientModule getNetboxClientModule() {
161         return netboxClientModule;
162     }
163
164     public ResourceModule getResourceModule() {
165         return resourceModule;
166     }
167
168     public SaltstackAdapterModule getSaltstackAdapterModule() {
169         return saltstackAdapterModule;
170     }
171
172     public SqlModule getSqlModule() {
173         return sqlModule;
174     }
175 }