From 7eb234559c64c4702ae621d7d2f531868677cdae Mon Sep 17 00:00:00 2001 From: sebdet Date: Wed, 8 May 2019 11:33:43 +0200 Subject: Fix model_type missing Fix model missing in some cases (new DCAE Blueprint), also removed useless fields in MicroService Object Issue-ID: CLAMP-370 Change-Id: Ia246b5d58309aceb3168107a4bf76b92b23add7a Signed-off-by: sebdet --- .../sdc/controller/installer/BlueprintParser.java | 40 +++++++++++++++------- .../sdc/controller/installer/MicroService.java | 18 ++++------ .../resources/clds/camel/routes/flexible-flow.xml | 6 ++-- 3 files changed, 36 insertions(+), 28 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java index 809904f22..aca2ed01d 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java @@ -29,6 +29,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import java.util.AbstractMap; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -61,12 +62,12 @@ public class BlueprintParser { public Set getMicroServices(String blueprintString) { Set microServices = new HashSet<>(); JsonObject jsonObject = BlueprintParser.convertToJson(blueprintString); - JsonObject results = jsonObject.get(NODE_TEMPLATES).getAsJsonObject(); + JsonObject nodeTemplateList = jsonObject.get(NODE_TEMPLATES).getAsJsonObject(); - for (Entry entry : results.entrySet()) { + for (Entry entry : nodeTemplateList.entrySet()) { JsonObject nodeTemplate = entry.getValue().getAsJsonObject(); if (nodeTemplate.get(TYPE).getAsString().contains(DCAE_NODES)) { - MicroService microService = getNodeRepresentation(entry); + MicroService microService = getNodeRepresentation(entry, nodeTemplateList); microServices.add(microService); } } @@ -89,7 +90,7 @@ public class BlueprintParser { } String msName = theBiggestMicroServiceKey.toLowerCase().contains(HOLMES_PREFIX) ? HOLMES : TCA; return Collections - .singletonList(new MicroService(msName, "onap.policies.monitoring.cdap.tca.hi.lo.app", "", "", "")); + .singletonList(new MicroService(msName, "onap.policies.monitoring.cdap.tca.hi.lo.app", "", "")); } String getName(Entry entry) { @@ -118,8 +119,22 @@ public class BlueprintParser { return ""; } - String getModelType(Entry entry) { + String findModelTypeInTargetArray(JsonArray jsonArray, JsonObject nodeTemplateList) { + for (JsonElement elem : jsonArray) { + String modelType = getModelType( + new AbstractMap.SimpleEntry(elem.getAsJsonObject().get(TARGET).getAsString(), + nodeTemplateList.get(elem.getAsJsonObject().get(TARGET).getAsString()).getAsJsonObject()), + nodeTemplateList); + if (!modelType.isEmpty()) { + return modelType; + } + } + return ""; + } + + String getModelType(Entry entry, JsonObject nodeTemplateList) { JsonObject ob = entry.getValue().getAsJsonObject(); + // Search first in this node template if (ob.has(PROPERTIES)) { JsonObject properties = ob.get(PROPERTIES).getAsJsonObject(); if (properties.has(POLICYID)) { @@ -129,19 +144,18 @@ public class BlueprintParser { } } } + // Then it's may be a relationship + if (ob.has(RELATIONSHIPS)) { + return findModelTypeInTargetArray(ob.get(RELATIONSHIPS).getAsJsonArray(), nodeTemplateList); + } return ""; } - String getBlueprintName(Entry entry) { - return entry.getKey(); - } - - MicroService getNodeRepresentation(Entry entry) { + MicroService getNodeRepresentation(Entry entry, JsonObject nodeTemplateList) { String name = getName(entry); String getInputFrom = getInput(entry); - String modelType = getModelType(entry); - String blueprintName = getBlueprintName(entry); - return new MicroService(name, modelType, getInputFrom, "", blueprintName); + String modelType = getModelType(entry, nodeTemplateList); + return new MicroService(name, modelType, getInputFrom, ""); } private String getTarget(JsonObject elementObject) { diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java index ac4daeffb..9bc7a022a 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java @@ -29,16 +29,14 @@ import java.util.Objects; public class MicroService { private final String name; private final String modelType; - private final String blueprintName; private final String inputFrom; private String mappedNameJpa; - public MicroService(String name, String modelType, String inputFrom, String mappedNameJpa, String blueprintName) { + public MicroService(String name, String modelType, String inputFrom, String mappedNameJpa) { this.name = name; this.inputFrom = inputFrom; this.mappedNameJpa = mappedNameJpa; - this.modelType = modelType; - this.blueprintName = blueprintName; + this.modelType = modelType; } public String getName() { @@ -53,15 +51,10 @@ public class MicroService { return inputFrom; } - public String getBlueprintName() { - return blueprintName; - } - @Override public String toString() { return "MicroService{" + "name='" + name + '\'' + ", modelType='" + modelType + '\'' + ", inputFrom='" - + inputFrom + '\'' + ", mappedNameJpa='" + mappedNameJpa + '\'' + ", blueprintName='" - + blueprintName + '\'' + '}'; + + inputFrom + '\'' + ", mappedNameJpa='" + mappedNameJpa + '\'' + '}'; } public String getMappedNameJpa() { @@ -81,11 +74,12 @@ public class MicroService { return false; } MicroService that = (MicroService) o; - return name.equals(that.name) && modelType.equals(that.modelType) && inputFrom.equals(that.inputFrom) && mappedNameJpa.equals(that.mappedNameJpa) && blueprintName.equals(that.blueprintName); + return name.equals(that.name) && modelType.equals(that.modelType) && inputFrom.equals(that.inputFrom) + && mappedNameJpa.equals(that.mappedNameJpa); } @Override public int hashCode() { - return Objects.hash(name, modelType, inputFrom, mappedNameJpa, blueprintName); + return Objects.hash(name, modelType, inputFrom, mappedNameJpa); } } diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml index b24525fe9..5f8577720 100644 --- a/src/main/resources/clds/camel/routes/flexible-flow.xml +++ b/src/main/resources/clds/camel/routes/flexible-flow.xml @@ -601,7 +601,7 @@ + message="Query Closed Loop status from policy PDP: ${exchangeProperty[loopObject].getName()}" /> @@ -625,9 +625,9 @@ + message="Endpoint to query from Policy PDP: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/${exchangeProperty[operationalPolicyName]}/versions/deployed"> + uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/${exchangeProperty[operationalPolicyName]}/versions/deployed?bridgeEndpoint=true&useSystemProperties=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&httpClient.connectTimeout=10000&authMethod=Basic&authUsername={{clamp.config.policy.pap.userName}}&authPassword={{clamp.config.policy.pap.password}}" />