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.util.Arrays;
24 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
25 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
26 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
32 * This class initiates ONAP Policy Framework policy xacml pdp.
36 private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
38 // The policy xacml pdp Activator that activates the policy xacml pdp service
39 private XacmlPdpActivator activator;
41 // The parameters read in from JSON
42 private XacmlPdpParameterGroup parameterGroup;
44 // The argument message for some args that return a message
45 private String argumentMessage = null;
48 * Instantiates the policy xacml pdp service.
50 * @param args the command line arguments
52 public Main(final String[] args) {
53 final String argumentString = Arrays.toString(args);
54 LOGGER.info("Starting policy xacml pdp service with arguments - {}", argumentString);
56 // Check the arguments
57 final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
59 // The arguments return a string if there is a message to print and we should exit
60 argumentMessage = arguments.parse(args);
61 if (argumentMessage != null) {
62 LOGGER.info(argumentMessage);
66 // Validate that the arguments are sane
68 } catch (final PolicyXacmlPdpException e) {
69 LOGGER.error("start of policy xacml pdp service failed", e);
73 // Read the parameters
75 parameterGroup = new XacmlPdpParameterHandler().getParameters(arguments);
76 } catch (final Exception e) {
77 LOGGER.error("start of policy xacml pdp service failed", e);
81 // Now, create the activator for the policy xacml pdp service
82 activator = new XacmlPdpActivator(parameterGroup);
84 // Start the activator
86 activator.initialize();
87 } catch (final PolicyXacmlPdpException e) {
88 LOGGER.error("start of policy xacml pdp service failed, used parameters are " + Arrays.toString(args), e);
92 // Add a shutdown hook to shut everything down in an orderly manner
93 Runtime.getRuntime().addShutdownHook(new PolicyXacmlPdpShutdownHookClass());
94 LOGGER.info("Started policy xacml pdp service");
98 * Get the parameters specified in JSON.
100 * @return the parameters
102 public XacmlPdpParameterGroup getParameters() {
103 return parameterGroup;
107 * Get the argumentMessage string.
109 * @return the argumentMessage
111 public String getArgumentMessage() {
112 return argumentMessage;
116 * Shut down Execution.
118 * @throws PolicyXacmlPdpException on shutdown errors
120 public void shutdown() throws PolicyXacmlPdpException {
121 // clear the parameterGroup variable
122 parameterGroup = null;
124 // clear the xacml pdp activator
125 if (activator != null) {
126 activator.terminate();
131 * The Class PolicyXacmlPdpShutdownHookClass terminates the policy xacml pdp service when its run
134 private class PolicyXacmlPdpShutdownHookClass extends Thread {
138 * @see java.lang.Runnable#run()
143 // Shutdown the policy xacml pdp service and wait for everything to stop
144 activator.terminate();
145 } catch (final PolicyXacmlPdpException e) {
146 LOGGER.warn("error occured during shut down of the policy xacml pdp service", e);
154 * @param args the arguments
156 public static void main(final String[] args) {