summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-07-30 16:58:54 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-07-31 15:35:49 +0100
commit37d8ade146096bf343f494163a528f75b2161095 (patch)
tree695aa4b86a35bf02c824c56357dd31f0686c21b5
parentce63c402be2f4c5e437eefa1cbe327c3a9d0caad (diff)
Add start and parameter handling
Add startup code, command line parsing, service start, and parameter handling for the policy distribution service. Issue-ID: POLICY-922 Change-Id: Ie664aba6541304cf9b635541e9688c681b24952d Signed-off-by: liamfallon <liam.fallon@ericsson.com>
-rw-r--r--.gitignore1
-rw-r--r--forwarding/forwarding-pap/forwarding-pap-engine/pom.xml35
-rw-r--r--forwarding/forwarding-pap/forwarding-pap-standalone/pom.xml35
-rw-r--r--forwarding/forwarding-pap/pom.xml40
-rw-r--r--forwarding/pom.xml6
-rw-r--r--main/main-lifecycle/pom.xml35
-rw-r--r--main/main-parameters/pom.xml35
-rw-r--r--main/main-startstop/pom.xml35
-rw-r--r--main/pom.xml49
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionException.java47
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionRuntimeException.java47
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java64
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java82
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java79
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionCommandLineArguments.java243
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java145
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/startstop/package-info.java25
-rw-r--r--main/src/main/resources/version.txt4
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/TestExceptions.java39
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java46
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java127
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java31
-rw-r--r--main/src/test/resources/parameters/BadParameters.json3
-rw-r--r--main/src/test/resources/parameters/EmptyParameters.json0
-rw-r--r--main/src/test/resources/parameters/InvalidParameters.json3
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json3
-rw-r--r--main/src/test/resources/parameters/NoParameters.json2
-rw-r--r--plugins/pom.xml (renamed from main/main-rest/pom.xml)13
-rw-r--r--pom.xml27
-rw-r--r--reception/pom.xml7
-rw-r--r--reception/reception-decoding/pom.xml41
-rw-r--r--reception/reception-decoding/reception-decoding-pdpa/pom.xml35
-rw-r--r--reception/reception-decoding/reception-decoding-pdpd/pom.xml35
-rw-r--r--reception/reception-decoding/reception-decoding-pdpx/pom.xml35
-rw-r--r--reception/reception-handling/pom.xml39
-rw-r--r--reception/reception-handling/reception-handling-sdc/pom.xml35
36 files changed, 1065 insertions, 463 deletions
diff --git a/.gitignore b/.gitignore
index 236c0b3b..74887b48 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
.classpath
.jupiter
.pydevproject
+.checkstyle
target
.metadata/
/bin/
diff --git a/forwarding/forwarding-pap/forwarding-pap-engine/pom.xml b/forwarding/forwarding-pap/forwarding-pap-engine/pom.xml
deleted file mode 100644
index 97bb31d7..00000000
--- a/forwarding/forwarding-pap/forwarding-pap-engine/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.forwarding.forwarding-pap</groupId>
- <artifactId>forwarding-pap</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>forwarding-pap-engine</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module carries out forwarding of policies to PAPs embedded in a policy engine.</description>
-
- <dependencies>
- </dependencies>
-</project>
diff --git a/forwarding/forwarding-pap/forwarding-pap-standalone/pom.xml b/forwarding/forwarding-pap/forwarding-pap-standalone/pom.xml
deleted file mode 100644
index ea9f9d73..00000000
--- a/forwarding/forwarding-pap/forwarding-pap-standalone/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.forwarding.forwarding-pap</groupId>
- <artifactId>forwarding-pap</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>forwarding-pap-standalone</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module carries out forwarding of policies to standalone PAPs.</description>
-
- <dependencies>
- </dependencies>
-</project>
diff --git a/forwarding/forwarding-pap/pom.xml b/forwarding/forwarding-pap/pom.xml
deleted file mode 100644
index 076cc81f..00000000
--- a/forwarding/forwarding-pap/pom.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.forwarding</groupId>
- <artifactId>forwarding</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.policy.distribution.forwarding.forwarding-pap</groupId>
- <artifactId>forwarding-pap</artifactId>
- <packaging>pom</packaging>
-
- <name>${project.artifactId}</name>
- <description>The module of Policy Distribution that handles forwarding of policies to PAPs (Policy Administration Points).</description>
-
- <modules>
- <module>forwarding-pap-engine</module>
- <module>forwarding-pap-standalone</module>
- </modules>
-</project>
diff --git a/forwarding/pom.xml b/forwarding/pom.xml
index de7e0036..741d6772 100644
--- a/forwarding/pom.xml
+++ b/forwarding/pom.xml
@@ -26,14 +26,8 @@
<version>2.0.0-SNAPSHOT</version>
</parent>
- <groupId>org.onap.policy.distribution.forwarding</groupId>
<artifactId>forwarding</artifactId>
- <packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>The module of Policy Distribution that forwards policies to other components.</description>
-
- <modules>
- <module>forwarding-pap</module>
- </modules>
</project>
diff --git a/main/main-lifecycle/pom.xml b/main/main-lifecycle/pom.xml
deleted file mode 100644
index 14f929bd..00000000
--- a/main/main-lifecycle/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.main</groupId>
- <artifactId>main</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>main-lifecycle</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module contains the lifecycle management for policy distribution</description>
-
- <dependencies>
- </dependencies>
-</project>
diff --git a/main/main-parameters/pom.xml b/main/main-parameters/pom.xml
deleted file mode 100644
index 32955b9a..00000000
--- a/main/main-parameters/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.main</groupId>
- <artifactId>main</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>main-parameters</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module carries out parameter handling for policy distribution</description>
-
- <dependencies>
- </dependencies>
-</project>
diff --git a/main/main-startstop/pom.xml b/main/main-startstop/pom.xml
deleted file mode 100644
index 2700a689..00000000
--- a/main/main-startstop/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.main</groupId>
- <artifactId>main</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>main-startstop</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module starts and stops policy distribution</description>
-
- <dependencies>
- </dependencies>
-</project>
diff --git a/main/pom.xml b/main/pom.xml
index 934d57ca..1084f937 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -26,17 +26,50 @@
<version>2.0.0-SNAPSHOT</version>
</parent>
- <groupId>org.onap.policy.distribution.main</groupId>
<artifactId>main</artifactId>
- <packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>The main module of Policy Distribution that handles startup, lifecycle management, and parameters.</description>
- <modules>
- <module>main-startstop</module>
- <module>main-parameters</module>
- <module>main-lifecycle</module>
- <module>main-rest</module>
- </modules>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>common-parameters</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <!-- Output the version of the distribution service -->
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/version.txt</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>false</filtering>
+ <excludes>
+ <exclude>**/version.txt</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ </build>
+
</project>
diff --git a/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionException.java b/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionException.java
new file mode 100644
index 00000000..807fd936
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionException.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main;
+
+/**
+ * This exception will be called if an error occurs in policy distribution service.
+ */
+public class PolicyDistributionException extends Exception {
+ private static final long serialVersionUID = -8507246953751956974L;
+
+ /**
+ * Instantiates a new policy distribution exception with a message.
+ *
+ * @param message the message
+ */
+ public PolicyDistributionException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Instantiates a new policy distribution exception with a message and a caused by exception.
+ *
+ * @param message the message
+ * @param e the exception that caused this exception to be thrown
+ */
+ public PolicyDistributionException(final String message, final Exception e) {
+ super(message, e);
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionRuntimeException.java b/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionRuntimeException.java
new file mode 100644
index 00000000..5999e680
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionRuntimeException.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main;
+
+/**
+ * This runtime exception will be called if a runtime error occurs when using policy distribution.
+ */
+public class PolicyDistributionRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = -8507246953751956974L;
+
+ /**
+ * Instantiates a new policy distribution runtime exception with a message.
+ *
+ * @param message the message
+ */
+ public PolicyDistributionRuntimeException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Instantiates a new policy distribution runtime exception with a message and a caused by exception.
+ *
+ * @param message the message
+ * @param e the exception that caused this exception to be thrown
+ */
+ public PolicyDistributionRuntimeException(final String message, final Exception e) {
+ super(message, e);
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java
new file mode 100644
index 00000000..f4180e01
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.parameters;
+
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
+
+public class DistributionParameterGroup implements ParameterGroup {
+ private String name;
+
+ /**
+ * Create the distribution parameter group.
+ *
+ * @param name the parameter group name
+ */
+ public DistributionParameterGroup(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Return the name of this parameter group instance
+ *
+ * @return name the parameter group name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Validate the parameter group
+ *
+ * @return the result of the validation
+ */
+ @Override
+ public GroupValidationResult validate() {
+ GroupValidationResult validationResult = new GroupValidationResult(this);
+
+ if (name == null || name.trim().length() == 0) {
+ validationResult.setResult("name", ValidationStatus.INVALID, "must be a non-blank string");
+ }
+
+ return validationResult;
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java
new file mode 100644
index 00000000..98d302c4
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.parameters;
+
+import java.io.FileReader;
+
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * This class handles reading, parsing and validating of policy distribution parameters from JSON files.
+ */
+public class DistributionParameterHandler {
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(DistributionParameterHandler.class);
+
+ /**
+ * Read the parameters from the parameter file.
+ *
+ * @param arguments the arguments passed to policy distribution
+ * @return the parameters read from the configuration file
+ * @throws PolicyDistributionException on parameter exceptions
+ */
+ public DistributionParameterGroup getParameters(final DistributionCommandLineArguments arguments) throws PolicyDistributionException {
+ DistributionParameterGroup distributionParameterGroup = null;
+
+ // Read the parameters
+ try {
+ // Read the parameters from JSON using Gson
+ final Gson gson = new GsonBuilder().create();
+ distributionParameterGroup = gson.fromJson(new FileReader(arguments.getFullConfigurationFilePath()), DistributionParameterGroup.class);
+ } catch (final Exception e) {
+ final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath()
+ + "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage();
+ LOGGER.error(errorMessage, e);
+ throw new PolicyDistributionException(errorMessage, e);
+ }
+
+ // The JSON processing returns null if there is an empty file
+ if (distributionParameterGroup == null) {
+ final String errorMessage = "no parameters found in \"" + arguments.getConfigurationFilePath() + "\"";
+ LOGGER.error(errorMessage);
+ throw new PolicyDistributionException(errorMessage);
+ }
+
+ // validate the parameters
+ final GroupValidationResult validationResult = distributionParameterGroup.validate();
+ if (!validationResult.isValid()) {
+ String returnMessage =
+ "validation error(s) on parameters from \"" + arguments.getConfigurationFilePath() + "\"\n";
+ returnMessage += validationResult.getResult();
+
+ LOGGER.error(returnMessage);
+ throw new PolicyDistributionException(returnMessage);
+ }
+
+ return distributionParameterGroup;
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java
new file mode 100644
index 00000000..3ac13389
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.startstop;
+
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.parameters.DistributionParameterGroup;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class wraps a distributor so that it can be activated as a complete service together with
+ * all its distribution and forwarding handlers.
+ */
+public class DistributionActivator {
+ // The logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(DistributionActivator.class);
+
+ // The parameters of this policy distribution activator
+ private final DistributionParameterGroup distributionParameterGroup;
+
+ /**
+ * Instantiate the activator for policy distribution as a complete service.
+ *
+ * @param distributionParameterGroup the parameters for the distribution service
+ */
+ public DistributionActivator(final DistributionParameterGroup distributionParameterGroup) {
+ this.distributionParameterGroup = distributionParameterGroup;
+ }
+
+ /**
+ * Initialize distribution as a complete service.
+ *
+ * @throws PolicyDistributionException on errors in initializing the service
+ */
+ public void initialize() throws PolicyDistributionException {
+ LOGGER.debug("Policy distribution starting as a service . . .");
+
+ // Real code for starting up the handlers goes here
+
+ LOGGER.debug("Policy distribution started as a service");
+ }
+
+ /**
+ * Terminate policy distribution.
+ *
+ * @throws PolicyDistributionException on termination errors
+ */
+ public void terminate() throws PolicyDistributionException {
+ // Shut down all handlers
+
+ }
+
+ /**
+ * Get the parameters used by the activator.
+ *
+ * @return the parameters of the activator
+ */
+ public DistributionParameterGroup getParameterGroup() {
+ return distributionParameterGroup;
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionCommandLineArguments.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionCommandLineArguments.java
new file mode 100644
index 00000000..7bd1d06d
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionCommandLineArguments.java
@@ -0,0 +1,243 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.startstop;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URL;
+import java.util.Arrays;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
+
+/**
+ * This class reads and handles command line parameters for the policy distribution main program.
+ */
+public class DistributionCommandLineArguments {
+ private static final String FILE_MESSAGE_PREAMBLE = " file \"";
+ private static final int HELP_LINE_LENGTH = 120;
+
+ // Apache Commons CLI options
+ private final Options options;
+
+ // The command line options
+ private String configurationFilePath = null;
+
+ /**
+ * Construct the options for the CLI editor.
+ */
+ public DistributionCommandLineArguments() {
+ //@formatter:off
+ options = new Options();
+ options.addOption(Option.builder("h")
+ .longOpt("help")
+ .desc("outputs the usage of this command")
+ .required(false)
+ .type(Boolean.class)
+ .build());
+ options.addOption(Option.builder("v")
+ .longOpt("version")
+ .desc("outputs the version of policy distribution")
+ .required(false)
+ .type(Boolean.class)
+ .build());
+ options.addOption(Option.builder("c")
+ .longOpt("config-file")
+ .desc("the full path to the configuration file to use, the configuration file must be a Json file containing the policy distribution parameters")
+ .hasArg()
+ .argName("CONFIG_FILE")
+ .required(false)
+ .type(String.class)
+ .build());
+ //@formatter:on
+ }
+
+ /**
+ * Construct the options for the CLI editor and parse in the given arguments.
+ *
+ * @param args The command line arguments
+ */
+ public DistributionCommandLineArguments(final String[] args) {
+ // Set up the options with the default constructor
+ this();
+
+ // Parse the arguments
+ try {
+ parse(args);
+ } catch (final PolicyDistributionException e) {
+ throw new PolicyDistributionRuntimeException("parse error on policy distribution parameters", e);
+ }
+ }
+
+ /**
+ * Parse the command line options.
+ *
+ * @param args The command line arguments
+ * @return a string with a message for help and version, or null if there is no message
+ * @throws PolicyDistributionException on command argument errors
+ */
+ public String parse(final String[] args) throws PolicyDistributionException {
+ // Clear all our arguments
+ setConfigurationFilePath(null);
+
+ CommandLine commandLine = null;
+ try {
+ commandLine = new DefaultParser().parse(options, args);
+ } catch (final ParseException e) {
+ throw new PolicyDistributionException("invalid command line arguments specified : " + e.getMessage());
+ }
+
+ // Arguments left over after Commons CLI does its stuff
+ final String[] remainingArgs = commandLine.getArgs();
+
+ if (remainingArgs.length > 0 && commandLine.hasOption('c') || remainingArgs.length > 0) {
+ throw new PolicyDistributionException("too many command line arguments specified : " + Arrays.toString(args));
+ }
+
+ if (remainingArgs.length == 1) {
+ configurationFilePath = remainingArgs[0];
+ }
+
+ if (commandLine.hasOption('h')) {
+ return help(Main.class.getCanonicalName());
+ }
+
+ if (commandLine.hasOption('v')) {
+ return version();
+ }
+
+ if (commandLine.hasOption('c')) {
+ setConfigurationFilePath(commandLine.getOptionValue('c'));
+ }
+
+ return null;
+ }
+
+ /**
+ * Validate the command line options.
+ *
+ * @throws PolicyDistributionException on command argument validation errors
+ */
+ public void validate() throws PolicyDistributionException {
+ validateReadableFile("policy distribution configuration", configurationFilePath);
+ }
+
+ /**
+ * Print version information for policy distribution.
+ *
+ * @return the version string
+ */
+ public String version() {
+ return ResourceUtils.getResourceAsString("version.txt");
+ }
+
+ /**
+ * Print help information for policy distribution.
+ *
+ * @param mainClassName the main class name
+ * @return the help string
+ */
+ public String help(final String mainClassName) {
+ final HelpFormatter helpFormatter = new HelpFormatter();
+ final StringWriter stringWriter = new StringWriter();
+ final PrintWriter stringPW = new PrintWriter(stringWriter);
+
+ helpFormatter.printHelp(stringPW, HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, 0, 0,
+ "");
+
+ return stringWriter.toString();
+ }
+
+ /**
+ * Gets the configuration file path.
+ *
+ * @return the configuration file path
+ */
+ public String getConfigurationFilePath() {
+ return configurationFilePath;
+ }
+
+ /**
+ * Gets the full expanded configuration file path.
+ *
+ * @return the configuration file path
+ */
+ public String getFullConfigurationFilePath() {
+ return ResourceUtils.getFilePath4Resource(getConfigurationFilePath());
+ }
+
+ /**
+ * Sets the configuration file path.
+ *
+ * @param configurationFilePath the configuration file path
+ */
+ public void setConfigurationFilePath(final String configurationFilePath) {
+ this.configurationFilePath = configurationFilePath;
+
+ }
+
+ /**
+ * Check set configuration file path.
+ *
+ * @return true, if check set configuration file path
+ */
+ public boolean checkSetConfigurationFilePath() {
+ return configurationFilePath != null && configurationFilePath.length() > 0;
+ }
+
+ /**
+ * Validate readable file.
+ *
+ * @param fileTag the file tag
+ * @param fileName the file name
+ * @throws PolicyDistributionException on the file name passed as a parameter
+ */
+ private void validateReadableFile(final String fileTag, final String fileName) throws PolicyDistributionException {
+ if (fileName == null || fileName.length() == 0) {
+ throw new PolicyDistributionException(fileTag + " file was not specified as an argument");
+ }
+
+ // The file name refers to a resource on the local file system
+ final URL fileURL = ResourceUtils.getUrl4Resource(fileName);
+ if (fileURL == null) {
+ throw new PolicyDistributionException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist");
+ }
+
+ final File theFile = new File(fileURL.getPath());
+ if (!theFile.exists()) {
+ throw new PolicyDistributionException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist");
+ }
+ if (!theFile.isFile()) {
+ throw new PolicyDistributionException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is not a normal file");
+ }
+ if (!theFile.canRead()) {
+ throw new PolicyDistributionException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is ureadable");
+ }
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java
new file mode 100644
index 00000000..019b7786
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java
@@ -0,0 +1,145 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.startstop;
+
+import java.util.Arrays;
+
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.parameters.DistributionParameterGroup;
+import org.onap.policy.distribution.main.parameters.DistributionParameterHandler;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class initiates ONAP Policy Framework policy distribution.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class Main {
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(Main.class);
+
+ // The policy distribution Activator that activates the policy distribution service
+ private DistributionActivator activator;
+
+ // The parameters read in from JSON
+ private DistributionParameterGroup parameterGroup;
+
+ /**
+ * Instantiates the policy distribution service.
+ *
+ * @param args the command line arguments
+ */
+ public Main(final String[] args) {
+ String argumentString = Arrays.toString(args);
+ LOGGER.info("Starting policy distribution service with arguments {} . . .", argumentString);
+
+ // Check the arguments
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ try {
+ // The arguments return a string if there is a message to print and we should exit
+ final String argumentMessage = arguments.parse(args);
+ if (argumentMessage != null) {
+ LOGGER.info(argumentMessage);
+ return;
+ }
+
+ // Validate that the arguments are sane
+ arguments.validate();
+ } catch (final PolicyDistributionException e) {
+ LOGGER.error("start of policy distribution service failed", e);
+ return;
+ }
+
+ // Read the parameters
+ try {
+ parameterGroup = new DistributionParameterHandler().getParameters(arguments);
+ } catch (final Exception e) {
+ LOGGER.error("start of policy distribution service failed", e);
+ return;
+ }
+
+ // Now, create the activator for the policy distribution service
+ activator = new DistributionActivator(parameterGroup);
+
+ // Start the activator
+ try {
+ activator.initialize();
+ } catch (final PolicyDistributionException e) {
+ LOGGER.error("start of policy distribution service failed, used parameters are " + Arrays.toString(args),
+ e);
+ return;
+ }
+
+ // Add a shutdown hook to shut everything down in an orderly manner
+ Runtime.getRuntime().addShutdownHook(new PolicyDistributionShutdownHookClass());
+ LOGGER.exit("Started policy distribution service");
+ }
+
+ /**
+ * Get the parameters specified in JSON.
+ *
+ * @return the parameters
+ */
+ public DistributionParameterGroup getParameters() {
+ return parameterGroup;
+ }
+
+ /**
+ * Shut down Execution.
+ *
+ * @throws PolicyDistributionException on shutdown errors
+ */
+ public void shutdown() throws PolicyDistributionException {
+ if (activator != null) {
+ activator.terminate();
+ }
+ }
+
+ /**
+ * The Class PolicyDistributionShutdownHookClass terminates the policy distribution service when its run method is
+ * called.
+ */
+ private class PolicyDistributionShutdownHookClass extends Thread {
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ try {
+ // Shutdown the policy distribution service and wait for everything to stop
+ activator.terminate();
+ } catch (final PolicyDistributionException e) {
+ LOGGER.warn("error occured during shut down of the policy distribution service", e);
+ }
+ }
+ }
+
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ */
+ public static void main(final String[] args) {
+ new Main(args);
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/package-info.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/package-info.java
new file mode 100644
index 00000000..19b9f951
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/package-info.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ * Provides ONAP policy distribution as a complete service together with all its reception and forwarding support.
+ * A main method to allow ONAP policy distribution execution from the command line is also provided.
+ */
+package org.onap.policy.distribution.main.startstop;
diff --git a/main/src/main/resources/version.txt b/main/src/main/resources/version.txt
new file mode 100644
index 00000000..c617841e
--- /dev/null
+++ b/main/src/main/resources/version.txt
@@ -0,0 +1,4 @@
+ONAP Policy Framework Distribution Service
+Version: ${project.version}
+Built (UTC): ${maven.build.timestamp}
+ONAP https://wiki.onap.org \ No newline at end of file
diff --git a/main/src/test/java/org/onap/policy/distribution/main/TestExceptions.java b/main/src/test/java/org/onap/policy/distribution/main/TestExceptions.java
new file mode 100644
index 00000000..b3140978
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/TestExceptions.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class TestExceptions {
+
+ @Test
+ public void test() {
+ assertNotNull(new PolicyDistributionException("Message"));
+ assertNotNull(new PolicyDistributionException("Message", new IOException()));
+
+ assertNotNull(new PolicyDistributionRuntimeException("Message"));
+ assertNotNull(new PolicyDistributionRuntimeException("Message", new IOException()));
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java
new file mode 100644
index 00000000..bf553918
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class TestParameterGroup {
+
+ @Test
+ public void testParameterGroup() {
+ DistributionParameterGroup parameterGroup = new DistributionParameterGroup("groupName");
+ assertEquals("groupName", parameterGroup.getName());
+ assertTrue(parameterGroup.isValid());
+
+ parameterGroup = new DistributionParameterGroup(null);
+ assertNull(parameterGroup.getName());
+ assertFalse(parameterGroup.isValid());
+
+ parameterGroup = new DistributionParameterGroup("");
+ assertEquals("", parameterGroup.getName());
+ assertFalse(parameterGroup.isValid());
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java
new file mode 100644
index 00000000..5b938988
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
+
+public class TestParameterHandler {
+ @Test
+ public void testParameterHandlerNoParameterFile() throws PolicyDistributionException {
+ String[] noArgumentString = { "-c", "parameters/NoParameterFile.json" };
+
+ DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("error reading parameters from \"parameters/NoParameterFile.json\"\n"
+ + "(FileNotFoundException):parameters/NoParameterFile.json (No such file or directory)",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerEmptyParameters() throws PolicyDistributionException {
+ String[] emptyArgumentString = { "-c", "parameters/EmptyParameters.json" };
+
+ DistributionCommandLineArguments emptyArguments = new DistributionCommandLineArguments();
+ emptyArguments.parse(emptyArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(emptyArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerBadParameters() throws PolicyDistributionException {
+ String[] badArgumentString = { "-c", "parameters/BadParameters.json" };
+
+ DistributionCommandLineArguments badArguments = new DistributionCommandLineArguments();
+ badArguments.parse(badArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(badArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("error reading parameters from \"parameters/BadParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerInvalidParameters() throws PolicyDistributionException {
+ String[] invalidArgumentString = { "-c", "parameters/InvalidParameters.json" };
+
+ DistributionCommandLineArguments invalidArguments = new DistributionCommandLineArguments();
+ invalidArguments.parse(invalidArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(invalidArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("error reading parameters from \"parameters/InvalidParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerNoParameters() throws PolicyDistributionException {
+ String[] noArgumentString = { "-c", "parameters/NoParameters.json" };
+
+ DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("validation error(s) on parameters from \"parameters/NoParameters.json\"\n"
+ + "parameter group \"null\" type "
+ + "\"org.onap.policy.distribution.main.parameters.DistributionParameterGroup\""
+ + " INVALID, parameter group has status INVALID\n"
+ + " field \"name\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string\n",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerMinumumParameters() throws PolicyDistributionException {
+ String[] minArgumentString = { "-c", "parameters/MinimumParameters.json" };
+
+ DistributionCommandLineArguments minArguments = new DistributionCommandLineArguments();
+ minArguments.parse(minArgumentString);
+
+ DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(minArguments);
+ assertEquals("nameFromFile", parGroup.getName());
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
new file mode 100644
index 00000000..781a2ab8
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.startstop;
+
+import org.junit.Test;
+
+public class TestMain {
+
+ @Test
+ public void testMain() {
+ Main.main(null);
+ }
+}
diff --git a/main/src/test/resources/parameters/BadParameters.json b/main/src/test/resources/parameters/BadParameters.json
new file mode 100644
index 00000000..de2040cc
--- /dev/null
+++ b/main/src/test/resources/parameters/BadParameters.json
@@ -0,0 +1,3 @@
+{
+ "name" : []
+} \ No newline at end of file
diff --git a/main/src/test/resources/parameters/EmptyParameters.json b/main/src/test/resources/parameters/EmptyParameters.json
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/main/src/test/resources/parameters/EmptyParameters.json
diff --git a/main/src/test/resources/parameters/InvalidParameters.json b/main/src/test/resources/parameters/InvalidParameters.json
new file mode 100644
index 00000000..de2040cc
--- /dev/null
+++ b/main/src/test/resources/parameters/InvalidParameters.json
@@ -0,0 +1,3 @@
+{
+ "name" : []
+} \ No newline at end of file
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
new file mode 100644
index 00000000..02b2afad
--- /dev/null
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -0,0 +1,3 @@
+{
+ "name": "nameFromFile"
+} \ No newline at end of file
diff --git a/main/src/test/resources/parameters/NoParameters.json b/main/src/test/resources/parameters/NoParameters.json
new file mode 100644
index 00000000..7a73a41b
--- /dev/null
+++ b/main/src/test/resources/parameters/NoParameters.json
@@ -0,0 +1,2 @@
+{
+} \ No newline at end of file
diff --git a/main/main-rest/pom.xml b/plugins/pom.xml
index c7dd8561..0776f2fb 100644
--- a/main/main-rest/pom.xml
+++ b/plugins/pom.xml
@@ -21,15 +21,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.onap.policy.distribution.main</groupId>
- <artifactId>main</artifactId>
+ <groupId>org.onap.policy.distribution</groupId>
+ <artifactId>policy-distribution</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
- <artifactId>main-rest</artifactId>
+ <artifactId>plugins</artifactId>
+
<name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module contains common REST handling for policy distribution</description>
-
- <dependencies>
- </dependencies>
+ <description>The module of Policy Distribution that holds plugins for custom policy reception and forwarding.</description>
+ <packaging>pom</packaging>
</project>
diff --git a/pom.xml b/pom.xml
index 116d7436..94ebc28b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,6 +26,7 @@
<groupId>org.onap.policy.parent</groupId>
<artifactId>integration</artifactId>
<version>2.0.0-SNAPSHOT</version>
+ <relativePath/>
</parent>
<groupId>org.onap.policy.distribution</groupId>
@@ -40,8 +41,34 @@
<module>main</module>
<module>reception</module>
<module>forwarding</module>
+ <module>plugins</module>
</modules>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-ext</artifactId>
+ <version>1.8.0-beta2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ </dependencies>
+
<distributionManagement>
<site>
<id>ecomp-site</id>
diff --git a/reception/pom.xml b/reception/pom.xml
index 2b275857..4fdd1f38 100644
--- a/reception/pom.xml
+++ b/reception/pom.xml
@@ -26,15 +26,8 @@
<version>2.0.0-SNAPSHOT</version>
</parent>
- <groupId>org.onap.policy.distribution.reception</groupId>
<artifactId>reception</artifactId>
- <packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>The module of Policy Distribution that handles reception of policies from other systems.</description>
-
- <modules>
- <module>reception-handling</module>
- <module>reception-decoding</module>
- </modules>
</project>
diff --git a/reception/reception-decoding/pom.xml b/reception/reception-decoding/pom.xml
deleted file mode 100644
index 1906f47d..00000000
--- a/reception/reception-decoding/pom.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.reception</groupId>
- <artifactId>reception</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.policy.distribution.reception.reception-decoding</groupId>
- <artifactId>reception-decoding</artifactId>
- <packaging>pom</packaging>
-
- <name>${project.artifactId}</name>
- <description>The module of Policy Distribution that handles decoding of policies of various types.</description>
-
- <modules>
- <module>reception-decoding-pdpx</module>
- <module>reception-decoding-pdpd</module>
- <module>reception-decoding-pdpa</module>
- </modules>
-</project>
diff --git a/reception/reception-decoding/reception-decoding-pdpa/pom.xml b/reception/reception-decoding/reception-decoding-pdpa/pom.xml
deleted file mode 100644
index 462645b4..00000000
--- a/reception/reception-decoding/reception-decoding-pdpa/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.reception.reception-decoding</groupId>
- <artifactId>reception-decoding</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>reception-decoding-pdpa</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module carries out decoding of APEX policies</description>
-
- <dependencies>
- </dependencies>
-</project>
diff --git a/reception/reception-decoding/reception-decoding-pdpd/pom.xml b/reception/reception-decoding/reception-decoding-pdpd/pom.xml
deleted file mode 100644
index 14c07b28..00000000
--- a/reception/reception-decoding/reception-decoding-pdpd/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.reception.reception-decoding</groupId>
- <artifactId>reception-decoding</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>reception-decoding-pdpd</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module carries out decoding of Drools policies</description>
-
- <dependencies>
- </dependencies>
-</project>
diff --git a/reception/reception-decoding/reception-decoding-pdpx/pom.xml b/reception/reception-decoding/reception-decoding-pdpx/pom.xml
deleted file mode 100644
index 362f1b3d..00000000
--- a/reception/reception-decoding/reception-decoding-pdpx/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.reception.reception-decoding</groupId>
- <artifactId>reception-decoding</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>reception-decoding-pdpx</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module carries out decoding of XACML policies</description>
-
- <dependencies>
- </dependencies>
-</project>
diff --git a/reception/reception-handling/pom.xml b/reception/reception-handling/pom.xml
deleted file mode 100644
index 13c4b8b2..00000000
--- a/reception/reception-handling/pom.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.reception</groupId>
- <artifactId>reception</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.policy.distribution.reception.reception-handling</groupId>
- <artifactId>reception-handling</artifactId>
- <packaging>pom</packaging>
-
- <name>${project.artifactId}</name>
- <description>The module of Policy Distribution that handles reception of policies from other systems.</description>
-
- <modules>
- <module>reception-handling-sdc</module>
- </modules>
-</project>
diff --git a/reception/reception-handling/reception-handling-sdc/pom.xml b/reception/reception-handling/reception-handling-sdc/pom.xml
deleted file mode 100644
index d4176333..00000000
--- a/reception/reception-handling/reception-handling-sdc/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.distribution.reception.reception-handling</groupId>
- <artifactId>reception-handling</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>reception-handling-sdc</artifactId>
- <name>${project.artifactId}</name>
- <description>[${project.parent.artifactId}] module handles the communication towards SDC for policy distribution</description>
-
- <dependencies>
- </dependencies>
-</project>