summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java151
1 files changed, 82 insertions, 69 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java
index 3a53b59cb..70badae93 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java
@@ -24,42 +24,42 @@ import java.io.File;
import java.net.URL;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.basicmodel.service.AbstractParameters;
-import org.onap.policy.apex.model.basicmodel.service.ParameterService;
-import org.onap.policy.apex.service.parameters.ApexParameterValidator;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.service.parameters.ApexParameterConstants;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.apex.core.engine.EngineParameters;
/**
- * This class holds the parameters for an Apex Engine Service with multiple engine threads running
- * multiple engines.
+ * This class holds the parameters for an Apex Engine Service with multiple engine threads running multiple engines.
*
- * <p>The following parameters are defined:
+ * <p>
+ * The following parameters are defined:
* <ol>
- * <li>name: The name of the Apex engine service, which can be set to any value that matches the
- * regular expression {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#NAME_REGEXP}.
- * <li>version: The name of the Apex engine service, which can be set to any value that matches the
- * regular expression {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#VERSION_REGEXP}.
+ * <li>name: The name of the Apex engine service, which can be set to any value that matches the regular expression
+ * {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#NAME_REGEXP}.
+ * <li>version: The name of the Apex engine service, which can be set to any value that matches the regular expression
+ * {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#VERSION_REGEXP}.
* <li>id: The ID of the Apex engine service, which can be set to any integer value by a user.
- * <li>instanceCount: The number of Apex engines to spawn in this engine service. Each engine
- * executes in its own thread.
- * <li>deploymentPort: The port that the Apex Engine Service will open so that it can be managed
- * using the EngDep protocol. The EngDep protocol allows the engine service to be monitored, to
- * start and stop engines in the engine service, and to update the policy model of the engine
- * service.
- * <li>engineParameters: Parameters (a {@link EngineParameters} instance) that all of the engines in
- * the engine service will use. All engine threads use the same parameters and act as a pool of
- * engines. Engine parameters specify the executors and context management for the engines.
- * <li>policyModelFileName: The full path to the policy model file name to deploy on the engine
- * service.
- * <li>periodicEventPeriod: The period in milliseconds at which the periodic event PERIOIC_EVENT
- * will be generated by APEX, 0 means no periodic event generation, negative values are illegal.
+ * <li>instanceCount: The number of Apex engines to spawn in this engine service. Each engine executes in its own
+ * thread.
+ * <li>deploymentPort: The port that the Apex Engine Service will open so that it can be managed using the EngDep
+ * protocol. The EngDep protocol allows the engine service to be monitored, to start and stop engines in the engine
+ * service, and to update the policy model of the engine service.
+ * <li>engineParameters: Parameters (a {@link EngineParameters} instance) that all of the engines in the engine service
+ * will use. All engine threads use the same parameters and act as a pool of engines. Engine parameters specify the
+ * executors and context management for the engines.
+ * <li>policyModelFileName: The full path to the policy model file name to deploy on the engine service.
+ * <li>periodicEventPeriod: The period in milliseconds at which the periodic event PERIOIC_EVENT will be generated by
+ * APEX, 0 means no periodic event generation, negative values are illegal.
* </ol>
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class EngineServiceParameters extends AbstractParameters implements ApexParameterValidator {
+public class EngineServiceParameters implements ParameterGroup {
private static final int MAX_PORT = 65535;
// @formatter:off
@@ -78,6 +78,9 @@ public class EngineServiceParameters extends AbstractParameters implements ApexP
/** The default EngDep deployment port of the Apex engine service. */
public static final int DEFAULT_DEPLOYMENT_PORT = 34421;
+ // Constants for repeated strings
+ private static final String POLICY_MODEL_FILE_NAME = "policyModelFileName";
+
// Apex engine service parameters
private String name = DEFAULT_NAME;
private String version = DEFAULT_VERSION;
@@ -92,12 +95,14 @@ public class EngineServiceParameters extends AbstractParameters implements ApexP
private EngineParameters engineParameters = new EngineParameters();
/**
- * Constructor to create an apex engine service parameters instance and register the instance
- * with the parameter service.
+ * Constructor to create an apex engine service parameters instance and register the instance with the parameter
+ * service.
*/
public EngineServiceParameters() {
- super(EngineServiceParameters.class.getCanonicalName());
- ParameterService.registerParameters(EngineServiceParameters.class, this);
+ super();
+
+ // Set the name for the parameters
+ this.name = ApexParameterConstants.ENGINE_SERVICE_GROUP_NAME;
}
/**
@@ -221,16 +226,14 @@ public class EngineServiceParameters extends AbstractParameters implements ApexP
/**
* Sets the file name of the policy engine for deployment on the engine service.
*
- * @param policyModelFileName the file name of the policy engine for deployment on the engine
- * service
+ * @param policyModelFileName the file name of the policy engine for deployment on the engine service
*/
public void setPolicyModelFileName(final String policyModelFileName) {
this.policyModelFileName = policyModelFileName;
}
/**
- * Get the period in milliseconds at which periodic events are sent, zero means no periodic
- * events are being sent.
+ * Get the period in milliseconds at which periodic events are sent, zero means no periodic events are being sent.
*
* @return the periodic period
*/
@@ -239,8 +242,8 @@ public class EngineServiceParameters extends AbstractParameters implements ApexP
}
/**
- * Set the period in milliseconds at which periodic events are sent, zero means no periodic
- * events are to be sent, negative values are illegal.
+ * Set the period in milliseconds at which periodic events are sent, zero means no periodic events are to be sent,
+ * negative values are illegal.
*
* @param periodicEventPeriod the periodic period
*/
@@ -272,57 +275,67 @@ public class EngineServiceParameters extends AbstractParameters implements ApexP
* @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
*/
@Override
- public String validate() {
- final StringBuilder errorMessageBuilder = new StringBuilder();
-
- try {
- new AxArtifactKey(name, version);
- } catch (final Exception e) {
- errorMessageBuilder.append(" name [" + name + "] and/or version [" + version + "] invalid\n");
- errorMessageBuilder.append(" " + e.getMessage() + "\n");
+ public GroupValidationResult validate() {
+ final GroupValidationResult result = new GroupValidationResult(this);
+
+ if (name == null || !name.matches(AxKey.NAME_REGEXP)) {
+ result.setResult("name", ValidationStatus.INVALID,
+ "name is invalid, it must match regular expression" + AxKey.NAME_REGEXP);
+ }
+
+ if (version == null || !version.matches(AxKey.VERSION_REGEXP)) {
+ result.setResult("version", ValidationStatus.INVALID,
+ "version is invalid, it must match regular expression" + AxKey.VERSION_REGEXP);
}
if (id < 0) {
- errorMessageBuilder.append(
- " id not specified or specified value [" + id + "] invalid, must be specified as id >= 0\n");
+ result.setResult("id", ValidationStatus.INVALID,
+ "id not specified or specified value [" + id + "] invalid, must be specified as id >= 0");
}
if (instanceCount < 1) {
- errorMessageBuilder.append(
- " instanceCount [" + instanceCount + "] invalid, must be specified as instanceCount >= 1\n");
+ result.setResult("instanceCount", ValidationStatus.INVALID,
+ "instanceCount [" + instanceCount + "] invalid, must be specified as instanceCount >= 1");
}
if (deploymentPort < 1 || deploymentPort > MAX_PORT) {
- errorMessageBuilder.append(
- " deploymentPort [" + deploymentPort + "] invalid, must be specified as 1024 <= port <= 65535\n");
+ result.setResult("deploymentPort", ValidationStatus.INVALID, "deploymentPort [" + deploymentPort
+ + "] invalid, must be specified as 1024 <= port <= 65535");
}
if (policyModelFileName != null) {
- if (policyModelFileName.trim().length() == 0) {
- errorMessageBuilder.append(" policyModelFileName [" + policyModelFileName
- + "] invalid, must be specified as a non-empty string\n");
- } else {
- // The file name can refer to a resource on the local file system or on the class
- // path
- final URL fileURL = ResourceUtils.getUrl4Resource(policyModelFileName);
- if (fileURL == null) {
- errorMessageBuilder.append(
- " policyModelFileName [" + policyModelFileName + "] not found or is not a plain file\n");
- } else {
- final File policyModelFile = new File(fileURL.getPath());
- if (!policyModelFile.isFile()) {
- errorMessageBuilder.append(" policyModelFileName [" + policyModelFileName
- + "] not found or is not a plain file\n");
- }
- }
- }
+ validatePolicyModelFileName(result);
}
if (periodicEventPeriod < 0) {
- errorMessageBuilder.append(" periodicEventPeriod [" + periodicEventPeriod
- + "] invalid, must be specified in milliseconds as >=0\n");
+ result.setResult("periodicEventPeriod", ValidationStatus.INVALID, "periodicEventPeriod ["
+ + periodicEventPeriod + "] invalid, must be specified in milliseconds as >=0");
}
- return errorMessageBuilder.toString();
+ return result;
+ }
+
+ /**
+ * Validate the policy model file name parameter
+ * @param result the variable in which to store the result of the validation
+ */
+ private void validatePolicyModelFileName(final GroupValidationResult result) {
+ if (policyModelFileName.trim().length() == 0) {
+ result.setResult(POLICY_MODEL_FILE_NAME, ValidationStatus.INVALID, "\""
+ + policyModelFileName + "\" invalid, must be specified as a non-empty string");
+ return;
+ }
+
+ // The file name can refer to a resource on the local file system or on the class
+ // path
+ final URL fileURL = ResourceUtils.getUrl4Resource(policyModelFileName);
+ if (fileURL == null) {
+ result.setResult(POLICY_MODEL_FILE_NAME, ValidationStatus.INVALID, "not found or is not a plain file");
+ } else {
+ final File policyModelFile = new File(fileURL.getPath());
+ if (!policyModelFile.isFile()) {
+ result.setResult(POLICY_MODEL_FILE_NAME, ValidationStatus.INVALID, "not found or is not a plain file");
+ }
+ }
}
}