2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
5 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pdpx.main.startstop;
25 import java.util.Arrays;
27 import org.onap.policy.common.utils.resources.MessageConstants;
28 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
29 import org.onap.policy.pdpx.main.PolicyXacmlPdpRuntimeException;
30 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
31 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
37 * This class initiates ONAP Policy Framework policy xacml pdp.
41 private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
43 // The policy xacml pdp Activator that activates the policy xacml pdp service
44 private XacmlPdpActivator activator;
47 private String argumentMessage;
50 * Instantiates the policy xacml pdp service.
52 * @param args the command line arguments
53 * @throws PolicyXacmlPdpException if an error occurs
55 public Main(final String[] args) throws PolicyXacmlPdpException {
56 final var argumentString = Arrays.toString(args);
57 LOGGER.info("Starting policy xacml pdp service with arguments - {}", argumentString);
59 // Check the arguments
60 final var 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
72 // Read the parameters
73 XacmlPdpParameterGroup parameterGroup = new XacmlPdpParameterHandler().getParameters(arguments);
75 // Now, create the activator for the policy xacml pdp service
76 activator = new XacmlPdpActivator(parameterGroup);
77 XacmlPdpActivator.setCurrent(activator);
79 // Start the activator
82 // Add a shutdown hook to shut everything down in an orderly manner
83 Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
84 var successMsg = String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_XACML_PDP);
85 LOGGER.info(successMsg);
89 * Shut down Execution.
92 public synchronized void shutdown() {
93 // clear the xacml pdp activator
94 if (activator != null && activator.isAlive()) {
101 * The main method. The NOSONAR is for security hotspot for checking
102 * command line arguments. Since we use XacmlPdpCommandLineArguments
103 * and validate the arguments the NOSONAR is ok to clear it.
105 * @param args the arguments
107 public static void main(final String[] args) { //NOSONAR
110 } catch (RuntimeException | PolicyXacmlPdpException e) {
111 throw new PolicyXacmlPdpRuntimeException(
112 String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_XACML_PDP), e);