diff options
author | 2018-05-23 11:21:11 +0300 | |
---|---|---|
committer | 2018-05-23 11:30:13 +0300 | |
commit | 3e4c18770957b55e2f80da32c3a32caa908f1386 (patch) | |
tree | 8a94c656300e75e38febfe9826ad36fc54fe14f5 /dcaedt_tools | |
parent | da9db1b89e8c9199da4791a2ccd26d1628120a08 (diff) |
Upgrade dt-be-main
Update sources for dcae-dt-be-main to latest version
Change-Id: I3d58a2dc32611c0ca90f1c97e1294a17d5748623
Issue-ID: SDC-1359
Signed-off-by: Stone, Avi (as206k) <as206k@att.com>
Diffstat (limited to 'dcaedt_tools')
14 files changed, 478 insertions, 118 deletions
diff --git a/dcaedt_tools/src/main/java/json/templateInfo/NodeToDelete.java b/dcaedt_tools/src/main/java/json/templateInfo/NodeToDelete.java new file mode 100644 index 0000000..f79be40 --- /dev/null +++ b/dcaedt_tools/src/main/java/json/templateInfo/NodeToDelete.java @@ -0,0 +1,30 @@ +package json.templateInfo; + +import com.google.gson.annotations.SerializedName; + +import javax.annotation.Generated; + +@Generated("net.hexar.json2pojo") +public class NodeToDelete { + + @SerializedName("type") + private String type; + @SerializedName("nodeName") + private String nodeName; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getNodeName() { + return nodeName; + } + + public void setNodeName(String nodeName) { + this.nodeName = nodeName; + } +} diff --git a/dcaedt_tools/src/main/java/json/templateInfo/TemplateInfo.java b/dcaedt_tools/src/main/java/json/templateInfo/TemplateInfo.java index c34aaef..c7e69db 100644 --- a/dcaedt_tools/src/main/java/json/templateInfo/TemplateInfo.java +++ b/dcaedt_tools/src/main/java/json/templateInfo/TemplateInfo.java @@ -17,8 +17,12 @@ public class TemplateInfo { private String Description; @SerializedName("name") private String Name; + @SerializedName("flowType") + private String FlowType; @SerializedName("relations") private List<Relation> Relations; + @SerializedName("nodesToDelete") + private List<NodeToDelete> NodesToDelete; @SerializedName("subCategory") private String SubCategory; @SerializedName("updateIfExist") @@ -56,6 +60,22 @@ public class TemplateInfo { Name = name; } + public String getFlowType() { + return FlowType; + } + + public void setFlowType(String flowType) { + FlowType = flowType; + } + + public List<NodeToDelete> getNodesToDelete() { + return NodesToDelete; + } + + public void setNodesToDelete(List<NodeToDelete> nodesToDelete) { + NodesToDelete = nodesToDelete; + } + public List<Relation> getRelations() { return Relations; } diff --git a/dcaedt_tools/src/main/java/tools/DeployTemplate.java b/dcaedt_tools/src/main/java/tools/DeployTemplate.java index d5c368f..d319542 100644 --- a/dcaedt_tools/src/main/java/tools/DeployTemplate.java +++ b/dcaedt_tools/src/main/java/tools/DeployTemplate.java @@ -29,10 +29,18 @@ public class DeployTemplate { } public void deploy(Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap) { - List<ResourceDetailed> vfcmtList = dcaeRestClient.getAllVfcmts(); + ArrayList<ResourceDetailed> vfcmtList = new ArrayList(); + List<ResourceDetailed> regularVfcmtList = dcaeRestClient.getAllVfcmts(); + if (regularVfcmtList != null) { + vfcmtList.addAll(regularVfcmtList); + } + List<ResourceDetailed> baseVfcmtList = dcaeRestClient.getAllBaseVfcmts(); + if (baseVfcmtList != null) { + vfcmtList.addAll(baseVfcmtList); + } List<TemplateInfo> updatedTemplateInfos = new ArrayList<>(); - vfcmtList.stream().forEach(vfcmt -> + vfcmtList.forEach(vfcmt -> templateInfoToJsonObjectMap.keySet().stream().filter(templateInfo -> templateInfo.getName().equalsIgnoreCase(vfcmt.getName())).forEach(templateInfo -> { update(vfcmt, templateInfo, templateInfoToJsonObjectMap.get(templateInfo)); updatedTemplateInfos.add(templateInfo); @@ -47,9 +55,17 @@ public class DeployTemplate { private void verify(Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap) { AtomicInteger foundCount = new AtomicInteger(); debugLogger.log("Starting verify deployment"); - List<ResourceDetailed> vfcmtList = dcaeRestClient.getAllVfcmts(); + ArrayList<ResourceDetailed> vfcmtList = new ArrayList(); + List<ResourceDetailed> regularVfcmtList = dcaeRestClient.getAllVfcmts(); + if (regularVfcmtList != null) { + vfcmtList.addAll(regularVfcmtList); + } + List<ResourceDetailed> baseVfcmtList = dcaeRestClient.getAllBaseVfcmts(); + if (baseVfcmtList != null) { + vfcmtList.addAll(baseVfcmtList); + } - templateInfoToJsonObjectMap.keySet().stream() + templateInfoToJsonObjectMap.keySet() .forEach(templateInfo -> vfcmtList.stream() .filter(vfcmt -> vfcmt.getName().equalsIgnoreCase(templateInfo.getName())) .forEach(vfcmt -> foundCount.getAndIncrement())); @@ -73,8 +89,6 @@ public class DeployTemplate { createVFCMTRequest.setCategory(templateInfo.getCategory()); ResourceDetailed vfcmt = dcaeRestClient.createResource(createVFCMTRequest); - jsonObject.addProperty("cid", vfcmt.getUuid()); - saveAndCertify(jsonObject, vfcmt); } catch (HttpServerErrorException e) { @@ -87,13 +101,13 @@ public class DeployTemplate { private void update(ResourceDetailed vfcmt, TemplateInfo templateInfo, JsonObject jsonObject) { ResourceDetailed checkedoutVfcmt = vfcmt; try { - Boolean checkoutChecking = checkUserIfResourceCheckedOut(dcaeRestClient.getUserId(), vfcmt); - if (checkoutChecking != null && checkoutChecking) { + boolean vfcmtIsCheckedOut = isCheckedOut(vfcmt); + if (vfcmtIsCheckedOut && differentUserCannotCheckout(dcaeRestClient.getUserId(), vfcmt)){ report.addErrorMessage(FAILED_UPDATE_VFCMT + vfcmt.getName() + ", cannot checkout vfcmt"); return; } if (templateInfo.getUpdateIfExist()) { - if (checkoutChecking == null) { + if (!vfcmtIsCheckedOut) { checkedoutVfcmt = dcaeRestClient.checkoutVfcmt(vfcmt.getUuid()); } if (checkedoutVfcmt != null) { @@ -114,6 +128,7 @@ public class DeployTemplate { } private void saveAndCertify(JsonObject jsonObject, ResourceDetailed checkedoutVfcmt) { + jsonObject.addProperty("cid", checkedoutVfcmt.getUuid()); if (saveCompositionAndCertify(checkedoutVfcmt, jsonObject)) { report.addUpdatedMessage("vfcmt: " + checkedoutVfcmt.getName() + " updated successfully"); } else { @@ -140,18 +155,19 @@ public class DeployTemplate { 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; - } + private boolean isCheckedOut(ResourceDetailed asset) { + return DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == DcaeBeConstants.LifecycleStateEnum.findState(asset.getLifecycleState()); + } + + private Boolean differentUserCannotCheckout(String userId, ResourceDetailed asset) { + 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/ItemAndAlias.java b/dcaedt_tools/src/main/java/tools/ItemAndAlias.java new file mode 100644 index 0000000..e282a58 --- /dev/null +++ b/dcaedt_tools/src/main/java/tools/ItemAndAlias.java @@ -0,0 +1,20 @@ +package tools; + +import json.response.ItemsResponse.Item; + +public class ItemAndAlias { + private final Item item; + private final String alias; + public ItemAndAlias(Item item, String alias) { + this.item = item; + this.alias = alias; + } + + public Item getItem() { + return item; + } + + public String getAlias() { + return alias; + } +} diff --git a/dcaedt_tools/src/main/java/tools/LoggerError.java b/dcaedt_tools/src/main/java/tools/LoggerError.java index 325bfc1..9ec985b 100644 --- a/dcaedt_tools/src/main/java/tools/LoggerError.java +++ b/dcaedt_tools/src/main/java/tools/LoggerError.java @@ -10,4 +10,9 @@ public class LoggerError { public void log(String logLine) { System.err.println(logLine); } + + public void log(String logLine, Exception e) { + System.err.println(logLine); + e.printStackTrace(); + } } diff --git a/dcaedt_tools/src/main/java/tools/Main.java b/dcaedt_tools/src/main/java/tools/Main.java index 72b6e42..bf02c44 100644 --- a/dcaedt_tools/src/main/java/tools/Main.java +++ b/dcaedt_tools/src/main/java/tools/Main.java @@ -61,11 +61,11 @@ public class Main { debugLogger.log( "VFCMT template deployment completed successfully"); } catch (RuntimeException e) { - errLogger.log("ERROR - Template deployment failed with error " + e); + errLogger.log("ERROR - Template deployment failed with error " + e, e); } catch (ConnectException e) { - errLogger.log( "ERROR - Failed connection to server, are you on AT&T network? {}" + e); + errLogger.log( "ERROR - Failed connection to server, are you on AT&T network? {}" + e, e); } catch (IOException e) { - errLogger.log( "ERROR - Fatal Error! " + e); + errLogger.log( "ERROR - Fatal Error! " + e, e); } finally { debugLogger.log(report.toString()); } diff --git a/dcaedt_tools/src/main/java/tools/NodeData.java b/dcaedt_tools/src/main/java/tools/NodeData.java index f89105b..e9043de 100644 --- a/dcaedt_tools/src/main/java/tools/NodeData.java +++ b/dcaedt_tools/src/main/java/tools/NodeData.java @@ -9,13 +9,15 @@ public class NodeData { private final JsonArray properties; private final JsonObject typeInfo; private final String nodeName; + private final String aliasBelong; - NodeData(JsonArray capabilities, JsonArray requirements, JsonArray properties, JsonObject typeInfo, String nodeName) { + NodeData(JsonArray capabilities, JsonArray requirements, JsonArray properties, JsonObject typeInfo, String nodeName, String aliasBelong) { this.capabilities = capabilities; this.requirements = requirements; this.properties = properties; this.typeInfo = typeInfo; this.nodeName = nodeName; + this.aliasBelong = aliasBelong; } public JsonArray getCapabilities() { @@ -37,4 +39,12 @@ public class NodeData { public String getName() { return nodeName; } + + public String getNameWithAlias() { + return aliasBelong + "." + nodeName; + } + + public String getAliasBelong() { + return aliasBelong; + } } diff --git a/dcaedt_tools/src/main/java/tools/TemplateContainer.java b/dcaedt_tools/src/main/java/tools/TemplateContainer.java index ee16d22..a5bca1f 100644 --- a/dcaedt_tools/src/main/java/tools/TemplateContainer.java +++ b/dcaedt_tools/src/main/java/tools/TemplateContainer.java @@ -6,6 +6,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import json.response.ItemsResponse.Item; import json.templateInfo.Composition; +import json.templateInfo.NodeToDelete; import json.templateInfo.Relation; import json.templateInfo.TemplateInfo; import org.apache.commons.lang3.StringUtils; @@ -19,6 +20,7 @@ import java.util.concurrent.atomic.AtomicReference; public class TemplateContainer { private static final String NODES = "nodes"; private static final String RELATIONSHIP = "relationship"; + public static final String ASSIGNMENT = "assignment"; private static long nidCounter = 0; private final IReport report; private final IDcaeRestClient dcaeRestClient; @@ -34,12 +36,12 @@ public class TemplateContainer { this.elementsByFolderNames = elementsByFolderNames; } - private List<Item> findTemplate(TemplateInfo templateInfo) { - AtomicReference<List<Item>> items = new AtomicReference<>(); + private List<ItemAndAlias> findTemplate(TemplateInfo templateInfo) { + AtomicReference<List<ItemAndAlias>> items = new AtomicReference<>(); items.set(new ArrayList<>()); elementsByFolderNames.keySet().stream() .forEach(folderName -> { - List<Item> itemList = returnMatchedTemplate(folderName, templateInfo); + List<ItemAndAlias> itemList = returnMatchedTemplate(folderName, templateInfo); items.get().addAll(itemList); }); if (items.get().size() == templateInfo.getComposition().size()) { @@ -48,13 +50,13 @@ public class TemplateContainer { return new ArrayList<>(); } - private List<Item> returnMatchedTemplate(String folderName, TemplateInfo templateInfo) { - List<Item> items = new ArrayList<>(); + private List<ItemAndAlias> returnMatchedTemplate(String folderName, TemplateInfo templateInfo) { + List<ItemAndAlias> items = new ArrayList<>(); elementsByFolderNames.get(folderName).stream() .forEach(item -> templateInfo.getComposition().stream().forEach(composition -> { if (composition.getType().equalsIgnoreCase(item.getName())) { - items.add(item); + items.add(new ItemAndAlias(item, composition.getAlias())); } })); return items; @@ -64,7 +66,7 @@ public class TemplateContainer { public Map<TemplateInfo, JsonObject> getCdumps() { Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap = new HashMap<>(); for (TemplateInfo templateInfo : templateInfos) { - List<Item> items = findTemplate(templateInfo); + List<ItemAndAlias> items = findTemplate(templateInfo); if (items == null || items.isEmpty()) { report.addErrorMessage("vfcmt: " + templateInfo.getName() + ". DCAE Component not found"); continue; @@ -74,37 +76,35 @@ public class TemplateContainer { return templateInfoToJsonObjectMap; } - private JsonObject getCdumpJsonObject(List<Item> items, TemplateInfo templateInfo) { + private JsonObject getCdumpJsonObject(List<ItemAndAlias> ItemsAndAlias, TemplateInfo templateInfo) { JsonObject cdumpJsonObject = generateCdumpInput(templateInfo); - Map<Item, Map<String, NodeData>> itemMapHashMap = new HashMap<>(); + Map<ItemAndAlias, Map<String, NodeData>> itemMapHashMap = new HashMap<>(); JsonArray relationsJsonArray = new JsonArray(); - for (Item item : items) { + for (ItemAndAlias itemAndAlias : ItemsAndAlias) { + Item item = itemAndAlias.getItem(); debugLogger.log("Creating cdump for item: " + item.getName()); JsonArray jsonArrayNode = cdumpJsonObject.getAsJsonArray(NODES); JsonParser jsonParser = new JsonParser(); JsonArray allNodeTemplates = jsonParser.parse(dcaeRestClient.getItemModel(item.getItemId())).getAsJsonObject().get("data").getAsJsonObject().get("model").getAsJsonObject().get(NODES).getAsJsonArray(); Map<String, NodeData> stringRelationsDataMap = new HashMap<>(); for (JsonElement nodeElement : allNodeTemplates) { + if (checkIfNeedToSkip(templateInfo.getNodesToDelete(), nodeElement, item.getName())) { + continue; + } JsonObject responseModelJson = nodeElement.getAsJsonObject(); JsonObject responseTypeInfoJson = jsonParser.parse(dcaeRestClient.getItemType(item.getItemId(), responseModelJson.get("type").getAsString())).getAsJsonObject().get("data").getAsJsonObject().get("type").getAsJsonObject(); - JsonObject jsonObjectElement = newVfcmtJSON(responseModelJson.get("name").getAsString(), item.getModels().get(0).getItemId()); + String nodeName = itemAndAlias.getAlias() + "." + responseModelJson.get("name").getAsString(); + JsonObject jsonObjectElement = newNodeTemplate(nodeName, 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()); + NodeData nodeData = createNodeData(responseModelJson, responseTypeInfoJson, responseModelJson.get("name").getAsString(), itemAndAlias.getAlias()); + fillPropertiesValue(nodeData); 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); + addCdumpData(responseModelJson, jsonObjectElement, nid, nodeData); jsonArrayNode.add(jsonObjectElement); } - itemMapHashMap.put(item, stringRelationsDataMap); + itemMapHashMap.put(itemAndAlias, stringRelationsDataMap); } JsonElement jsonElement = createTemplateInfoRelations(templateInfo, itemMapHashMap); if (jsonElement != null && jsonElement.isJsonArray()) { @@ -123,6 +123,56 @@ public class TemplateContainer { return cdumpJsonObject; } + private void addCdumpData(JsonObject responseModelJson, JsonObject jsonObjectElement, String nid, NodeData 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); + } + + private void fillPropertiesValue(NodeData nodeData) { + for (Iterator<JsonElement> iterator = nodeData.getProperties().iterator(); iterator.hasNext(); ) { + JsonElement property = iterator.next(); + if (!property.isJsonObject()) { + continue; + } + if (property.getAsJsonObject().has("value")) { + continue; + } + JsonElement jsonElement = new JsonObject(); + if (property.getAsJsonObject().has(ASSIGNMENT) && + property.getAsJsonObject().get(ASSIGNMENT).getAsJsonObject().has("value")) { + jsonElement = property.getAsJsonObject().get(ASSIGNMENT).getAsJsonObject().get("value"); + } else if (property.getAsJsonObject().has("default")) { + jsonElement = property.getAsJsonObject().get("default"); + } else if (property.getAsJsonObject().has(ASSIGNMENT) && + property.getAsJsonObject().get(ASSIGNMENT).getAsJsonObject().has("input") && + property.getAsJsonObject().get(ASSIGNMENT).getAsJsonObject().get("input").getAsJsonObject().has("default")) { + jsonElement = property.getAsJsonObject().get(ASSIGNMENT).getAsJsonObject().get("input").getAsJsonObject().get("default"); + } + property.getAsJsonObject().add("value", jsonElement); + } + + } + + private boolean checkIfNeedToSkip(List<NodeToDelete> nodesToDelete, JsonElement nodeElement, String itemName) { + return nodesToDelete != null && nodesToDelete.stream().anyMatch(nodeToDelete -> { + if (nodeToDelete.getType().equalsIgnoreCase(itemName)) { + String nodeName = nodeElement.getAsJsonObject().get("name").toString().replace("\"", ""); + if (nodeToDelete.getNodeName().equalsIgnoreCase(nodeName)) { + debugLogger.log("Skipping node: " + nodeToDelete.getNodeName() + ", Item name: " + itemName); + return true; + } + } + return false; + }); + } + //We need it only for printing the relations (front end requirement) private JsonElement createNData(String name, String nid) { JsonObject ndataElement = new JsonObject(); @@ -138,9 +188,9 @@ public class TemplateContainer { return ndataElement; } - private JsonElement createSelfRelations(Map<Item, Map<String, NodeData>> nodeDataByNidByItem) { + private JsonElement createSelfRelations(Map<ItemAndAlias, Map<String, NodeData>> nodeDataByNidByItem) { JsonArray jsonArrayRelations = new JsonArray(); - for (Item item : nodeDataByNidByItem.keySet()) { + for (ItemAndAlias item : nodeDataByNidByItem.keySet()) { Map<String, NodeData> nodeDataByNid = nodeDataByNidByItem.get(item); if (nodeDataByNid.size() < 2) { continue; @@ -173,12 +223,12 @@ public class TemplateContainer { 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()); + relationElement.addProperty("name1", fromNode.getNameWithAlias()); 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); + relationElement.addProperty("name2", fromNode.getAliasBelong() + "." + toNodeName); metaData.addProperty("n2", toNId); String capabilityFullName = requirement.get("capability").getAsJsonObject().get("name").toString(); String capabilityShortName = StringUtils.substringAfterLast(capabilityFullName, "."); @@ -202,14 +252,14 @@ public class TemplateContainer { return jsonArrayRelations; } - private NodeData createNodeData(JsonObject responseModelJson, JsonObject responseTypeInfoJson, String nodeName) { + private NodeData createNodeData(JsonObject responseModelJson, JsonObject responseTypeInfoJson, String nodeName, String aliasBelong) { 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); + return new NodeData(capabilities, requirements, properties, responseTypeInfoJson, nodeName, aliasBelong); } - private JsonArray createTemplateInfoRelations(TemplateInfo templateInfo, Map<Item, Map<String, NodeData>> nodeDataByNidByItem) { + private JsonArray createTemplateInfoRelations(TemplateInfo templateInfo, Map<ItemAndAlias, Map<String, NodeData>> nodeDataByNidByItem) { JsonArray jsonArrayRelations = new JsonArray(); if (templateInfo.getRelations() == null) { @@ -226,19 +276,26 @@ public class TemplateContainer { String toComponentNodeName = StringUtils.substringAfterLast(toComponent, "."); boolean findTo = false; boolean findFrom = false; - for (Item item : nodeDataByNidByItem.keySet()) { + for (ItemAndAlias 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(); + .filter(element -> fromComponentAlias.equalsIgnoreCase(element.getAlias()) + && element.getAlias().equalsIgnoreCase(currentNodeData.getAliasBelong()) + && element.getAlias().equalsIgnoreCase(item.getAlias()) + && element.getType().equalsIgnoreCase(item.getItem().getName()) + && fromComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny(); if (isFoundComposition.isPresent()) { boolean isFound = findNode(relation.getFromRequirement(), currentNodeData.getRequirements()); if (isFound) { + if (findFrom) { + report.addErrorMessage("Found 2 match nodes, using the second one. from relation: " + relation.getFromRequirement()); + } relationElement.addProperty("rid", "ink." + nid + "." + nidCounter++); relationElement.addProperty("n1", nid); - relationElement.addProperty("name1", currentNodeData.getName()); + relationElement.addProperty("name1", currentNodeData.getNameWithAlias()); metaData.addProperty("n1", nid); metaData.addProperty("p1", relation.getFromRequirement()); JsonArray relationship = new JsonArray(); @@ -257,12 +314,19 @@ public class TemplateContainer { } isFoundComposition = templateInfo.getComposition().stream() - .filter(element -> toComponentAlias.equalsIgnoreCase(element.getAlias()) && element.getType().equalsIgnoreCase(item.getName()) && toComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny(); + .filter(element -> toComponentAlias.equalsIgnoreCase(element.getAlias()) + && element.getAlias().equalsIgnoreCase(currentNodeData.getAliasBelong()) + && element.getAlias().equalsIgnoreCase(item.getAlias()) + && element.getType().equalsIgnoreCase(item.getItem().getName()) + && toComponentNodeName.equalsIgnoreCase(currentNodeData.getName())).findAny(); if (isFoundComposition.isPresent()) { boolean isFound = findNode(relation.getToCapability(), currentNodeData.getCapabilities()); if (isFound) { + if (findTo) { + report.addErrorMessage("Found 2 match nodes, using the second one. to relation: " + relation.getToCapability()); + } relationElement.addProperty("n2", nid); - relationElement.addProperty("name2", currentNodeData.getName()); + relationElement.addProperty("name2", currentNodeData.getNameWithAlias()); metaData.addProperty("n2", nid); metaData.addProperty("p2", relation.getToCapability()); findTo = true; @@ -307,7 +371,7 @@ public class TemplateContainer { return false; } - private JsonObject newVfcmtJSON(String name, String description) { + private JsonObject newNodeTemplate(String name, String description) { JsonObject json = new JsonObject(); json.addProperty("name", name); json.addProperty("description", description); @@ -317,7 +381,7 @@ public class TemplateContainer { private JsonObject generateCdumpInput(TemplateInfo templateInfo) { JsonObject json = new JsonObject(); json.addProperty("version", 0); - json.addProperty("flowType", templateInfo.getName()); + json.addProperty("flowType", templateInfo.getFlowType()); json.add(NODES, new JsonArray()); json.add("inputs", new JsonArray()); diff --git a/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java b/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java index 5e81038..7e991d7 100644 --- a/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java +++ b/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java @@ -17,6 +17,7 @@ import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import javax.annotation.PostConstruct; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -74,6 +75,12 @@ public class DcaeRestClient implements IDcaeRestClient { } @Override + public List<ResourceDetailed> getAllBaseVfcmts() { + String url = buildRequestPath("/getResourcesByMonitoringTemplateCategory"); + 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); diff --git a/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java b/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java index 677175b..bfe3595 100644 --- a/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java +++ b/dcaedt_tools/src/main/java/utilities/IDcaeRestClient.java @@ -15,6 +15,8 @@ public interface IDcaeRestClient { List<ResourceDetailed> getAllVfcmts(); + List<ResourceDetailed> getAllBaseVfcmts(); + ResourceDetailed createResource(CreateVFCMTRequest resource); ResourceDetailed checkoutVfcmt(String vfcmtUuid); diff --git a/dcaedt_tools/src/main/resources/conf/config.json b/dcaedt_tools/src/main/resources/conf/config.json index 5b0f542..4ca81cc 100644 --- a/dcaedt_tools/src/main/resources/conf/config.json +++ b/dcaedt_tools/src/main/resources/conf/config.json @@ -1,51 +1,207 @@ { "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" - }] - } - ] + "name": "Syslog Collector Template", + "flowType": "Syslog Collector", + "description": "Syslog Collector", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "false", + "composition": [{ + "type": "SyslogCollector", + "alias": "Syslog" + }, { + "type": "Existing Topic", + "alias": "eTopic" + }], + "relations": [{ + "fromComponent": "Syslog.SyslogCollector", + "fromRequirement": "stream_publish_0", + "toComponent": "eTopic.topic", + "toCapability": "topic" + }], + "nodesToDelete": [ + { + "type": "SyslogCollector", + "nodeName": "topic0" + }] + },{ + "name": "Syslog MSEA Template", + "flowType": "Syslog MSEA", + "description": "Syslog MSEA", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "false", + "composition": [{ + "type": "Map", + "alias": "Map" + }, { + "type": "Supplement", + "alias": "Sup" + }, { + "type": "Enrich", + "alias": "Enr" + }, { + "type": "Alert", + "alias": "Ale" + }], + "relations": [{ + "fromComponent": "Sup.Supplement", + "fromRequirement": "dependency", + "toComponent": "Map.Map", + "toCapability": "feature" + },{ + "fromComponent": "Enr.Enrich", + "fromRequirement": "dependency", + "toComponent": "Sup.Supplement", + "toCapability": "feature" + },{ + "fromComponent": "Ale.Alert", + "fromRequirement": "dependency", + "toComponent": "Enr.Enrich", + "toCapability": "feature" + }] + },{ + "name": "Status Poller Collector Template", + "flowType": "Status Poller Collector", + "description": "Status Poller Collector", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "false", + "composition": [{ + "type": "StatusPoller", + "alias": "sPoller" + }, { + "type": "Existing Topic", + "alias": "eTopic0" + }], + "relations": [{ + "fromComponent": "sPoller.StatusPoller", + "fromRequirement": "stream_publish_0", + "toComponent": "eTopic0.topic", + "toCapability": "topic" + }], + "nodesToDelete": [ + { + "type": "StatusPoller", + "nodeName": "topic0" + }] + }, { + "name": "Status Poller MSE Template", + "flowType": "Status Poller MSE", + "description": "Status Poller MSE", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "false", + "composition": [{ + "type": "Map", + "alias": "Map" + }, { + "type": "Supplement", + "alias": "Sup" + }, { + "type": "Enrich", + "alias": "Enr" + }], + "relations": [{ + "fromComponent": "Sup.Supplement", + "fromRequirement": "dependency", + "toComponent": "Map.Map", + "toCapability": "feature" + },{ + "fromComponent": "Enr.Enrich", + "fromRequirement": "dependency", + "toComponent": "Sup.Supplement", + "toCapability": "feature" + }] + }, { + "name": "FOI Collector Template", + "flowType": "FOI Collector", + "description": "FOI Collector", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "false", + "composition": [{ + "type": "FOICollector", + "alias": "fCollector" + }, { + "type": "Existing Feed", + "alias": "eFeed" + }], + "relations": [{ + "fromComponent": "fCollector.FoiSftp", + "fromRequirement": "stream_publish_0", + "toComponent": "eFeed.feed", + "toCapability": "feed" + }], + "nodesToDelete": [ + { + "type": "FOICollector", + "nodeName": "feed0" + }] + }, { + "name": "SNMP MSE Template", + "flowType": "SNMP MSE", + "description": "SNMP MSE", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "false", + "composition": [{ + "type": "Map", + "alias": "Map" + }, { + "type": "Supplement", + "alias": "Sup" + }, { + "type": "Enrich", + "alias": "Enr" + }], + "relations": [{ + "fromComponent": "Sup.Supplement", + "fromRequirement": "dependency", + "toComponent": "Map.Map", + "toCapability": "feature" + },{ + "fromComponent": "Enr.Enrich", + "fromRequirement": "dependency", + "toComponent": "Sup.Supplement", + "toCapability": "feature" + }] + }, { + "name": "Docker Map Template", + "flowType": "Docker Map", + "description": "Docker Map", + "category": "Template", + "subCategory":"Base Monitoring Template", + "updateIfExist": "false", + "composition": [{ + "type": "DockerMap", + "alias": "dMp" + }, { + "type": "Existing Feed", + "alias": "eFeed" + }, { + "type": "Existing Topic", + "alias": "eTopic" + }], + "relations": [{ + "fromComponent": "dMp.DockerMap", + "fromRequirement": "stream_subscribe_0", + "toComponent": "eFeed.feed", + "toCapability": "feed" + }, { + "fromComponent": "dMp.DockerMap", + "fromRequirement": "stream_publish_0", + "toComponent": "eTopic.topic", + "toCapability": "topic" + }], + "nodesToDelete": [ + { + "type": "DockerMap", + "nodeName": "feed0" + }, + { + "type": "DockerMap", + "nodeName": "topic0" + }] + }] }
\ No newline at end of file diff --git a/dcaedt_tools/src/test/java/BaseTest.java b/dcaedt_tools/src/test/java/BaseTest.java index 49534a5..f618f2d 100644 --- a/dcaedt_tools/src/test/java/BaseTest.java +++ b/dcaedt_tools/src/test/java/BaseTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.when; abstract class BaseTest { static final String USER_ID = "userId"; static final String TEMPLATE_INFO_NAME = "templateInfoName"; + static final String TEMPLATE_INFO_FLOWTYPE = "templateInfoFlowType"; static final String VFCMT_NAME1 = "my vfcmt1"; static final String UUID1 = "my uuid1"; static final String VFCMT_NAME2 = "my vfcmt2"; @@ -127,25 +128,26 @@ abstract class BaseTest { resourceDetailed.setUuid(UUID3); resourceDetaileds.add(resourceDetailed); - List<ResourceDetailed> resourceDetaileds2 = new ArrayList<>(); + List<ResourceDetailed> resourceDetailed2 = new ArrayList<>(); resourceDetailed = new ResourceDetailed(); resourceDetailed.setName(VFCMT_NAME1); resourceDetailed.setUuid(UUID1); resourceDetailed.setLifecycleState("NOT_CERTIFIED_CHECKOUT"); resourceDetailed.setLastUpdaterUserId(USER_ID); - resourceDetaileds2.add(resourceDetailed); + resourceDetailed2.add(resourceDetailed); resourceDetailed = new ResourceDetailed(); resourceDetailed.setName(VFCMT_NAME2); resourceDetailed.setUuid(UUID2); - resourceDetaileds2.add(resourceDetailed); + resourceDetailed2.add(resourceDetailed); resourceDetailed = new ResourceDetailed(); resourceDetailed.setName(VFCMT_NAME3); resourceDetailed.setUuid(UUID3); - resourceDetaileds2.add(resourceDetailed); + resourceDetailed2.add(resourceDetailed); resourceDetailed = new ResourceDetailed(); resourceDetailed.setName(TEMPLATE_INFO_NAME); resourceDetailed.setUuid(UUID3); - resourceDetaileds2.add(resourceDetailed); - when(dcaeRestClient.getAllVfcmts()).thenReturn(resourceDetaileds, resourceDetaileds2); + resourceDetailed2.add(resourceDetailed); + when(dcaeRestClient.getAllVfcmts()).thenReturn(resourceDetaileds, resourceDetailed2); + when(dcaeRestClient.getAllBaseVfcmts()).thenReturn(new ArrayList<>()); } } diff --git a/dcaedt_tools/src/test/java/DeployTemplateTest.java b/dcaedt_tools/src/test/java/DeployTemplateTest.java index 3fe0a7d..6a8a019 100644 --- a/dcaedt_tools/src/test/java/DeployTemplateTest.java +++ b/dcaedt_tools/src/test/java/DeployTemplateTest.java @@ -26,6 +26,7 @@ public class DeployTemplateTest extends BaseTest { templateInfoToJsonObjectMap = new HashMap<>(); TemplateInfo templateInfo = new TemplateInfo(); templateInfo.setName(VFCMT_NAME1); + templateInfo.setFlowType(TEMPLATE_INFO_FLOWTYPE); templateInfo.setCategory("category"); templateInfo.setSubCategory("subCategory"); templateInfo.setDescription("description"); @@ -33,6 +34,7 @@ public class DeployTemplateTest extends BaseTest { templateInfoToJsonObjectMap.put(templateInfo, new JsonObject()); templateInfo = new TemplateInfo(); templateInfo.setName(TEMPLATE_INFO_NAME); + templateInfo.setFlowType(TEMPLATE_INFO_FLOWTYPE); templateInfo.setCategory("category"); templateInfo.setSubCategory("subCategory"); templateInfo.setDescription("description"); diff --git a/dcaedt_tools/src/test/java/TemplateContainerTest.java b/dcaedt_tools/src/test/java/TemplateContainerTest.java index 7c3d287..b4ddc17 100644 --- a/dcaedt_tools/src/test/java/TemplateContainerTest.java +++ b/dcaedt_tools/src/test/java/TemplateContainerTest.java @@ -2,6 +2,7 @@ import com.google.gson.JsonObject; import json.response.ItemsResponse.Item; import json.response.ItemsResponse.Model; import json.templateInfo.Composition; +import json.templateInfo.NodeToDelete; import json.templateInfo.Relation; import json.templateInfo.TemplateInfo; import org.junit.Assert; @@ -28,6 +29,7 @@ public class TemplateContainerTest extends BaseTest { templateInfos = new ArrayList<>(); TemplateInfo templateInfo = new TemplateInfo(); templateInfo.setName(TEMPLATE_INFO_NAME); + templateInfo.setFlowType(TEMPLATE_INFO_FLOWTYPE); Composition composition = new Composition(); composition.setType(ELEMENT_NAME3); composition.setAlias(ALIAS_NAME3); @@ -84,10 +86,28 @@ public class TemplateContainerTest extends BaseTest { } @Test + public void getCdumpsWithDeleteNode_returnOneCdumpWithDeletedNode() { + NodeToDelete nodeToDelete = new NodeToDelete(); + nodeToDelete.setNodeName("SomeNameFromRequirement"); + nodeToDelete.setType("my element3"); + templateInfos.get(0).setNodesToDelete(Collections.singletonList(nodeToDelete)); + templateContainer = new TemplateContainer(report, dcaeRestClient, templateInfos, elementsByFolderNames); + + Map<TemplateInfo, JsonObject> templateInfoJsonObjectMap = templateContainer.getCdumps(); + JsonObject jsonObject = templateInfoJsonObjectMap.get(templateInfos.get(0)); + String result = jsonObject.toString(); + + verifyDeletedNodeCdump(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); + templateInfo.setFlowType(TEMPLATE_INFO_FLOWTYPE); List<Composition> compositionList = new ArrayList<>(); Composition composition = new Composition(); composition.setType(ELEMENT_NAME3); @@ -141,17 +161,23 @@ public class TemplateContainerTest extends BaseTest { 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(",\"name2\":\"my alias2.SomeNameToCapability\",")); + Assert.assertTrue(result.contains(",\"name1\":\"my alias3.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 expectedResultStart = "{\"version\":0,\"flowType\":\"templateInfoFlowType\",\"nodes\":[{\"name\":\"my alias3.SomeNameFromRequirement\",\"description\":\"\",\"id\":\"e45ec9d7-01df-4cb1-896f-aff2a6ca5a8b\",\"nid\":\"n."; + String expectedResultMid = "\",\"capabilities\":[{\"name\":\"SomeNameToCapability\"}],\"requirements\":[{\"name\":\"SomeNameFromRequirement\"}],\"properties\":[{\"value\":{}}],\"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)); } + + private void verifyDeletedNodeCdump(String result) { + String expectedResult = "{\"version\":0,\"flowType\":\"templateInfoFlowType\",\"nodes\":[],\"inputs\":[],\"outputs\":[],\"relations\":[]}"; + Assert.assertEquals(expectedResult, result); + } } |