diff options
author | ramverma <ram.krishna.verma@ericsson.com> | 2018-08-13 17:19:09 +0100 |
---|---|---|
committer | ramverma <ram.krishna.verma@ericsson.com> | 2018-08-15 16:20:15 +0100 |
commit | 046b5040ce97e5faf59f3f302331bd9da6e80d02 (patch) | |
tree | 3c06aaef38565040e7cc8463a8d3b7b1a81bf4c6 /forwarding/src | |
parent | 635cde469ace4c7d60ba87bc0f9e4b26db59a1d1 (diff) |
Adding code for bootstrapping policy distribution
* Code changes for initializing handlers & related plugins from
configuration parameter JSON file.
* Using common parameter service for refering parameters at multiple
places.
* Moved related parameters classes from "main" to "reception" to avoid maven
cyclic dependency errors.
* Added test cases for new code chnages. The test coverage is around
95%.
* Changed logging from slf4j to common-logging.
Change-Id: Ifb77cfaa6e6472d43295a7c41a49ddd657c0e2c2
Issue-ID: POLICY-1035
Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'forwarding/src')
-rw-r--r-- | forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java b/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java new file mode 100644 index 00000000..3bde5009 --- /dev/null +++ b/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java @@ -0,0 +1,97 @@ +/*- + * ============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.forwarding.parameters; + +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ValidationStatus; + +/** + * Class to hold all the policy forwarder parameters. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class PolicyForwarderParameters implements ParameterGroup { + private String forwarderType; + private String forwarderClassName; + + /** + * Constructor for instantiating PolicyForwarderParameters. + * + * @param forwarderType the policy forwarder type + * @param forwarderClassName the policy forwarder class name + */ + public PolicyForwarderParameters(final String forwarderType, final String forwarderClassName) { + this.forwarderType = forwarderType; + this.forwarderClassName = forwarderClassName; + } + + /** + * Return the forwarderType of this PolicyForwarderParameters instance. + * + * @return the forwarderType + */ + public String getForwarderType() { + return forwarderType; + } + + /** + * Return the forwarderClassName of this PolicyForwarderParameters instance. + * + * @return the forwarderClassName + */ + public String getForwarderClassName() { + return forwarderClassName; + } + + @Override + public String getName() { + return null; + } + + /** + * Validate the policy forwarder parameters. + * + */ + @Override + public GroupValidationResult validate() { + final GroupValidationResult validationResult = new GroupValidationResult(this); + if (forwarderType == null || forwarderType.trim().length() == 0) { + validationResult.setResult("forwarderType", ValidationStatus.INVALID, "must be a non-blank string"); + } + if (forwarderClassName == null || forwarderClassName.trim().length() == 0) { + validationResult.setResult("forwarderClassName", ValidationStatus.INVALID, + "must be a non-blank string containing full class name of the forwarder"); + } else { + validatePolicyForwarderClass(validationResult); + } + return validationResult; + } + + private void validatePolicyForwarderClass(final GroupValidationResult validationResult) { + try { + Class.forName(forwarderClassName); + } catch (final ClassNotFoundException e) { + validationResult.setResult("forwarderClassName", ValidationStatus.INVALID, + "policy forwarder class not found in classpath"); + } + } +} |