Passing taskParameters from ApexConfig to policy logic
[policy/apex-pdp.git] / core / core-engine / src / main / java / org / onap / policy / apex / core / engine / EngineParameters.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.core.engine;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Map.Entry;
28 import java.util.TreeMap;
29 import lombok.Getter;
30 import lombok.Setter;
31 import org.onap.policy.apex.context.parameters.ContextParameters;
32 import org.onap.policy.common.parameters.GroupValidationResult;
33 import org.onap.policy.common.parameters.ParameterGroup;
34 import org.onap.policy.common.parameters.ValidationResult;
35
36 /**
37  * This class holds the parameters for a single Apex engine. This parameter class holds parameters for context schemas
38  * and context albums for the engine and a map of the logic flavour executors defined for the engine and the parameters
39  * for each of those executors.
40  *
41  * <p>The context parameters for the engine are held in a {@link ContextParameters} instance. This instance holds the
42  * parameters for context schema handling that will be used by the engine as well as the context album distribution,
43  * locking, and persistence parameters.
44  *
45  * <p>In Apex, an engine can be configured to use many logic flavours. The executors for each logic flavour are
46  * identified by their name. Each logic flavour executor must have an instance of {@link ExecutorParameters} defined for
47  * it, which specifies the executor plugins to use for that logic flavour executor and specific parameters for those
48  * executor plugins.
49  *
50  * @author Liam Fallon (liam.fallon@ericsson.com)
51  */
52 @Getter
53 @Setter
54 public class EngineParameters implements ParameterGroup {
55     private ContextParameters contextParameters = new ContextParameters();
56
57     // Parameter group name
58     private String name;
59
60     // A map of parameters for executors of various logic types
61     private Map<String, ExecutorParameters> executorParameterMap = new TreeMap<>();
62
63     // A list of parameters to be passed to the task, so that they can be used in the logic
64     private List<TaskParameters> taskParameters = new ArrayList<>();
65
66     /**
67      * Constructor to create an engine parameters instance and register the instance with the parameter service.
68      */
69     public EngineParameters() {
70         super();
71
72         // Set the name for the parameters
73         this.name = EngineParameterConstants.MAIN_GROUP_NAME;
74     }
75
76     @Override
77     public GroupValidationResult validate() {
78         final GroupValidationResult result = new GroupValidationResult(this);
79
80         result.setResult("contextParameters", contextParameters.validate());
81
82         for (Entry<String, ExecutorParameters> executorParEntry : executorParameterMap.entrySet()) {
83             result.setResult("executorParameterMap", executorParEntry.getKey(), executorParEntry.getValue().validate());
84         }
85         for (TaskParameters taskParam : taskParameters) {
86             ValidationResult taskParamValidationResult = taskParam.validate("taskParameters");
87             result.setResult(taskParamValidationResult.getName(), taskParamValidationResult.getStatus(),
88                 taskParamValidationResult.getResult());
89         }
90         return result;
91     }
92
93
94 }