private NodeImpl(NodeBuilder base) { if (base.getKey() == null) { this._key = new NodeKey( base.getNodeId() ); this._nodeId = base.getNodeId(); } else { this._key = base.getKey(); this._nodeId = _key.getNodeId(); } this._nodeType = base.getNodeType(); switch (base.augmentation.size()) { case 0: this.augmentation = Collections.emptyMap(); break; case 1: final Map.Entry<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.usc.channel.rev150101.topology.attributes.Node>>, Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.usc.channel.rev150101.topology.attributes.Node>> e = base.augmentation.entrySet().iterator().next(); this.augmentation = Collections.<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.usc.channel.rev150101.topology.attributes.Node>>, Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.usc.channel.rev150101.topology.attributes.Node>>singletonMap(e.getKey(), e.getValue()); break; default : this.augmentation = new HashMap<>(base.augmentation); } }
private void initLocalController() { NodeBuilder nodeBuilder = new NodeBuilder(); NodeId nodeId = new NodeId(localHostName); localController = nodeBuilder.setNodeType(NODE_TYPE_CONTROLLER).setNodeId(nodeId).setKey(new NodeKey(nodeId)) .build(); }
/** * add a node to local topology, when the node exists in node list of * topology, then only update the refer number of the node * * @param node * the adding node */ public synchronized void addNode(Node node) { if (node != null) { String nodeId = node.getKey().getNodeId().getValue(); Integer num = nodeReferList.get(nodeId); // filter same node using nodeId // Note: here only has the nodes related with current controller, // but all of nodes including nodes related with other controllers // should have unique nodeId if (num == null) { // not exsits, add node and one refer number localNodeList.add(node); nodeReferList.put(nodeId, 1); } else { // exsits,only add refer number nodeReferList.put(nodeId, num + 1); } } }
/** * Builds a node for the provided id. Passes node attributes to NodeBuilder * to build a node. * * @param id * node id * @param type * node type * @return new node */ public static Node createNode(String id, String type) { NodeId nodeId = new NodeId(id); NodeKey nodeKey = new NodeKey(nodeId); NodeBuilder nodeBuilder = new NodeBuilder(); nodeBuilder.setNodeId(nodeId); nodeBuilder.setKey(nodeKey); nodeBuilder.setNodeType(type); return nodeBuilder.build(); }
public NodeBuilder(Node base) { if (base.getKey() == null) { this._key = new NodeKey( base.getNodeId() ); this._nodeId = base.getNodeId(); } else { this._key = base.getKey(); this._nodeId = _key.getNodeId(); } this._nodeType = base.getNodeType(); if (base instanceof NodeImpl) { NodeImpl impl = (NodeImpl) base; if (!impl.augmentation.isEmpty()) { this.augmentation = new HashMap<>(impl.augmentation); } } else if (base instanceof AugmentationHolder) { @SuppressWarnings("unchecked") AugmentationHolder<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.usc.channel.rev150101.topology.attributes.Node> casted =(AugmentationHolder<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.usc.channel.rev150101.topology.attributes.Node>) base; if (!casted.augmentations().isEmpty()) { this.augmentation = new HashMap<>(casted.augmentations()); } } }
/** * get the node identifier belongs to a particular topology * * @param topologyId * topology id * @param nodeId * node id * @return node identifier */ public static InstanceIdentifier<Node> getNodeIdentifier(String topologyId, String nodeId) { return InstanceIdentifier.builder(UscTopology.class) .child(Topology.class, new TopologyKey(new TopologyId(topologyId))) .child(Node.class, new NodeKey(new NodeId(nodeId))).build(); }