Fix the DCAE integration Bugs
[holmes/engine-management.git] / engine-d / src / test / java / org / onap / holmes / engine / EngineDActiveAppTest.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 package org.onap.holmes.engine;\r
17 \r
18 public class EngineDActiveAppTest {\r
19     public static void main(String[] args) throws Exception {\r
20         String test = "package org.onap.holmes.droolsRule;\n"\r
21                 + "\n"\r
22                 + "import org.onap.holmes.common.dmaap.DmaapService;\n"\r
23                 + "import org.onap.holmes.common.api.stat.VesAlarm;\n"\r
24                 + "import org.onap.holmes.common.aai.CorrelationUtil;\n"\r
25                 + "import org.onap.holmes.common.dmaap.entity.PolicyMsg;\n"\r
26                 + "import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;\n"\r
27                 + "import org.onap.holmes.common.utils.DroolsLog;\n"\r
28                 + " \n"\r
29                 + "\n"\r
30                 + "rule \"Relation_analysis_Rule\"\n"\r
31                 + "salience 200\n"\r
32                 + "no-loop true\n"\r
33                 + "    when\n"\r
34                 + "        $root : VesAlarm(alarmIsCleared == 0,\n"\r
35                 + "            $sourceId: sourceId, sourceId != null && !sourceId.equals(\"\"),\n"\r
36                 + "\t\t\t$sourceName: sourceName, sourceName != null && !sourceName.equals(\"\"),\n"\r
37                 + "\t\t\t$startEpochMicrosec: startEpochMicrosec,\n"\r
38                 + "            specificProblem in (\"Fault_MultiCloud_VMFailure\"),\n"\r
39                 + "            $eventId: eventId)\n"\r
40                 + "        $child : VesAlarm( eventId != $eventId, parentId == null,\n"\r
41                 + "            CorrelationUtil.getInstance().isTopologicallyRelated(sourceId, $sourceId, $sourceName),\n"\r
42                 + "            specificProblem in (\"Slave MPU is offline\"),\n"\r
43                 + "            startEpochMicrosec < $startEpochMicrosec + 60000 && startEpochMicrosec > $startEpochMicrosec - 60000 )\n"\r
44                 + "    then\n"\r
45                 + "\t\tDroolsLog.printInfo(\"===========================================================\");\n"\r
46                 + "\t\tDroolsLog.printInfo(\"Relation_analysis_Rule: rootId=\" + $root.getEventId() + \", childId=\" + $child.getEventId());\n"\r
47                 + "\t\t$child.setParentId($root.getEventId());\n"\r
48                 + "\t\tupdate($child);\n"\r
49                 + "\t\t\n"\r
50                 + "end\n"\r
51                 + "\n"\r
52                 + "rule \"root_has_child_handle_Rule\"\n"\r
53                 + "salience 150\n"\r
54                 + "no-loop true\n"\r
55                 + "\twhen\n"\r
56                 + "\t\t$root : VesAlarm(alarmIsCleared == 0, rootFlag == 0, $eventId: eventId)\n"\r
57                 + "\t\t$child : VesAlarm(eventId != $eventId, parentId == $eventId)\n"\r
58                 + "\tthen\n"\r
59                 + "\t\tDroolsLog.printInfo(\"===========================================================\");\n"\r
60                 + "\t\tDroolsLog.printInfo(\"root_has_child_handle_Rule: rootId=\" + $root.getEventId() + \", childId=\" + $child.getEventId());\n"\r
61                 + "\t\tDmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class);\n"\r
62                 + "\t\tPolicyMsg policyMsg = dmaapService.getPolicyMsg($root, $child, \"org.onap.holmes.droolsRule\");\n"\r
63                 + "        dmaapService.publishPolicyMsg(policyMsg, \"unauthenticated.DCAE_CL_OUTPUT\");\n"\r
64                 + "\t\t$root.setRootFlag(1);\n"\r
65                 + "\t\tupdate($root);\n"\r
66                 + "end\n"\r
67                 + "\n"\r
68                 + "rule \"root_no_child_handle_Rule\"\n"\r
69                 + "salience 100\n"\r
70                 + "no-loop true\n"\r
71                 + "    when\n"\r
72                 + "        $root : VesAlarm(alarmIsCleared == 0, rootFlag == 0,\n"\r
73                 + "            sourceId != null && !sourceId.equals(\"\"),\n"\r
74                 + "\t\t\tsourceName != null && !sourceName.equals(\"\"),\n"\r
75                 + "            specificProblem in (\"Fault_MultiCloud_VMFailure\"))\n"\r
76                 + "    then\n"\r
77                 + "\t\tDroolsLog.printInfo(\"===========================================================\");\n"\r
78                 + "\t\tDroolsLog.printInfo(\"root_no_child_handle_Rule: rootId=\" + $root.getEventId());\n"\r
79                 + "\t\tDmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class);\n"\r
80                 + "\t\tPolicyMsg policyMsg = dmaapService.getPolicyMsg($root, null, \"org.onap.holmes.droolsRule\");\n"\r
81                 + "        dmaapService.publishPolicyMsg(policyMsg, \"unauthenticated.DCAE_CL_OUTPUT\");\n"\r
82                 + "\t\t$root.setRootFlag(1);\n"\r
83                 + "\t\tupdate($root);\n"\r
84                 + "end\n"\r
85                 + "\n"\r
86                 + "rule \"root_cleared_handle_Rule\"\n"\r
87                 + "salience 100\n"\r
88                 + "no-loop true\n"\r
89                 + "    when\n"\r
90                 + "        $root : VesAlarm(alarmIsCleared == 1, rootFlag == 1)\n"\r
91                 + "    then\n"\r
92                 + "\t\tDroolsLog.printInfo(\"===========================================================\");\n"\r
93                 + "\t\tDroolsLog.printInfo(\"root_cleared_handle_Rule: rootId=\" + $root.getEventId());\n"\r
94                 + "\t\tDmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class);\n"\r
95                 + "\t\tPolicyMsg policyMsg = dmaapService.getPolicyMsg($root, null, \"org.onap.holmes.droolsRule\");\n"\r
96                 + "        dmaapService.publishPolicyMsg(policyMsg, \"unauthenticated.DCAE_CL_OUTPUT\");\n"\r
97                 + "\t\tretract($root);\n"\r
98                 + "end\n"\r
99                 + "\n"\r
100                 + "rule \"child_handle_Rule\"\n"\r
101                 + "salience 100\n"\r
102                 + "no-loop true\n"\r
103                 + "    when\n"\r
104                 + "        $child : VesAlarm(alarmIsCleared == 1, rootFlag == 0)\n"\r
105                 + "    then\n"\r
106                 + "\t\tDroolsLog.printInfo(\"===========================================================\");\n"\r
107                 + "\t\tDroolsLog.printInfo(\"child_handle_Rule: childId=\" + $child.getEventId());\n"\r
108                 + "\t\tretract($child);\n"\r
109                 + "end";\r
110         String filePath = "E:\\项目代码\\ONAP\\holmes\\engine-management\\engine-d-standalone\\src\\main\\assembly\\conf\\engine-d.yml";\r
111         new EngineDActiveApp().run(new String[]{"server", filePath});\r
112     }\r
113 }\r