aboutsummaryrefslogtreecommitdiffstats
path: root/ncomp-sirius-manager-console/src/main/groovy/org
diff options
context:
space:
mode:
Diffstat (limited to 'ncomp-sirius-manager-console/src/main/groovy/org')
-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
5 files changed, 779 insertions, 0 deletions
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"]]))
+ }
+}
+