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;
44 // The parameters read in from JSON
45 private XacmlPdpParameterGroup parameterGroup;
47 // The argument message for some args that return a message
48 private String argumentMessage = null;
51 * Instantiates the policy xacml pdp service.
53 * @param args the command line arguments
55 public Main(final String[] args) {
56 final String argumentString = Arrays.toString(args);
57 LOGGER.info("Starting policy xacml pdp service with arguments - {}", argumentString);
59 // Check the arguments
60 final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
62 // The arguments return a string if there is a message to print and we should exit
63 argumentMessage = arguments.parse(args);
64 if (argumentMessage != null) {
65 LOGGER.info(argumentMessage);
69 // Validate that the arguments are sane
71 } catch (final PolicyXacmlPdpException e) {
72 LOGGER.error("start of policy xacml pdp service failed", e);
76 // Read the parameters
78 parameterGroup = new XacmlPdpParameterHandler().getParameters(arguments);
79 } catch (final Exception e) {
80 LOGGER.error("start of policy xacml pdp service failed", e);
84 // Read the properties
85 Properties props = new Properties();
87 String propFile = arguments.getFullPropertyFilePath();
88 try (FileInputStream stream = new FileInputStream(propFile)) {
91 } catch (final Exception e) {
92 LOGGER.error("start of xacml pdp service failed", e);
96 // Now, create the activator for the policy xacml pdp service
97 activator = new XacmlPdpActivator(parameterGroup, props);
99 // Start the activator
102 } catch (final RuntimeException e) {
103 LOGGER.error("start of policy xacml pdp service failed, used parameters are " + Arrays.toString(args), e);
107 // Add a shutdown hook to shut everything down in an orderly manner
108 Runtime.getRuntime().addShutdownHook(new PolicyXacmlPdpShutdownHookClass());
109 LOGGER.info("Started policy xacml pdp service");
113 * Get the parameters specified in JSON.
115 * @return the parameters
117 public XacmlPdpParameterGroup getParameters() {
118 return parameterGroup;
122 * Get the argumentMessage string.
124 * @return the argumentMessage
126 public String getArgumentMessage() {
127 return argumentMessage;
131 * Shut down Execution.
133 * @throws PolicyXacmlPdpException on shutdown errors
135 public void shutdown() {
136 // clear the parameterGroup variable
137 parameterGroup = null;
139 // clear the xacml pdp activator
140 if (activator != null) {
146 * The Class PolicyXacmlPdpShutdownHookClass terminates the policy xacml pdp service when its run
149 private class PolicyXacmlPdpShutdownHookClass extends Thread {
153 * @see java.lang.Runnable#run()
157 // Shutdown the policy xacml pdp service and wait for everything to stop
165 * @param args the arguments
167 public static void main(final String[] args) {