[POLICY-11] Sample Query with variable arguments
[policy/drools-applications.git] / vfwsim / src / main / resources / vFWsim.drl
1 /*-
2  * ============LICENSE_START=======================================================
3  * vFW simulator
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21
22 package org.openecomp.policy.sim.vfw;
23
24 import org.openecomp.policy.appc.Request;
25
26 import org.openecomp.policy.controlloop.ControlLoopEventStatus;
27 import org.openecomp.policy.controlloop.ControlLoopTargetType;
28 import org.openecomp.policy.controlloop.VirtualControlLoopEvent;
29
30 import org.openecomp.policy.drools.system.PolicyEngine;
31
32 rule "vFWsim.ONSET"
33 when
34         $onset : OnsetEvent()
35 then
36         String WHERE = drools.getRule().getPackage() + "." + drools.getRule().getName();
37         
38         try {
39                 System.out.println(WHERE + ": " + "DCAE[ONSET|" + $onset.requestID + "|" + 
40                                    $onset.dcaeTopic + "] -> PDP-D" );                   
41                 PolicyEngine.manager.deliver($onset.dcaeTopic, $onset.toDcaeOnset());
42                 insert(new AppcResponseEvent($onset.requestID.toString(), $onset.appcTopic, $onset.appcResponseCode));
43         } catch (Exception e) {
44                 e.printStackTrace();
45         } finally {
46                 retract($onset);
47         }       
48 end
49
50 rule "vFWsim.APPC.RESPONSE"
51 when
52         $appcResponse : AppcResponseEvent( code > 0 )
53         $request : Request( getCommonHeader().RequestID.toString() == $appcResponse.requestID )
54 then
55         String WHERE = drools.getRule().getPackage() + "." + drools.getRule().getName();
56         
57         try {
58                 System.out.println(WHERE + ": " + "APPC[" + $appcResponse.code + "|" + $appcResponse.requestID + "|" + 
59                                    $appcResponse.appcTopic + "] -> PDP-D" );
60                          
61                 PolicyEngine.manager.deliver($appcResponse.appcTopic, 
62                                              AppcResponseEvent.toResponse($appcResponse.requestID, $appcResponse.code));
63         } catch (Exception e) {
64                 e.printStackTrace();
65         } finally {
66                 retract($appcResponse);
67                 retract($request);
68         }
69 end