From 4593656e1f168c067e2a37389aeaa67889c1c173 Mon Sep 17 00:00:00 2001 From: Vidyashree-Huawei Date: Wed, 22 Jan 2020 17:25:46 +0530 Subject: Create a camel route that would retrieve all the DCAE blueprints Retreive all the DCAE blueprints and update DcaeInventoryCache Change-Id: Ia03a89c1871119a208094c014e5cb8aa8b4f71d3 Issue-ID: CLAMP-573 Signed-off-by: Vidyashree-Huawei --- .../clamp/clds/model/dcae/DcaeInventoryCache.java | 2 +- .../clds/model/dcae/DcaeInventoryResponse.java | 11 ------ .../loop/components/external/DcaeComponent.java | 33 ++++++++++++++++- .../resources/clds/camel/routes/dcae-flows.xml | 43 ++++++++++++++++++++++ 4 files changed, 75 insertions(+), 14 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java index 558102c5..19bc23d5 100644 --- a/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java +++ b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java @@ -36,7 +36,7 @@ import java.util.concurrent.ConcurrentHashMap; */ public class DcaeInventoryCache { - private Map> blueprintsMap = new ConcurrentHashMap<>(); + private static Map> blueprintsMap = new ConcurrentHashMap<>(); /** * Add Dcae inventory response. diff --git a/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java index bdf6e70f..67bd026d 100644 --- a/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java +++ b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java @@ -53,9 +53,6 @@ public class DcaeInventoryResponse implements Comparable @Expose private String asdcResourceId; - @Expose - private String selfLink; - public String getTypeName() { return typeName; } @@ -96,14 +93,6 @@ public class DcaeInventoryResponse implements Comparable this.asdcResourceId = asdcResourceId; } - public String getSelfLink() { - return selfLink; - } - - public void setSelfLink(String selfLink) { - this.selfLink = selfLink; - } - @Override public int compareTo(DcaeInventoryResponse otherResponse) { int thisResourceId = Integer.parseInt(this.asdcResourceId); diff --git a/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java b/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java index 9b131299..7a0d8b4b 100644 --- a/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java +++ b/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java @@ -24,10 +24,17 @@ package org.onap.clamp.loop.components.external; import com.google.gson.JsonObject; - +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; import java.util.UUID; - import org.apache.camel.Exchange; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse; import org.onap.clamp.clds.model.dcae.DcaeOperationStatusResponse; import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.loop.Loop; @@ -164,4 +171,26 @@ public class DcaeComponent extends ExternalComponent { } return this.getState(); } + + /** + * Convert the json response to a DcaeInventoryResponse. + * + * @param responseBody The DCAE response Json paylaod + * @return list of DcaeInventoryResponse + * @throws ParseException In case of issues with the Json parsing + */ + public static List convertToDcaeInventoryResponse(String responseBody) + throws ParseException { + JSONParser parser = new JSONParser(); + JSONObject jsonObj = (JSONObject) parser.parse(responseBody); + JSONArray itemsArray = (JSONArray) jsonObj.get("items"); + Iterator it = itemsArray.iterator(); + List inventoryResponseList = new LinkedList<>(); + while (it.hasNext()) { + JSONObject item = (JSONObject) it.next(); + DcaeInventoryResponse response = JsonUtils.GSON.fromJson(item.toString(), DcaeInventoryResponse.class); + inventoryResponseList.add(response); + } + return inventoryResponseList; + } } diff --git a/src/main/resources/clds/camel/routes/dcae-flows.xml b/src/main/resources/clds/camel/routes/dcae-flows.xml index fb3bc90e..6c963349 100644 --- a/src/main/resources/clds/camel/routes/dcae-flows.xml +++ b/src/main/resources/clds/camel/routes/dcae-flows.xml @@ -213,4 +213,47 @@ + + + + + + + GET + + + ${exchangeProperty[X-ONAP-RequestID]} + + + + ${exchangeProperty[X-ONAP-InvocationID]} + + + + ${exchangeProperty[X-ONAP-PartnerName]} + + + + + + + + + + ${exchangeProperty[dcaeResponseList]} + + + ${body} + + + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg