summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2020-01-29 09:50:33 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2020-01-30 12:15:09 +0000
commit393e00b78140a27232d961fcdae70b99af2cdbbe (patch)
tree9ece796dd23034536a3ae9e64ed5e03c71d73f1c /services
parent18e4f9625363459dac24be15b74210e2886097b9 (diff)
Remove content section from ToscaPolicy properties in APEX
Currently APEX specific information is placed under properties|content in ToscaPolicy. Avoid keeping under "content" and keep the information directly under properties. Change-Id: Ic437271c9a2d71104013b5568af5525df4a4bb56 Issue-ID: POLICY-2332 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'services')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java23
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java8
2 files changed, 20 insertions, 11 deletions
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
index 8150ff9c5..72987de0a 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
@@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
import org.onap.policy.apex.service.engine.main.ApexMain;
@@ -46,6 +47,8 @@ import org.slf4j.LoggerFactory;
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
public class ApexEngineHandler {
+ private static final String POLICY_TYPE_IMPL = "policy_type_impl";
+
private static final Logger LOGGER = LoggerFactory.getLogger(ApexEngineHandler.class);
private ApexMain apexMain;
@@ -88,17 +91,21 @@ public class ApexEngineHandler {
throws ApexStarterException {
Map<ToscaPolicyIdentifier, String[]> policyArgsMap = new LinkedHashMap<>();
for (ToscaPolicy policy : policies) {
- Object properties = policy.getProperties().get("content");
final StandardCoder standardCoder = new StandardCoder();
- String policyModel;
+ String policyModel = "";
String apexConfig;
+ JsonObject apexConfigJsonObject = new JsonObject();
try {
- JsonObject body = standardCoder.decode(standardCoder.encode(properties), JsonObject.class);
- final JsonObject engineServiceParameters = body.get("engineServiceParameters").getAsJsonObject();
- policyModel = standardCoder.encode(engineServiceParameters.get("policy_type_impl"));
- engineServiceParameters.remove("policy_type_impl");
- apexConfig = standardCoder.encode(body);
- } catch (final CoderException e) {
+ for (Entry<String, Object> property : policy.getProperties().entrySet()) {
+ JsonObject body = standardCoder.decode(standardCoder.encode(property.getValue()), JsonObject.class);
+ if ("engineServiceParameters".equals(property.getKey())) {
+ policyModel = standardCoder.encode(body.get(POLICY_TYPE_IMPL));
+ body.remove(POLICY_TYPE_IMPL);
+ }
+ apexConfigJsonObject.add(property.getKey(), body);
+ }
+ apexConfig = standardCoder.encode(apexConfigJsonObject);
+ } catch (CoderException e) {
throw new ApexStarterException(e);
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java
index 78d9d769b..21d0137f3 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * 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.
@@ -71,8 +71,10 @@ public class TestListenerUtils {
toscaPolicy.setVersion(policyVersion);
toscaPolicy.setName(policyName);
final Map<String, Object> propertiesMap = new LinkedHashMap<>();
- Object properties = new StandardCoder().decode(new File(policyFilePath), JsonObject.class);
- propertiesMap.put("content", properties);
+ JsonObject properties = new StandardCoder().decode(new File(policyFilePath), JsonObject.class);
+ properties.entrySet().forEach(entry -> {
+ propertiesMap.put(entry.getKey(), entry.getValue());
+ });
toscaPolicy.setProperties(propertiesMap);
return toscaPolicy;
}