2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pdpx.main.startstop;
24 import java.util.Arrays;
25 import java.util.Properties;
27 import org.onap.policy.common.endpoints.utils.ParameterUtils;
28 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
29 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
30 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
36 * This class initiates ONAP Policy Framework policy xacml pdp.
40 private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
42 // The policy xacml pdp Activator that activates the policy xacml pdp service
43 private XacmlPdpActivator activator;
46 private String argumentMessage = null;
49 * Instantiates the policy xacml pdp service.
51 * @param args the command line arguments
52 * @throws PolicyXacmlPdpException if an error occurs
54 public Main(final String[] args) throws PolicyXacmlPdpException {
55 final String argumentString = Arrays.toString(args);
56 LOGGER.info("Starting policy xacml pdp service with arguments - {}", argumentString);
58 // Check the arguments
59 final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
61 // The arguments return a string if there is a message to print and we should exit
62 argumentMessage = arguments.parse(args);
63 if (argumentMessage != null) {
64 LOGGER.info(argumentMessage);
68 // Validate that the arguments are sane
71 // Read the parameters
72 XacmlPdpParameterGroup parameterGroup = new XacmlPdpParameterHandler().getParameters(arguments);
74 // Read the properties
75 Properties props = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup());
77 // Now, create the activator for the policy xacml pdp service
78 activator = new XacmlPdpActivator(parameterGroup, props);
79 XacmlPdpActivator.setCurrent(activator);
81 // Start the activator
84 // Add a shutdown hook to shut everything down in an orderly manner
85 Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
86 LOGGER.info("Started policy xacml pdp service");
90 * Shut down Execution.
92 * @throws PolicyXacmlPdpException on shutdown errors
94 public synchronized void shutdown() {
95 // clear the xacml pdp activator
96 if (activator != null && activator.isAlive()) {
105 * @param args the arguments
107 public static void main(final String[] args) {
110 } catch (RuntimeException | PolicyXacmlPdpException e) {
111 LOGGER.error("start of policy xacml pdp service failed", e);