aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorVidyashree-Huawei <vidyashree.rama@huawei.com>2020-01-22 17:25:46 +0530
committerVidyashree-Huawei <vidyashree.rama@huawei.com>2020-01-29 14:40:39 +0530
commit4593656e1f168c067e2a37389aeaa67889c1c173 (patch)
tree3f78537a494fb32b3aed1e32e74c79887839219b /src/main
parent33fc823baeda6d4e872614b146ab865823a3ca0f (diff)
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 <vidyashree.rama@huawei.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryCache.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java11
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java33
-rw-r--r--src/main/resources/clds/camel/routes/dcae-flows.xml43
4 files changed, 75 insertions, 14 deletions
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<String, Set<DcaeInventoryResponse>> blueprintsMap = new ConcurrentHashMap<>();
+ private static Map<String, Set<DcaeInventoryResponse>> 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<DcaeInventoryResponse>
@Expose
private String asdcResourceId;
- @Expose
- private String selfLink;
-
public String getTypeName() {
return typeName;
}
@@ -96,14 +93,6 @@ public class DcaeInventoryResponse implements Comparable<DcaeInventoryResponse>
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<DcaeInventoryResponse> 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<DcaeInventoryResponse> 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 @@
</doTry>
</route>
+ <route id="get-all-dcae-blueprint-inventory">
+ <from uri="direct:get-all-dcae-blueprint-inventory" />
+ <log loggingLevel="INFO"
+ message="Getting all DCAE blueprint from inventory" />
+ <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('DCAE', 'Getting all blueprint from inventory')" />
+ <doTry>
+ <setHeader headerName="CamelHttpMethod">
+ <constant>GET</constant>
+ </setHeader>
+ <setHeader headerName="X-ONAP-RequestID">
+ <simple>${exchangeProperty[X-ONAP-RequestID]}
+ </simple>
+ </setHeader>
+ <setHeader headerName="X-ONAP-InvocationID">
+ <simple>${exchangeProperty[X-ONAP-InvocationID]}
+ </simple>
+ </setHeader>
+ <setHeader headerName="X-ONAP-PartnerName">
+ <simple>${exchangeProperty[X-ONAP-PartnerName]}
+ </simple>
+ </setHeader>
+ <log loggingLevel="INFO"
+ message="Endpoint to query Blueprints from DCAE inventory: {{clamp.config.dcae.inventory.url}}/dcae-service-types?${header[CamelHttpQuery]}"></log>
+ <toD uri="{{clamp.config.dcae.inventory.url}}/dcae-service-types;bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.dcae.deployment.userName}}&amp;authPassword={{clamp.config.dcae.deployment.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=30000&amp;authenticationPreemptive=true&amp;connectionClose=true" />
+ <convertBodyTo type="java.lang.String" />
+ <setProperty propertyName="dcaeResponseList">
+ <method ref="org.onap.clamp.loop.components.external.DcaeComponent"
+ method="convertToDcaeInventoryResponse(${body})" />
+ </setProperty>
+ <split>
+ <simple>${exchangeProperty[dcaeResponseList]}</simple>
+ <convertBodyTo type="org.onap.clamp.clds.model.dcae.DcaeInventoryResponse" />
+ <setProperty propertyName="dcaeResponse">
+ <simple>${body}</simple>
+ </setProperty>
+ <to uri="bean:org.onap.clamp.clds.model.dcae.DcaeInventoryCache?method=addDcaeInventoryResponse(${exchangeProperty[dcaeResponse]})" />
+ </split>
+ <doFinally>
+ <to uri="direct:reset-raise-http-exception-flag" />
+ <to uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()" />
+ </doFinally>
+ </doTry>
+ </route>
</routes> \ No newline at end of file