aboutsummaryrefslogtreecommitdiffstats
path: root/ncomp-sirius-manager-console
diff options
context:
space:
mode:
authorlj1412 <lji@research.att.com>2017-02-14 15:11:44 +0000
committerlj1412 <lji@research.att.com>2017-02-14 15:11:46 +0000
commit033f0c30154107ddf36cd682c860e95025bf00b0 (patch)
tree4113f2053aac75642c51b11bfae9a0a608c1ed72 /ncomp-sirius-manager-console
parentf6e50f2cec6365ea71696c58a96aa923eb3a1a10 (diff)
Init ncomp.sirius.manager
Change-Id: I6691ecd21a942c96cb20cf3baa297e4b2dc7f970 Signed-off-by: lj1412 <lji@research.att.com>
Diffstat (limited to 'ncomp-sirius-manager-console')
-rw-r--r--ncomp-sirius-manager-console/.classpath24
-rw-r--r--ncomp-sirius-manager-console/.gitignore1
-rw-r--r--ncomp-sirius-manager-console/.project35
-rw-r--r--ncomp-sirius-manager-console/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--ncomp-sirius-manager-console/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--ncomp-sirius-manager-console/.settings/org.eclipse.jdt.groovy.core.prefs2
-rw-r--r--ncomp-sirius-manager-console/.settings/org.eclipse.m2e.core.prefs4
-rw-r--r--ncomp-sirius-manager-console/LICENSE.txt22
-rw-r--r--ncomp-sirius-manager-console/META-INF/MANIFEST.MF12
-rw-r--r--ncomp-sirius-manager-console/build.properties3
-rw-r--r--ncomp-sirius-manager-console/pom.xml187
-rw-r--r--ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/console/Console.groovy217
-rw-r--r--ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/console/Utils.groovy176
-rw-r--r--ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/AlertUtils.groovy98
-rw-r--r--ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/Ecore2Xcore.groovy68
-rw-r--r--ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/TableUtils.groovy220
16 files changed, 1079 insertions, 0 deletions
diff --git a/ncomp-sirius-manager-console/.classpath b/ncomp-sirius-manager-console/.classpath
new file mode 100644
index 0000000..3c48086
--- /dev/null
+++ b/ncomp-sirius-manager-console/.classpath
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/groovy">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
+ <classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/ncomp-sirius-manager-drools"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/ncomp-sirius-manager-console/.gitignore b/ncomp-sirius-manager-console/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/ncomp-sirius-manager-console/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/ncomp-sirius-manager-console/.project b/ncomp-sirius-manager-console/.project
new file mode 100644
index 0000000..03b5fc1
--- /dev/null
+++ b/ncomp-sirius-manager-console/.project
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ncomp-sirius-manager-console</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
diff --git a/ncomp-sirius-manager-console/.settings/org.eclipse.core.resources.prefs b/ncomp-sirius-manager-console/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..99f26c0
--- /dev/null
+++ b/ncomp-sirius-manager-console/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
diff --git a/ncomp-sirius-manager-console/.settings/org.eclipse.jdt.core.prefs b/ncomp-sirius-manager-console/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..443e085
--- /dev/null
+++ b/ncomp-sirius-manager-console/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/ncomp-sirius-manager-console/.settings/org.eclipse.jdt.groovy.core.prefs b/ncomp-sirius-manager-console/.settings/org.eclipse.jdt.groovy.core.prefs
new file mode 100644
index 0000000..ae98fea
--- /dev/null
+++ b/ncomp-sirius-manager-console/.settings/org.eclipse.jdt.groovy.core.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+groovy.compiler.level=24
diff --git a/ncomp-sirius-manager-console/.settings/org.eclipse.m2e.core.prefs b/ncomp-sirius-manager-console/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/ncomp-sirius-manager-console/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/ncomp-sirius-manager-console/LICENSE.txt b/ncomp-sirius-manager-console/LICENSE.txt
new file mode 100644
index 0000000..30471b5
--- /dev/null
+++ b/ncomp-sirius-manager-console/LICENSE.txt
@@ -0,0 +1,22 @@
+
+/*-
+ * ============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============================================
+ */
+
+ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property.
diff --git a/ncomp-sirius-manager-console/META-INF/MANIFEST.MF b/ncomp-sirius-manager-console/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..03938de
--- /dev/null
+++ b/ncomp-sirius-manager-console/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: ncomp-sirius-manager-console
+Bundle-SymbolicName: ncomp-sirius-manager-console
+Bundle-Version: 0.1.0.qualifier
+Export-Package: org.openecomp.ncomp.sirius.manager.console,
+ org.openecomp.ncomp.sirius.manager.groovy
+Require-Bundle: org.apache.log4j;bundle-version="1.2.15",
+ org.eclipse.emf.ecore;bundle-version="2.10.2",
+ ncomp-core-model;bundle-version="0.1.0",
+ ncomp-sirius-manager-server;bundle-version="0.1.0",
+ ncomp-utils-java;bundle-version="0.1.0"
diff --git a/ncomp-sirius-manager-console/build.properties b/ncomp-sirius-manager-console/build.properties
new file mode 100644
index 0000000..4c7cc27
--- /dev/null
+++ b/ncomp-sirius-manager-console/build.properties
@@ -0,0 +1,3 @@
+source.. = src/main/groovy/
+bin.includes = META-INF/,\
+ .
diff --git a/ncomp-sirius-manager-console/pom.xml b/ncomp-sirius-manager-console/pom.xml
new file mode 100644
index 0000000..b7ea795
--- /dev/null
+++ b/ncomp-sirius-manager-console/pom.xml
@@ -0,0 +1,187 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.openecomp.ncomp.sirius.manager</groupId>
+ <artifactId>ncomp-sirius-manager-console</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ </properties>
+
+
+ <pluginRepositories>
+ <!-- Black Duck plugin dependencies -->
+ <pluginRepository>
+ <id>JCenter</id>
+ <name>JCenter Repository</name>
+ <url>http://jcenter.bintray.com</url>
+ </pluginRepository>
+
+ <pluginRepository>
+ <id>Restlet</id>
+ <name>Restlet Repository</name>
+ <url>http://maven.restlet.com</url>
+ </pluginRepository>
+ </pluginRepositories>
+<build>
+ <sourceDirectory>src/main/groovy</sourceDirectory>
+ <plugins>
+ <!-- blackduck maven plugin -->
+ <plugin>
+ <groupId>com.blackducksoftware.integration</groupId>
+ <artifactId>hub-maven-plugin</artifactId>
+ <version>1.4.0</version>
+ <inherited>false</inherited>
+ <configuration>
+ <hubProjectName>${project.name}</hubProjectName>
+ <outputDirectory>${project.basedir}</outputDirectory>
+ </configuration>
+ <executions>
+ <execution>
+ <id>create-bdio-file</id>
+ <phase>package</phase>
+ <goals>
+ <goal>createHubOutput</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- site maven plugin -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.6</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-webdav-jackrabbit</artifactId>
+ <version>2.10</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <!-- 2.8.0-01 and later require maven-compiler-plugin 3.1 or higher -->
+ <version>3.1</version>
+ <configuration>
+ <compilerId>groovy-eclipse-compiler</compilerId>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-eclipse-compiler</artifactId>
+ <version>2.9.1-01</version>
+ </dependency>
+ <!-- for 2.8.0-01 and later you must have an explicit dependency on
+ groovy-eclipse-batch -->
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-eclipse-batch</artifactId>
+ <version>2.3.7-01</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings
+ only. It has no influence on the Maven build itself. -->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.apache.maven.plugins
+ </groupId>
+ <artifactId>
+ maven-compiler-plugin
+ </artifactId>
+ <versionRange>
+ [3.1,)
+ </versionRange>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>2.4.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.ncomp.utils</groupId>
+ <artifactId>ncomp-utils-java</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.ncomp.sirius.manager</groupId>
+ <artifactId>ncomp-sirius-manager-server</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+
+ <distributionManagement>
+ <repository>
+ <id>osecomp-nexus-releases</id>
+ <name>OSECOMP Release Repository</name>
+ <url>${openecomp.nexus.releases}</url>
+ </repository>
+ <snapshotRepository>
+ <id>osecomp-nexus-snapshots</id>
+ <name>OSECOMP Snapshot Repository</name>
+ <url>${openecomp.nexus.snapshots}</url>
+ </snapshotRepository>
+ <site>
+ <id>dcae-javadoc</id>
+ <url>${site.urlroot}/${project.artifactId}/${project.version}/</url>
+ </site>
+ </distributionManagement>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.10.4</version>
+ <configuration>
+ <failOnError>false</failOnError>
+ <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
+ <docletArtifact>
+ <groupId>org.umlgraph</groupId>
+ <artifactId>umlgraph</artifactId>
+ <version>5.6</version>
+ </docletArtifact>
+ <additionalparam>-views</additionalparam>
+ <useStandardDocletOptions>true</useStandardDocletOptions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+
+</project>
diff --git a/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/console/Console.groovy b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/console/Console.groovy
new file mode 100644
index 0000000..4f7f038
--- /dev/null
+++ b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/console/Console.groovy
@@ -0,0 +1,217 @@
+
+/*-
+ * ============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============================================
+ */
+
+package org.openecomp.ncomp.sirius.manager.console
+
+import java.util.Properties;
+import java.util.TimeZone;
+
+import org.openecomp.ncomp.core.logs.LogMessage;
+import org.openecomp.ncomp.sirius.manager.AbstractClient;
+
+import org.json.JSONObject
+import org.json.JSONArray
+
+import org.openecomp.ncomp.utils.PropertyUtil
+
+import org.eclipse.emf.ecore.EObject;
+
+import static org.openecomp.ncomp.sirius.manager.console.Utils.*
+import static org.openecomp.ncomp.webservice.utils.DateUtils.dateFromString
+
+class Console {
+ protected AbstractClient client
+ private String language
+ private String namespace
+ public Console(String filename, String name) {
+ // ALWAYS USE GMT.
+ Properties props = PropertyUtil.getPropertiesFromClasspath(filename);
+ language = props.getProperty("${name}.language", "somf");
+ namespace = props.getProperty("${name}.namespace", null);
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+ public Console() {
+ language = "somf"
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+ public create(String path, o) {
+ def json = null
+ switch (o) {
+ case String: json = new JSONObject(o); break
+ case JSONObject: json = o; break
+ case EObject:
+ case Map: json = object2json(o); break
+ default: throw new RuntimeException("Unable to determine JSON: $o")
+ }
+ // println json.toString(2)
+ return json2object(client.create(fixPath(path),json));
+ }
+ public update(String path, o) {
+ def json = null
+ // println "o=$o"
+ switch (o) {
+ case String: json = new JSONObject(o); break
+ case JSONObject: json = o; break
+ case EObject:
+ case Map: json = object2json(o); break
+ default: throw new RuntimeException("Unable to determine JSON: $o")
+ }
+ // println json.toString(2)
+ return json2object(client.update(fixPath(path),json));
+ }
+ public delete(String path) {
+ return json2object(client.delete(fixPath(path)))
+ }
+ public def list(String path, int levels = 1) {
+ def x = client.list(fixPath(path),levels)
+ return json2object(x)
+ }
+ public def listAll(String path) {
+ JSONObject x = client.listAll(fixPath(path))
+ return json2object(x.get("list"))
+ }
+ public def listReferences(String path, boolean recursive = true) {
+ JSONObject x = client.listReferences(fixPath(path),recursive)
+ return json2object(x.get("list"))
+ }
+ public def operation(String path, String name, o = "{}", Long timeout = null) {
+ def json = null
+ switch (o) {
+ case String: json = new JSONObject(o); break
+ case JSONObject: json = o; break
+ case EObject:
+ case Map: json = object2json(o); break
+ }
+ switch (language) {
+ case "restconf":
+ return json2object(client.operationOdl("/restconf/operations/$namespace:$name",timeout,json))
+ }
+ return json2object(client.operation(fixPath(path),name,timeout,json))
+ }
+ def String fixPath(String path) {
+ if (path.startsWith("/gui")) return path
+ if (path.startsWith("/south")) return path
+ if (!path.startsWith("/")) path = "/$path"
+ if (!path.startsWith("/resources")) path = "/resources$path"
+ return path
+ }
+ public void printMetrics(String path, start, end) {
+ switch (start) { case String: start = dateFromString(start); break }
+ switch (end) { case String: end = dateFromString(end); break }
+ def values = client.operationPath("/resources",ModelPackage.eINSTANCE.abstractManagementServer,"getValues",
+ null, null, path, start.time, end.time, null, false)
+ def table = [ header : ["Time", "Metric", "Value"], rows : []]
+ values.each {
+ def row = []
+ row += new Date(it.time)
+ row += it.metricName
+ row += it.value
+ table.rows += [row]
+ }
+ pTable(table)
+ }
+ public void printMetricsAll(String path, List<String> metrics, start, end, options = null) {
+ switch (start) { case String: start = dateFromString(start); break }
+ switch (end) { case String: end = dateFromString(end); break }
+ def values = client.operationPath("/resources",ModelPackage.eINSTANCE.abstractManagementServer,"getValuesAll",
+ null, path, metrics, start.time, end.time, fixOptions(options))
+ def table = [ header : [
+ "Path",
+ "Time",
+ "Metric",
+ "Value"
+ ], rows : []]
+ values.each {
+ def row = []
+ row += it.resourceName
+ row += new Date(it.time)
+ row += it.metricName
+ row += it.value
+ table.rows += [row]
+ }
+ pTable(table)
+ }
+ public void printMessages(String path, start, end) {
+ if (start == null) start = '-1day'
+ if (end == null) end = 'now'
+ switch (start) { case String: start = dateFromString(start); break }
+ switch (end) { case String: end = dateFromString(end); break }
+ def values = client.operationPath("/resources",ModelPackage.eINSTANCE.abstractManagementServer,"getMessages",
+ null, path, start.time, end.time)
+ def table = [ header : [
+ "Time",
+ "Level",
+ "Path",
+ "Message"
+ ], rows : []]
+ values.each { LogMessage msg ->
+ def row = []
+ row += new Date(msg.time)
+ row += msg.level
+ row += msg.resourceName
+ row += msg.message
+ table.rows += [row]
+ }
+ pTable(table)
+ }
+
+ public void saveTableCsv(t,filename) {
+ def f = new File(filename)
+ new File(filename).withWriter { out ->
+ def row = []
+ t.columns.each { row += it.colName }
+ out.writeLine row.join(",")
+ t.rows.each { r ->
+ row = []
+ r.cells.each { row += it.value }
+ out.writeLine row.join(",")
+ }
+ }
+ }
+ String rootDirectory = null
+ public create(String path) {
+ if (rootDirectory == null)
+ throw new RuntimeException("rootDirectory is NULL")
+ File file = new File("$rootDirectory/${fixPath(path)}.json")
+ if (! file.exists())
+ throw new RuntimeException("file does not exist: $file")
+ def json = null
+ try { json = new JSONObject(file.text) } catch (e) {
+ throw new RuntimeException("JSON error: $file : $e")
+ }
+ create(path,json)
+ }
+ public update(String path) {
+ if (rootDirectory == null)
+ throw new RuntimeException("rootDirectory is NULL")
+ File file = new File("$rootDirectory/${fixPath(path)}.json")
+ if (! file.exists())
+ throw new RuntimeException("file does not exist: $file")
+ def json = null
+ try { json = new JSONObject(file.text) } catch (e) {
+ throw new RuntimeException("JSON error: $file : $e")
+ }
+ update(path,json)
+ }
+
+}
+
+
diff --git a/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/console/Utils.groovy b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/console/Utils.groovy
new file mode 100644
index 0000000..b00aa38
--- /dev/null
+++ b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/console/Utils.groovy
@@ -0,0 +1,176 @@
+
+/*-
+ * ============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============================================
+ */
+
+package org.openecomp.ncomp.sirius.manager.console
+
+import org.eclipse.emf.common.util.BasicEList
+import org.eclipse.emf.common.util.EList;
+
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.EPackage
+import org.eclipse.emf.ecore.EObject;
+
+import org.json.JSONObject
+import org.json.JSONArray
+
+import static org.openecomp.ncomp.sirius.manager.ManagementServer.ecore2json
+
+
+class Utils {
+
+ static def object2json(o) {
+ switch (o) {
+ case List:
+ def j = [] as JSONArray
+ o.each { j.put(object2json(it)) }
+ return j
+ case Map:
+ def j = [:] as JSONObject
+ o.each { k,v -> j.put(k,object2json(v)) }
+ return j
+ case EObject:
+ return ecore2json(o, 100, null, true)
+ case boolean:
+ case long:
+ case int:
+ case double:
+ case Boolean:
+ case Long:
+ case Integer:
+ case String: return o; break
+ case GString: return o.toString(); break
+ case null: break;
+ default: println "Unable to convert: $o ${o.getClass().name}"
+ }
+ }
+ static def json2object (o) {
+ switch (o) {
+ case JSONObject:
+ def m = [:]
+ o.map.each { n,v -> m[n] = json2object(v) }
+ return m
+ case JSONArray:
+ def a = []
+ o.myArrayList.each { a += json2object(it) }
+ return a
+ case Integer:
+ case Long:
+ case Double:
+ case Boolean:
+ case boolean:
+ case int:
+ case double:
+ case String: return o; break
+ case GString: return o.toString(); break
+ case null: break;
+ default:
+ if (o.getClass().name != 'org.json.JSONObject$Null')
+ println "Unable to json2object convert: $o ${o.getClass().name}"
+ }
+ }
+
+ static cloneMap(m) {
+ return json2object(object2json(m))
+ }
+
+ static def void pTable (m, format = "txt", PrintStream out) {
+ def s = [:]
+ def style = 'style="border: 1px solid black; border-collapse: collapse;"'
+ m.header.eachWithIndex {n,i->
+ def l = "$n".size()
+ if (!s[i] || l > s[i]) s[i] = l
+ }
+ m.rows.each { row ->
+ // out.println "row = $row"
+ (0..m.header.size()-1).each { i ->
+ def n = row[i]
+ def l = "$n".size()
+ if (!s[i] || l > s[i]) s[i] = l
+ }
+ }
+ // println "$s"
+ def row = []
+ def j = 1
+ m.header.eachWithIndex {n,i->
+ row += String.format("%${s[i]}s",n)
+ j += 3 + s[i]
+ }
+ switch (format) {
+ case "mediawiki":
+ out.println '{| class="wikitable"'
+ out.println "! ${row.join('\n! ')}"
+ break
+ case "html":
+ out.println "<table $style>"
+ out.println "<tr $style><th $style>${row.join('</th><th '+style+'>')}</th></tr>"
+ break
+ default:
+ out.println "_"*j
+ out.println "| ${row.join(' | ')} |"
+ out.println "_"*j
+ break;
+ }
+ m.rows.each { r ->
+ row = []
+ (0..m.header.size()-1).each { k ->
+ row += String.format("%${s[k]}s",r[k])
+ }
+ switch (format) {
+ case "mediawiki": out.println "|-\n| ${row.join('\n| ')}"; break
+ case "html": out.println "<tr $style><td $style>${row.join('</td><td '+style+'>')}</td></tr>"; break
+ default: out.println "| ${row.join(' | ')} |"; break
+ }
+ }
+ switch (format) {
+ case "mediawiki": out.println "|}"; break
+ case "html": out.println '</table>'; break
+ default: out.println "_"*j; break
+ }
+ }
+
+ static def p(x) { Utils.object2json(x).toString(2) }
+
+ static def runCmd(String cmd, long timeout) {
+ def sout = new StringBuffer()
+ def serr = new StringBuffer()
+ Process proc = cmd.execute()
+ Thread t1 = proc.consumeProcessOutputStream(sout)
+ Thread t2 = proc.consumeProcessErrorStream(serr)
+ Date d1 = new Date()
+ proc.waitForOrKill(timeout)
+ if (proc.exitValue() != 0) {
+ System.err.println "Non Zero exit value: $cmd ${proc.exitValue()}"
+ }
+ Date d2 = new Date()
+ long duration = d2.time - d1.time
+ if (duration > 0.5 * timeout) {
+ System.err.println "Command took long time: $cmd took ${duration}ms with timeout=${timeout}ms"
+ }
+ t1.join()
+ t2.join()
+ if (sout.toString() != "") println "output: $sout"
+ if (serr.toString() != "") println "error: $serr"
+ return [out:sout.toString(),err:serr.toString()]
+ }
+
+}
+
diff --git a/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/AlertUtils.groovy b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/AlertUtils.groovy
new file mode 100644
index 0000000..62c1138
--- /dev/null
+++ b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/AlertUtils.groovy
@@ -0,0 +1,98 @@
+
+/*-
+ * ============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============================================
+ */
+
+package org.openecomp.ncomp.sirius.manager.groovy
+
+import static org.openecomp.ncomp.sirius.manager.console.Utils.cloneMap
+
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+import org.openecomp.ncomp.core.function.Function;
+import org.openecomp.ncomp.core.function.RuleFunction;
+
+class AlertUtils {
+ def console
+ def AlertUtils() {}
+ def AlertUtils(console) {
+ this.console = console
+ }
+ def void addAlertTemplates (path,aName, boolean save = true) {
+ console.listAll(path).each { tName ->
+ def m = [alertingTemplate : ['$ref':"/configuration/alertTemplates/$aName"], '$nosave' : 1 ]
+// println "$tName"
+ update(tName,m)
+ }
+ copyAlerts(path)
+ if (save) console.update("/",[:])
+ }
+ def void addAlertTemplatesFromFile(String fileName) {
+ File f = new File(fileName)
+ f.readLines().each { line ->
+ String[] a = line.split("\\|")
+ if (a.length != 2) return
+ addAlertTemplates(a[0], a[1], false)
+ }
+ console.update("/",[:])
+ }
+ def void addAlertTemplatesFromFunction(path, function, boolean save = true) {
+ def ret = console.operation("/","evaluate",[path:path, function:function])
+ ret.returns.each { v ->
+ def m = [alertingTemplate : ['$ref':"/configuration/alertTemplates/$v.value"], '$nosave' : 1 ]
+ update(v.path,m)
+ }
+ copyAlerts(path)
+ if (save) console.update("/",[:])
+ }
+ def void copyAlerts (path) {
+ def t = console.list("/configuration",1000).alertTemplates
+// println t
+ console.listAll(path).each { p ->
+ def m = console.list(p,0)
+ if (m.alertingTemplate == null || m.alertingTemplate['$ref'] == "NULL") return
+ def t2 = m.alertingTemplate['$ref'].split("/")[3]
+ def t3 = t[t2]
+ t3['$nosave'] = 1
+// println "$p $m.alertingTemplate $t2 $t3"
+ console.update(p,t3)
+ }
+ }
+ def alert(metricName,lowerBound,upperBound,severity = "SEV2", duration = null, maxDelay = null) {
+ return [
+ '$class':"org.openecomp.ncomp.sirius.manager.model.ThresholdAlert",
+ metricName:metricName,
+ lowerBound:lowerBound,
+ upperBound:upperBound,
+ duration:duration,
+ maxDelay:maxDelay,
+ severity:severity,
+ ]
+ }
+ def update (path,v) {
+// println "Updating $path"
+ try {
+ console.update(path,v)
+ }
+ catch (e) {
+ console.create(path,v)
+ }
+ }
+
+}
+
diff --git a/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/Ecore2Xcore.groovy b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/Ecore2Xcore.groovy
new file mode 100644
index 0000000..30bbbb7
--- /dev/null
+++ b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/Ecore2Xcore.groovy
@@ -0,0 +1,68 @@
+
+/*-
+ * ============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============================================
+ */
+
+package org.openecomp.ncomp.sirius.manager.groovy
+
+import groovy.text.SimpleTemplateEngine
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EOperation
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+
+class Ecore2Xcore {
+ EPackage p
+ String subName
+ def env
+ public Ecore2Xcore(EPackage p) {
+ this.p = p
+ env = [
+ p: p,
+ ]
+ }
+ public add(k,v) {
+ env[k] = v
+ }
+ public void generate(String file, String templateDirectory) {
+ SimpleTemplateEngine engine = new SimpleTemplateEngine()
+ println "Creating $file"
+ println env
+ println "$env.pName"
+ def x = engine.createTemplate(new File("$templateDirectory/xcore").text).make(env)
+ def f = new File(file)
+ f.delete()
+ f.parentFile.mkdirs()
+ f << x
+// println "x=$x"
+ }
+ def void test() {
+ EClass c
+ c.getEReferences().each { EReference ref ->
+ ref.isContainment() ? "contains" : "refers"
+ ref.eType.name
+ }
+ c.getEAttributes().each { EAttribute attr ->
+ attr.eType.name
+ }
+ }
+}
diff --git a/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/TableUtils.groovy b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/TableUtils.groovy
new file mode 100644
index 0000000..5f2c818
--- /dev/null
+++ b/ncomp-sirius-manager-console/src/main/groovy/org/openecomp/ncomp/sirius/manager/groovy/TableUtils.groovy
@@ -0,0 +1,220 @@
+
+/*-
+ * ============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============================================
+ */
+
+package org.openecomp.ncomp.sirius.manager.groovy
+
+import static org.openecomp.ncomp.sirius.manager.console.Utils.cloneMap
+
+class TableUtils {
+ def console
+ def TableUtils() {}
+ def TableUtils(console) {
+ this.console = console
+ }
+ def newOption(options) {
+ def res = ['$class':"org.openecomp.ncomp.core.metrics.SequenceMetricValueOption",options:[:],'$nosave':1]
+ options.each { o ->
+ if (o.TYPE == null)
+ throw new RuntimeException("option should have TYPE")
+ def oo = ['$class':"org.openecomp.ncomp.core.metrics.${o.TYPE}MetricValueOption"]
+ o.each { n, v ->
+ if (n == "TYPE") return
+ oo[n] = v
+ }
+ res.options[o.name] = oo
+ }
+ return res
+ }
+
+ def newLogTable(treePath,tablePath,minLevel,minSeverity,prefixResourcePath,duration,aggregationDuration) {
+ [
+ '$class':"org.openecomp.ncomp.sirius.manager.tableTemplate.LogTableTemplate",
+ treePath:treePath,
+ tablePath:tablePath,
+ minLevel:minLevel,
+ minSeverity:minSeverity,
+ prefixResourcePath:prefixResourcePath,
+ duration:duration,
+ aggregationDuration:aggregationDuration,
+ '$nosave':1
+ ]
+ }
+
+ def newTable(treePath,tablePath,rowPath) {
+ [
+ '$class':"org.openecomp.ncomp.sirius.manager.tableTemplate.TableTemplate",
+ treePath:treePath,
+ tablePath:tablePath,
+ rowPath:rowPath,
+ columns:[:],
+ '$nosave':1
+ ]
+ }
+
+ def newIteratorTableTemplate(treePath,tablePath,rowPaths,filter,recursive="true") {
+ [
+ '$class':"org.openecomp.ncomp.sirius.manager.tableTemplate.IteratorTableTemplate",
+ treePath:treePath,
+ tablePath:tablePath,
+ iterator: [
+ '$class': "org.openecomp.ncomp.core.function.IteratorUsingFunction",
+ paths:rowPaths,
+ recursive:recursive,
+ filter:filter,
+ ],
+ columns:[:],
+ '$nosave':1
+ ]
+ }
+
+
+ def newTimeTable(treePath,tablePath,rowPath,duration) {
+ [
+ '$class':"org.openecomp.ncomp.sirius.manager.tableTemplate.TimeTableTemplate",
+ treePath:treePath,
+ tablePath:tablePath,
+ rowPath:rowPath,
+ duration:duration,
+ columns:[:],
+ '$nosave':1
+ ]
+ }
+
+
+ def newColumnA(t,name,path) {
+ t.columns[name] = [
+ '$class':"org.openecomp.ncomp.sirius.manager.tableTemplate.TableTemplateAttributeColumn",
+ path:path,
+ '$nosave':1
+ ]
+ }
+ def newColumnM(t,name, path,option) {
+ t.columns[name] = [
+ '$class':"org.openecomp.ncomp.sirius.manager.tableTemplate.TableTemplateMetricColumn",
+ path:path,
+ option:['$ref':"/configuration/metricOptions/$option"],
+ '$nosave':1
+
+ ]
+ }
+
+ def update (path,v) {
+ println "Updating $path"
+ try {
+ console.update(path,v)
+ }
+ catch (Exception e) {
+ console.create(path,v)
+ }
+ }
+
+ def update2(String p,t) {
+ update(p,t)
+ // create last24HourTable
+ // treePath,tablePath,rowPath
+ def t2 = newTable(t.treePath,t.tablePath.replace("daily","last24Hour"),t.rowPath)
+ def t3 = newTable(t.treePath,t.tablePath.replace("daily","lastHour"),t.rowPath)
+ t.columns.each { n, col ->
+ println "$n $col"
+ t2.columns[n] = col
+ def col1 = cloneMap(col)
+ if (col1.option != null) col1.option['$ref'] = col1.option['$ref'].replace("daily","hourly")
+ t3.columns[n] = col1
+ }
+ update(p.replace("daily","last24Hour"),t2)
+ update(p.replace("daily","lastHour"),t3)
+
+ }
+
+
+ def setupLogging () {
+ update("/configuration/tableTemplates/log-ALL-2hour",newLogTable("/",'/reports/logging/2hour/ALL',null,null,'',"-2hour",null))
+ update("/configuration/tableTemplates/log-WARN-2hour",newLogTable("/",'/reports/logging/2hour/WARN','WARN',null,'',"-2hour",null))
+ update("/configuration/tableTemplates/log-SEV1-2hour",newLogTable("/",'/reports/logging/2hour/SEV1',null,"SEV1",'',"-2hour",null))
+ update("/configuration/tableTemplates/log-SEV2-2hour",newLogTable("/",'/reports/logging/2hour/SEV2',null,"SEV2",'',"-2hour",null))
+ update("/configuration/tableTemplates/log-ALL-1day",newLogTable("/",'/reports/logging/1day/ALL',null,null,'',"-1day","1hour"))
+ update("/configuration/tableTemplates/log-WARN-1day",newLogTable("/",'/reports/logging/1day/WARN','WARN',null,'',"-1day","1hour"))
+ update("/configuration/tableTemplates/log-SEV1-1day",newLogTable("/",'/reports/logging/1day/SEV1',null,"SEV1",'',"-1day","1hour"))
+ update("/configuration/tableTemplates/log-SEV2-1day",newLogTable("/",'/reports/logging/1day/SEV2',null,"SEV2",'',"-1day","1hour"))
+ update("/configuration/tableTemplates/log-ALL-1week",newLogTable("/",'/reports/logging/1week/ALL',null,null,'',"-7day","1day"))
+ update("/configuration/tableTemplates/log-WARN-1week",newLogTable("/",'/reports/logging/1week/WARN','WARN',null,'',"-7day","1day"))
+ update("/configuration/tableTemplates/log-SEV1-1week",newLogTable("/",'/reports/logging/1week/SEV1',null,"SEV1",'',"-7day","1day"))
+ update("/configuration/tableTemplates/log-SEV2-1week",newLogTable("/",'/reports/logging/1week/SEV2',null,"SEV2",'',"-7day","1day"))
+ update("/configuration/tableTemplates/log-mail",newLogTable("/",'/reports/logging/mail',null,"SEV1",'',"-1hour","99999day"))
+ }
+
+ def setupLogCount() {
+ def ccc= "org.openecomp.ncomp.core.function.FunctionMatchAttribute"
+ def ccc2="org.openecomp.ncomp.core.function.FunctionMatchInstanceOf"
+ def f = [
+ '$class': "org.openecomp.ncomp.core.function.RuleFunction",
+ rules:[
+ [ action : [ value:"true"], matches: [[
+ '$class':ccc2,
+ ePackage:"org.openecomp.ncomp.core.logs.LogsPackage",
+ eName:"LogMessageContainer"
+ ]] ],
+ [ action : [ value:"false"] ],
+ ]
+ ]
+ def t = newIteratorTableTemplate("/","/reports/logging/count",["/"],f)
+ newColumnA(t,"path", '$path')
+ newColumnA(t,"class", '$class')
+ newColumnM(t,"Logmessage (last hour)", "/logMessageStats/ALL/count","hourlyCount")
+ newColumnM(t,"SEV1 Logmessage (last hour)", "/logMessageStats/SEV1/count","hourlyCount")
+ newColumnM(t,"SEV2 Logmessage (last hour)", "/logMessageStats/SEV2/count","hourlyCount")
+ newColumnM(t,"Logmessage (last day)", "/logMessageStats/ALL/count","dailyCount")
+ newColumnM(t,"SEV1 Logmessage (last day)", "/logMessageStats/SEV1/count","dailyCount")
+ newColumnM(t,"SEV2 Logmessage (last day)", "/logMessageStats/SEV2/count","dailyCount")
+ update("/configuration/tableTemplates/logging-count",t)
+ }
+
+
+ def setupSuspended() {
+ def ccc= "org.openecomp.ncomp.core.function.FunctionMatchAttribute"
+ def f = [
+ '$class': "org.openecomp.ncomp.core.function.RuleFunction",
+ rules:[
+ [ action : [ value:"true"], matches: [['$class':ccc,path:"/operationalState",match:"SUSPENDED"]] ],
+ [ action : [ value:"false"] ],
+ ]
+ ]
+ def t = newIteratorTableTemplate("/","/reports/suspended",["/"],f)
+ newColumnA(t,"path", '$path')
+ newColumnA(t,"class", '$class')
+ newColumnA(t,"Operational State", "/operationalState")
+ update("/configuration/tableTemplates/suspended",t)
+ }
+
+ def setupOptions() {
+ ["Average","Count","Max","Min","Sum"].each { aggr ->
+ println "here$aggr"
+ def x = [[name:"basic",TYPE:"Basic"],[name:"aggregation",TYPE:"Aggregation",duration:"1day",aggregationType:aggr.toUpperCase()]]
+ update("/configuration/metricOptions/daily$aggr",newOption(x))
+ println "here2$aggr"
+ x[1].duration = "1hour"
+ update("/configuration/metricOptions/hourly$aggr",newOption(x))
+ }
+ println "here3"
+ update("/configuration/metricOptions/default",newOption([[name:"basic",TYPE:"Basic"]]))
+ }
+}
+