2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.service.parameters.engineservice;
26 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
27 import org.onap.policy.apex.model.basicmodel.service.AbstractParameters;
28 import org.onap.policy.apex.model.basicmodel.service.ParameterService;
29 import org.onap.policy.apex.service.parameters.ApexParameterValidator;
30 import org.onap.policy.common.utils.resources.ResourceUtils;
32 import org.onap.policy.apex.core.engine.EngineParameters;
35 * This class holds the parameters for an Apex Engine Service with multiple engine threads running
39 * 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
42 * regular expression {@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
44 * regular expression {@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
47 * executes in its own thread.
48 * <li>deploymentPort: The port that the Apex Engine Service will open so that it can be managed
49 * using the EngDep protocol. The EngDep protocol allows the engine service to be monitored, to
50 * start and stop engines in the engine service, and to update the policy model of the engine
52 * <li>engineParameters: Parameters (a {@link EngineParameters} instance) that all of the engines in
53 * the engine service will use. All engine threads use the same parameters and act as a pool of
54 * engines. Engine parameters specify the executors and context management for the engines.
55 * <li>policyModelFileName: The full path to the policy model file name to deploy on the engine
57 * <li>periodicEventPeriod: The period in milliseconds at which the periodic event PERIOIC_EVENT
58 * will be generated by APEX, 0 means no periodic event generation, negative values are illegal.
61 * @author Liam Fallon (liam.fallon@ericsson.com)
63 public class EngineServiceParameters extends AbstractParameters implements ApexParameterValidator {
64 private static final int MAX_PORT = 65535;
67 /** The default name of the Apex engine service. */
68 public static final String DEFAULT_NAME = "ApexEngineService";
70 /** The default version of the Apex engine service. */
71 public static final String DEFAULT_VERSION = "1.0.0";
73 /** The default ID of the Apex engine service. */
74 public static final int DEFAULT_ID = -1;
76 /** The default instance count for the Apex engine service. */
77 public static final int DEFAULT_INSTANCE_COUNT = 1;
79 /** The default EngDep deployment port of the Apex engine service. */
80 public static final int DEFAULT_DEPLOYMENT_PORT = 34421;
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 policyModelFileName = 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
97 * with the parameter service.
99 public EngineServiceParameters() {
100 super(EngineServiceParameters.class.getCanonicalName());
101 ParameterService.registerParameters(EngineServiceParameters.class, this);
105 * Gets the key of the Apex engine service.
107 * @return the Apex engine service key
109 public AxArtifactKey getEngineKey() {
110 return new AxArtifactKey(name, version);
114 * Sets the key of the Apex engine service.
116 * @param key the the Apex engine service key
118 public void setEngineKey(final AxArtifactKey key) {
119 this.setName(key.getName());
120 this.setVersion(key.getVersion());
124 * Gets the name of the engine service.
126 * @return the name of the engine service
128 public String getName() {
133 * Sets the name of the engine service.
135 * @param name the name of the engine service
137 public void setName(final String name) {
142 * Gets the version of the engine service.
144 * @return the version of the engine service
146 public String getVersion() {
151 * Sets the version of the engine service.
153 * @param version the version of the engine service
155 public void setVersion(final String version) {
156 this.version = version;
160 * Gets the id of the engine service.
162 * @return the id of the engine service
169 * Sets the id of the engine service.
171 * @param id the id of the engine service
173 public void setId(final int id) {
178 * Gets the instance count of the engine service.
180 * @return the instance count of the engine service
182 public int getInstanceCount() {
183 return instanceCount;
187 * Sets the instance count of the engine service.
189 * @param instanceCount the instance count of the engine service
191 public void setInstanceCount(final int instanceCount) {
192 this.instanceCount = instanceCount;
196 * Gets the deployment port of the engine service.
198 * @return the deployment port of the engine service
200 public int getDeploymentPort() {
201 return deploymentPort;
205 * Sets the deployment port of the engine service.
207 * @param deploymentPort the deployment port of the engine service
209 public void setDeploymentPort(final int deploymentPort) {
210 this.deploymentPort = deploymentPort;
214 * Gets the file name of the policy engine for deployment on the engine service.
216 * @return the file name of the policy engine for deployment on the engine service
218 public String getPolicyModelFileName() {
219 return ResourceUtils.getFilePath4Resource(policyModelFileName);
223 * Sets the file name of the policy engine for deployment on the engine service.
225 * @param policyModelFileName the file name of the policy engine for deployment on the engine
228 public void setPolicyModelFileName(final String policyModelFileName) {
229 this.policyModelFileName = policyModelFileName;
233 * Get the period in milliseconds at which periodic events are sent, zero means no periodic
234 * events are being sent.
236 * @return the periodic period
238 public long getPeriodicEventPeriod() {
239 return periodicEventPeriod;
243 * Set the period in milliseconds at which periodic events are sent, zero means no periodic
244 * events are to be sent, negative values are illegal.
246 * @param periodicEventPeriod the periodic period
248 public void setPeriodicEventPeriod(final long periodicEventPeriod) {
249 this.periodicEventPeriod = periodicEventPeriod;
253 * Gets the engine parameters for engines in the engine service.
255 * @return the engine parameters for engines in the engine service
257 public EngineParameters getEngineParameters() {
258 return engineParameters;
262 * Sets the engine parameters for engines in the engine service.
264 * @param engineParameters the engine parameters for engines in the engine service
266 public void setEngineParameters(final EngineParameters engineParameters) {
267 this.engineParameters = engineParameters;
273 * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
276 public String validate() {
277 final StringBuilder errorMessageBuilder = new StringBuilder();
280 new AxArtifactKey(name, version);
281 } catch (final Exception e) {
282 errorMessageBuilder.append(" name [" + name + "] and/or version [" + version + "] invalid\n");
283 errorMessageBuilder.append(" " + e.getMessage() + "\n");
287 errorMessageBuilder.append(
288 " id not specified or specified value [" + id + "] invalid, must be specified as id >= 0\n");
291 if (instanceCount < 1) {
292 errorMessageBuilder.append(
293 " instanceCount [" + instanceCount + "] invalid, must be specified as instanceCount >= 1\n");
296 if (deploymentPort < 1 || deploymentPort > MAX_PORT) {
297 errorMessageBuilder.append(
298 " deploymentPort [" + deploymentPort + "] invalid, must be specified as 1024 <= port <= 65535\n");
301 if (policyModelFileName != null) {
302 if (policyModelFileName.trim().length() == 0) {
303 errorMessageBuilder.append(" policyModelFileName [" + policyModelFileName
304 + "] invalid, must be specified as a non-empty string\n");
306 // The file name can refer to a resource on the local file system or on the class
308 final URL fileURL = ResourceUtils.getUrl4Resource(policyModelFileName);
309 if (fileURL == null) {
310 errorMessageBuilder.append(
311 " policyModelFileName [" + policyModelFileName + "] not found or is not a plain file\n");
313 final File policyModelFile = new File(fileURL.getPath());
314 if (!policyModelFile.isFile()) {
315 errorMessageBuilder.append(" policyModelFileName [" + policyModelFileName
316 + "] not found or is not a plain file\n");
322 if (periodicEventPeriod < 0) {
323 errorMessageBuilder.append(" periodicEventPeriod [" + periodicEventPeriod
324 + "] invalid, must be specified in milliseconds as >=0\n");
327 return errorMessageBuilder.toString();