public VnfcFlowModel build(){ return new VnfcFlowModel(this); }
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(); }
Set<String> inventoryModelVnfcsSet = new HashSet<String>(); for (Node<Vnfc> node : dependencyModel.getDependencies()) { dependencyModelVnfcSet.add(node.getChild().getVnfcType().toLowerCase()); if (node.getChild().isMandatory()) { dependencyModelMandatoryVnfcSet.add(node.getChild().getVnfcType().toLowerCase()); for (Vnfc vnfc : inventoryModel.getVnf().getVnfcs()) { inventoryModelVnfcsSet.add(vnfc.getVnfcType().toLowerCase());
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 void populateFlowModel(VnfcFlowModel flowModel, InventoryModel inventoryModel) { Iterator<List<Vnfc>> flowIterator = null; for(Vnfc vnfcFromInventory:inventoryModel.getVnf().getVnfcs()){ flowIterator = flowModel.getModelIterator(); String vnfcType = vnfcFromInventory.getVnfcType(); while (flowIterator.hasNext()){ for(Vnfc vnfcFromFlowModel:flowIterator.next() ){ if(vnfcType.equalsIgnoreCase(vnfcFromFlowModel.getVnfcType())){ vnfcFromFlowModel.setVnfcName(vnfcFromInventory.getVnfcName()); vnfcFromFlowModel.addVms(vnfcFromInventory.getVserverList()); } } } } }
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); throw new InvalidDependencyModel("Error parsing dependency model. " + e.getMessage()); return new VnfcDependencyModel(dependencies);
@Override public String toString() { StringBuilder stringBuilder = new StringBuilder("Flow Model : "); Iterator<List<Vnfc>> iterator = getModelIterator(); while(iterator.hasNext()){ for(Vnfc vnfc:iterator.next()){ stringBuilder.append(vnfc.toString()).append(", \n"); } } return stringBuilder.toString(); }
@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()); }
private void validateInput(String dependencyType, String flowStrategy, Map<String, String> params) { DependencyTypes dependencyTypes = DependencyTypes.findByString(dependencyType); if(dependencyTypes == null){ throw new RuntimeException("Dependency type from the input : " + dependencyType +" is invalid."); } FlowStrategies flowStrategies = FlowStrategies.findByString(flowStrategy); if(flowStrategies == null){ throw new RuntimeException("Flow Strategy from the input : " + flowStrategy +" is invalid."); } String vnfType = params.get(Constants.VNF_TYPE); if(vnfType ==null || vnfType.length() ==0){ throw new RuntimeException("Vnf Type is not passed in the input"); } String vnfVersion = params.get(Constants.VNF_VERION); if(vnfVersion == null || vnfVersion.length() ==0){ throw new RuntimeException("Vnf Version not found"); } }
public VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) { if(logger.isTraceEnabled()){ logger.trace("Entering into buildFlowModel with dependency model = " + dependencyModel + "inventory model = " +inventoryModel); } if(dependencyModel == null || dependencyModel.getDependencies() ==null || dependencyModel.getDependencies().size() ==0){ logger.debug("Dependency model not available, building flow model with sequence"); throw new InvalidDependencyModel("Dependency model either null or does not contain any dependency"); } VnfcFlowModel flowModel = buildFlowModel(dependencyModel); if(logger.isDebugEnabled()){ logger.debug("Flow Model without instance data: \n" + flowModel); } logger.info("Populating flow model with A&AI data"); populateFlowModel(flowModel,inventoryModel); if(logger.isDebugEnabled()){ logger.debug("Flow Model with instance data: \n" + flowModel); } return flowModel; }
@Override public String toString() { StringBuilder stringBuilder = new StringBuilder("dependencies = "); for(Node node:dependencies){ stringBuilder.append(node.toString()).append(", "); } return stringBuilder.toString(); } }
private InventoryModel readInventoryModel(SvcLogicContext context) { String vnfId = context.getAttribute("input.action-identifiers.vnf-id"); String vnfType = context.getAttribute("vnf.type"); String vnfVersion = context.getAttribute("vnf.version"); String vnfcCountStr = context.getAttribute("vnf.vnfcCount"); Integer vnfcCount = Integer.parseInt(vnfcCountStr); Vnf vnf = new Vnf(vnfId,vnfType,vnfVersion); for(Integer i=0;i<vnfcCount;i++){ String vnfcName = context.getAttribute("vnf.vnfc["+ i+"].name"); String vnfcType = context.getAttribute("vnf.vnfc["+ i+"].type"); String vmCountStr = context.getAttribute("vnf.vnfc["+ i+"].vm_count"); if(vnfcType ==null || vnfcType.length() ==0){ throw new RuntimeException("Could not retrieve VNFC Type from DG Context for vnf.vnfc["+ i+"].type"); } Integer vmCount = Integer.parseInt(vmCountStr); Vnfc vnfc = new Vnfc(vnfcType,null,vnfcName); for(Integer j=0;j<vmCount;j++){ String vmURL = context.getAttribute("vnf.vnfc["+i+"].vm["+j+"].url"); Vserver vm = new Vserver(vmURL); vnfc.addVm(vm); } vnf.addVnfc(vnfc); } return new InventoryModel(vnf); }
private void reconcileFlowModel(VnfcFlowModel flowModel) { Iterator<List<Vnfc>> flowIterator = flowModel.getModelIterator(); while (flowIterator.hasNext()) { Iterator<Vnfc> vnfcIterator = flowIterator.next().iterator(); while (vnfcIterator.hasNext()) { Vnfc vnfc = vnfcIterator.next(); if (vnfc.getVserverList().size() == 0) { if (logger.isDebugEnabled()) { logger.debug("No vservers present for Vnfc type: " + vnfc.getVnfcType() + ". Hence, removing it from the flow model."); } vnfcIterator.remove(); } } } } }
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; }
modelIdentifier, DependencyTypes.findByString(dependencyType)); } catch (DependencyModelNotFound e) { String msg = EELFResourceManager.format(Msg.DEPENDENCY_MODEL_NOT_FOUND,params.get(Constants.VNF_TYPE), e.getMessage()); FlowStrategies.findByString(flowStrategy));
private void populateContext(VnfcFlowModel flowModel, SvcLogicContext context) { int flowIndex=0; Iterator<List<Vnfc>> iterator = flowModel.getModelIterator(); while (iterator.hasNext()){ for(Vnfc vnfc:iterator.next()){ context.setAttribute("vnfcFlow["+flowIndex+"].vnfcName",vnfc.getVnfcName()); context.setAttribute("vnfcFlow["+flowIndex+"].vnfcType",vnfc.getVnfcType()); context.setAttribute("vnfcFlow["+flowIndex+"].resilienceType",vnfc.getResilienceType()); context.setAttribute("vnfcFlow["+flowIndex+"].vmCount",Integer.toString(vnfc.getVserverList().size())); int vmIndex =0; for(Vserver vm :vnfc.getVserverList()){ context.setAttribute("vnfcFlow["+flowIndex+"].vm["+vmIndex+"].url",vm.getUrl()); vmIndex++; } flowIndex++; } } context.setAttribute("vnfcFlowCount",Integer.toString(flowIndex)); }