98c49ce233e93d05b40630bc80ec091b67c041a0
[policy/engine.git] / BRMSGateway / src / main / java / org / onap / policy / brmsInterface / BRMSGateway.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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 package org.onap.policy.brmsInterface;
22
23 import org.onap.policy.api.NotificationScheme;
24 import org.onap.policy.api.PolicyEngine;
25 import org.onap.policy.api.PolicyException;
26 import org.onap.policy.common.logging.flexlogger.FlexLogger;
27 import org.onap.policy.common.logging.flexlogger.Logger;
28 import org.onap.policy.xacml.api.XACMLErrorConstants;
29
30 /**
31  * BRMSGateway: This application acts as the Gateway interface between the PDP XACML and PDP Drools. The listens for
32  * BRMS based policies and pushes them to the specified Policy Repository, from where the PDP Drools reads the Rule Jar.
33  * 
34  * @version 0.1
35  */
36 class BRMSGateway {
37         
38     private static final Logger logger = FlexLogger.getLogger(BRMSGateway.class);
39     private static final String CONFIGFILE = "config.properties";
40
41     private static PolicyEngine policyEngine = null;
42
43     private BRMSGateway() {
44         // Default private constructor
45     }
46     
47     public static void main(String[] args) throws Exception {
48         // Initialize Handler.
49         logger.info("Initializing BRMS Handler");
50         BRMSHandler bRMSHandler = null;
51         try {
52             bRMSHandler = new BRMSHandler(CONFIGFILE);
53         } catch (PolicyException e) {
54             logger.error("Check your property file: " + e.getMessage(), e);
55             System.exit(1);
56         }
57
58         // Set Handler with Auto Notification and initialize policyEngine
59         try {
60             logger.info("Initializing policyEngine with Auto Notifications");
61             policyEngine = new PolicyEngine(CONFIGFILE, NotificationScheme.AUTO_ALL_NOTIFICATIONS, bRMSHandler);
62         } catch (Exception e) {
63             logger.error(XACMLErrorConstants.ERROR_UNKNOWN + "Error while Initializing Policy Engine " + e.getMessage(),
64                     e);
65         }
66
67         // Keep Running....
68         Runnable runnable = () -> {
69             while (true) {
70                 try {
71                     Thread.sleep(30000);
72                 } catch (InterruptedException e) {
73                     logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Thread Exception " + e.getMessage());
74                     Thread.currentThread().interrupt();
75                 }
76             }
77         };
78         Thread thread = new Thread(runnable);
79         thread.start();
80     }
81
82     public static PolicyEngine getPolicyEngine() {
83         return policyEngine;
84     }
85 }