summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/main
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-02-23 19:07:28 +0000
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-02-23 19:43:20 +0000
commitd6f916f52c57b0ca00a6d7c48910a3462e724793 (patch)
tree8d690afb701de7e893b33106acb2b71413ad72e5 /services/services-engine/src/main
parentf0fd964e343fe5a9cc2044d417fadf6cdd1ef0d1 (diff)
Add support for retrieving apex-policyModel from metadata
Apex policyModel had been provided under policy properties for apex-pdp. Additional support included to retrieve the policyModel from metadata if PAP supplied it as metadataSet. Issue-ID: POLICY-3834 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: Ic810d78cf01c507c5b4d167f28ae6f7729132238
Diffstat (limited to 'services/services-engine/src/main')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
index 2e97c54fc..72cbd2800 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
@@ -29,7 +29,9 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import org.onap.policy.apex.core.engine.EngineParameters;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
@@ -63,6 +65,7 @@ public class ApexParameterHandler {
private static final String POLICY_TYPE_IMPL = "policy_type_impl";
private static final String APEX_POLICY_MODEL = "apexPolicyModel";
+ private static final String METADATA_SET = "metadataSet";
private String policyModel;
private String apexConfig;
@@ -171,14 +174,28 @@ public class ApexParameterHandler {
apexConfigJsonObject.add(property.getKey(), body);
}
apexConfig = standardCoder.encode(apexConfigJsonObject);
+
+ // populate policyModel from metadata if present
+ Optional<Map<String, Object>> metadata =
+ Optional.ofNullable(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0)
+ .entrySet().iterator().next().getValue().getMetadata());
+ if (metadata.isPresent() && metadata.get().containsKey(METADATA_SET)) {
+ JsonElement body = standardCoder.convert(metadata.get(), JsonObject.class);
+ policyModel = extractPolicyModel(standardCoder, body);
+ }
} catch (Exception e) {
throw new ApexException("Parsing config and model from the tosca policy failed.", e);
}
}
private String extractPolicyModel(StandardCoder standardCoder, JsonElement body) throws CoderException {
- // Check for "policy_type_impl"
- JsonElement policyTypeImplObject = ((JsonObject) body).get(POLICY_TYPE_IMPL);
+ JsonElement policyTypeImplObject = null;
+ // Check for "policy_type_impl, if not present check for "metadataSet"
+ if (body.getAsJsonObject().has(POLICY_TYPE_IMPL)) {
+ policyTypeImplObject = ((JsonObject) body).get(POLICY_TYPE_IMPL);
+ } else if (body.getAsJsonObject().has(METADATA_SET)) {
+ policyTypeImplObject = ((JsonObject) body).get(METADATA_SET);
+ }
if (null == policyTypeImplObject) {
return null;
}