Roll versions
[ccsdk/sli/plugins.git] / ccsdk-plugins-lighty / src / main / java / org / onap / ccsdk / sli / plugins / lighty / CcsdkPluginsLightyModule.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.plugins.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.plugins.prop.lighty.PropertiesNodeModule;
22 import org.onap.ccsdk.sli.plugins.prop.lighty.RestApiCallNodeModule;
23 import org.onap.ccsdk.sli.plugins.restconf.lighty.RestconfClientModule;
24 import org.onap.ccsdk.sli.plugins.sshapicall.lighty.SshApiCallModule;
25 import org.onap.ccsdk.sli.plugins.template.lighty.TemplateNodeModule;
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 groups all other LightyModules 
31  * from the ccsdk-sli-plugins repository so they can be all treated as one component (for example started/stopped at once).
32  * For more information about the lighty.io visit the website https://lighty.io.
33  */
34 public class CcsdkPluginsLightyModule extends AbstractLightyModule {
35
36     private static final Logger LOG = LoggerFactory.getLogger(CcsdkPluginsLightyModule.class);
37
38     private PropertiesNodeModule propertiesNodeModule;
39     private RestApiCallNodeModule restApiCallNodeModule;
40     private RestconfClientModule restconfClientModule;
41     private SshApiCallModule sshApiCallModule;
42     private TemplateNodeModule templateNodeModule;
43
44     protected boolean initProcedure() {
45         LOG.debug("Initializing CCSDK Plugins Lighty module...");
46
47         this.propertiesNodeModule = new PropertiesNodeModule();
48         if (!CcsdkLightyUtils.startLightyModule(propertiesNodeModule)) {
49             LOG.error("Unable to start PropertiesNodeModule in CCSDK Plugins Lighty module!");
50             return false;
51         }
52
53         this.restApiCallNodeModule = new RestApiCallNodeModule();
54         if (!CcsdkLightyUtils.startLightyModule(restApiCallNodeModule)) {
55             LOG.error("Unable to start RestApiCallNodeModule in CCSDK Plugins Lighty module!");
56             return false;
57         }
58
59         this.restconfClientModule = new RestconfClientModule(restApiCallNodeModule.getPropertiesNode());
60         if (!CcsdkLightyUtils.startLightyModule(restconfClientModule)) {
61             LOG.error("Unable to start RestconfClientModule in CCSDK Plugins Lighty module!");
62             return false;
63         }
64
65         this.sshApiCallModule = new SshApiCallModule();
66         if (!CcsdkLightyUtils.startLightyModule(sshApiCallModule)) {
67             LOG.error("Unable to start SshApiCallModule in CCSDK Plugins Lighty module!");
68             return false;
69         }
70
71         this.templateNodeModule = new TemplateNodeModule();
72         if (!CcsdkLightyUtils.startLightyModule(templateNodeModule)) {
73             LOG.error("Unable to start TemplateNodeModule in CCSDK Plugins Lighty module!");
74             return false;
75         }
76
77         LOG.debug("CCSDK Plugins Lighty module was initialized successfully");
78         return true;
79     }
80
81     protected boolean stopProcedure() {
82         LOG.debug("Stopping CCSDK Plugins Lighty module...");
83
84         boolean stopSuccessful = true;
85
86         if (!CcsdkLightyUtils.stopLightyModule(templateNodeModule)) {
87             stopSuccessful = false;
88         }
89
90         if (!CcsdkLightyUtils.stopLightyModule(sshApiCallModule)) {
91             stopSuccessful = false;
92         }
93
94         if (!CcsdkLightyUtils.stopLightyModule(restconfClientModule)) {
95             stopSuccessful = false;
96         }
97
98         if (!CcsdkLightyUtils.stopLightyModule(restApiCallNodeModule)) {
99             stopSuccessful = false;
100         }
101
102         if (!CcsdkLightyUtils.stopLightyModule(propertiesNodeModule)) {
103             stopSuccessful = false;
104         }
105
106         if (stopSuccessful) {
107             LOG.debug("CCSDK Plugins Lighty module was stopped successfully");
108         } else {
109             LOG.error("CCSDK Plugins Lighty module was not stopped successfully!");
110         }
111         return stopSuccessful;
112     }
113
114     public PropertiesNodeModule getPropertiesNodeModule() {
115         return propertiesNodeModule;
116     }
117
118     public RestApiCallNodeModule getRestApiCallNodeModule() {
119         return restApiCallNodeModule;
120     }
121
122     public RestconfClientModule getRestconfClientModule() {
123         return restconfClientModule;
124     }
125
126     public SshApiCallModule getSshApiCallModule() {
127         return sshApiCallModule;
128     }
129
130     public TemplateNodeModule getTemplateNodeModule() {
131         return templateNodeModule;
132     }
133 }