summaryrefslogtreecommitdiffstats
path: root/dcaedt_tools
diff options
context:
space:
mode:
Diffstat (limited to 'dcaedt_tools')
-rw-r--r--dcaedt_tools/src/ReadMe.txt8
-rw-r--r--dcaedt_tools/src/main/java/json/response/ElementsResponse/Data.java23
-rw-r--r--dcaedt_tools/src/main/java/json/response/ElementsResponse/Element.java73
-rw-r--r--dcaedt_tools/src/main/java/json/response/ElementsResponse/ElementsResponse.java53
-rw-r--r--dcaedt_tools/src/main/java/json/response/ItemsResponse/Data.java22
-rw-r--r--dcaedt_tools/src/main/java/json/response/ItemsResponse/Element.java53
-rw-r--r--dcaedt_tools/src/main/java/json/response/ItemsResponse/Item.java203
-rw-r--r--dcaedt_tools/src/main/java/json/response/ItemsResponse/ItemsResponse.java53
-rw-r--r--dcaedt_tools/src/main/java/json/response/ItemsResponse/Model.java62
-rw-r--r--dcaedt_tools/src/main/java/tools/DeployTemplate.java10
-rw-r--r--dcaedt_tools/src/main/java/tools/EntitiesRetriever.java33
-rw-r--r--dcaedt_tools/src/main/java/tools/ItemAndAlias.java8
-rw-r--r--dcaedt_tools/src/main/java/tools/Main.java15
-rw-r--r--dcaedt_tools/src/main/java/tools/NodeData.java7
-rw-r--r--dcaedt_tools/src/main/java/tools/TemplateContainer.java50
-rw-r--r--dcaedt_tools/src/main/java/utilities/DcaeRestClient.java26
-rw-r--r--dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java8
-rw-r--r--dcaedt_tools/src/main/java/utilities/IReport.java2
-rw-r--r--dcaedt_tools/src/main/java/utilities/Report.java11
-rw-r--r--dcaedt_tools/src/main/resources/conf/config.json269
-rw-r--r--dcaedt_tools/src/test/java/BaseTest.java67
-rw-r--r--dcaedt_tools/src/test/java/EntitiesRetrieverTest.java29
-rw-r--r--dcaedt_tools/src/test/java/TemplateContainerTest.java35
23 files changed, 282 insertions, 838 deletions
diff --git a/dcaedt_tools/src/ReadMe.txt b/dcaedt_tools/src/ReadMe.txt
index 4657a81..9813f98 100644
--- a/dcaedt_tools/src/ReadMe.txt
+++ b/dcaedt_tools/src/ReadMe.txt
@@ -61,4 +61,10 @@ config.json example:
}]
}
]
- } \ No newline at end of file
+ }
+
+
+ exit codes:
+ 0 - completed successfully
+ 1 - completed with errors
+ 2 - failed \ No newline at end of file
diff --git a/dcaedt_tools/src/main/java/json/response/ElementsResponse/Data.java b/dcaedt_tools/src/main/java/json/response/ElementsResponse/Data.java
deleted file mode 100644
index 15876af..0000000
--- a/dcaedt_tools/src/main/java/json/response/ElementsResponse/Data.java
+++ /dev/null
@@ -1,23 +0,0 @@
-
-package json.response.ElementsResponse;
-
-import java.util.List;
-import javax.annotation.Generated;
-import com.google.gson.annotations.SerializedName;
-
-@Generated("net.hexar.json2pojo")
-@SuppressWarnings("unused")
-public class Data {
-
- @SerializedName("elements")
- private List<Element> mElements;
-
- public List<Element> getElements() {
- return mElements;
- }
-
- public void setElements(List<Element> elements) {
- mElements = elements;
- }
-
-}
diff --git a/dcaedt_tools/src/main/java/json/response/ElementsResponse/Element.java b/dcaedt_tools/src/main/java/json/response/ElementsResponse/Element.java
deleted file mode 100644
index 6402061..0000000
--- a/dcaedt_tools/src/main/java/json/response/ElementsResponse/Element.java
+++ /dev/null
@@ -1,73 +0,0 @@
-
-package json.response.ElementsResponse;
-
-import java.util.List;
-import javax.annotation.Generated;
-import com.google.gson.annotations.SerializedName;
-
-@Generated("net.hexar.json2pojo")
-@SuppressWarnings("unused")
-public class Element {
-
- @SerializedName("catalog")
- private String mCatalog;
- @SerializedName("catalogId")
- private Long mCatalogId;
- @SerializedName("id")
- private Long mId;
- @SerializedName("itemId")
- private String mItemId;
- @SerializedName("labels")
- private List<String> mLabels;
- @SerializedName("name")
- private String mName;
-
- public String getCatalog() {
- return mCatalog;
- }
-
- public void setCatalog(String catalog) {
- mCatalog = catalog;
- }
-
- public Long getCatalogId() {
- return mCatalogId;
- }
-
- public void setCatalogId(Long catalogId) {
- mCatalogId = catalogId;
- }
-
- public Long getId() {
- return mId;
- }
-
- public void setId(Long id) {
- mId = id;
- }
-
- public String getItemId() {
- return mItemId;
- }
-
- public void setItemId(String itemId) {
- mItemId = itemId;
- }
-
- public List<String> getLabels() {
- return mLabels;
- }
-
- public void setLabels(List<String> labels) {
- mLabels = labels;
- }
-
- public String getName() {
- return mName;
- }
-
- public void setName(String name) {
- mName = name;
- }
-
-}
diff --git a/dcaedt_tools/src/main/java/json/response/ElementsResponse/ElementsResponse.java b/dcaedt_tools/src/main/java/json/response/ElementsResponse/ElementsResponse.java
deleted file mode 100644
index 02dcdf2..0000000
--- a/dcaedt_tools/src/main/java/json/response/ElementsResponse/ElementsResponse.java
+++ /dev/null
@@ -1,53 +0,0 @@
-
-package json.response.ElementsResponse;
-
-import javax.annotation.Generated;
-import com.google.gson.annotations.SerializedName;
-import json.response.Error;
-
-@Generated("net.hexar.json2pojo")
-@SuppressWarnings("unused")
-public class ElementsResponse {
-
- @SerializedName("data")
- private Data mData;
- @SerializedName("error")
- private Error mError;
- @SerializedName("id")
- private Object mId;
- @SerializedName("timestamp")
- private Long mTimestamp;
-
- public Data getData() {
- return mData;
- }
-
- public void setData(Data data) {
- mData = data;
- }
-
- public Error getError() {
- return mError;
- }
-
- public void setError(Error error) {
- mError = error;
- }
-
- public Object getId() {
- return mId;
- }
-
- public void setId(Object id) {
- mId = id;
- }
-
- public Long getTimestamp() {
- return mTimestamp;
- }
-
- public void setTimestamp(Long timestamp) {
- mTimestamp = timestamp;
- }
-
-}
diff --git a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Data.java b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Data.java
deleted file mode 100644
index 36fcb09..0000000
--- a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Data.java
+++ /dev/null
@@ -1,22 +0,0 @@
-
-package json.response.ItemsResponse;
-
-import javax.annotation.Generated;
-import com.google.gson.annotations.SerializedName;
-
-@Generated("net.hexar.json2pojo")
-@SuppressWarnings("unused")
-public class Data {
-
- @SerializedName("element")
- private Element mElement;
-
- public Element getElement() {
- return mElement;
- }
-
- public void setElement(Element element) {
- mElement = element;
- }
-
-}
diff --git a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Element.java b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Element.java
deleted file mode 100644
index 5d56a25..0000000
--- a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Element.java
+++ /dev/null
@@ -1,53 +0,0 @@
-
-package json.response.ItemsResponse;
-
-import java.util.List;
-import javax.annotation.Generated;
-import com.google.gson.annotations.SerializedName;
-
-@Generated("net.hexar.json2pojo")
-@SuppressWarnings("unused")
-public class Element {
-
- @SerializedName("id")
- private Long mId;
- @SerializedName("itemId")
- private String mItemId;
- @SerializedName("items")
- private List<Item> mItems;
- @SerializedName("name")
- private String mName;
-
- public Long getId() {
- return mId;
- }
-
- public void setId(Long id) {
- mId = id;
- }
-
- public String getItemId() {
- return mItemId;
- }
-
- public void setItemId(String itemId) {
- mItemId = itemId;
- }
-
- public List<Item> getItems() {
- return mItems;
- }
-
- public void setItems(List<Item> items) {
- mItems = items;
- }
-
- public String getName() {
- return mName;
- }
-
- public void setName(String name) {
- mName = name;
- }
-
-}
diff --git a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Item.java b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Item.java
deleted file mode 100644
index 6f0e518..0000000
--- a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Item.java
+++ /dev/null
@@ -1,203 +0,0 @@
-
-package json.response.ItemsResponse;
-
-import java.util.List;
-import javax.annotation.Generated;
-import com.google.gson.annotations.SerializedName;
-
-@Generated("net.hexar.json2pojo")
-@SuppressWarnings("unused")
-public class Item {
-
- @SerializedName("artifacts")
- private List<Artifact> mArtifacts;
- @SerializedName("catalog")
- private String mCatalog;
- @SerializedName("catalogId")
- private Long mCatalogId;
- @SerializedName("category")
- private String mCategory;
- @SerializedName("description")
- private String mDescription;
- @SerializedName("id")
- private Long mId;
- @SerializedName("invariantUUID")
- private String mInvariantUUID;
- @SerializedName("itemId")
- private String mItemId;
- @SerializedName("lastUpdaterFullName")
- private String mLastUpdaterFullName;
- @SerializedName("lastUpdaterUserId")
- private String mLastUpdaterUserId;
- @SerializedName("lifecycleState")
- private String mLifecycleState;
- @SerializedName("models")
- private List<Model> mModels;
- @SerializedName("name")
- private String mName;
- @SerializedName("resourceType")
- private String mResourceType;
- @SerializedName("subCategory")
- private String mSubCategory;
- @SerializedName("toscaModelURL")
- private String mToscaModelURL;
- @SerializedName("toscaResourceName")
- private String mToscaResourceName;
- @SerializedName("uuid")
- private String mUuid;
- @SerializedName("version")
- private String mVersion;
-
- public List<Artifact> getArtifacts() {
- return mArtifacts;
- }
-
- public void setArtifacts(List<Artifact> artifacts) {
- mArtifacts = artifacts;
- }
-
- public String getCatalog() {
- return mCatalog;
- }
-
- public void setCatalog(String catalog) {
- mCatalog = catalog;
- }
-
- public Long getCatalogId() {
- return mCatalogId;
- }
-
- public void setCatalogId(Long catalogId) {
- mCatalogId = catalogId;
- }
-
- public String getCategory() {
- return mCategory;
- }
-
- public void setCategory(String category) {
- mCategory = category;
- }
-
- public String getDescription() {
- return mDescription;
- }
-
- public void setDescription(String description) {
- mDescription = description;
- }
-
- public Long getId() {
- return mId;
- }
-
- public void setId(Long id) {
- mId = id;
- }
-
- public String getInvariantUUID() {
- return mInvariantUUID;
- }
-
- public void setInvariantUUID(String invariantUUID) {
- mInvariantUUID = invariantUUID;
- }
-
- public String getItemId() {
- return mItemId;
- }
-
- public void setItemId(String itemId) {
- mItemId = itemId;
- }
-
- public String getLastUpdaterFullName() {
- return mLastUpdaterFullName;
- }
-
- public void setLastUpdaterFullName(String lastUpdaterFullName) {
- mLastUpdaterFullName = lastUpdaterFullName;
- }
-
- public String getLastUpdaterUserId() {
- return mLastUpdaterUserId;
- }
-
- public void setLastUpdaterUserId(String lastUpdaterUserId) {
- mLastUpdaterUserId = lastUpdaterUserId;
- }
-
- public String getLifecycleState() {
- return mLifecycleState;
- }
-
- public void setLifecycleState(String lifecycleState) {
- mLifecycleState = lifecycleState;
- }
-
- public List<Model> getModels() {
- return mModels;
- }
-
- public void setModels(List<Model> models) {
- mModels = models;
- }
-
- public String getName() {
- return mName;
- }
-
- public void setName(String name) {
- mName = name;
- }
-
- public String getResourceType() {
- return mResourceType;
- }
-
- public void setResourceType(String resourceType) {
- mResourceType = resourceType;
- }
-
- public String getSubCategory() {
- return mSubCategory;
- }
-
- public void setSubCategory(String subCategory) {
- mSubCategory = subCategory;
- }
-
- public String getToscaModelURL() {
- return mToscaModelURL;
- }
-
- public void setToscaModelURL(String toscaModelURL) {
- mToscaModelURL = toscaModelURL;
- }
-
- public String getToscaResourceName() {
- return mToscaResourceName;
- }
-
- public void setToscaResourceName(String toscaResourceName) {
- mToscaResourceName = toscaResourceName;
- }
-
- public String getUuid() {
- return mUuid;
- }
-
- public void setUuid(String uuid) {
- mUuid = uuid;
- }
-
- public String getVersion() {
- return mVersion;
- }
-
- public void setVersion(String version) {
- mVersion = version;
- }
-
-}
diff --git a/dcaedt_tools/src/main/java/json/response/ItemsResponse/ItemsResponse.java b/dcaedt_tools/src/main/java/json/response/ItemsResponse/ItemsResponse.java
deleted file mode 100644
index 5b64b59..0000000
--- a/dcaedt_tools/src/main/java/json/response/ItemsResponse/ItemsResponse.java
+++ /dev/null
@@ -1,53 +0,0 @@
-
-package json.response.ItemsResponse;
-
-import javax.annotation.Generated;
-import com.google.gson.annotations.SerializedName;
-import json.response.Error;
-
-@Generated("net.hexar.json2pojo")
-@SuppressWarnings("unused")
-public class ItemsResponse {
-
- @SerializedName("data")
- private Data mData;
- @SerializedName("error")
- private Error mError;
- @SerializedName("id")
- private Object mId;
- @SerializedName("timestamp")
- private Long mTimestamp;
-
- public Data getData() {
- return mData;
- }
-
- public void setData(Data data) {
- mData = data;
- }
-
- public Error getError() {
- return mError;
- }
-
- public void setError(Error error) {
- mError = error;
- }
-
- public Object getId() {
- return mId;
- }
-
- public void setId(Object id) {
- mId = id;
- }
-
- public Long getTimestamp() {
- return mTimestamp;
- }
-
- public void setTimestamp(Long timestamp) {
- mTimestamp = timestamp;
- }
-
-}
diff --git a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Model.java b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Model.java
deleted file mode 100644
index 036b16b..0000000
--- a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Model.java
+++ /dev/null
@@ -1,62 +0,0 @@
-
-package json.response.ItemsResponse;
-
-import javax.annotation.Generated;
-import com.google.gson.annotations.SerializedName;
-
-@Generated("net.hexar.json2pojo")
-@SuppressWarnings("unused")
-public class Model {
-
- @SerializedName("description")
- private String mDescription;
- @SerializedName("id")
- private String mId;
- @SerializedName("itemId")
- private String mItemId;
- @SerializedName("name")
- private String mName;
- @SerializedName("version")
- private String mVersion;
-
- public String getDescription() {
- return mDescription;
- }
-
- public void setDescription(String description) {
- mDescription = description;
- }
-
- public String getId() {
- return mId;
- }
-
- public void setId(String id) {
- mId = id;
- }
-
- public String getItemId() {
- return mItemId;
- }
-
- public void setItemId(String itemId) {
- mItemId = itemId;
- }
-
- public String getName() {
- return mName;
- }
-
- public void setName(String name) {
- mName = name;
- }
-
- public String getVersion() {
- return mVersion;
- }
-
- public void setVersion(String version) {
- mVersion = version;
- }
-
-}
diff --git a/dcaedt_tools/src/main/java/tools/DeployTemplate.java b/dcaedt_tools/src/main/java/tools/DeployTemplate.java
index d319542..556316b 100644
--- a/dcaedt_tools/src/main/java/tools/DeployTemplate.java
+++ b/dcaedt_tools/src/main/java/tools/DeployTemplate.java
@@ -29,7 +29,7 @@ public class DeployTemplate {
}
public void deploy(Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap) {
- ArrayList<ResourceDetailed> vfcmtList = new ArrayList();
+ ArrayList<ResourceDetailed> vfcmtList = new ArrayList<>();
List<ResourceDetailed> regularVfcmtList = dcaeRestClient.getAllVfcmts();
if (regularVfcmtList != null) {
vfcmtList.addAll(regularVfcmtList);
@@ -55,7 +55,7 @@ public class DeployTemplate {
private void verify(Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap) {
AtomicInteger foundCount = new AtomicInteger();
debugLogger.log("Starting verify deployment");
- ArrayList<ResourceDetailed> vfcmtList = new ArrayList();
+ ArrayList<ResourceDetailed> vfcmtList = new ArrayList<>();
List<ResourceDetailed> regularVfcmtList = dcaeRestClient.getAllVfcmts();
if (regularVfcmtList != null) {
vfcmtList.addAll(regularVfcmtList);
@@ -91,10 +91,11 @@ public class DeployTemplate {
saveAndCertify(jsonObject, vfcmt);
- } catch (HttpServerErrorException e) {
+ } catch (Exception e) {
String msg = FAILED_UPDATE_VFCMT + templateInfo.getName() + ", With general message: " + e.getMessage();
report.addErrorMessage(msg);
errLogger.log(msg + " " + e);
+ report.setStatusCode(2);
}
}
@@ -120,10 +121,11 @@ public class DeployTemplate {
} else {
report.addNotUpdatedMessage("vfcmt: " + vfcmt.getName() + " found, but didn't update.");
}
- } catch (HttpServerErrorException e) {
+ } catch (Exception e) {
String msg = FAILED_UPDATE_VFCMT + vfcmt.getName() + ", With general message: " + e.getMessage();
report.addErrorMessage(msg);
errLogger.log( msg + " " + e);
+ report.setStatusCode(2);
}
}
diff --git a/dcaedt_tools/src/main/java/tools/EntitiesRetriever.java b/dcaedt_tools/src/main/java/tools/EntitiesRetriever.java
deleted file mode 100644
index 0c31ddf..0000000
--- a/dcaedt_tools/src/main/java/tools/EntitiesRetriever.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package tools;
-
-import json.response.ElementsResponse.Element;
-import json.response.ItemsResponse.Item;
-import utilities.IDcaeRestClient;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-
-public class EntitiesRetriever {
- private final IDcaeRestClient dcaeRestClient;
-
- EntitiesRetriever(IDcaeRestClient dcaeRestClient) {
-
- this.dcaeRestClient = dcaeRestClient;
- }
-
- public Map<String, List<Item>> getElementsByFolder() {
- List<Element> elementList = dcaeRestClient.getElements();
- Map<String, List<Item>> elementsByFolderNames = new HashMap<>();
-
- for (Element element : elementList) {
- List<Item> items = dcaeRestClient.getItem(element.getName());
- if (items == null) {
- continue;
- }
- elementsByFolderNames.put(element.getName(), items);
- }
- return elementsByFolderNames;
- }
-}
diff --git a/dcaedt_tools/src/main/java/tools/ItemAndAlias.java b/dcaedt_tools/src/main/java/tools/ItemAndAlias.java
index e282a58..dae65ef 100644
--- a/dcaedt_tools/src/main/java/tools/ItemAndAlias.java
+++ b/dcaedt_tools/src/main/java/tools/ItemAndAlias.java
@@ -1,16 +1,16 @@
package tools;
-import json.response.ItemsResponse.Item;
+import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
public class ItemAndAlias {
- private final Item item;
+ private final Resource item;
private final String alias;
- public ItemAndAlias(Item item, String alias) {
+ public ItemAndAlias(Resource item, String alias) {
this.item = item;
this.alias = alias;
}
- public Item getItem() {
+ public Resource getItem() {
return item;
}
diff --git a/dcaedt_tools/src/main/java/tools/Main.java b/dcaedt_tools/src/main/java/tools/Main.java
index bf02c44..142b6bd 100644
--- a/dcaedt_tools/src/main/java/tools/Main.java
+++ b/dcaedt_tools/src/main/java/tools/Main.java
@@ -4,10 +4,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonObject;
import json.Environment;
-import json.response.ItemsResponse.Item;
+
import json.templateInfo.DeployTemplateConfig;
import json.templateInfo.TemplateInfo;
+import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
import utilities.IDcaeRestClient;
import utilities.IReport;
import utilities.Report;
@@ -35,7 +36,7 @@ public class Main {
debugLogger.log("Starting VFCMT template deployment");
if (args.length != 2) {
errLogger.log("Got " + args.length + ", but expecting exactly 2 arguments ONLY!");
- return;
+ System.exit(2);
}
debugLogger.log("Arguments:");
Arrays.stream(args).forEach(arg -> debugLogger.log(arg));
@@ -50,8 +51,7 @@ public class Main {
IDcaeRestClient dcaeRestClient = new DcaeRestClient(environment.getCredential());
dcaeRestClient.init(environment);
- EntitiesRetriever entitiesRetriever = new EntitiesRetriever(dcaeRestClient);
- Map<String, List<Item>> elementsByFolderNames = entitiesRetriever.getElementsByFolder();
+ Map<String, List<Resource>> elementsByFolderNames = dcaeRestClient.getDcaeCatalog();
TemplateContainer templateContainer = new TemplateContainer(report, dcaeRestClient, deployTemplateConfig.getTemplateInfo(), elementsByFolderNames);
Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap = templateContainer.getCdumps();
@@ -59,15 +59,20 @@ public class Main {
DeployTemplate deployTemplate = new DeployTemplate(report, dcaeRestClient);
deployTemplate.deploy(templateInfoToJsonObjectMap);
- debugLogger.log( "VFCMT template deployment completed successfully");
+ debugLogger.log( "VFCMT template deployment completed");
+
} catch (RuntimeException e) {
errLogger.log("ERROR - Template deployment failed with error " + e, e);
+ report.setStatusCode(2);
} catch (ConnectException e) {
errLogger.log( "ERROR - Failed connection to server, are you on AT&T network? {}" + e, e);
+ report.setStatusCode(2);
} catch (IOException e) {
errLogger.log( "ERROR - Fatal Error! " + e, e);
+ report.setStatusCode(2);
} finally {
debugLogger.log(report.toString());
+ report.reportAndExit();
}
}
diff --git a/dcaedt_tools/src/main/java/tools/NodeData.java b/dcaedt_tools/src/main/java/tools/NodeData.java
index e9043de..a2df502 100644
--- a/dcaedt_tools/src/main/java/tools/NodeData.java
+++ b/dcaedt_tools/src/main/java/tools/NodeData.java
@@ -2,6 +2,7 @@ package tools;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
+import org.apache.commons.lang3.StringUtils;
public class NodeData {
private final JsonArray capabilities;
@@ -41,7 +42,11 @@ public class NodeData {
}
public String getNameWithAlias() {
- return aliasBelong + "." + nodeName;
+ if (StringUtils.isBlank(aliasBelong)) {
+ return nodeName;
+ } else {
+ return aliasBelong + "." + nodeName;
+ }
}
public String getAliasBelong() {
diff --git a/dcaedt_tools/src/main/java/tools/TemplateContainer.java b/dcaedt_tools/src/main/java/tools/TemplateContainer.java
index a5bca1f..b8b7b5a 100644
--- a/dcaedt_tools/src/main/java/tools/TemplateContainer.java
+++ b/dcaedt_tools/src/main/java/tools/TemplateContainer.java
@@ -4,12 +4,12 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import json.response.ItemsResponse.Item;
import json.templateInfo.Composition;
import json.templateInfo.NodeToDelete;
import json.templateInfo.Relation;
import json.templateInfo.TemplateInfo;
import org.apache.commons.lang3.StringUtils;
+import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
import utilities.IDcaeRestClient;
import utilities.IReport;
@@ -20,16 +20,16 @@ import java.util.concurrent.atomic.AtomicReference;
public class TemplateContainer {
private static final String NODES = "nodes";
private static final String RELATIONSHIP = "relationship";
- public static final String ASSIGNMENT = "assignment";
+ private static final String ASSIGNMENT = "assignment";
private static long nidCounter = 0;
private final IReport report;
private final IDcaeRestClient dcaeRestClient;
private final List<TemplateInfo> templateInfos;
- private final Map<String, List<Item>> elementsByFolderNames;
+ private final Map<String, List<Resource>> elementsByFolderNames;
private LoggerDebug debugLogger = LoggerDebug.getInstance();
- public TemplateContainer(IReport report, IDcaeRestClient dcaeRestClient, List<TemplateInfo> templateInfos, Map<String, List<Item>> elementsByFolderNames) {
+ public TemplateContainer(IReport report, IDcaeRestClient dcaeRestClient, List<TemplateInfo> templateInfos, Map<String, List<Resource>> elementsByFolderNames) {
this.report = report;
this.dcaeRestClient = dcaeRestClient;
this.templateInfos = templateInfos;
@@ -69,6 +69,7 @@ public class TemplateContainer {
List<ItemAndAlias> items = findTemplate(templateInfo);
if (items == null || items.isEmpty()) {
report.addErrorMessage("vfcmt: " + templateInfo.getName() + ". DCAE Component not found");
+ report.setStatusCode(1);
continue;
}
templateInfoToJsonObjectMap.put(templateInfo, getCdumpJsonObject(items, templateInfo));
@@ -81,20 +82,21 @@ public class TemplateContainer {
Map<ItemAndAlias, Map<String, NodeData>> itemMapHashMap = new HashMap<>();
JsonArray relationsJsonArray = new JsonArray();
for (ItemAndAlias itemAndAlias : ItemsAndAlias) {
- Item item = itemAndAlias.getItem();
+ Resource item = itemAndAlias.getItem();
debugLogger.log("Creating cdump for item: " + item.getName());
JsonArray jsonArrayNode = cdumpJsonObject.getAsJsonArray(NODES);
JsonParser jsonParser = new JsonParser();
- JsonArray allNodeTemplates = jsonParser.parse(dcaeRestClient.getItemModel(item.getItemId())).getAsJsonObject().get("data").getAsJsonObject().get("model").getAsJsonObject().get(NODES).getAsJsonArray();
+ JsonObject modelResponse = jsonParser.parse(dcaeRestClient.getItemModel(item.getUuid())).getAsJsonObject().get("data").getAsJsonObject().get("model").getAsJsonObject();
+ JsonArray allNodeTemplates = modelResponse.get(NODES).getAsJsonArray();
Map<String, NodeData> stringRelationsDataMap = new HashMap<>();
for (JsonElement nodeElement : allNodeTemplates) {
if (checkIfNeedToSkip(templateInfo.getNodesToDelete(), nodeElement, item.getName())) {
continue;
}
JsonObject responseModelJson = nodeElement.getAsJsonObject();
- JsonObject responseTypeInfoJson = jsonParser.parse(dcaeRestClient.getItemType(item.getItemId(), responseModelJson.get("type").getAsString())).getAsJsonObject().get("data").getAsJsonObject().get("type").getAsJsonObject();
- String nodeName = itemAndAlias.getAlias() + "." + responseModelJson.get("name").getAsString();
- JsonObject jsonObjectElement = newNodeTemplate(nodeName, item.getModels().get(0).getItemId());
+ JsonObject responseTypeInfoJson = jsonParser.parse(dcaeRestClient.getItemType(item.getUuid(), responseModelJson.get("type").getAsString())).getAsJsonObject().get("data").getAsJsonObject().get("type").getAsJsonObject();
+ String nodeName = itemAndAlias.getAlias() != "" ? itemAndAlias.getAlias() + "." + responseModelJson.get("name").getAsString() : responseModelJson.get("name").getAsString();
+ JsonObject jsonObjectElement = newNodeTemplate(nodeName, modelResponse.get("itemId").getAsString());
jsonObjectElement.addProperty("id", responseTypeInfoJson.get("itemId").getAsString().split("/")[0]);
String nid = "n." + new Date().getTime() + "." + nidCounter++;
jsonObjectElement.addProperty("nid", nid);
@@ -228,7 +230,7 @@ public class TemplateContainer {
metaData.addProperty("n1", nidListByRequirement.get(requirement));
metaData.addProperty("p1", requirement.get("name").toString().replaceAll("\"", ""));
relationElement.addProperty("n2", toNId);
- relationElement.addProperty("name2", fromNode.getAliasBelong() + "." + toNodeName);
+ relationElement.addProperty("name2", StringUtils.isBlank(fromNode.getAliasBelong()) ? toNodeName : fromNode.getAliasBelong() + "." + toNodeName);
metaData.addProperty("n2", toNId);
String capabilityFullName = requirement.get("capability").getAsJsonObject().get("name").toString();
String capabilityShortName = StringUtils.substringAfterLast(capabilityFullName, ".");
@@ -270,10 +272,18 @@ public class TemplateContainer {
JsonObject relationElement = new JsonObject();
String fromComponent = relation.getFromComponent();
String toComponent = relation.getToComponent();
- String fromComponentAlias = StringUtils.substringBefore(fromComponent, ".");
- String fromComponentNodeName = StringUtils.substringAfterLast(fromComponent, ".");
- String toComponentAlias = StringUtils.substringBefore(toComponent, ".");
- String toComponentNodeName = StringUtils.substringAfterLast(toComponent, ".");
+ String fromComponentAlias = "";
+ String fromComponentNodeName = fromComponent;
+ if ((fromComponent.contains("."))) {
+ fromComponentAlias = StringUtils.substringBefore(fromComponent, ".");
+ fromComponentNodeName = StringUtils.substringAfterLast(fromComponent, ".");
+ }
+ String toComponentAlias = "";
+ String toComponentNodeName = toComponent;
+ if (toComponent.contains(".")) {
+ toComponentAlias = StringUtils.substringBefore(toComponent, ".");
+ toComponentNodeName = StringUtils.substringAfterLast(toComponent, ".");
+ }
boolean findTo = false;
boolean findFrom = false;
for (ItemAndAlias item : nodeDataByNidByItem.keySet()) {
@@ -281,12 +291,14 @@ public class TemplateContainer {
for (String nid : nodeDataByNid.keySet()) {
NodeData currentNodeData = nodeDataByNid.get(nid);
+ String finalFromComponentAlias = fromComponentAlias;
+ String finalFromComponentNodeName = fromComponentNodeName;
Optional<Composition> isFoundComposition = templateInfo.getComposition().stream()
- .filter(element -> fromComponentAlias.equalsIgnoreCase(element.getAlias())
+ .filter(element -> finalFromComponentAlias.equalsIgnoreCase(element.getAlias())
&& element.getAlias().equalsIgnoreCase(currentNodeData.getAliasBelong())
&& element.getAlias().equalsIgnoreCase(item.getAlias())
&& element.getType().equalsIgnoreCase(item.getItem().getName())
- && fromComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny();
+ && finalFromComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny();
if (isFoundComposition.isPresent()) {
boolean isFound = findNode(relation.getFromRequirement(), currentNodeData.getRequirements());
if (isFound) {
@@ -313,12 +325,14 @@ public class TemplateContainer {
}
+ String finalToComponentNodeName = toComponentNodeName;
+ String finalToComponentAlias = toComponentAlias;
isFoundComposition = templateInfo.getComposition().stream()
- .filter(element -> toComponentAlias.equalsIgnoreCase(element.getAlias())
+ .filter(element -> finalToComponentAlias.equalsIgnoreCase(element.getAlias())
&& element.getAlias().equalsIgnoreCase(currentNodeData.getAliasBelong())
&& element.getAlias().equalsIgnoreCase(item.getAlias())
&& element.getType().equalsIgnoreCase(item.getItem().getName())
- && toComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny();
+ && finalToComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny();
if (isFoundComposition.isPresent()) {
boolean isFound = findNode(relation.getToCapability(), currentNodeData.getCapabilities());
if (isFound) {
diff --git a/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java b/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java
index 7e991d7..ee6cdc7 100644
--- a/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java
+++ b/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java
@@ -2,14 +2,12 @@ package utilities;
import json.Credential;
import json.Environment;
-import json.response.ElementsResponse.Element;
-import json.response.ElementsResponse.ElementsResponse;
-import json.response.ItemsResponse.Item;
-import json.response.ItemsResponse.ItemsResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest;
+import org.onap.sdc.dcae.composition.restmodels.canvas.DcaeComponentCatalog;
+import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import org.springframework.http.*;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
@@ -17,10 +15,10 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -30,6 +28,7 @@ public class DcaeRestClient implements IDcaeRestClient {
private static final String GET_RESOURCES_BY_CATEGORY = "/getResourcesByCategory";
private static final String CREATE_VFCMT = "/createVFCMT";
private static final String ELEMENTS = "/elements";
+ private static final String CATALOG = "/catalog";
private static final String ECOMP_INSTANCE_ID_HEADER = "X-ECOMP-InstanceID";
@@ -102,16 +101,13 @@ public class DcaeRestClient implements IDcaeRestClient {
return resourceDetailedResponse.getBody();
}
- @Override
- public List<Element> getElements() {
- String url = buildRequestPath(ELEMENTS);
- return client.getForObject(url, ElementsResponse.class).getData().getElements();
- }
- @Override
- public List<Item> getItem(String element) {
- String url = buildRequestPath("/"+ element + ELEMENTS);
- return client.getForObject(url, ItemsResponse.class).getData().getElement() == null ? null : client.getForObject(url, ItemsResponse.class).getData().getElement().getItems();
- }
+ @Override
+ public Map<String, List<Resource>> getDcaeCatalog() {
+ String url = buildRequestPath(CATALOG);
+ DcaeComponentCatalog catalog = client.getForObject(url, DcaeComponentCatalog.class);
+ return catalog.getElements().stream().collect(Collectors.toMap(DcaeComponentCatalog.SubCategoryFolder::getName, DcaeComponentCatalog.SubCategoryFolder::getItems));
+ }
+
@Override
public String getItemModel(String elementId) {
diff --git a/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java b/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java
index bfe3595..a1ccdbe 100644
--- a/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java
+++ b/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java
@@ -1,12 +1,12 @@
package utilities;
import json.Environment;
-import json.response.ElementsResponse.Element;
-import json.response.ItemsResponse.Item;
import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest;
+import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import java.util.List;
+import java.util.Map;
public interface IDcaeRestClient {
void init(Environment environment);
@@ -23,9 +23,7 @@ public interface IDcaeRestClient {
ResourceDetailed checkinVfcmt(String vfcmtUuid);
- List<Element> getElements();
-
- List<Item> getItem(String element);
+ Map<String, List<Resource>> getDcaeCatalog();
String getItemModel(String elementId);
diff --git a/dcaedt_tools/src/main/java/utilities/IReport.java b/dcaedt_tools/src/main/java/utilities/IReport.java
index 4c5f8af..5f4099c 100644
--- a/dcaedt_tools/src/main/java/utilities/IReport.java
+++ b/dcaedt_tools/src/main/java/utilities/IReport.java
@@ -5,4 +5,6 @@ public interface IReport {
void addUpdatedMessage(String message);
void addNotUpdatedMessage(String message);
void addErrorMessage(String message);
+ void setStatusCode(int statusCode);
+ void reportAndExit();
}
diff --git a/dcaedt_tools/src/main/java/utilities/Report.java b/dcaedt_tools/src/main/java/utilities/Report.java
index 8f79056..0b99603 100644
--- a/dcaedt_tools/src/main/java/utilities/Report.java
+++ b/dcaedt_tools/src/main/java/utilities/Report.java
@@ -9,6 +9,7 @@ public class Report implements IReport {
private List<String> updated = new ArrayList<>();
private List<String> notUpdated = new ArrayList<>();
private List<String> error = new ArrayList<>();
+ private int statusCode = 0;
@Override
public void addCreatedMessage(String message) {
@@ -51,4 +52,14 @@ public class Report implements IReport {
}
return stringBuilder.toString();
}
+
+
+ public void reportAndExit() {
+ System.exit(statusCode);
+ }
+
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
+ }
+
}
diff --git a/dcaedt_tools/src/main/resources/conf/config.json b/dcaedt_tools/src/main/resources/conf/config.json
index 4ca81cc..f7c07d7 100644
--- a/dcaedt_tools/src/main/resources/conf/config.json
+++ b/dcaedt_tools/src/main/resources/conf/config.json
@@ -1,6 +1,7 @@
+
{
"templateInfo": [{
- "name": "Syslog Collector Template",
+ "name": "Syslog Collector",
"flowType": "Syslog Collector",
"description": "Syslog Collector",
"category": "Template",
@@ -8,24 +9,10 @@
"updateIfExist": "false",
"composition": [{
"type": "SyslogCollector",
- "alias": "Syslog"
- }, {
- "type": "Existing Topic",
- "alias": "eTopic"
- }],
- "relations": [{
- "fromComponent": "Syslog.SyslogCollector",
- "fromRequirement": "stream_publish_0",
- "toComponent": "eTopic.topic",
- "toCapability": "topic"
- }],
- "nodesToDelete": [
- {
- "type": "SyslogCollector",
- "nodeName": "topic0"
- }]
+ "alias": ""
+ }]
},{
- "name": "Syslog MSEA Template",
+ "name": "Syslog MSEA",
"flowType": "Syslog MSEA",
"description": "Syslog MSEA",
"category": "Template",
@@ -33,60 +20,37 @@
"updateIfExist": "false",
"composition": [{
"type": "Map",
- "alias": "Map"
+ "alias": ""
}, {
"type": "Supplement",
- "alias": "Sup"
+ "alias": ""
}, {
"type": "Enrich",
- "alias": "Enr"
+ "alias": ""
}, {
"type": "Alert",
- "alias": "Ale"
+ "alias": ""
}],
"relations": [{
- "fromComponent": "Sup.Supplement",
+ "fromComponent": "Supplement",
"fromRequirement": "dependency",
- "toComponent": "Map.Map",
+ "toComponent": "Map",
"toCapability": "feature"
},{
- "fromComponent": "Enr.Enrich",
+ "fromComponent": "Enrich",
"fromRequirement": "dependency",
- "toComponent": "Sup.Supplement",
+ "toComponent": "Supplement",
"toCapability": "feature"
},{
- "fromComponent": "Ale.Alert",
+ "fromComponent": "Alert",
"fromRequirement": "dependency",
- "toComponent": "Enr.Enrich",
+ "toComponent": "Enrich",
"toCapability": "feature"
}]
- },{
- "name": "Status Poller Collector Template",
- "flowType": "Status Poller Collector",
- "description": "Status Poller Collector",
- "category": "Template",
- "subCategory":"Base Monitoring Template",
- "updateIfExist": "false",
- "composition": [{
- "type": "StatusPoller",
- "alias": "sPoller"
- }, {
- "type": "Existing Topic",
- "alias": "eTopic0"
- }],
- "relations": [{
- "fromComponent": "sPoller.StatusPoller",
- "fromRequirement": "stream_publish_0",
- "toComponent": "eTopic0.topic",
- "toCapability": "topic"
- }],
- "nodesToDelete": [
- {
- "type": "StatusPoller",
- "nodeName": "topic0"
- }]
- }, {
- "name": "Status Poller MSE Template",
+ },
+
+ {
+ "name": "Status Poller MSE",
"flowType": "Status Poller MSE",
"description": "Status Poller MSE",
"category": "Template",
@@ -94,27 +58,27 @@
"updateIfExist": "false",
"composition": [{
"type": "Map",
- "alias": "Map"
+ "alias": ""
}, {
"type": "Supplement",
- "alias": "Sup"
+ "alias": ""
}, {
"type": "Enrich",
- "alias": "Enr"
+ "alias": ""
}],
"relations": [{
- "fromComponent": "Sup.Supplement",
+ "fromComponent": "Supplement",
"fromRequirement": "dependency",
- "toComponent": "Map.Map",
+ "toComponent": "Map",
"toCapability": "feature"
},{
- "fromComponent": "Enr.Enrich",
+ "fromComponent": "Enrich",
"fromRequirement": "dependency",
- "toComponent": "Sup.Supplement",
+ "toComponent": "Supplement",
"toCapability": "feature"
}]
}, {
- "name": "FOI Collector Template",
+ "name": "FOI Collector",
"flowType": "FOI Collector",
"description": "FOI Collector",
"category": "Template",
@@ -122,24 +86,11 @@
"updateIfExist": "false",
"composition": [{
"type": "FOICollector",
- "alias": "fCollector"
- }, {
- "type": "Existing Feed",
- "alias": "eFeed"
- }],
- "relations": [{
- "fromComponent": "fCollector.FoiSftp",
- "fromRequirement": "stream_publish_0",
- "toComponent": "eFeed.feed",
- "toCapability": "feed"
- }],
- "nodesToDelete": [
- {
- "type": "FOICollector",
- "nodeName": "feed0"
- }]
+ "alias": ""
+ }]
+
}, {
- "name": "SNMP MSE Template",
+ "name": "SNMP MSE",
"flowType": "SNMP MSE",
"description": "SNMP MSE",
"category": "Template",
@@ -147,27 +98,27 @@
"updateIfExist": "false",
"composition": [{
"type": "Map",
- "alias": "Map"
+ "alias": ""
}, {
"type": "Supplement",
- "alias": "Sup"
+ "alias": ""
}, {
"type": "Enrich",
- "alias": "Enr"
+ "alias": ""
}],
"relations": [{
- "fromComponent": "Sup.Supplement",
+ "fromComponent": "Supplement",
"fromRequirement": "dependency",
- "toComponent": "Map.Map",
+ "toComponent": "Map",
"toCapability": "feature"
},{
- "fromComponent": "Enr.Enrich",
+ "fromComponent": "Enrich",
"fromRequirement": "dependency",
- "toComponent": "Sup.Supplement",
+ "toComponent": "Supplement",
"toCapability": "feature"
}]
}, {
- "name": "Docker Map Template",
+ "name": "Docker Map",
"flowType": "Docker Map",
"description": "Docker Map",
"category": "Template",
@@ -175,33 +126,125 @@
"updateIfExist": "false",
"composition": [{
"type": "DockerMap",
- "alias": "dMp"
- }, {
- "type": "Existing Feed",
- "alias": "eFeed"
+ "alias": ""
+ }]
+ },
+ {
+ "name": "SAM Collector",
+ "flowType": "SAM Collector",
+ "description": "SAM Collector",
+ "category": "Template",
+ "subCategory":"Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [{
+ "type": "SAMCollector1806",
+ "alias": ""
+ }]
+ },
+ {
+ "name": "SNMP PM Poller",
+ "flowType": "SNMP PM Poller",
+ "description": "SNMP PM Poller",
+ "category": "Template",
+ "subCategory":"Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [{
+ "type": "PM Poller",
+ "alias": ""
+ }]
+ },
+ {
+ "name": "Status Poller Collector",
+ "flowType": "Status Poller Collector",
+ "description": "Status Poller Collector",
+ "category": "Template",
+ "subCategory": "Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [
+ {
+ "type": "StatusPoller",
+ "alias": ""
+ }]
+ },
+ {
+ "name": "VES Collector",
+ "flowType": "VES Collector",
+ "description": "VES Collector",
+ "category": "Template",
+ "subCategory":"Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [{
+ "type": "VES Collector",
+ "alias": ""
+ }]
+ },
+ {
+ "name": "VES Fault SE",
+ "flowType": "VES Fault SE",
+ "description": "VES Fault SE",
+ "category": "Template",
+ "subCategory":"Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [{
+ "type": "Supplement",
+ "alias": ""
}, {
- "type": "Existing Topic",
- "alias": "eTopic"
+ "type": "Enrich",
+ "alias": ""
}],
"relations": [{
- "fromComponent": "dMp.DockerMap",
- "fromRequirement": "stream_subscribe_0",
- "toComponent": "eFeed.feed",
- "toCapability": "feed"
- }, {
- "fromComponent": "dMp.DockerMap",
- "fromRequirement": "stream_publish_0",
- "toComponent": "eTopic.topic",
- "toCapability": "topic"
- }],
- "nodesToDelete": [
- {
- "type": "DockerMap",
- "nodeName": "feed0"
- },
- {
- "type": "DockerMap",
- "nodeName": "topic0"
- }]
+ "fromComponent": "Enrich",
+ "fromRequirement": "dependency",
+ "toComponent": "Supplement",
+ "toCapability": "feature"
+ }]
+ },
+ {
+ "name": "Docker Supplement",
+ "flowType": "Docker Supplement",
+ "description": "Docker Supplement",
+ "category": "Template",
+ "subCategory":"Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [{
+ "type": "Docker_Supplement",
+ "alias": ""
+ }]
+ },
+ {
+ "name": "Docker Enrich",
+ "flowType": "Docker Enrich",
+ "description": "Docker Enrich",
+ "category": "Template",
+ "subCategory":"Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [{
+ "type": "DockerEnrich",
+ "alias": ""
+ }]
+ },
+ {
+ "name": "MIB Poller",
+ "flowType": "MIB Poller",
+ "description": "MIB Poller",
+ "category": "Template",
+ "subCategory":"Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [{
+ "type": "MIBPoller",
+ "alias": ""
+ }]
+ },
+ {
+ "name": "Discovery Poller",
+ "flowType": "Discovery Poller",
+ "description": "Discovery Poller",
+ "category": "Template",
+ "subCategory":"Base Monitoring Template",
+ "updateIfExist": "false",
+ "composition": [{
+ "type": "Discovery",
+ "alias": ""
+ }]
}]
} \ No newline at end of file
diff --git a/dcaedt_tools/src/test/java/BaseTest.java b/dcaedt_tools/src/test/java/BaseTest.java
index f618f2d..d3a6ed5 100644
--- a/dcaedt_tools/src/test/java/BaseTest.java
+++ b/dcaedt_tools/src/test/java/BaseTest.java
@@ -1,17 +1,16 @@
-import json.response.ElementsResponse.Element;
-import json.response.ItemsResponse.Item;
-import json.response.ItemsResponse.Model;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import utilities.IDcaeRestClient;
import utilities.IReport;
import java.util.ArrayList;
-import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
@@ -47,8 +46,7 @@ abstract class BaseTest {
public void setup() {
when(dcaeRestClient.getUserId()).thenReturn(USER_ID);
mockGetAllVfcmt();
- mockGetElements();
- mockGetItems();
+ mockGetCatalog();
mockGetItemModel();
mockGetItemType();
mockCheckoutVfcmtAndCreateResource();
@@ -70,46 +68,29 @@ abstract class BaseTest {
}
private void mockGetItemModel() {
- when(dcaeRestClient.getItemModel(anyString())).thenReturn("{\"data\":{\"model\":{\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameFromRequirement\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}",
- "{\"data\":{\"model\":{\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameToCapability\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}");
+ when(dcaeRestClient.getItemModel(anyString())).thenReturn("{\"data\":{\"model\":{\"itemId\":\"\",\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameFromRequirement\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}",
+ "{\"data\":{\"model\":{\"itemId\":\"\",\"nodes\":[{\"capability\":{\"type\":\"someType\"}, \"type\":\"type\", \"name\":\"SomeNameToCapability\", \"requirements\":[{\"name\":\"SomeNameFromRequirement\"}], \"properties\":[{}], \"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"type\":\"type\"}]}}}");
}
- private void mockGetItems() {
- when(dcaeRestClient.getItem(ELEMENT_NAME1)).thenReturn(null);
- List<Item> items = new ArrayList<>();
- Item item = new Item();
- item.setName(ITEM_NAME1);
- Model model = new Model();
- model.setItemId("");
- List<Model> models = Collections.singletonList(model);
- item.setModels(models);
- items.add(item);
- item = new Item();
- item.setName(ITEM_NAME2);
- item.setModels(models);
- items.add(item);
- when(dcaeRestClient.getItem(ELEMENT_NAME2)).thenReturn(items);
- items = new ArrayList<>();
- item = new Item();
- item.setName(ITEM_NAME3);
- item.setModels(models);
- items.add(item);
- when(dcaeRestClient.getItem(ELEMENT_NAME3)).thenReturn(items);
- }
+ private void mockGetCatalog() {
+ Map<String, List<Resource>> catalog = new HashMap<>();
+ catalog.put(ELEMENT_NAME1, null);
+ List<Resource> items = new ArrayList<>();
+ Resource item = new Resource();
+ item.setName(ITEM_NAME1);
+ items.add(item);
+ item = new Resource();
+ item.setName(ITEM_NAME2);
+ items.add(item);
+ catalog.put(ELEMENT_NAME2, items);
+ items = new ArrayList<>();
+ item = new Resource();
+ item.setName(ITEM_NAME3);
+ items.add(item);
+ catalog.put(ELEMENT_NAME3, items);
+ when(dcaeRestClient.getDcaeCatalog()).thenReturn(catalog);
+ }
- private void mockGetElements() {
- List<Element> elements = new ArrayList<>();
- Element element = new Element();
- element.setName(ELEMENT_NAME1);
- elements.add(element);
- element = new Element();
- element.setName(ELEMENT_NAME2);
- elements.add(element);
- element = new Element();
- element.setName(ELEMENT_NAME3);
- elements.add(element);
- when(dcaeRestClient.getElements()).thenReturn(elements);
- }
private void mockGetAllVfcmt() {
List<ResourceDetailed> resourceDetaileds = new ArrayList<>();
diff --git a/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java b/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java
deleted file mode 100644
index ea7eb2b..0000000
--- a/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-
-import json.response.ItemsResponse.Item;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.InjectMocks;
-import tools.EntitiesRetriever;
-
-import java.util.List;
-import java.util.Map;
-
-
-public class EntitiesRetrieverTest extends BaseTest {
-
- @InjectMocks
- EntitiesRetriever entitiesRetriever;
-
- @Before
- @Override
- public void setup() {
- super.setup();
- }
-
- @Test
- public void getElementsByFolder_returns2Items() {
- Map<String, List<Item>> result = entitiesRetriever.getElementsByFolder();
- Assert.assertTrue(result.size() == 2);
- }
-}
diff --git a/dcaedt_tools/src/test/java/TemplateContainerTest.java b/dcaedt_tools/src/test/java/TemplateContainerTest.java
index b4ddc17..6b09991 100644
--- a/dcaedt_tools/src/test/java/TemplateContainerTest.java
+++ b/dcaedt_tools/src/test/java/TemplateContainerTest.java
@@ -1,6 +1,4 @@
import com.google.gson.JsonObject;
-import json.response.ItemsResponse.Item;
-import json.response.ItemsResponse.Model;
import json.templateInfo.Composition;
import json.templateInfo.NodeToDelete;
import json.templateInfo.Relation;
@@ -8,6 +6,7 @@ import json.templateInfo.TemplateInfo;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
import tools.TemplateContainer;
import java.util.*;
@@ -21,7 +20,7 @@ public class TemplateContainerTest extends BaseTest {
private TemplateContainer templateContainer;
private List<TemplateInfo> templateInfos;
- private Map<String, List<Item>> elementsByFolderNames;
+ private Map<String, List<Resource>> elementsByFolderNames;
@Before
@Override
public void setup() {
@@ -36,14 +35,9 @@ public class TemplateContainerTest extends BaseTest {
templateInfo.setComposition(Collections.singletonList(composition));
templateInfos.add(templateInfo);
elementsByFolderNames = new HashMap<>();
- Item item = new Item();
+ Resource item = new Resource();
item.setName(ELEMENT_NAME3);
- item.setItemId("");
- Model model = new Model();
- model.setItemId("");
- List<Model> models = Collections.singletonList(model);
- item.setModels(models);
- List<Item> items = new ArrayList<>(Collections.singletonList(item));
+ List<Resource> items = new ArrayList<>(Collections.singletonList(item));
elementsByFolderNames.put(TEMPLATE_INFO_NAME, items);
}
@@ -60,9 +54,9 @@ public class TemplateContainerTest extends BaseTest {
@Test
public void getCdumps_returnNotFoundEmptyList() {
elementsByFolderNames = new HashMap<>();
- Item item = new Item();
+ Resource item = new Resource();
item.setName(ELEMENT_NAME2);
- List<Item> items = new ArrayList<>(Collections.singletonList(item));
+ List<Resource> items = new ArrayList<>(Collections.singletonList(item));
elementsByFolderNames.put(TEMPLATE_INFO_NAME, items);
templateContainer = new TemplateContainer(report, dcaeRestClient, templateInfos, elementsByFolderNames);
@@ -126,22 +120,13 @@ public class TemplateContainerTest extends BaseTest {
templateInfo.setRelations(Collections.singletonList(relation));
templateInfos.add(templateInfo);
elementsByFolderNames = new HashMap<>();
- List<Item> itemList = new ArrayList<>();
- Item item = new Item();
+ List<Resource> itemList = new ArrayList<>();
+ Resource item = new Resource();
item.setName(ELEMENT_NAME3);
- item.setItemId("");
- Model model = new Model();
- model.setItemId("");
- List<Model> models = Collections.singletonList(model);
- item.setModels(models);
itemList.add(item);
- item = new Item();
+ item = new Resource();
item.setName(ELEMENT_NAME2);
- item.setItemId("");
- model = new Model();
- model.setItemId("");
- models = Collections.singletonList(model);
- item.setModels(models);
+
itemList.add(item);
elementsByFolderNames.put(TEMPLATE_INFO_NAME, itemList);
templateContainer = new TemplateContainer(report, dcaeRestClient, templateInfos, elementsByFolderNames);