aboutsummaryrefslogtreecommitdiffstats
path: root/ncomp-sirius-manager-generator/src/main/templates/Server.java
diff options
context:
space:
mode:
Diffstat (limited to 'ncomp-sirius-manager-generator/src/main/templates/Server.java')
-rw-r--r--ncomp-sirius-manager-generator/src/main/templates/Server.java135
1 files changed, 135 insertions, 0 deletions
diff --git a/ncomp-sirius-manager-generator/src/main/templates/Server.java b/ncomp-sirius-manager-generator/src/main/templates/Server.java
new file mode 100644
index 0000000..638a9ab
--- /dev/null
+++ b/ncomp-sirius-manager-generator/src/main/templates/Server.java
@@ -0,0 +1,135 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ */
+
+// Autogenerated
+// Do not edit but extend this class as needed
+package $packageName;
+
+import static org.openecomp.ncomp.utils.PropertyUtil.getPropertiesFromClasspath;
+
+import java.io.IOException;
+import java.util.Properties;
+import java.util.TimeZone;
+
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EFactory;
+
+import org.openecomp.entity.EcompComponent;
+import org.openecomp.entity.EcompSubComponent;
+import org.openecomp.entity.EcompSubComponentInstance;
+import org.openecomp.ncomp.sirius.manager.Jetty8Server;
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+
+import ${p.nsURI}.${name};
+
+<% g.subApis.each { api ->
+if (api.type == "P") return
+def n1 = api.subName
+if (n1 == null) return
+%>
+import ${api.packageName()}.${api.m.prefix}${api.factoryName()};
+<% } %>
+
+<% g.subClients.each { api -> %>
+import ${api.o.eClass().EPackage.nsURI}.${api.o.eClass().name};
+import ${api.packageName()}.${prefix}${api.o.eClass().name}Client;
+<% } %>
+
+
+public class $cName implements ISiriusServer {
+ public static final Logger logger = Logger.getLogger(${cName}.class);
+ String serverPath;
+ ManagementServer server;
+ ${prefix}${name} controller;
+ String directory = "data";
+// LocationControllerApi api ;
+ Jetty8Server webServer;
+ ${prefix}${fName} f = new ${prefix}${fName}(this);
+
+<% g.subApis.each { api ->
+ if (api.type == "P") return
+ def n1 = api.subName
+ if (n1 == null) return
+%>
+ String ${n1}Path;
+ ManagementServer ${n1}Server;
+<% } %>
+<% g.subClients.each { api -> %>
+ ${api.o.eClass().name} $api.clientName;
+<% } %>
+ public ${prefix}${name}Server(String filename) throws IOException {
+ logger.warn("controller restarting");
+ ${prefix}${name}.ecoreSetup();
+ props = getPropertiesFromClasspath(filename);
+ serverPath = (String) props.get("server.dir");
+ server = new ManagementServer(f, "${name}", serverPath, filename);
+ server.addFactory(f);
+<% g.factories.each { factory ->
+ if (g.useNew[factory]) { %>
+ server.addFactory(new ${factory}(this));
+ <% } else { %>
+ server.addFactory(${factory}.eINSTANCE);
+ <% } %>
+<% } %>
+ server.addRuntimeFactories(this);
+ server.start();
+ }
+ public void runWebserver() throws IOException {
+ controller = (${prefix}${name}) server.find("/").o;
+ webServer = new Jetty8Server("${nsPrefix}.properties");
+ webServer.add("/resources",server);
+<% g.aliases.each { %>
+ webServer.add("$it",controller);
+<%}%>
+
+<% g.subApis.each { api ->
+ if (api.type == "A" || api.type == "P") return
+ def n1 = api.subName
+%>
+ EFactory ${n1}Factory = new ${api.m.prefix}${api.factoryName()}(this);
+ ${n1}Path = serverPath + "/${n1}";
+ ${n1}Server = new ManagementServer(${n1}Factory, "${api.o.eClass().name}", ${n1}Path, "${n1}.properties");
+ ${n1}Server.start();
+ webServer.add("/${n1}",${n1}Server);
+<% } %>
+
+<% g.subClients.each { api -> %>
+ $api.clientName = new ${prefix}${api.o.eClass().name}Client("${nsPrefix}.properties", "$api.clientName");
+<% } %>
+ logger.info("Joining webserver");
+ webServer.join();
+ }
+ static Properties props = null;
+ public static void main(String []args) throws IOException {
+ // ALWAYS USE GMT.
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+ ${prefix}${name}Server s = new ${prefix}${name}Server("${nsPrefix}.properties");
+ s.runWebserver();
+ }
+ public ${name} getController() {
+ return controller;
+ }
+ public ManagementServer getServer() {
+ return server;
+ }
+}