d33ae1697f59ac6e91aa8f8a7a75daf005ac1999
[policy/apex-pdp.git] /
1 /*-
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.service.parameters.engineservice;
24
25 import javax.validation.Valid;
26 import lombok.Getter;
27 import lombok.Setter;
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;
40
41 // @formatter:off
42 /**
43  * This class holds the parameters for an Apex Engine Service with multiple engine threads running multiple engines.
44  *
45  * <p>The following parameters are defined:
46  * <ol>
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
53  * thread.
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.
62  * </ol>
63  */
64 // @formatter:on
65 @Getter
66 @Setter
67 @NotNull
68 public class EngineServiceParameters implements ParameterGroup {
69     private static final int MAX_PORT = 65535;
70
71     // @formatter:off
72     /** The default name of the Apex engine service. */
73     public static final String DEFAULT_NAME = "ApexEngineService";
74
75     /** The default version of the Apex engine service. */
76     public static final String DEFAULT_VERSION = "1.0.0";
77
78     /** The default ID of the Apex engine service. */
79     public static final int DEFAULT_ID = -1;
80
81     /** The default instance count for the Apex engine service. */
82     public static final int DEFAULT_INSTANCE_COUNT  = 1;
83
84     /** The default EngDep deployment port of the Apex engine service. */
85     public static final int DEFAULT_DEPLOYMENT_PORT = 34421;
86
87     // Constants for repeated strings
88
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;
94     @Min(0)
95     private int    id                  = DEFAULT_ID;
96     @Min(1)
97     private int    instanceCount       = DEFAULT_INSTANCE_COUNT;
98     @Min(1)
99     @Max(MAX_PORT)
100     private int    deploymentPort      = DEFAULT_DEPLOYMENT_PORT;
101     @NotBlank
102     private String policyModel = null;
103     @Min(0)
104     private long   periodicEventPeriod = 0;
105     // @formatter:on
106
107     // Apex engine internal parameters
108     private @Valid EngineParameters engineParameters = new EngineParameters();
109
110     /**
111      * Constructor to create an apex engine service parameters instance and register the instance with the parameter
112      * service.
113      */
114     public EngineServiceParameters() {
115         super();
116
117         // Set the name for the parameters
118         this.name = ApexParameterConstants.ENGINE_SERVICE_GROUP_NAME;
119     }
120
121     /**
122      * Gets the key of the Apex engine service.
123      *
124      * @return the Apex engine service key
125      */
126     public AxArtifactKey getEngineKey() {
127         return new AxArtifactKey(name, version);
128     }
129
130     /**
131      * Sets the key of the Apex engine service.
132      *
133      * @param key the the Apex engine service key
134      */
135     public void setEngineKey(final AxArtifactKey key) {
136         this.setName(key.getName());
137         this.setVersion(key.getVersion());
138     }
139
140     /**
141      * {@inheritDoc}.
142      */
143     @Override
144     public BeanValidationResult validate() {
145         return new BeanValidator().validateTop(getClass().getSimpleName(), this);
146     }
147
148 }