2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.service.parameters.engineservice;
25 import javax.validation.Valid;
28 import org.onap.policy.apex.core.engine.EngineParameters;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
31 import org.onap.policy.apex.service.parameters.ApexParameterConstants;
32 import org.onap.policy.common.parameters.BeanValidationResult;
33 import org.onap.policy.common.parameters.BeanValidator;
34 import org.onap.policy.common.parameters.ParameterGroup;
35 import org.onap.policy.common.parameters.annotations.Max;
36 import org.onap.policy.common.parameters.annotations.Min;
37 import org.onap.policy.common.parameters.annotations.NotBlank;
38 import org.onap.policy.common.parameters.annotations.NotNull;
39 import org.onap.policy.common.parameters.annotations.Pattern;
43 * This class holds the parameters for an Apex Engine Service with multiple engine threads running multiple engines.
45 * <p>The following parameters are defined:
47 * <li>name: The name of the Apex engine service, which can be set to any value that matches the regular expression
48 * {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#NAME_REGEXP}.
49 * <li>version: The name of the Apex engine service, which can be set to any value that matches the regular expression
50 * {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#VERSION_REGEXP}.
51 * <li>id: The ID of the Apex engine service, which can be set to any integer value by a user.
52 * <li>instanceCount: The number of Apex engines to spawn in this engine service. Each engine executes in its own
54 * <li>deploymentPort: The port that the Apex Engine Service will open so that it can be managed using the EngDep
55 * protocol. The EngDep protocol allows the engine service to be monitored, to start and stop engines in the engine
56 * service, and to update the policy model of the engine service.
57 * <li>engineParameters: Parameters (a {@link EngineParameters} instance) that all of the engines in the engine service
58 * will use. All engine threads use the same parameters and act as a pool of engines. Engine parameters specify the
59 * executors and context management for the engines.
60 * <li>periodicEventPeriod: The period in milliseconds at which the periodic event PERIOIC_EVENT will be generated by
61 * APEX, 0 means no periodic event generation, negative values are illegal.
68 public class EngineServiceParameters implements ParameterGroup {
69 private static final int MAX_PORT = 65535;
72 /** The default name of the Apex engine service. */
73 public static final String DEFAULT_NAME = "ApexEngineService";
75 /** The default version of the Apex engine service. */
76 public static final String DEFAULT_VERSION = "1.0.0";
78 /** The default ID of the Apex engine service. */
79 public static final int DEFAULT_ID = -1;
81 /** The default instance count for the Apex engine service. */
82 public static final int DEFAULT_INSTANCE_COUNT = 1;
84 /** The default EngDep deployment port of the Apex engine service. */
85 public static final int DEFAULT_DEPLOYMENT_PORT = 34421;
87 // Constants for repeated strings
89 // Apex engine service parameters
90 @Pattern(regexp = AxKey.NAME_REGEXP)
91 private String name = DEFAULT_NAME;
92 @Pattern(regexp = AxKey.VERSION_REGEXP)
93 private String version = DEFAULT_VERSION;
95 private int id = DEFAULT_ID;
97 private int instanceCount = DEFAULT_INSTANCE_COUNT;
100 private int deploymentPort = DEFAULT_DEPLOYMENT_PORT;
102 private String policyModel = null;
104 private long periodicEventPeriod = 0;
107 // Apex engine internal parameters
108 private @Valid EngineParameters engineParameters = new EngineParameters();
111 * Constructor to create an apex engine service parameters instance and register the instance with the parameter
114 public EngineServiceParameters() {
117 // Set the name for the parameters
118 this.name = ApexParameterConstants.ENGINE_SERVICE_GROUP_NAME;
122 * Gets the key of the Apex engine service.
124 * @return the Apex engine service key
126 public AxArtifactKey getEngineKey() {
127 return new AxArtifactKey(name, version);
131 * Sets the key of the Apex engine service.
133 * @param key the the Apex engine service key
135 public void setEngineKey(final AxArtifactKey key) {
136 this.setName(key.getName());
137 this.setVersion(key.getVersion());
144 public BeanValidationResult validate() {
145 return new BeanValidator().validateTop(getClass().getSimpleName(), this);