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;
26 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
27 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
28 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
34 * This class initiates ONAP Policy Framework policy xacml pdp.
38 private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
40 // The policy xacml pdp Activator that activates the policy xacml pdp service
41 private XacmlPdpActivator activator;
44 private String argumentMessage = null;
47 * Instantiates the policy xacml pdp service.
49 * @param args the command line arguments
50 * @throws PolicyXacmlPdpException if an error occurs
52 public Main(final String[] args) throws PolicyXacmlPdpException {
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
69 // Read the parameters
70 XacmlPdpParameterGroup parameterGroup = new XacmlPdpParameterHandler().getParameters(arguments);
72 // Now, create the activator for the policy xacml pdp service
73 activator = new XacmlPdpActivator(parameterGroup);
74 XacmlPdpActivator.setCurrent(activator);
76 // Start the activator
79 // Add a shutdown hook to shut everything down in an orderly manner
80 Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
81 LOGGER.info("Started policy xacml pdp service");
85 * Shut down Execution.
87 * @throws PolicyXacmlPdpException on shutdown errors
89 public synchronized void shutdown() {
90 // clear the xacml pdp activator
91 if (activator != null && activator.isAlive()) {
100 * @param args the arguments
102 public static void main(final String[] args) {
105 } catch (RuntimeException | PolicyXacmlPdpException e) {
106 LOGGER.error("start of policy xacml pdp service failed", e);