summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorSébastien Determe <sebastien.determe@intl.att.com>2020-04-14 23:22:50 +0000
committerGerrit Code Review <gerrit@onap.org>2020-04-14 23:22:50 +0000
commit10266c923850e842e14c602d772ce2ebbc77fe89 (patch)
tree72f3c6df04b1ca51905b2ce2bd32ca7b08584269 /src/main
parent0f3c8ae745988969aca1f605635b291367ecd69d (diff)
parent3ec03cca444a2810005053a308ed0f3ecb00b063 (diff)
Merge "CDS attributes are not shown properly in UI"
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/CdsServices.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java104
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java21
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java44
-rw-r--r--src/main/resources/clds/json-schema/operational_policies/operational_policy.json30
5 files changed, 142 insertions, 59 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/CdsServices.java b/src/main/java/org/onap/clamp/clds/client/CdsServices.java
index fe1937ab..f25e8b80 100644
--- a/src/main/java/org/onap/clamp/clds/client/CdsServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/CdsServices.java
@@ -136,7 +136,7 @@ public class CdsServices {
if (isComplexType(type, dataTypes)) {
inputObject.add(key, handleComplexType(type, dataTypes));
} else {
- inputObject.addProperty(key, "");
+ inputObject.add(key, entry.getValue());
}
}
return inputObject;
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java b/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
index 81e30cf4..ce1f9469 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
@@ -26,7 +26,10 @@ package org.onap.clamp.clds.tosca.update.execution.cds;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+
import java.util.Map;
+import java.util.Set;
+
import org.onap.clamp.clds.tosca.update.execution.ToscaMetadataProcess;
import org.onap.clamp.loop.service.Service;
import org.onap.clamp.tosca.DictionaryService;
@@ -58,9 +61,11 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
}
private static void generatePayload(JsonObject childObject, Service serviceModel) {
- generatePayloadPerResource(childObject, "VF", serviceModel);
- generatePayloadPerResource(childObject, "PNF", serviceModel);
- addToJsonArray(childObject, "anyOf", createBlankEntry());
+ JsonArray schemaAnyOf = new JsonArray();
+ schemaAnyOf.addAll(createBlankEntry());
+ schemaAnyOf.addAll(generatePayloadPerResource("VF", serviceModel));
+ schemaAnyOf.addAll(generatePayloadPerResource("PNF", serviceModel));
+ addToJsonArray(childObject, "anyOf", schemaAnyOf);
}
private static void generateOperation(JsonObject childObject, Service serviceModel) {
@@ -92,8 +97,8 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
}
- private static void generatePayloadPerResource(JsonObject childObject, String resourceName,
- Service serviceModel) {
+ private static JsonArray generatePayloadPerResource(String resourceName,
+ Service serviceModel) {
JsonArray schemaAnyOf = new JsonArray();
for (Map.Entry<String, JsonElement> entry : serviceModel.getResourceDetails().getAsJsonObject(resourceName)
@@ -105,13 +110,14 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
.entrySet()) {
JsonObject obj = new JsonObject();
obj.addProperty("title", workflowsEntry.getKey());
- obj.add("properties", createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(),
- controllerProperties));
+ obj.add("properties",
+ createInputPropertiesForPayload(workflowsEntry.getValue().getAsJsonObject(),
+ controllerProperties));
schemaAnyOf.add(obj);
}
}
}
- addToJsonArray(childObject, "anyOf", schemaAnyOf);
+ return schemaAnyOf;
}
private static JsonArray createBlankEntry() {
@@ -123,20 +129,6 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
return result;
}
- private static JsonObject createPayloadProperty(JsonObject workFlow, JsonObject controllerProperties) {
- JsonObject payloadResult = new JsonObject();
-
- payloadResult.add("artifact_name",
- createAnyOfJsonProperty("artifact_name", controllerProperties.get("sdnc_model_name").getAsString()));
- payloadResult.add("artifact_version",
- createAnyOfJsonProperty("artifact_version",
- controllerProperties.get("sdnc_model_version").getAsString()));
- payloadResult.add("mode", createAnyOfJsonProperty("mode", "async"));
-
- payloadResult.add("data", createAnyOfJsonObject("data", workFlow.getAsJsonObject("inputs")));
- return payloadResult;
- }
-
private static JsonObject createAnyOfJsonProperty(String name, String defaultValue) {
JsonObject result = new JsonObject();
result.addProperty("title", name);
@@ -157,9 +149,73 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
private static void addToJsonArray(JsonObject childObject, String section, JsonArray value) {
if (childObject.getAsJsonArray(section) != null) {
childObject.getAsJsonArray(section).addAll(value);
- }
- else {
+ } else {
childObject.add(section, value);
}
}
+
+ /**
+ * Returns the properties of payload based on the cds work flows.
+ *
+ * @param workFlow cds work flows to update payload
+ * @param controllerProperties cds properties to get blueprint name and
+ * version
+ * @return returns the properties of payload
+ */
+ public static JsonObject createInputPropertiesForPayload(JsonObject workFlow,
+ JsonObject controllerProperties) {
+ String artifactName = controllerProperties.get("sdnc_model_name").getAsString();
+ String artifactVersion = controllerProperties.get("sdnc_model_version").getAsString();
+ JsonObject inputs = workFlow.getAsJsonObject("inputs");
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.add("artifact_name", createAnyOfJsonProperty(
+ "artifact name", artifactName));
+ jsonObject.add("artifact_version", createAnyOfJsonProperty(
+ "artifact version", artifactVersion));
+ jsonObject.add("mode", createCdsInputProperty(
+ "mode", "string", "async"));
+ jsonObject.add("data", createDataProperty(inputs));
+
+ return jsonObject;
+ }
+
+ private static JsonObject createDataProperty(JsonObject inputs) {
+ JsonObject data = new JsonObject();
+ data.addProperty("title", "data");
+ data.add("properties", addDataFields(inputs));
+ return data;
+ }
+
+ private static JsonObject addDataFields(JsonObject inputs) {
+ JsonObject jsonObject = new JsonObject();
+ Set<Map.Entry<String, JsonElement>> entrySet = inputs.entrySet();
+ for (Map.Entry<String, JsonElement> entry : entrySet) {
+ String key = entry.getKey();
+ JsonObject inputProperty = inputs.getAsJsonObject(key);
+ if (inputProperty.get("type") == null) {
+ jsonObject.add(entry.getKey(),
+ createAnyOfJsonObject(key,
+ addDataFields(entry.getValue().getAsJsonObject())));
+ } else {
+ jsonObject.add(entry.getKey(),
+ createCdsInputProperty(key,
+ inputProperty.get("type").getAsString(),
+ null));
+ }
+ }
+ return jsonObject;
+ }
+
+ private static JsonObject createCdsInputProperty(String title,
+ String type,
+ String defaultValue) {
+ JsonObject property = new JsonObject();
+ property.addProperty("title", title);
+ property.addProperty("type", type);
+ if (defaultValue != null) {
+ property.addProperty("default", defaultValue);
+ }
+ property.addProperty("format", "textarea");
+ return property;
+ }
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
index 033f2ceb..3765277d 100644
--- a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
@@ -201,11 +201,13 @@ public class LegacyOperationalPolicy {
policy.getAsJsonObject().remove(ACTOR);
String actorStr = actor.getAsJsonObject().get(ACTOR).getAsString();
policy.getAsJsonObject().addProperty(ACTOR, actorStr);
- policy.getAsJsonObject().addProperty(RECIPE, getRecipe(actor));
if ("CDS".equalsIgnoreCase(actorStr)) {
- addPayloadAttributes(actor.getAsJsonObject(ACTOR).getAsJsonObject(RECIPE), policy);
+ policy.getAsJsonObject().addProperty(RECIPE, getRecipe(actor));
+ addCdsPayloadAttributes(actor.getAsJsonObject(RECIPE), policy);
} else {
+ policy.getAsJsonObject().addProperty(RECIPE,
+ actor.getAsJsonObject().get(RECIPE).getAsString());
addPayloadAttributes(actor, policy);
}
}
@@ -226,7 +228,20 @@ public class LegacyOperationalPolicy {
}
}
+ private static void addCdsPayloadAttributes(JsonObject jsonObject,
+ JsonElement policy) {
+ JsonElement payloadElem = jsonObject.getAsJsonObject().get(PAYLOAD);
+ JsonObject payloadObject = payloadElem != null ?
+ payloadElem.getAsJsonObject() : null;
+ if (payloadObject != null) {
+ policy.getAsJsonObject().add(PAYLOAD,
+ payloadObject);
+ } else {
+ policy.getAsJsonObject().addProperty(PAYLOAD, "");
+ }
+ }
+
private static String getRecipe(JsonObject actor) {
- return actor.getAsJsonObject().get("type").getAsString();
+ return actor.getAsJsonObject().get("recipe").getAsJsonObject().get("recipe").getAsString();
}
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
index 44ee1197..4e362d84 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
@@ -24,13 +24,17 @@
package org.onap.clamp.policy.operational;
+import static org.onap.clamp.clds.tosca.update.execution.cds.ToscaMetadataCdsProcess.createInputPropertiesForPayload;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+
import java.io.IOException;
import java.util.Map.Entry;
+
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.loop.service.Service;
@@ -70,7 +74,7 @@ public class OperationalPolicyRepresentationBuilder {
for (JsonElement actor : actors) {
if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get("title").getAsString())) {
- actor.getAsJsonObject().get("properties").getAsJsonObject().get("type").getAsJsonObject()
+ actor.getAsJsonObject().get("properties").getAsJsonObject().get("recipe").getAsJsonObject()
.get("anyOf").getAsJsonArray()
.addAll(createAnyOfArrayForCdsRecipe(modelJson));
}
@@ -195,8 +199,9 @@ public class OperationalPolicyRepresentationBuilder {
for (Entry<String, JsonElement> workflowsEntry : workflows.entrySet()) {
JsonObject obj = new JsonObject();
obj.addProperty("title", workflowsEntry.getKey());
+ obj.addProperty("type", "object");
obj.add("properties", createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(),
- controllerProperties));
+ controllerProperties, workflowsEntry.getKey()));
schemaArray.add(obj);
}
@@ -205,26 +210,27 @@ public class OperationalPolicyRepresentationBuilder {
return schemaArray;
}
- private static JsonObject createPayloadProperty(JsonObject workFlow, JsonObject controllerProperties) {
- JsonObject type = new JsonObject();
- type.addProperty("title", "Payload (YAML)");
- type.addProperty("type", "string");
- type.addProperty("default", createDefaultStringForPayload(workFlow, controllerProperties));
- type.addProperty("format", "textarea");
+ private static JsonObject createPayloadProperty(JsonObject workFlow,
+ JsonObject controllerProperties, String workFlowName) {
+ JsonObject payload = new JsonObject();
+ payload.addProperty("title", "Payload (YAML)");
+ payload.addProperty("type", "object");
+ payload.add("properties", createInputPropertiesForPayload(workFlow,
+ controllerProperties));
JsonObject properties = new JsonObject();
- properties.add("type", type);
+ properties.add("recipe", createRecipeForCdsWorkflow(workFlowName));
+ properties.add("payload", payload);
return properties;
}
- private static String createDefaultStringForPayload(JsonObject workFlow, JsonObject controllerProperties) {
- String artifactName = controllerProperties.get("sdnc_model_name").toString();
- String artifactVersion = controllerProperties.get("sdnc_model_version").toString();
- String data = workFlow.getAsJsonObject("inputs").toString();
- StringBuilder builder = new StringBuilder("'").append("artifact_name : ").append(artifactName).append("\n")
- .append("artifact_version : ").append(artifactVersion).append("\n")
- .append("mode : async").append("\n")
- .append("data : ").append("'").append("\\").append("'").append(data).append("\\").append("'")
- .append("'");
- return builder.toString();
+ private static JsonObject createRecipeForCdsWorkflow(String workflow) {
+ JsonObject recipe = new JsonObject();
+ recipe.addProperty("title", "recipe");
+ recipe.addProperty("type", "string");
+ recipe.addProperty("default", workflow);
+ JsonObject options = new JsonObject();
+ options.addProperty("hidden", true);
+ recipe.add("options", options);
+ return recipe;
}
}
diff --git a/src/main/resources/clds/json-schema/operational_policies/operational_policy.json b/src/main/resources/clds/json-schema/operational_policies/operational_policy.json
index 49d7878a..7214b022 100644
--- a/src/main/resources/clds/json-schema/operational_policies/operational_policy.json
+++ b/src/main/resources/clds/json-schema/operational_policies/operational_policy.json
@@ -99,6 +99,7 @@
"anyOf": [
{
"title": "APPC",
+ "type": "object",
"properties": {
"actor": {
"title": "actor",
@@ -108,7 +109,7 @@
"hidden": true
}
},
- "type": {
+ "recipe": {
"title": "recipe",
"type": "string",
"default": "",
@@ -129,6 +130,7 @@
},
{
"title": "SO",
+ "type": "object",
"properties": {
"actor": {
"title": "actor",
@@ -138,7 +140,7 @@
"hidden": true
}
},
- "type": {
+ "recipe": {
"title": "recipe",
"type": "string",
"default": "",
@@ -156,6 +158,7 @@
},
{
"title": "SDNC",
+ "type": "object",
"properties": {
"actor": {
"title": "actor",
@@ -165,7 +168,7 @@
"hidden": true
}
},
- "type": {
+ "recipe": {
"title": "recipe",
"type": "string",
"default": "",
@@ -183,6 +186,7 @@
},
{
"title": "VFC",
+ "type": "object",
"properties": {
"actor": {
"title": "actor",
@@ -192,12 +196,9 @@
"hidden": true
}
},
- "type": {
+ "recipe": {
"title": "recipe",
"type": "string",
- "required": [
- "payload"
- ],
"default": "",
"enum": [
"ModifyConfig"
@@ -212,6 +213,7 @@
},
{
"title": "CDS",
+ "type": "object",
"properties": {
"actor": {
"title": "actor",
@@ -221,17 +223,21 @@
"hidden": true
}
},
- "type": {
+ "recipe": {
"title": "recipe",
"type": "object",
- "required": [
- "payload"
- ],
"anyOf": [
{
"title": "user-defined",
+ "type": "object",
"properties": {
- "type": {
+ "recipe": {
+ "title": "recipe",
+ "type": "string",
+ "default": "user-defined",
+ "format": "textarea"
+ },
+ "payload": {
"title": "Payload (YAML)",
"type": "string",
"default": "",