@Override public boolean equals(Object object){ if(object == null){ return false; } if(!(object instanceof Node)){ return false; } Node node = (Node)object; return this.child.equals(node.getChild()); }
@Override public String toString() { StringBuilder stringBuilder = new StringBuilder("dependencies = "); for(Node node:dependencies){ stringBuilder.append(node.toString()).append(", "); } return stringBuilder.toString(); } }
private void addDependencies(Set<Node<Vnfc>> nodes, Node node, String[] parentList) { for (String type : parentList) { String parentType = getVnfcType(type); Node<Vnfc> parentNode = getNode(nodes, parentType); if (parentNode != null) { logger.debug("VNFC already exists for VNFC type: " + parentType + ". Adding it to parent list "); node.addParent(parentNode.getChild()); } else { logger.debug("VNFC does not exist for VNFC type: " + parentType + ". Creating new VNFC "); parentNode = new Node<>(new Vnfc(parentType, null)); node.addParent(parentNode.getChild()); logger.debug("Adding VNFC to dependency model : " + parentNode); nodes.add(parentNode); } } }
private VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel) throws InvalidDependencyModel { Set<Node<Vnfc>> dependencies = dependencyModel.getDependencies(); graph = new Graph(dependencies.size()); for(Node<Vnfc> node:dependencies){ graph.addVertex(node.getChild()); } for(Node node:dependencies){ Vnfc child = (Vnfc)node.getChild(); List<Vnfc> parents = node.getParents(); for(Vnfc parent:parents){ graph.addEdge(child,parent); } } List<List<Vnfc>> dependencyList = orderDependencies(); VnfcFlowModel.VnfcFlowModelBuilder builder = new VnfcFlowModel.VnfcFlowModelBuilder(); int count=0; int flowModelSize = 0; for(List<Vnfc> vnfcList:dependencyList){ builder.addMetadata(count,vnfcList); flowModelSize += vnfcList.size(); count++; } if(flowModelSize != dependencies.size()){ throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies"); } return builder.build(); }
if (vnfcNode != null) { logger.debug("Dependency node already exists for vnfc Type: " + vnfcType); if (StringUtils.isEmpty(vnfcNode.getChild().getResilienceType())) { logger.debug("Updating resilience type, dependencies and mandatory attribute for VNFC type: " + vnfcType); vnfcNode.getChild().setResilienceType(resilienceType); if (parentList != null && parentList.length > 0) { addDependencies(dependencies, vnfcNode, parentList); vnfcNode.getChild().setMandatory(mandatory); vnfcNode = new Node<>(new Vnfc(vnfcType, resilienceType, null, mandatory)); if (parentList != null && parentList.length > 0) addDependencies(dependencies, vnfcNode, parentList);
private Node<Vnfc> getNode(Set<Node<Vnfc>> nodes, String vnfcType) { Iterator itr = nodes.iterator(); Node<Vnfc> node; while (itr.hasNext()) { node = (Node<Vnfc>) itr.next(); if (node.getChild().getVnfcType().equalsIgnoreCase(vnfcType)) { return node; } } return null; }