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>periodicEventPeriod: The period in milliseconds at which the periodic event PERIOIC_EVENT will be generated by
55 * APEX, 0 means no periodic event generation, negative values are illegal.
61 public class EngineServiceParameters implements ParameterGroup {
62 private static final int MAX_PORT = 65535;
65 /** The default name of the Apex engine service. */
66 public static final String DEFAULT_NAME = "ApexEngineService";
68 /** The default version of the Apex engine service. */
69 public static final String DEFAULT_VERSION = "1.0.0";
71 /** The default ID of the Apex engine service. */
72 public static final int DEFAULT_ID = -1;
74 /** The default instance count for the Apex engine service. */
75 public static final int DEFAULT_INSTANCE_COUNT = 1;
77 /** The default EngDep deployment port of the Apex engine service. */
78 public static final int DEFAULT_DEPLOYMENT_PORT = 34421;
80 // Constants for repeated strings
82 // Apex engine service parameters
83 private String name = DEFAULT_NAME;
84 private String version = DEFAULT_VERSION;
85 private int id = DEFAULT_ID;
86 private int instanceCount = DEFAULT_INSTANCE_COUNT;
87 private int deploymentPort = DEFAULT_DEPLOYMENT_PORT;
88 private String policyModel = null;
89 private long periodicEventPeriod = 0;
92 // Apex engine internal parameters
93 private EngineParameters engineParameters = new EngineParameters();
96 * Constructor to create an apex engine service parameters instance and register the instance with the parameter
99 public EngineServiceParameters() {
102 // Set the name for the parameters
103 this.name = ApexParameterConstants.ENGINE_SERVICE_GROUP_NAME;
107 * Gets the key of the Apex engine service.
109 * @return the Apex engine service key
111 public AxArtifactKey getEngineKey() {
112 return new AxArtifactKey(name, version);
116 * Sets the key of the Apex engine service.
118 * @param key the the Apex engine service key
120 public void setEngineKey(final AxArtifactKey key) {
121 this.setName(key.getName());
122 this.setVersion(key.getVersion());
129 public GroupValidationResult validate() {
130 final GroupValidationResult result = new GroupValidationResult(this);
132 validateStringParameters(result);
134 validateNumericParameters(result);
136 if (StringUtils.isBlank(policyModel)) {
137 result.setResult("policyModel", ValidationStatus.INVALID, "must be specified");
139 result.setResult("engineParameters", engineParameters.validate());
145 * Validate string parameters.
147 * @param result the result of string parameter validation
149 private void validateStringParameters(final GroupValidationResult result) {
150 if (name == null || !name.matches(AxKey.NAME_REGEXP)) {
151 result.setResult("name", ValidationStatus.INVALID,
152 "name is invalid, it must match regular expression" + AxKey.NAME_REGEXP);
155 if (version == null || !version.matches(AxKey.VERSION_REGEXP)) {
156 result.setResult("version", ValidationStatus.INVALID,
157 "version is invalid, it must match regular expression" + AxKey.VERSION_REGEXP);
162 * Validate numeric parameters.
164 * @param result the result of numeric parameter validation
166 private void validateNumericParameters(final GroupValidationResult result) {
168 result.setResult("id", ValidationStatus.INVALID,
169 "id not specified or specified value [" + id + "] invalid, must be specified as id >= 0");
172 if (instanceCount < 1) {
173 result.setResult("instanceCount", ValidationStatus.INVALID,
174 "instanceCount [" + instanceCount + "] invalid, must be specified as instanceCount >= 1");
177 if (deploymentPort < 1 || deploymentPort > MAX_PORT) {
178 result.setResult("deploymentPort", ValidationStatus.INVALID, "deploymentPort [" + deploymentPort
179 + "] invalid, must be specified as 1024 <= port <= 65535");
182 if (periodicEventPeriod < 0) {
183 result.setResult("periodicEventPeriod", ValidationStatus.INVALID, "periodicEventPeriod ["
184 + periodicEventPeriod + "] invalid, must be specified in milliseconds as >=0");