diff options
author | a.sreekumar <ajith.sreekumar@est.tech> | 2020-02-13 11:17:54 +0000 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@est.tech> | 2020-02-20 17:03:05 +0000 |
commit | 8f8df7ee1ddb20b03cedb17dccdc79fc291cc678 (patch) | |
tree | 6ed8b1ebb110992c5e7985100478ab5b216d185d /services/services-engine/src/main | |
parent | 8d22852d50a9b76dd05f68fef2717bb37f3b5bc6 (diff) |
Passing taskParameters from ApexConfig to policy logic
TaskParameters can be used to pass parameters from ApexConfig to the policy logic. In the config, these are optional.
Usage as below:
{
"engineParameters": {
"taskParameters": [
{
"key": "ParameterKey1",
"value": "ParameterValue1"
},
{
"taskId": "TaskIdVal",
"key": "ParameterKey2",
"value": "ParameterValue2"
}
]
}
}
In the taskLogic, taskParameters can be accessed as below:
eg: executor.parameters.get("ParameterKey1"))
If taskId is provided in ApexConfig for an entry, then that
parameter is updated only for that particular task. Otherwise, the task
parameter is added to all tasks.
Change-Id: I9e1b3d3697428309e7d86db40b63ffe822935b69
Issue-ID: POLICY-2364
Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'services/services-engine/src/main')
-rw-r--r-- | services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParametersJsonAdapter.java | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParametersJsonAdapter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParametersJsonAdapter.java index 1b8dacad4..5319d763e 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParametersJsonAdapter.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParametersJsonAdapter.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,10 +28,10 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; - import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; import java.util.Map.Entry; - import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; import org.onap.policy.apex.context.parameters.ContextParameters; import org.onap.policy.apex.context.parameters.DistributorParameters; @@ -41,8 +41,11 @@ import org.onap.policy.apex.context.parameters.SchemaHelperParameters; import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.ExecutorParameters; +import org.onap.policy.apex.core.engine.TaskParameters; import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.parameters.ParameterRuntimeException; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -67,6 +70,8 @@ public class EngineServiceParametersJsonAdapter private static final String EXECUTOR_PARAMETERS = "executorParameters"; // @formatter:on + private static StandardCoder standardCoder = new StandardCoder(); + /** * {@inheritDoc}. */ @@ -98,10 +103,38 @@ public class EngineServiceParametersJsonAdapter // Executor parameter wrangling getExecutorParameters(engineParametersJsonObject, engineParameters, context); + // Task parameter wrangling + getTaskParametersList(engineParametersJsonObject, engineParameters); return engineParameters; } /** + * Method to get the task parameters list for Apex. + * + * @param engineParametersJsonObject The input JSON + * @param engineParameters The output parameters + */ + private void getTaskParametersList(JsonObject engineParametersJsonObject, EngineParameters engineParameters) { + final JsonElement parametersElement = engineParametersJsonObject.get("taskParameters"); + + // configurable parameters are optional so if the element does not exist, just return + if (parametersElement == null) { + return; + } + List<TaskParameters> parametersList = new ArrayList<>(); + parametersElement.getAsJsonArray().forEach(taskParam -> { + TaskParameters parameters = null; + try { + parameters = standardCoder.decode(standardCoder.encode(taskParam), TaskParameters.class); + } catch (CoderException e) { + throw new ParameterRuntimeException("Error reading taskParameters from the config json provided."); + } + parametersList.add(parameters); + }); + engineParameters.setTaskParameters(parametersList); + } + + /** * Get the context parameters for Apex. * * @param engineParametersJsonObject The input JSON |