diff options
Diffstat (limited to 'dcaedt_tools/src')
48 files changed, 2943 insertions, 0 deletions
diff --git a/dcaedt_tools/src/ReadMe.txt b/dcaedt_tools/src/ReadMe.txt new file mode 100644 index 0000000..4657a81 --- /dev/null +++ b/dcaedt_tools/src/ReadMe.txt @@ -0,0 +1,64 @@ +How to run: +mvn exec:java -Dexec.mainClass=Main -Dexec.args="'environment.json' 'config.json'" + +environment.json example: + +{ + "dcaeBeHost": "http://135.91.225.81", + "dcaeBePort": "8080", + "apiPath": "/dcae" + "userEditor": "admin" +} + +config.json example: + { + "templateInfo": [{ + "name": "SNMP Fault", + "description": "SNMP FM with Map-Supplement-Enrich", + "category": "Template / Base Monitoring Template", + "subCategory":"some subCategory", + "updateIfExist": "true", + "composition": [{ + "type": "Map", + "alias": "mapper" + }, { + "type": "Supplement", + "alias": "sup" + }, { + "type": "Enrich", + "alias": "enrich" + }] + }, + { + "name": "FOI", + "description": "FOI SFTP with FOI-Collector and Docker-Map", + "category": "Template / Base Monitoring Template", + "subCategory":"some subCategory", + "updateIfExist": "true", + "composition": [{ + "type": "FOI Collector", + "alias": "collector" + }, { + "type": "DockerMap", + "alias": "map" + }], + "relation": [{ + "fromComponent": "collector.FOISftp", + "fromRequirement": "stream_publish_0", + "toComponent": "map.topic1", + "toCapability": "topic" + }] + }, + { + "name": "Syslog non-VES Collector", + "description": "Syslog flow with Syslog Collector", + "category": "Template / Base Monitoring Template", + "subCategory":"some subCategory", + "updateIfExist": "true", + "composition": [{ + "type": "Syslog", + "alias": "collector" + }] + } + ] + }
\ No newline at end of file diff --git a/dcaedt_tools/src/main/java/json/Credential.java b/dcaedt_tools/src/main/java/json/Credential.java new file mode 100644 index 0000000..001e7cf --- /dev/null +++ b/dcaedt_tools/src/main/java/json/Credential.java @@ -0,0 +1,62 @@ + +package json; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Credential { + + @SerializedName("editor") + private String Editor; + @SerializedName("firstName") + private String FirstName; + @SerializedName("lastName") + private String LastName; + @SerializedName("password") + private String Password; + @SerializedName("username") + private String Username; + + public String getEditor() { + return Editor; + } + + public void setEditor(String editor) { + Editor = editor; + } + + public String getFirstName() { + return FirstName; + } + + public void setFirstName(String firstName) { + FirstName = firstName; + } + + public String getLastName() { + return LastName; + } + + public void setLastName(String lastName) { + LastName = lastName; + } + + public String getPassword() { + return Password; + } + + public void setPassword(String password) { + Password = password; + } + + public String getUsername() { + return Username; + } + + public void setUsername(String username) { + Username = username; + } + +} diff --git a/dcaedt_tools/src/main/java/json/Credentials.java b/dcaedt_tools/src/main/java/json/Credentials.java new file mode 100644 index 0000000..817391a --- /dev/null +++ b/dcaedt_tools/src/main/java/json/Credentials.java @@ -0,0 +1,23 @@ + +package json; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Credentials { + + @SerializedName("credentials") + private List<Credential> Credentials; + + public List<Credential> getCredentials() { + return Credentials; + } + + public void setCredentials(List<Credential> credentials) { + Credentials = credentials; + } + +} diff --git a/dcaedt_tools/src/main/java/json/Environment.java b/dcaedt_tools/src/main/java/json/Environment.java new file mode 100644 index 0000000..8ce6dfc --- /dev/null +++ b/dcaedt_tools/src/main/java/json/Environment.java @@ -0,0 +1,51 @@ + +package json; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Environment { + + @SerializedName("apiPath") + private String ApiPath; + @SerializedName("dcaeBeHost") + private String DcaeBeHost; + @SerializedName("dcaeBePort") + private String DcaeBePort; + @SerializedName("credential") + private Credential credential; + + public String getApiPath() { + return ApiPath; + } + + public void setApiPath(String apiPath) { + ApiPath = apiPath; + } + + public String getDcaeBeHost() { + return DcaeBeHost; + } + + public void setDcaeBeHost(String dcaeBeHost) { + DcaeBeHost = dcaeBeHost; + } + + public String getDcaeBePort() { + return DcaeBePort; + } + + public void setDcaeBePort(String dcaeBePort) { + DcaeBePort = dcaeBePort; + } + + public Credential getCredential() { + return credential; + } + + public void setCredential(Credential credential) { + this.credential = credential; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ElementsResponse/Data.java b/dcaedt_tools/src/main/java/json/response/ElementsResponse/Data.java new file mode 100644 index 0000000..15876af --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ElementsResponse/Data.java @@ -0,0 +1,23 @@ + +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 new file mode 100644 index 0000000..6402061 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ElementsResponse/Element.java @@ -0,0 +1,73 @@ + +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 new file mode 100644 index 0000000..02dcdf2 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ElementsResponse/ElementsResponse.java @@ -0,0 +1,53 @@ + +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/Error.java b/dcaedt_tools/src/main/java/json/response/Error.java new file mode 100644 index 0000000..bf68ac1 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/Error.java @@ -0,0 +1,11 @@ + +package json.response; + +import javax.annotation.Generated; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Error { + + +} diff --git a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Artifact.java b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Artifact.java new file mode 100644 index 0000000..c8cf275 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Artifact.java @@ -0,0 +1,102 @@ + +package json.response.ItemsResponse; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Artifact { + + @SerializedName("artifactChecksum") + private String mArtifactChecksum; + @SerializedName("artifactDescription") + private String mArtifactDescription; + @SerializedName("artifactGroupType") + private String mArtifactGroupType; + @SerializedName("artifactLabel") + private String mArtifactLabel; + @SerializedName("artifactName") + private String mArtifactName; + @SerializedName("artifactType") + private String mArtifactType; + @SerializedName("artifactURL") + private String mArtifactURL; + @SerializedName("artifactUUID") + private String mArtifactUUID; + @SerializedName("artifactVersion") + private String mArtifactVersion; + + public String getArtifactChecksum() { + return mArtifactChecksum; + } + + public void setArtifactChecksum(String artifactChecksum) { + mArtifactChecksum = artifactChecksum; + } + + public String getArtifactDescription() { + return mArtifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + mArtifactDescription = artifactDescription; + } + + public String getArtifactGroupType() { + return mArtifactGroupType; + } + + public void setArtifactGroupType(String artifactGroupType) { + mArtifactGroupType = artifactGroupType; + } + + public String getArtifactLabel() { + return mArtifactLabel; + } + + public void setArtifactLabel(String artifactLabel) { + mArtifactLabel = artifactLabel; + } + + public String getArtifactName() { + return mArtifactName; + } + + public void setArtifactName(String artifactName) { + mArtifactName = artifactName; + } + + public String getArtifactType() { + return mArtifactType; + } + + public void setArtifactType(String artifactType) { + mArtifactType = artifactType; + } + + public String getArtifactURL() { + return mArtifactURL; + } + + public void setArtifactURL(String artifactURL) { + mArtifactURL = artifactURL; + } + + public String getArtifactUUID() { + return mArtifactUUID; + } + + public void setArtifactUUID(String artifactUUID) { + mArtifactUUID = artifactUUID; + } + + public String getArtifactVersion() { + return mArtifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + mArtifactVersion = artifactVersion; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ItemsResponse/Data.java b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Data.java new file mode 100644 index 0000000..36fcb09 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Data.java @@ -0,0 +1,22 @@ + +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 new file mode 100644 index 0000000..5d56a25 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Element.java @@ -0,0 +1,53 @@ + +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 new file mode 100644 index 0000000..6f0e518 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Item.java @@ -0,0 +1,203 @@ + +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 new file mode 100644 index 0000000..5b64b59 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ItemsResponse/ItemsResponse.java @@ -0,0 +1,53 @@ + +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 new file mode 100644 index 0000000..036b16b --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ItemsResponse/Model.java @@ -0,0 +1,62 @@ + +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/json/response/ModelResponse/Assignment.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Assignment.java new file mode 100644 index 0000000..40d8e19 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Assignment.java @@ -0,0 +1,22 @@ + +package json.response.ModelResponse; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Assignment { + + @SerializedName("value") + private String mValue; + + public String getValue() { + return mValue; + } + + public void setValue(String value) { + mValue = value; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/Capability.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Capability.java new file mode 100644 index 0000000..ced2415 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Capability.java @@ -0,0 +1,63 @@ + +package json.response.ModelResponse; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Capability { + + @SerializedName("dcae.capabilities.stream.subscribe") + private DcaeCapabilitiesStreamSubscribe mDcaeCapabilitiesStreamSubscribe; + @SerializedName("id") + private String mId; + @SerializedName("name") + private String mName; + @SerializedName("properties") + private List<Property> mProperties; + @SerializedName("type") + private Type mType; + + public DcaeCapabilitiesStreamSubscribe getDcaeCapabilitiesStreamSubscribe() { + return mDcaeCapabilitiesStreamSubscribe; + } + + public void setDcaeCapabilitiesStreamSubscribe(DcaeCapabilitiesStreamSubscribe dcaeCapabilitiesStreamSubscribe) { + mDcaeCapabilitiesStreamSubscribe = dcaeCapabilitiesStreamSubscribe; + } + + public String getId() { + return mId; + } + + public void setId(String id) { + mId = id; + } + + public String getName() { + return mName; + } + + public void setName(String name) { + mName = name; + } + + public List<Property> getProperties() { + return mProperties; + } + + public void setProperties(List<Property> properties) { + mProperties = properties; + } + + public Type getType() { + return mType; + } + + public void setType(Type type) { + mType = type; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/Data.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Data.java new file mode 100644 index 0000000..26ea28f --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Data.java @@ -0,0 +1,22 @@ + +package json.response.ModelResponse; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Data { + + @SerializedName("model") + private Model mModel; + + public Model getModel() { + return mModel; + } + + public void setModel(Model model) { + mModel = model; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/DcaeCapabilitiesStreamSubscribe.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/DcaeCapabilitiesStreamSubscribe.java new file mode 100644 index 0000000..e244f52 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/DcaeCapabilitiesStreamSubscribe.java @@ -0,0 +1,23 @@ + +package json.response.ModelResponse; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class DcaeCapabilitiesStreamSubscribe { + + @SerializedName("properties") + private List<Property> mProperties; + + public List<Property> getProperties() { + return mProperties; + } + + public void setProperties(List<Property> properties) { + mProperties = properties; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/Format.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Format.java new file mode 100644 index 0000000..37ef8ec --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Format.java @@ -0,0 +1,22 @@ + +package json.response.ModelResponse; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Format { + + @SerializedName("equal") + private String mEqual; + + public String getEqual() { + return mEqual; + } + + public void setEqual(String equal) { + mEqual = equal; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/Model.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Model.java new file mode 100644 index 0000000..2b94678 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Model.java @@ -0,0 +1,73 @@ + +package json.response.ModelResponse; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Model { + + @SerializedName("catalog") + private String mCatalog; + @SerializedName("catalogId") + private Long mCatalogId; + @SerializedName("id") + private Long mId; + @SerializedName("itemId") + private String mItemId; + @SerializedName("name") + private String mName; + @SerializedName("nodes") + private List<Node> mNodes; + + 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 String getName() { + return mName; + } + + public void setName(String name) { + mName = name; + } + + public List<Node> getNodes() { + return mNodes; + } + + public void setNodes(List<Node> nodes) { + mNodes = nodes; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/ModelResponse.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/ModelResponse.java new file mode 100644 index 0000000..fbe995a --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/ModelResponse.java @@ -0,0 +1,52 @@ + +package json.response.ModelResponse; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class ModelResponse { + + @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/ModelResponse/Node.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Node.java new file mode 100644 index 0000000..63576e4 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Node.java @@ -0,0 +1,73 @@ + +package json.response.ModelResponse; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Node { + + @SerializedName("capabilities") + private List<Capability> mCapabilities; + @SerializedName("description") + private String mDescription; + @SerializedName("name") + private String mName; + @SerializedName("properties") + private List<Property> mProperties; + @SerializedName("requirements") + private List<Requirement> mRequirements; + @SerializedName("type") + private String mType; + + public List<Capability> getCapabilities() { + return mCapabilities; + } + + public void setCapabilities(List<Capability> capabilities) { + mCapabilities = capabilities; + } + + public String getDescription() { + return mDescription; + } + + public void setDescription(String description) { + mDescription = description; + } + + public String getName() { + return mName; + } + + public void setName(String name) { + mName = name; + } + + public List<Property> getProperties() { + return mProperties; + } + + public void setProperties(List<Property> properties) { + mProperties = properties; + } + + public List<Requirement> getRequirements() { + return mRequirements; + } + + public void setRequirements(List<Requirement> requirements) { + mRequirements = requirements; + } + + public String getType() { + return mType; + } + + public void setType(String type) { + mType = type; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/NodeFilter.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/NodeFilter.java new file mode 100644 index 0000000..11dfaff --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/NodeFilter.java @@ -0,0 +1,23 @@ + +package json.response.ModelResponse; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class NodeFilter { + + @SerializedName("capabilities") + private List<Capability> mCapabilities; + + public List<Capability> getCapabilities() { + return mCapabilities; + } + + public void setCapabilities(List<Capability> capabilities) { + mCapabilities = capabilities; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/Property.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Property.java new file mode 100644 index 0000000..4edb3e7 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Property.java @@ -0,0 +1,53 @@ + +package json.response.ModelResponse; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Property { + + @SerializedName("assignment") + private Assignment mAssignment; + @SerializedName("format") + private List<Format> mFormat; + @SerializedName("name") + private String mName; + @SerializedName("type") + private String mType; + + public Assignment getAssignment() { + return mAssignment; + } + + public void setAssignment(Assignment assignment) { + mAssignment = assignment; + } + + public List<Format> getFormat() { + return mFormat; + } + + public void setFormat(List<Format> format) { + mFormat = format; + } + + public String getName() { + return mName; + } + + public void setName(String name) { + mName = name; + } + + public String getType() { + return mType; + } + + public void setType(String type) { + mType = type; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/Relationship.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Relationship.java new file mode 100644 index 0000000..78b3e0d --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Relationship.java @@ -0,0 +1,22 @@ + +package json.response.ModelResponse; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Relationship { + + @SerializedName("type") + private String mType; + + public String getType() { + return mType; + } + + public void setType(String type) { + mType = type; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/Requirement.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Requirement.java new file mode 100644 index 0000000..29a89cb --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Requirement.java @@ -0,0 +1,52 @@ + +package json.response.ModelResponse; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Requirement { + + @SerializedName("capability") + private Capability mCapability; + @SerializedName("name") + private String mName; + @SerializedName("node_filter") + private NodeFilter mNodeFilter; + @SerializedName("relationship") + private Relationship mRelationship; + + public Capability getCapability() { + return mCapability; + } + + public void setCapability(Capability capability) { + mCapability = capability; + } + + public String getName() { + return mName; + } + + public void setName(String name) { + mName = name; + } + + public NodeFilter getNodeFilter() { + return mNodeFilter; + } + + public void setNodeFilter(NodeFilter nodeFilter) { + mNodeFilter = nodeFilter; + } + + public Relationship getRelationship() { + return mRelationship; + } + + public void setRelationship(Relationship relationship) { + mRelationship = relationship; + } + +} diff --git a/dcaedt_tools/src/main/java/json/response/ModelResponse/Type.java b/dcaedt_tools/src/main/java/json/response/ModelResponse/Type.java new file mode 100644 index 0000000..4e54518 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/response/ModelResponse/Type.java @@ -0,0 +1,32 @@ + +package json.response.ModelResponse; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Type { + + @SerializedName("id") + private String mId; + @SerializedName("name") + private String mName; + + public String getId() { + return mId; + } + + public void setId(String id) { + mId = id; + } + + public String getName() { + return mName; + } + + public void setName(String name) { + mName = name; + } + +} diff --git a/dcaedt_tools/src/main/java/json/templateInfo/Composition.java b/dcaedt_tools/src/main/java/json/templateInfo/Composition.java new file mode 100644 index 0000000..b99ad75 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/templateInfo/Composition.java @@ -0,0 +1,32 @@ + +package json.templateInfo; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Composition { + + @SerializedName("alias") + private String Alias; + @SerializedName("type") + private String Type; + + public String getAlias() { + return Alias; + } + + public void setAlias(String alias) { + Alias = alias; + } + + public String getType() { + return Type; + } + + public void setType(String type) { + Type = type; + } + +} diff --git a/dcaedt_tools/src/main/java/json/templateInfo/DeployTemplateConfig.java b/dcaedt_tools/src/main/java/json/templateInfo/DeployTemplateConfig.java new file mode 100644 index 0000000..303418d --- /dev/null +++ b/dcaedt_tools/src/main/java/json/templateInfo/DeployTemplateConfig.java @@ -0,0 +1,22 @@ +package json.templateInfo; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class DeployTemplateConfig { + + @SerializedName("templateInfo") + private List<TemplateInfo> TemplateInfo; + + public List<TemplateInfo> getTemplateInfo() { + return TemplateInfo; + } + + public void setTemplateInfo(List<TemplateInfo> templateInfo) { + TemplateInfo = templateInfo; + } + +} diff --git a/dcaedt_tools/src/main/java/json/templateInfo/Relation.java b/dcaedt_tools/src/main/java/json/templateInfo/Relation.java new file mode 100644 index 0000000..cbe7cb9 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/templateInfo/Relation.java @@ -0,0 +1,50 @@ + +package json.templateInfo; + +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class Relation { + @SerializedName("fromComponent") + private String fromComponent; + @SerializedName("fromRequirement") + private String fromRequirement; + @SerializedName("toComponent") + private String toComponent; + @SerializedName("toCapability") + private String toCapability; + + public String getFromComponent() { + return fromComponent; + } + + public void setFromComponent(String fromComponent) { + this.fromComponent = fromComponent; + } + + public String getFromRequirement() { + return fromRequirement; + } + + public void setFromRequirement(String fromRequirement) { + this.fromRequirement = fromRequirement; + } + + public String getToComponent() { + return toComponent; + } + + public void setToComponent(String toComponent) { + this.toComponent = toComponent; + } + + public String getToCapability() { + return toCapability; + } + + public void setToCapability(String toCapability) { + this.toCapability = toCapability; + } +} diff --git a/dcaedt_tools/src/main/java/json/templateInfo/TemplateInfo.java b/dcaedt_tools/src/main/java/json/templateInfo/TemplateInfo.java new file mode 100644 index 0000000..c34aaef --- /dev/null +++ b/dcaedt_tools/src/main/java/json/templateInfo/TemplateInfo.java @@ -0,0 +1,83 @@ + +package json.templateInfo; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.SerializedName; + +@Generated("net.hexar.json2pojo") +@SuppressWarnings("unused") +public class TemplateInfo { + + @SerializedName("category") + private String Category; + @SerializedName("composition") + private List<json.templateInfo.Composition> Composition; + @SerializedName("description") + private String Description; + @SerializedName("name") + private String Name; + @SerializedName("relations") + private List<Relation> Relations; + @SerializedName("subCategory") + private String SubCategory; + @SerializedName("updateIfExist") + private Boolean UpdateIfExist; + + public String getCategory() { + return Category; + } + + public void setCategory(String category) { + Category = category; + } + + public List<json.templateInfo.Composition> getComposition() { + return Composition; + } + + public void setComposition(List<json.templateInfo.Composition> composition) { + Composition = composition; + } + + public String getDescription() { + return Description; + } + + public void setDescription(String description) { + Description = description; + } + + public String getName() { + return Name; + } + + public void setName(String name) { + Name = name; + } + + public List<Relation> getRelations() { + return Relations; + } + + public void setRelations(List<Relation> relations) { + Relations = relations; + } + + public String getSubCategory() { + return SubCategory; + } + + public void setSubCategory(String subCategory) { + SubCategory = subCategory; + } + + public Boolean getUpdateIfExist() { + return UpdateIfExist; + } + + public void setUpdateIfExist(Boolean updateIfExist) { + UpdateIfExist = updateIfExist; + } + +} diff --git a/dcaedt_tools/src/main/java/tools/DeployTemplate.java b/dcaedt_tools/src/main/java/tools/DeployTemplate.java new file mode 100644 index 0000000..d5c368f --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/DeployTemplate.java @@ -0,0 +1,157 @@ +package tools; +import com.google.gson.JsonObject; +import json.templateInfo.TemplateInfo; +import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest; +import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed; +import org.onap.sdc.dcae.composition.util.DcaeBeConstants; +import org.springframework.web.client.HttpServerErrorException; +import utilities.IDcaeRestClient; +import utilities.IReport; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + + +public class DeployTemplate { + private static final String FAILED_UPDATE_VFCMT = "Failed update vfcmt: "; + private static final String FAILED = "failed"; + private final IReport report; + private final IDcaeRestClient dcaeRestClient; + private LoggerError errLogger = LoggerError.getInstance(); + private LoggerDebug debugLogger = LoggerDebug.getInstance(); + + DeployTemplate(IReport report, IDcaeRestClient dcaeRestClient) { + + this.report = report; + this.dcaeRestClient = dcaeRestClient; + } + + public void deploy(Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap) { + List<ResourceDetailed> vfcmtList = dcaeRestClient.getAllVfcmts(); + + List<TemplateInfo> updatedTemplateInfos = new ArrayList<>(); + vfcmtList.stream().forEach(vfcmt -> + templateInfoToJsonObjectMap.keySet().stream().filter(templateInfo -> templateInfo.getName().equalsIgnoreCase(vfcmt.getName())).forEach(templateInfo -> { + update(vfcmt, templateInfo, templateInfoToJsonObjectMap.get(templateInfo)); + updatedTemplateInfos.add(templateInfo); + })); + templateInfoToJsonObjectMap.keySet().stream() + .filter(templateInfo -> !updatedTemplateInfos.contains(templateInfo)) + .forEach(templateInfo -> createNew(templateInfo, templateInfoToJsonObjectMap.get(templateInfo))); + + verify(templateInfoToJsonObjectMap); + } + + private void verify(Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap) { + AtomicInteger foundCount = new AtomicInteger(); + debugLogger.log("Starting verify deployment"); + List<ResourceDetailed> vfcmtList = dcaeRestClient.getAllVfcmts(); + + templateInfoToJsonObjectMap.keySet().stream() + .forEach(templateInfo -> vfcmtList.stream() + .filter(vfcmt -> vfcmt.getName().equalsIgnoreCase(templateInfo.getName())) + .forEach(vfcmt -> foundCount.getAndIncrement())); + if (foundCount.get() == templateInfoToJsonObjectMap.size()) { + debugLogger.log("Deployment verify finished successfully"); + } else { + errLogger.log("Deployment verify finished successfully"); + String msg = "Deployment verify finished with errors, found only: " + + foundCount.get() + " of " + templateInfoToJsonObjectMap.size() + " vfcmts"; + report.addErrorMessage(msg); + errLogger.log(msg); + } + } + + private void createNew(TemplateInfo templateInfo, JsonObject jsonObject) { + try { + CreateVFCMTRequest createVFCMTRequest = new CreateVFCMTRequest(); + createVFCMTRequest.setName(templateInfo.getName()); + createVFCMTRequest.setDescription(templateInfo.getDescription()); + createVFCMTRequest.setSubcategory(templateInfo.getSubCategory()); + createVFCMTRequest.setCategory(templateInfo.getCategory()); + ResourceDetailed vfcmt = dcaeRestClient.createResource(createVFCMTRequest); + + jsonObject.addProperty("cid", vfcmt.getUuid()); + + saveAndCertify(jsonObject, vfcmt); + + } catch (HttpServerErrorException e) { + String msg = FAILED_UPDATE_VFCMT + templateInfo.getName() + ", With general message: " + e.getMessage(); + report.addErrorMessage(msg); + errLogger.log(msg + " " + e); + } + } + + private void update(ResourceDetailed vfcmt, TemplateInfo templateInfo, JsonObject jsonObject) { + ResourceDetailed checkedoutVfcmt = vfcmt; + try { + Boolean checkoutChecking = checkUserIfResourceCheckedOut(dcaeRestClient.getUserId(), vfcmt); + if (checkoutChecking != null && checkoutChecking) { + report.addErrorMessage(FAILED_UPDATE_VFCMT + vfcmt.getName() + ", cannot checkout vfcmt"); + return; + } + if (templateInfo.getUpdateIfExist()) { + if (checkoutChecking == null) { + checkedoutVfcmt = dcaeRestClient.checkoutVfcmt(vfcmt.getUuid()); + } + if (checkedoutVfcmt != null) { + checkedoutVfcmt.setSubCategory(templateInfo.getSubCategory()); + checkedoutVfcmt.setCategory(templateInfo.getCategory()); + checkedoutVfcmt.setDescription(templateInfo.getDescription()); + dcaeRestClient.updateResource(checkedoutVfcmt); + saveAndCertify(jsonObject, checkedoutVfcmt); + } + } else { + report.addNotUpdatedMessage("vfcmt: " + vfcmt.getName() + " found, but didn't update."); + } + } catch (HttpServerErrorException e) { + String msg = FAILED_UPDATE_VFCMT + vfcmt.getName() + ", With general message: " + e.getMessage(); + report.addErrorMessage(msg); + errLogger.log( msg + " " + e); + } + } + + private void saveAndCertify(JsonObject jsonObject, ResourceDetailed checkedoutVfcmt) { + if (saveCompositionAndCertify(checkedoutVfcmt, jsonObject)) { + report.addUpdatedMessage("vfcmt: " + checkedoutVfcmt.getName() + " updated successfully"); + } else { + report.addErrorMessage("VFCMT " + checkedoutVfcmt.getName() + " failed to update"); + } + } + + private boolean saveCompositionAndCertify(ResourceDetailed vfcmt, JsonObject jsonObject) { + if (vfcmt.getUuid() == null) { + return false; + } + + debugLogger.log("Saving cdump of: " + vfcmt.getName() + " vfcmt"); + debugLogger.log(jsonObject.toString()); + + String responseEntity = dcaeRestClient.saveComposition(vfcmt.getUuid(), jsonObject.toString()); + if (responseEntity.equalsIgnoreCase(FAILED)) { + String msg = "Failed saving vfcmt: " + vfcmt.getName(); + report.addErrorMessage(msg); + errLogger.log(msg); + return false; + } + dcaeRestClient.certifyVfcmt(vfcmt.getUuid()); + return true; + } + + private Boolean checkUserIfResourceCheckedOut(String userId, ResourceDetailed asset) { + if (DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == DcaeBeConstants.LifecycleStateEnum.findState(asset.getLifecycleState())) { + String lastUpdaterUserId = asset.getLastUpdaterUserId(); + if (lastUpdaterUserId != null && !lastUpdaterUserId.equals(userId)) { + String msg = "User conflicts. Operation not allowed for user "+userId+" on resource checked out by "+lastUpdaterUserId; + report.addErrorMessage(msg); + errLogger.log(msg); + return true; + } else { + return false; + } + } + return null; + } +} diff --git a/dcaedt_tools/src/main/java/tools/EntitiesRetriever.java b/dcaedt_tools/src/main/java/tools/EntitiesRetriever.java new file mode 100644 index 0000000..0c31ddf --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/EntitiesRetriever.java @@ -0,0 +1,33 @@ +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/LoggerDebug.java b/dcaedt_tools/src/main/java/tools/LoggerDebug.java new file mode 100644 index 0000000..df177ed --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/LoggerDebug.java @@ -0,0 +1,13 @@ +package tools; + +public class LoggerDebug { + private static LoggerDebug instance = new LoggerDebug(); + + public static LoggerDebug getInstance() { + return instance; + } + + public void log(String logLine) { + System.out.println(logLine); + } +} diff --git a/dcaedt_tools/src/main/java/tools/LoggerError.java b/dcaedt_tools/src/main/java/tools/LoggerError.java new file mode 100644 index 0000000..325bfc1 --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/LoggerError.java @@ -0,0 +1,13 @@ +package tools; + +public class LoggerError { + private static LoggerError instance = new LoggerError(); + + public static LoggerError getInstance() { + return instance; + } + + public void log(String logLine) { + System.err.println(logLine); + } +} diff --git a/dcaedt_tools/src/main/java/tools/Main.java b/dcaedt_tools/src/main/java/tools/Main.java new file mode 100644 index 0000000..72b6e42 --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/Main.java @@ -0,0 +1,80 @@ +package tools; + +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 utilities.IDcaeRestClient; +import utilities.IReport; +import utilities.Report; +import utilities.DcaeRestClient; + +import java.io.*; +import java.net.ConnectException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class Main { + private static final String CONFIG_FILE = "DcaeDtDeployConfigFile"; + private static final String ENVIRONMENT_CONFIG = "environment.resource"; + + private static LoggerError errLogger = LoggerError.getInstance(); + private static LoggerDebug debugLogger = LoggerDebug.getInstance(); + + private Main() { + throw new IllegalAccessError("Utility class"); + } + + public static void main(String[] args) { + System.setProperty("logback.configurationFile", "conf/logback.xml"); + debugLogger.log("Starting VFCMT template deployment"); + if (args.length != 2) { + errLogger.log("Got " + args.length + ", but expecting exactly 2 arguments ONLY!"); + return; + } + debugLogger.log("Arguments:"); + Arrays.stream(args).forEach(arg -> debugLogger.log(arg)); + + initConfiguration(args); + IReport report = new Report(); + try { + ObjectMapper mapper = new ObjectMapper(); + DeployTemplateConfig deployTemplateConfig = mapper.readValue(new File(System.getProperty(CONFIG_FILE, "conf/config.json")), DeployTemplateConfig.class); + Environment environment = mapper.readValue(new File(System.getProperty(ENVIRONMENT_CONFIG, "conf/environment.json")), Environment.class); + + IDcaeRestClient dcaeRestClient = new DcaeRestClient(environment.getCredential()); + dcaeRestClient.init(environment); + + EntitiesRetriever entitiesRetriever = new EntitiesRetriever(dcaeRestClient); + Map<String, List<Item>> elementsByFolderNames = entitiesRetriever.getElementsByFolder(); + + TemplateContainer templateContainer = new TemplateContainer(report, dcaeRestClient, deployTemplateConfig.getTemplateInfo(), elementsByFolderNames); + Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap = templateContainer.getCdumps(); + + DeployTemplate deployTemplate = new DeployTemplate(report, dcaeRestClient); + deployTemplate.deploy(templateInfoToJsonObjectMap); + + debugLogger.log( "VFCMT template deployment completed successfully"); + } catch (RuntimeException e) { + errLogger.log("ERROR - Template deployment failed with error " + e); + } catch (ConnectException e) { + errLogger.log( "ERROR - Failed connection to server, are you on AT&T network? {}" + e); + } catch (IOException e) { + errLogger.log( "ERROR - Fatal Error! " + e); + } finally { + debugLogger.log(report.toString()); + } + } + + private static void initConfiguration(String[] args) { + System.setProperty(ENVIRONMENT_CONFIG, args[0]); + System.setProperty(CONFIG_FILE, args[1]); + } + + +} diff --git a/dcaedt_tools/src/main/java/tools/NodeData.java b/dcaedt_tools/src/main/java/tools/NodeData.java new file mode 100644 index 0000000..f89105b --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/NodeData.java @@ -0,0 +1,40 @@ +package tools; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +public class NodeData { + private final JsonArray capabilities; + private final JsonArray requirements; + private final JsonArray properties; + private final JsonObject typeInfo; + private final String nodeName; + + NodeData(JsonArray capabilities, JsonArray requirements, JsonArray properties, JsonObject typeInfo, String nodeName) { + this.capabilities = capabilities; + this.requirements = requirements; + this.properties = properties; + this.typeInfo = typeInfo; + this.nodeName = nodeName; + } + + public JsonArray getCapabilities() { + return capabilities; + } + + public JsonArray getRequirements() { + return requirements; + } + + public JsonArray getProperties() { + return properties; + } + + public JsonObject getTypeInfo() { + return typeInfo; + } + + public String getName() { + return nodeName; + } +} diff --git a/dcaedt_tools/src/main/java/tools/TemplateContainer.java b/dcaedt_tools/src/main/java/tools/TemplateContainer.java new file mode 100644 index 0000000..ee16d22 --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/TemplateContainer.java @@ -0,0 +1,329 @@ +package tools; + +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.Relation; +import json.templateInfo.TemplateInfo; +import org.apache.commons.lang3.StringUtils; +import utilities.IDcaeRestClient; +import utilities.IReport; + +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; + + +public class TemplateContainer { + private static final String NODES = "nodes"; + private static final String RELATIONSHIP = "relationship"; + 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 LoggerDebug debugLogger = LoggerDebug.getInstance(); + + + public TemplateContainer(IReport report, IDcaeRestClient dcaeRestClient, List<TemplateInfo> templateInfos, Map<String, List<Item>> elementsByFolderNames) { + this.report = report; + this.dcaeRestClient = dcaeRestClient; + this.templateInfos = templateInfos; + this.elementsByFolderNames = elementsByFolderNames; + } + + private List<Item> findTemplate(TemplateInfo templateInfo) { + AtomicReference<List<Item>> items = new AtomicReference<>(); + items.set(new ArrayList<>()); + elementsByFolderNames.keySet().stream() + .forEach(folderName -> { + List<Item> itemList = returnMatchedTemplate(folderName, templateInfo); + items.get().addAll(itemList); + }); + if (items.get().size() == templateInfo.getComposition().size()) { + return items.get(); + } + return new ArrayList<>(); + } + + private List<Item> returnMatchedTemplate(String folderName, TemplateInfo templateInfo) { + List<Item> items = new ArrayList<>(); + elementsByFolderNames.get(folderName).stream() + .forEach(item -> templateInfo.getComposition().stream().forEach(composition -> + { + if (composition.getType().equalsIgnoreCase(item.getName())) { + items.add(item); + } + })); + return items; + } + + + public Map<TemplateInfo, JsonObject> getCdumps() { + Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap = new HashMap<>(); + for (TemplateInfo templateInfo : templateInfos) { + List<Item> items = findTemplate(templateInfo); + if (items == null || items.isEmpty()) { + report.addErrorMessage("vfcmt: " + templateInfo.getName() + ". DCAE Component not found"); + continue; + } + templateInfoToJsonObjectMap.put(templateInfo, getCdumpJsonObject(items, templateInfo)); + } + return templateInfoToJsonObjectMap; + } + + private JsonObject getCdumpJsonObject(List<Item> items, TemplateInfo templateInfo) { + JsonObject cdumpJsonObject = generateCdumpInput(templateInfo); + Map<Item, Map<String, NodeData>> itemMapHashMap = new HashMap<>(); + JsonArray relationsJsonArray = new JsonArray(); + for (Item item : items) { + 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(); + Map<String, NodeData> stringRelationsDataMap = new HashMap<>(); + for (JsonElement nodeElement : allNodeTemplates) { + JsonObject responseModelJson = nodeElement.getAsJsonObject(); + JsonObject responseTypeInfoJson = jsonParser.parse(dcaeRestClient.getItemType(item.getItemId(), responseModelJson.get("type").getAsString())).getAsJsonObject().get("data").getAsJsonObject().get("type").getAsJsonObject(); + JsonObject jsonObjectElement = newVfcmtJSON(responseModelJson.get("name").getAsString(), item.getModels().get(0).getItemId()); + jsonObjectElement.addProperty("id", responseTypeInfoJson.get("itemId").getAsString().split("/")[0]); + String nid = "n." + new Date().getTime() + "." + nidCounter++; + jsonObjectElement.addProperty("nid", nid); + NodeData nodeData = createNodeData(responseModelJson, responseTypeInfoJson, responseModelJson.get("name").getAsString()); + stringRelationsDataMap.put(nid, nodeData); + jsonObjectElement.add("capabilities", nodeData.getCapabilities()); + jsonObjectElement.add("requirements", nodeData.getRequirements()); + jsonObjectElement.add("properties", nodeData.getProperties()); + jsonObjectElement.add("typeinfo", nodeData.getTypeInfo()); + JsonObject typeJsonObject = new JsonObject(); + typeJsonObject.addProperty("name", responseModelJson.get("type").getAsString()); + jsonObjectElement.add("type", typeJsonObject); + JsonElement ndataElement = createNData(responseModelJson.get("name").getAsString(), nid); + jsonObjectElement.add("ndata", ndataElement); + jsonArrayNode.add(jsonObjectElement); + } + itemMapHashMap.put(item, stringRelationsDataMap); + } + JsonElement jsonElement = createTemplateInfoRelations(templateInfo, itemMapHashMap); + if (jsonElement != null && jsonElement.isJsonArray()) { + for (JsonElement element : jsonElement.getAsJsonArray()) { + relationsJsonArray.add(element); + } + } + jsonElement = createSelfRelations(itemMapHashMap); + if (jsonElement != null && jsonElement.isJsonArray()) { + for (JsonElement element : jsonElement.getAsJsonArray()) { + relationsJsonArray.add(element); + } + + } + cdumpJsonObject.add("relations", relationsJsonArray); + return cdumpJsonObject; + } + + //We need it only for printing the relations (front end requirement) + private JsonElement createNData(String name, String nid) { + JsonObject ndataElement = new JsonObject(); + ndataElement.addProperty("name", nid); + ndataElement.addProperty("label", name); + ndataElement.addProperty("x",438); + ndataElement.addProperty("y",435); + ndataElement.addProperty("px",437); + ndataElement.addProperty("py",434); + ndataElement.add("ports", new JsonArray()); + ndataElement.addProperty("radius", 30); + + return ndataElement; + } + + private JsonElement createSelfRelations(Map<Item, Map<String, NodeData>> nodeDataByNidByItem) { + JsonArray jsonArrayRelations = new JsonArray(); + for (Item item : nodeDataByNidByItem.keySet()) { + Map<String, NodeData> nodeDataByNid = nodeDataByNidByItem.get(item); + if (nodeDataByNid.size() < 2) { + continue; + } + Map<JsonObject, String> nidListByRequirement = new HashMap<>(); + for (String nid : nodeDataByNid.keySet()) { + JsonArray jsonArrayRequirements = nodeDataByNid.get(nid).getRequirements(); + for (JsonElement requirement : jsonArrayRequirements) { + JsonObject jsonObject = requirement.getAsJsonObject(); + if (jsonObject.has("node")) { + nidListByRequirement.put(jsonObject, nid); + } + } + } + for (JsonObject requirement : nidListByRequirement.keySet()) { + String toNodeName = requirement.get("node").toString().replaceAll("\"", ""); + boolean isFound = false; + NodeData toNodeData; + String toNId = null; + for (String nid : nodeDataByNid.keySet()) { + toNodeData = nodeDataByNid.get(nid); + toNId = nid; + if (toNodeData.getName().equalsIgnoreCase(toNodeName)) { + isFound = true; + break; + } + } + if (isFound) { + JsonObject relationElement = new JsonObject(); + NodeData fromNode = nodeDataByNidByItem.get(item).get(nidListByRequirement.get(requirement)); + relationElement.addProperty("rid", "ink." + nidListByRequirement.get(requirement) + "." + nidCounter++); + relationElement.addProperty("n1", nidListByRequirement.get(requirement)); + relationElement.addProperty("name1", fromNode.getName()); + JsonObject metaData = new JsonObject(); + metaData.addProperty("n1", nidListByRequirement.get(requirement)); + metaData.addProperty("p1", requirement.get("name").toString().replaceAll("\"", "")); + relationElement.addProperty("n2", toNId); + relationElement.addProperty("name2", toNodeName); + metaData.addProperty("n2", toNId); + String capabilityFullName = requirement.get("capability").getAsJsonObject().get("name").toString(); + String capabilityShortName = StringUtils.substringAfterLast(capabilityFullName, "."); + metaData.addProperty("p2", capabilityShortName.replaceAll("\"", "")); + JsonArray relationship = new JsonArray(); + relationship.add(fromNode.getName().replaceAll("\"", "")); + JsonElement requirementRelationship = requirement.get(RELATIONSHIP); + if (requirementRelationship != null) { + relationship.add(requirementRelationship.getAsJsonObject().get("type").toString().replaceAll("\"", "")); + } else { + relationship.add((JsonElement) null); + } + + relationship.add(requirement.get("name").toString().replaceAll("\"", "")); + metaData.add(RELATIONSHIP, relationship); + relationElement.add("meta", metaData); + jsonArrayRelations.add(relationElement); + } + } + } + return jsonArrayRelations; + } + + private NodeData createNodeData(JsonObject responseModelJson, JsonObject responseTypeInfoJson, String nodeName) { + JsonArray capabilities = responseModelJson.get("capabilities").getAsJsonArray(); + JsonArray requirements = responseModelJson.get("requirements").getAsJsonArray(); + JsonArray properties = responseModelJson.get("properties").getAsJsonArray(); + return new NodeData(capabilities, requirements, properties, responseTypeInfoJson, nodeName); + } + + private JsonArray createTemplateInfoRelations(TemplateInfo templateInfo, Map<Item, Map<String, NodeData>> nodeDataByNidByItem) { + JsonArray jsonArrayRelations = new JsonArray(); + + if (templateInfo.getRelations() == null) { + return null; + } + for (Relation relation : templateInfo.getRelations()) { + JsonObject metaData = new JsonObject(); + 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, "."); + boolean findTo = false; + boolean findFrom = false; + for (Item item : nodeDataByNidByItem.keySet()) { + Map<String, NodeData> nodeDataByNid = nodeDataByNidByItem.get(item); + for (String nid : nodeDataByNid.keySet()) { + NodeData currentNodeData = nodeDataByNid.get(nid); + + Optional<Composition> isFoundComposition = templateInfo.getComposition().stream() + .filter(element -> fromComponentAlias.equalsIgnoreCase(element.getAlias()) && element.getType().equalsIgnoreCase(item.getName()) && fromComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny(); + if (isFoundComposition.isPresent()) { + boolean isFound = findNode(relation.getFromRequirement(), currentNodeData.getRequirements()); + if (isFound) { + relationElement.addProperty("rid", "ink." + nid + "." + nidCounter++); + relationElement.addProperty("n1", nid); + relationElement.addProperty("name1", currentNodeData.getName()); + metaData.addProperty("n1", nid); + metaData.addProperty("p1", relation.getFromRequirement()); + JsonArray relationship = new JsonArray(); + relationship.add(fromComponentNodeName); + String requirementRelationshipType = findRequirementType(relation.getFromRequirement(), currentNodeData.getRequirements()); + if (requirementRelationshipType != null) { + relationship.add(requirementRelationshipType); + } else { + relationship.add((JsonElement) null); + } + relationship.add(toComponentNodeName); + metaData.add(RELATIONSHIP, relationship); + findFrom = true; + } + + } + + isFoundComposition = templateInfo.getComposition().stream() + .filter(element -> toComponentAlias.equalsIgnoreCase(element.getAlias()) && element.getType().equalsIgnoreCase(item.getName()) && toComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny(); + if (isFoundComposition.isPresent()) { + boolean isFound = findNode(relation.getToCapability(), currentNodeData.getCapabilities()); + if (isFound) { + relationElement.addProperty("n2", nid); + relationElement.addProperty("name2", currentNodeData.getName()); + metaData.addProperty("n2", nid); + metaData.addProperty("p2", relation.getToCapability()); + findTo = true; + } + } + } + } + if (findTo && findFrom) { + relationElement.add("meta", metaData); + jsonArrayRelations.add(relationElement); + } else { + report.addErrorMessage("Didn't find match relation from: " + relation.getFromComponent() + ", to: "+ relation.getToComponent()); + } + } + + return jsonArrayRelations; + } + + private String findRequirementType(String fromRequirement, JsonArray requirements) { + Iterator<JsonElement> jsonElements = requirements.iterator(); + while (jsonElements.hasNext()) { + JsonObject jsonObject = (JsonObject) jsonElements.next(); + String name = jsonObject.get("name").getAsString(); + if (fromRequirement.equals(name) && jsonObject.has("type")) { + return jsonObject.get("type").toString().replaceAll("\"", ""); + } + } + + return null; + } + + private boolean findNode(String endPoint, JsonArray node) { + Iterator<JsonElement> jsonElements = node.iterator(); + while (jsonElements.hasNext()) { + JsonObject jsonObject = (JsonObject) jsonElements.next(); + String name = jsonObject.get("name").getAsString(); + if (endPoint.equals(name)) { + return true; + } + } + + return false; + } + + private JsonObject newVfcmtJSON(String name, String description) { + JsonObject json = new JsonObject(); + json.addProperty("name", name); + json.addProperty("description", description); + return json; + } + + private JsonObject generateCdumpInput(TemplateInfo templateInfo) { + JsonObject json = new JsonObject(); + json.addProperty("version", 0); + json.addProperty("flowType", templateInfo.getName()); + json.add(NODES, new JsonArray()); + + json.add("inputs", new JsonArray()); + json.add("outputs", new JsonArray()); + + return json; + + } +} diff --git a/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java b/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java new file mode 100644 index 0000000..5e81038 --- /dev/null +++ b/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java @@ -0,0 +1,151 @@ +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.sdc.ResourceDetailed; +import org.springframework.http.*; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Component("dcaerestclient") +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 ECOMP_INSTANCE_ID_HEADER = "X-ECOMP-InstanceID"; + private static final String USER_ID_HEADER = "USER_ID"; + + + private String uri; + private RestTemplate client; + private Credential credential; + + public DcaeRestClient(Credential credential) { + this.credential = credential; + } + + @Override + public String getUserId() { + return credential.getUsername(); + } + + @PostConstruct + @Override + public void init(Environment environment) { + credential = environment.getCredential(); + CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultHeaders(defaultHeaders(credential)).build(); + HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); + requestFactory.setHttpClient(httpClient); + client = new RestTemplate(requestFactory); + uri = String.format("%s:%s%s", environment.getDcaeBeHost(), environment.getDcaeBePort(), environment.getApiPath()); + } + + private List<BasicHeader> defaultHeaders(Credential credential) { + List<BasicHeader> headers = new ArrayList<>(); + headers.add(new BasicHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)); + headers.add(new BasicHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_OCTET_STREAM_VALUE)); + headers.add(new BasicHeader(ECOMP_INSTANCE_ID_HEADER, credential.getUsername())); + return headers; + } + + @Override + public List<ResourceDetailed> getAllVfcmts() { + String url = buildRequestPath(GET_RESOURCES_BY_CATEGORY); + return Arrays.asList(client.getForObject(url, ResourceDetailed[].class)); + } + + @Override + public ResourceDetailed createResource(CreateVFCMTRequest resource) { + String url = buildRequestPath(CREATE_VFCMT); + return client.postForObject(url, new HttpEntity<>(resource, postResourceHeaders(credential.getUsername())), ResourceDetailed.class); + } + + @Override + public ResourceDetailed checkoutVfcmt(String vfcmtUuid) { + String url = buildRequestPath(String.format("/checkout/vfcmt/%s", vfcmtUuid)); + ResponseEntity<ResourceDetailed> resourceDetailedResponse = client.exchange(url, HttpMethod.PUT, new HttpEntity(postResourceHeaders(credential.getUsername())), ResourceDetailed.class); + + return resourceDetailedResponse.getBody(); + } + + @Override + public ResourceDetailed checkinVfcmt(String vfcmtUuid) { + String url = buildRequestPath(String.format("/checkin/vfcmt/%s", vfcmtUuid)); + ResponseEntity<ResourceDetailed> resourceDetailedResponse = client.exchange(url, HttpMethod.PUT, new HttpEntity(postResourceHeaders(credential.getUsername())), ResourceDetailed.class); + + 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 String getItemModel(String elementId) { + String url = buildRequestPath("/"+ elementId +"/model"); + return client.getForObject(url, String.class); + } + @Override + public String getItemType(String elementId, String type) { + String url = buildRequestPath("/"+ elementId +"/type/"+ type +"/"); + return client.getForObject(url, String.class); + } + + @Override + public String saveComposition(String componentId, String body) { + String url = buildRequestPath("/saveComposition/" + componentId); + ResponseEntity<String> resourceDetailedResponse = client.exchange(url, HttpMethod.POST, new HttpEntity<>(body, postResourceHeaders(credential.getUsername())), String.class); + + return resourceDetailedResponse.getBody(); + } + + @Override + public String certifyVfcmt(String vfcmtUuid) { + String url = buildRequestPath(String.format("/certify/vfcmt/%s", vfcmtUuid)); + ResponseEntity<String> resourceDetailedResponse = client.exchange(url, HttpMethod.PUT, new HttpEntity(postResourceHeaders(credential.getUsername())), String.class); + + return resourceDetailedResponse.getBody(); + } + + private HttpHeaders postResourceHeaders(String userId) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON_UTF8); + headers.add(USER_ID_HEADER, userId); + return headers; + } + + private String buildRequestPath(String... args){ + return uri + Stream.of(args).collect(Collectors.joining()); + } + + @Override + public void updateResource(ResourceDetailed vfcmt) { + // Do nothing + } +} diff --git a/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java b/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java new file mode 100644 index 0000000..677175b --- /dev/null +++ b/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java @@ -0,0 +1,37 @@ +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.ResourceDetailed; + +import java.util.List; + +public interface IDcaeRestClient { + void init(Environment environment); + + String getUserId(); + + List<ResourceDetailed> getAllVfcmts(); + + ResourceDetailed createResource(CreateVFCMTRequest resource); + + ResourceDetailed checkoutVfcmt(String vfcmtUuid); + + ResourceDetailed checkinVfcmt(String vfcmtUuid); + + List<Element> getElements(); + + List<Item> getItem(String element); + + String getItemModel(String elementId); + + String getItemType(String elementId, String type); + + String saveComposition(String componentId, String body); + + String certifyVfcmt(String vfcmtUuid); + + void updateResource(ResourceDetailed vfcmt); +} diff --git a/dcaedt_tools/src/main/java/utilities/IReport.java b/dcaedt_tools/src/main/java/utilities/IReport.java new file mode 100644 index 0000000..4c5f8af --- /dev/null +++ b/dcaedt_tools/src/main/java/utilities/IReport.java @@ -0,0 +1,8 @@ +package utilities; + +public interface IReport { + void addCreatedMessage(String message); + void addUpdatedMessage(String message); + void addNotUpdatedMessage(String message); + void addErrorMessage(String message); +} diff --git a/dcaedt_tools/src/main/java/utilities/Report.java b/dcaedt_tools/src/main/java/utilities/Report.java new file mode 100644 index 0000000..8f79056 --- /dev/null +++ b/dcaedt_tools/src/main/java/utilities/Report.java @@ -0,0 +1,54 @@ +package utilities; + +import java.util.ArrayList; +import java.util.List; + +public class Report implements IReport { + + private List<String> created = new ArrayList<>(); + private List<String> updated = new ArrayList<>(); + private List<String> notUpdated = new ArrayList<>(); + private List<String> error = new ArrayList<>(); + + @Override + public void addCreatedMessage(String message) { + created.add(message); + } + + @Override + public void addUpdatedMessage(String message) { + updated.add(message); + } + + @Override + public void addNotUpdatedMessage(String message) { + notUpdated.add(message); + } + + @Override + public void addErrorMessage(String message) { + error.add(message); + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + if (!created.isEmpty()) { + stringBuilder.append("Created:").append(System.lineSeparator()); + created.forEach(msg -> stringBuilder.append(msg).append(System.lineSeparator())); + } + if (!updated.isEmpty()) { + stringBuilder.append("Updated:").append(System.lineSeparator()); + updated.forEach(msg -> stringBuilder.append(msg).append(System.lineSeparator())); + } + if (!notUpdated.isEmpty()) { + stringBuilder.append("Not updated:").append(System.lineSeparator()); + notUpdated.forEach(msg -> stringBuilder.append(msg).append(System.lineSeparator())); + } + if (!error.isEmpty()) { + stringBuilder.append("Error:").append(System.lineSeparator()); + error.forEach(msg -> stringBuilder.append(msg).append(System.lineSeparator())); + } + return stringBuilder.toString(); + } +} diff --git a/dcaedt_tools/src/main/resources/conf/config.json b/dcaedt_tools/src/main/resources/conf/config.json new file mode 100644 index 0000000..5b0f542 --- /dev/null +++ b/dcaedt_tools/src/main/resources/conf/config.json @@ -0,0 +1,51 @@ +{ + "templateInfo": [{ + "name": "SNMP Fault", + "description": "SNMP FM with Map-Supplement-Enrich", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "true", + "composition": [{ + "type": "Map", + "alias": "mapper" + }, { + "type": "Supplement", + "alias": "sup" + }, { + "type": "Enrich", + "alias": "enrich" + }] + }, + { + "name": "FOI", + "description": "FOI SFTP with FOI-Collector and Docker-Map", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "true", + "composition": [{ + "type": "foi", + "alias": "collector" + }, { + "type": "DockerMap", + "alias": "map" + }], + "relations": [{ + "fromComponent": "collector.foi", + "fromRequirement": "stream_publish_0", + "toComponent": "map.feed0", + "toCapability": "feed" + }] + }, + { + "name": "Syslog non-VES Collector", + "description": "Syslog flow with Syslog Collector", + "category": "Template", + "subCategory": "Base Monitoring Template", + "updateIfExist": "true", + "composition": [{ + "type": "Syslog", + "alias": "collector" + }] + } + ] +}
\ No newline at end of file diff --git a/dcaedt_tools/src/main/resources/conf/environment.json b/dcaedt_tools/src/main/resources/conf/environment.json new file mode 100644 index 0000000..abf66b9 --- /dev/null +++ b/dcaedt_tools/src/main/resources/conf/environment.json @@ -0,0 +1,12 @@ +{ + "dcaeBeHost": "http://localhost", + "dcaeBePort": "8446", + "apiPath": "", + "credential" :{ + "editor": "Carlos_Santana", + "username": "cs0008", + "password": "", + "firstName": "", + "lastName": "" + } +}
\ No newline at end of file diff --git a/dcaedt_tools/src/test/java/BaseTest.java b/dcaedt_tools/src/test/java/BaseTest.java new file mode 100644 index 0000000..49534a5 --- /dev/null +++ b/dcaedt_tools/src/test/java/BaseTest.java @@ -0,0 +1,151 @@ +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.ResourceDetailed; +import utilities.IDcaeRestClient; +import utilities.IReport; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +abstract class BaseTest { + static final String USER_ID = "userId"; + static final String TEMPLATE_INFO_NAME = "templateInfoName"; + static final String VFCMT_NAME1 = "my vfcmt1"; + static final String UUID1 = "my uuid1"; + static final String VFCMT_NAME2 = "my vfcmt2"; + static final String UUID2 = "my uuid2"; + static final String VFCMT_NAME3 = "my vfcmt3"; + static final String UUID3 = "my uuid3"; + static final String ELEMENT_NAME1 = "my element1"; + static final String ELEMENT_NAME2 = "my element2"; + static final String ELEMENT_NAME3 = "my element3"; + static final String ALIAS_NAME1 = "my alias1"; + static final String ALIAS_NAME2 = "my alias2"; + static final String ALIAS_NAME3 = "my alias3"; + static final String ITEM_NAME1 = "my item1"; + static final String ITEM_NAME2 = "my item2"; + static final String ITEM_NAME3 = "my item3"; + + @Mock + IReport report; + @Mock + IDcaeRestClient dcaeRestClient; + + @Before + public void setup() { + when(dcaeRestClient.getUserId()).thenReturn(USER_ID); + mockGetAllVfcmt(); + mockGetElements(); + mockGetItems(); + mockGetItemModel(); + mockGetItemType(); + mockCheckoutVfcmtAndCreateResource(); + when(dcaeRestClient.saveComposition(anyString(), anyString())).thenReturn("Composition Created"); + } + + private void mockCheckoutVfcmtAndCreateResource() { + ResourceDetailed resourceDetailed = new ResourceDetailed(); + resourceDetailed.setName(VFCMT_NAME1); + resourceDetailed.setUuid(UUID1); + resourceDetailed.setLifecycleState("NOT_CERTIFIED_CHECKOUT"); + resourceDetailed.setLastUpdaterUserId(USER_ID); + when(dcaeRestClient.checkoutVfcmt(anyString())).thenReturn(resourceDetailed); + when(dcaeRestClient.createResource(any())).thenReturn(resourceDetailed); + } + + private void mockGetItemType() { + when(dcaeRestClient.getItemType(anyString(), anyString())).thenReturn("{\"data\":{\"type\":{\"itemId\":\"e45ec9d7-01df-4cb1-896f-aff2a6ca5a8b/tosca.dcae.nodes.cdapApp.Map\", \"typeinfo\":\"typeInfo\"}}}"); + } + + 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\"}]}}}"); + } + + 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 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<>(); + ResourceDetailed resourceDetailed = new ResourceDetailed(); + resourceDetailed.setName(VFCMT_NAME1); + resourceDetailed.setUuid(UUID1); + resourceDetailed.setLifecycleState("NOT_CERTIFIED_CHECKOUT"); + resourceDetailed.setLastUpdaterUserId(USER_ID); + resourceDetaileds.add(resourceDetailed); + resourceDetailed = new ResourceDetailed(); + resourceDetailed.setName(VFCMT_NAME2); + resourceDetailed.setUuid(UUID2); + resourceDetaileds.add(resourceDetailed); + resourceDetailed = new ResourceDetailed(); + resourceDetailed.setName(VFCMT_NAME3); + resourceDetailed.setUuid(UUID3); + resourceDetaileds.add(resourceDetailed); + + List<ResourceDetailed> resourceDetaileds2 = new ArrayList<>(); + resourceDetailed = new ResourceDetailed(); + resourceDetailed.setName(VFCMT_NAME1); + resourceDetailed.setUuid(UUID1); + resourceDetailed.setLifecycleState("NOT_CERTIFIED_CHECKOUT"); + resourceDetailed.setLastUpdaterUserId(USER_ID); + resourceDetaileds2.add(resourceDetailed); + resourceDetailed = new ResourceDetailed(); + resourceDetailed.setName(VFCMT_NAME2); + resourceDetailed.setUuid(UUID2); + resourceDetaileds2.add(resourceDetailed); + resourceDetailed = new ResourceDetailed(); + resourceDetailed.setName(VFCMT_NAME3); + resourceDetailed.setUuid(UUID3); + resourceDetaileds2.add(resourceDetailed); + resourceDetailed = new ResourceDetailed(); + resourceDetailed.setName(TEMPLATE_INFO_NAME); + resourceDetailed.setUuid(UUID3); + resourceDetaileds2.add(resourceDetailed); + when(dcaeRestClient.getAllVfcmts()).thenReturn(resourceDetaileds, resourceDetaileds2); + } +} diff --git a/dcaedt_tools/src/test/java/DeployTemplateTest.java b/dcaedt_tools/src/test/java/DeployTemplateTest.java new file mode 100644 index 0000000..3fe0a7d --- /dev/null +++ b/dcaedt_tools/src/test/java/DeployTemplateTest.java @@ -0,0 +1,54 @@ +import com.google.gson.JsonObject; +import json.templateInfo.TemplateInfo; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import tools.DeployTemplate; + +import java.util.*; + +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class DeployTemplateTest extends BaseTest { + + @InjectMocks + DeployTemplate deployTemplate; + + private Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap; + + @Before + @Override + public void setup() { + super.setup(); + templateInfoToJsonObjectMap = new HashMap<>(); + TemplateInfo templateInfo = new TemplateInfo(); + templateInfo.setName(VFCMT_NAME1); + templateInfo.setCategory("category"); + templateInfo.setSubCategory("subCategory"); + templateInfo.setDescription("description"); + templateInfo.setUpdateIfExist(true); + templateInfoToJsonObjectMap.put(templateInfo, new JsonObject()); + templateInfo = new TemplateInfo(); + templateInfo.setName(TEMPLATE_INFO_NAME); + templateInfo.setCategory("category"); + templateInfo.setSubCategory("subCategory"); + templateInfo.setDescription("description"); + templateInfoToJsonObjectMap.put(templateInfo, new JsonObject()); + } + + @Test + public void deployHappyFlow() { + deployTemplate.deploy(templateInfoToJsonObjectMap); + verify(report, times(0)).addErrorMessage(anyString()); + } + + @Test + public void deploy_failedSaving_failedVerify() { + when(dcaeRestClient.saveComposition(anyString(), anyString())).thenReturn("failed"); + deployTemplate.deploy(templateInfoToJsonObjectMap); + verify(report, times(4)).addErrorMessage(anyString()); + } +} diff --git a/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java b/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java new file mode 100644 index 0000000..ea7eb2b --- /dev/null +++ b/dcaedt_tools/src/test/java/EntitiesRetrieverTest.java @@ -0,0 +1,29 @@ + +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 new file mode 100644 index 0000000..7c3d287 --- /dev/null +++ b/dcaedt_tools/src/test/java/TemplateContainerTest.java @@ -0,0 +1,157 @@ +import com.google.gson.JsonObject; +import json.response.ItemsResponse.Item; +import json.response.ItemsResponse.Model; +import json.templateInfo.Composition; +import json.templateInfo.Relation; +import json.templateInfo.TemplateInfo; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import tools.TemplateContainer; + +import java.util.*; + +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class TemplateContainerTest extends BaseTest { + + private TemplateContainer templateContainer; + + private List<TemplateInfo> templateInfos; + private Map<String, List<Item>> elementsByFolderNames; + @Before + @Override + public void setup() { + super.setup(); + templateInfos = new ArrayList<>(); + TemplateInfo templateInfo = new TemplateInfo(); + templateInfo.setName(TEMPLATE_INFO_NAME); + Composition composition = new Composition(); + composition.setType(ELEMENT_NAME3); + composition.setAlias(ALIAS_NAME3); + templateInfo.setComposition(Collections.singletonList(composition)); + templateInfos.add(templateInfo); + elementsByFolderNames = new HashMap<>(); + Item item = new Item(); + 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)); + elementsByFolderNames.put(TEMPLATE_INFO_NAME, items); + + } + + @Test + public void getCdumps_emptyTemplateInfo_returnEmptyMap() { + templateContainer = new TemplateContainer(report, dcaeRestClient, new ArrayList<>(), new HashMap<>()); + + Map<TemplateInfo, JsonObject> templateInfoJsonObjectMap = templateContainer.getCdumps(); + + Assert.assertTrue(templateInfoJsonObjectMap.size() == 0); + } + + @Test + public void getCdumps_returnNotFoundEmptyList() { + elementsByFolderNames = new HashMap<>(); + Item item = new Item(); + item.setName(ELEMENT_NAME2); + List<Item> items = new ArrayList<>(Collections.singletonList(item)); + elementsByFolderNames.put(TEMPLATE_INFO_NAME, items); + templateContainer = new TemplateContainer(report, dcaeRestClient, templateInfos, elementsByFolderNames); + + Map<TemplateInfo, JsonObject> templateInfoJsonObjectMap = templateContainer.getCdumps(); + + verify(report).addErrorMessage(anyString()); + Assert.assertTrue(templateInfoJsonObjectMap.size() == 0); + } + + @Test + public void getCdumps_returnOneCdump() { + templateContainer = new TemplateContainer(report, dcaeRestClient, templateInfos, elementsByFolderNames); + + Map<TemplateInfo, JsonObject> templateInfoJsonObjectMap = templateContainer.getCdumps(); + JsonObject jsonObject = templateInfoJsonObjectMap.get(templateInfos.get(0)); + String result = jsonObject.toString(); + + verifyCdump(result); + verify(report, times(0)).addErrorMessage(anyString()); + Assert.assertTrue(templateInfoJsonObjectMap.size() == 1); + } + + @Test + public void getChumps_returnOneChumpWithRelations() { + templateInfos = new ArrayList<>(); + TemplateInfo templateInfo = new TemplateInfo(); + templateInfo.setName(TEMPLATE_INFO_NAME); + List<Composition> compositionList = new ArrayList<>(); + Composition composition = new Composition(); + composition.setType(ELEMENT_NAME3); + composition.setAlias(ALIAS_NAME3); + compositionList.add(composition); + composition = new Composition(); + composition.setType(ELEMENT_NAME2); + composition.setAlias(ALIAS_NAME2); + compositionList.add(composition); + templateInfo.setComposition(compositionList); + Relation relation = new Relation(); + relation.setFromComponent(ALIAS_NAME3 + ".SomeNameFromRequirement"); + relation.setToComponent(ALIAS_NAME2 + ".SomeNameToCapability"); + relation.setFromRequirement("SomeNameFromRequirement"); + relation.setToCapability("SomeNameToCapability"); + templateInfo.setRelations(Collections.singletonList(relation)); + templateInfos.add(templateInfo); + elementsByFolderNames = new HashMap<>(); + List<Item> itemList = new ArrayList<>(); + Item item = new Item(); + 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.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); + + Map<TemplateInfo, JsonObject> templateInfoJsonObjectMap = templateContainer.getCdumps(); + JsonObject jsonObject = templateInfoJsonObjectMap.get(templateInfos.get(0)); + String result = jsonObject.toString(); + + verifyCdumpRelations(result); + verify(report, times(0)).addErrorMessage(anyString()); + Assert.assertTrue(templateInfoJsonObjectMap.size() == 1); + } + + private void verifyCdumpRelations(String result) { + Assert.assertTrue(result.contains("p2\":\"SomeNameToCapability\"")); + Assert.assertTrue(result.contains("\"SomeNameFromRequirement\",null,\"SomeNameToCapability\"")); + Assert.assertTrue(result.contains("\"relationship\":[")); + Assert.assertTrue(result.contains("\"n1\":\"n.")); + Assert.assertTrue(result.contains("\"relations\":[{")); + Assert.assertTrue(result.contains("\"name1\":\"SomeNameFromRequirement\"")); + Assert.assertTrue(result.contains("\"n2\":\"n.")); + Assert.assertTrue(result.contains("\"p1\":\"SomeNameFromRequirement\"")); + } + + private void verifyCdump(String result) { + String expectedResultStart = "{\"version\":0,\"flowType\":\"templateInfoName\",\"nodes\":[{\"name\":\"SomeNameFromRequirement\",\"description\":\"\",\"id\":\"e45ec9d7-01df-4cb1-896f-aff2a6ca5a8b\",\"nid\":\"n."; + String expectedResultMid = "\",\"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"requirements\":[{\"name\":\"SomeNameFromRequirement\"}],\"properties\":[{}],\"typeinfo\":{\"itemId\":\"e45ec9d7-01df-4cb1-896f-aff2a6ca5a8b/tosca.dcae.nodes.cdapApp.Map\",\"typeinfo\":\"typeInfo\"},\"type\":{\"name\":\"type\"},\"ndata\":{\"name\":\"n."; + String expectedResultEnd = "\",\"label\":\"SomeNameFromRequirement\",\"x\":438,\"y\":435,\"px\":437,\"py\":434,\"ports\":[],\"radius\":30}}],\"inputs\":[],\"outputs\":[],\"relations\":[]}"; + Assert.assertTrue(result.startsWith(expectedResultStart)); + Assert.assertTrue(result.contains(expectedResultMid)); + Assert.assertTrue(result.endsWith(expectedResultEnd)); + } +} |