2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pdpx.main.startstop;
23 import java.io.FileInputStream;
24 import java.util.Arrays;
25 import java.util.Properties;
27 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
28 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
29 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
35 * This class initiates ONAP Policy Framework policy xacml pdp.
39 private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
41 // The policy xacml pdp Activator that activates the policy xacml pdp service
42 private XacmlPdpActivator activator;
45 private String argumentMessage = null;
48 * Instantiates the policy xacml pdp service.
50 * @param args the command line arguments
51 * @throws PolicyXacmlPdpException if an error occurs
53 public Main(final String[] args) throws PolicyXacmlPdpException {
54 final String argumentString = Arrays.toString(args);
55 LOGGER.info("Starting policy xacml pdp service with arguments - {}", argumentString);
57 // Check the arguments
58 final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
60 // The arguments return a string if there is a message to print and we should exit
61 argumentMessage = arguments.parse(args);
62 if (argumentMessage != null) {
63 LOGGER.info(argumentMessage);
67 // Validate that the arguments are sane
70 // Read the parameters
71 XacmlPdpParameterGroup parameterGroup = new XacmlPdpParameterHandler().getParameters(arguments);
73 // Read the properties
74 Properties props = new Properties();
76 String propFile = arguments.getFullPropertyFilePath();
77 try (FileInputStream stream = new FileInputStream(propFile)) {
80 } catch (final Exception e) {
81 throw new PolicyXacmlPdpException("cannot load property file", e);
84 // Now, create the activator for the policy xacml pdp service
85 activator = new XacmlPdpActivator(parameterGroup, props);
86 XacmlPdpActivator.setCurrent(activator);
88 // Start the activator
91 // Add a shutdown hook to shut everything down in an orderly manner
92 Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
93 LOGGER.info("Started policy xacml pdp service");
97 * Shut down Execution.
99 * @throws PolicyXacmlPdpException on shutdown errors
101 public synchronized void shutdown() {
102 // clear the xacml pdp activator
103 if (activator != null && activator.isAlive()) {
112 * @param args the arguments
114 public static void main(final String[] args) {
117 } catch (RuntimeException | PolicyXacmlPdpException e) {
118 LOGGER.error("start of policy xacml pdp service failed", e);