2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
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.apex.service.parameters.engineservice;
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.policy.apex.core.engine.EngineParameters;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
30 import org.onap.policy.apex.service.parameters.ApexParameterConstants;
31 import org.onap.policy.common.parameters.GroupValidationResult;
32 import org.onap.policy.common.parameters.ParameterGroup;
33 import org.onap.policy.common.parameters.ValidationStatus;
37 * This class holds the parameters for an Apex Engine Service with multiple engine threads running multiple engines.
39 * <p>The following parameters are defined:
41 * <li>name: The name of the Apex engine service, which can be set to any value that matches the regular expression
42 * {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#NAME_REGEXP}.
43 * <li>version: The name of the Apex engine service, which can be set to any value that matches the regular expression
44 * {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#VERSION_REGEXP}.
45 * <li>id: The ID of the Apex engine service, which can be set to any integer value by a user.
46 * <li>instanceCount: The number of Apex engines to spawn in this engine service. Each engine executes in its own
48 * <li>deploymentPort: The port that the Apex Engine Service will open so that it can be managed using the EngDep
49 * protocol. The EngDep protocol allows the engine service to be monitored, to start and stop engines in the engine
50 * service, and to update the policy model of the engine service.
51 * <li>engineParameters: Parameters (a {@link EngineParameters} instance) that all of the engines in the engine service
52 * will use. All engine threads use the same parameters and act as a pool of engines. Engine parameters specify the
53 * executors and context management for the engines.
54 * <li>policyModelFileName: The full path to the policy model file name to deploy on the engine service.
55 * <li>periodicEventPeriod: The period in milliseconds at which the periodic event PERIOIC_EVENT will be generated by
56 * APEX, 0 means no periodic event generation, negative values are illegal.
62 public class EngineServiceParameters implements ParameterGroup {
63 private static final int MAX_PORT = 65535;
66 /** The default name of the Apex engine service. */
67 public static final String DEFAULT_NAME = "ApexEngineService";
69 /** The default version of the Apex engine service. */
70 public static final String DEFAULT_VERSION = "1.0.0";
72 /** The default ID of the Apex engine service. */
73 public static final int DEFAULT_ID = -1;
75 /** The default instance count for the Apex engine service. */
76 public static final int DEFAULT_INSTANCE_COUNT = 1;
78 /** The default EngDep deployment port of the Apex engine service. */
79 public static final int DEFAULT_DEPLOYMENT_PORT = 34421;
81 // Constants for repeated strings
83 // Apex engine service parameters
84 private String name = DEFAULT_NAME;
85 private String version = DEFAULT_VERSION;
86 private int id = DEFAULT_ID;
87 private int instanceCount = DEFAULT_INSTANCE_COUNT;
88 private int deploymentPort = DEFAULT_DEPLOYMENT_PORT;
89 private String policyModel = null;
90 private long periodicEventPeriod = 0;
93 // Apex engine internal parameters
94 private EngineParameters engineParameters = new EngineParameters();
97 * Constructor to create an apex engine service parameters instance and register the instance with the parameter
100 public EngineServiceParameters() {
103 // Set the name for the parameters
104 this.name = ApexParameterConstants.ENGINE_SERVICE_GROUP_NAME;
108 * Gets the key of the Apex engine service.
110 * @return the Apex engine service key
112 public AxArtifactKey getEngineKey() {
113 return new AxArtifactKey(name, version);
117 * Sets the key of the Apex engine service.
119 * @param key the the Apex engine service key
121 public void setEngineKey(final AxArtifactKey key) {
122 this.setName(key.getName());
123 this.setVersion(key.getVersion());
130 public GroupValidationResult validate() {
131 final GroupValidationResult result = new GroupValidationResult(this);
133 validateStringParameters(result);
135 validateNumericParameters(result);
137 if (StringUtils.isBlank(policyModel)) {
138 result.setResult("policyModel", ValidationStatus.INVALID, "must be specified");
140 result.setResult("engineParameters", engineParameters.validate());
146 * Validate string parameters.
148 * @param result the result of string parameter validation
150 private void validateStringParameters(final GroupValidationResult result) {
151 if (name == null || !name.matches(AxKey.NAME_REGEXP)) {
152 result.setResult("name", ValidationStatus.INVALID,
153 "name is invalid, it must match regular expression" + AxKey.NAME_REGEXP);
156 if (version == null || !version.matches(AxKey.VERSION_REGEXP)) {
157 result.setResult("version", ValidationStatus.INVALID,
158 "version is invalid, it must match regular expression" + AxKey.VERSION_REGEXP);
163 * Validate numeric parameters.
165 * @param result the result of numeric parameter validation
167 private void validateNumericParameters(final GroupValidationResult result) {
169 result.setResult("id", ValidationStatus.INVALID,
170 "id not specified or specified value [" + id + "] invalid, must be specified as id >= 0");
173 if (instanceCount < 1) {
174 result.setResult("instanceCount", ValidationStatus.INVALID,
175 "instanceCount [" + instanceCount + "] invalid, must be specified as instanceCount >= 1");
178 if (deploymentPort < 1 || deploymentPort > MAX_PORT) {
179 result.setResult("deploymentPort", ValidationStatus.INVALID, "deploymentPort [" + deploymentPort
180 + "] invalid, must be specified as 1024 <= port <= 65535");
183 if (periodicEventPeriod < 0) {
184 result.setResult("periodicEventPeriod", ValidationStatus.INVALID, "periodicEventPeriod ["
185 + periodicEventPeriod + "] invalid, must be specified in milliseconds as >=0");