- Use Set instead of List in Subnet's aggreagated NodeConnectors
to avoid handling dpulicates
- Style fixes
Change-Id: I037764503b5bc01791716a9f515825a706451153
Signed-off-by: Yevgeny Khodorkovsky <ykhodork@cisco.com>
*/
package org.opendaylight.controller.subnets.northbound;
*/
package org.opendaylight.controller.subnets.northbound;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.Consumes;
import java.util.Set;
import javax.ws.rs.Consumes;
throw new ResourceNotFoundException(RestMessages.NOCONTAINER.toString());
}
throw new ResourceNotFoundException(RestMessages.NOCONTAINER.toString());
}
- SubnetConfig cfgObject = new SubnetConfig(subnetName, subnet, new ArrayList<String>(0));
+ SubnetConfig cfgObject = new SubnetConfig(subnetName, subnet, new HashSet<String>(0));
Status status = switchManager.addSubnet(cfgObject);
if (status.isSuccess()) {
return Response.status(Response.Status.CREATED).build();
Status status = switchManager.addSubnet(cfgObject);
if (status.isSuccess()) {
return Response.status(Response.Status.CREATED).build();
} else {
Status st;
boolean successful = true;
} else {
Status st;
boolean successful = true;
- List<String> ports = subnetConf.getNodePorts();
+ Set<String> ports = subnetConf.getNodePorts();
if (action.equals("add")) {
// add new ports
if (action.equals("add")) {
// add new ports
* @param sp Set of NodeConnectors to add to the subnet
*/
public void addNodeConnectors(Set<NodeConnector> sp) {
* @param sp Set of NodeConnectors to add to the subnet
*/
public void addNodeConnectors(Set<NodeConnector> sp) {
- if (sp == null) {
- return;
- }
-
- for (NodeConnector p : sp) {
- this.nodeConnectors.add(p);
+ if (sp != null) {
+ this.nodeConnectors.addAll(sp);
private String subnet; // A.B.C.D/MM Where A.B.C.D is the Default
// Gateway IP (L3) or ARP Querier IP (L2
@XmlElement
private String subnet; // A.B.C.D/MM Where A.B.C.D is the Default
// Gateway IP (L3) or ARP Querier IP (L2
@XmlElement
- private List<String> nodePorts; // datapath ID/port list:
+ private Set<String> nodePorts; // datapath ID/port list:
// xx:xx:xx:xx:xx:xx:xx:xx/a,b,c-m,r-t,y
public SubnetConfig() {
}
// xx:xx:xx:xx:xx:xx:xx:xx/a,b,c-m,r-t,y
public SubnetConfig() {
}
- public SubnetConfig(String desc, String sub, List<String> sp) {
+ public SubnetConfig(String desc, String sub, Set<String> sp) {
name = desc;
subnet = sub;
nodePorts = sp;
name = desc;
subnet = sub;
nodePorts = sp;
public SubnetConfig(SubnetConfig subnetConfig) {
name = subnetConfig.name;
subnet = subnetConfig.subnet;
public SubnetConfig(SubnetConfig subnetConfig) {
name = subnetConfig.name;
subnet = subnetConfig.subnet;
- nodePorts = new ArrayList<String>(subnetConfig.nodePorts);
+ nodePorts = new HashSet<String>(subnetConfig.nodePorts);
}
public String getName() {
return name;
}
}
public String getName() {
return name;
}
- public List<String> getNodePorts() {
+ public Set<String> getNodePorts() {
private static final String SAVE = "Save";
private String subnetFileName, spanFileName, switchConfigFileName;
private final List<NodeConnector> spanNodeConnectors = new CopyOnWriteArrayList<NodeConnector>();
private static final String SAVE = "Save";
private String subnetFileName, spanFileName, switchConfigFileName;
private final List<NodeConnector> spanNodeConnectors = new CopyOnWriteArrayList<NodeConnector>();
- // set of Subnets keyed by the InetAddress
+ // Collection of Subnets keyed by the InetAddress
private ConcurrentMap<InetAddress, Subnet> subnets;
private ConcurrentMap<String, SubnetConfig> subnetsConfigList;
private ConcurrentMap<SpanConfig, SpanConfig> spanConfigList;
private ConcurrentMap<InetAddress, Subnet> subnets;
private ConcurrentMap<String, SubnetConfig> subnetsConfigList;
private ConcurrentMap<SpanConfig, SpanConfig> spanConfigList;
Set<NodeConnector> sp = conf.getSubnetNodeConnectors();
subnet.addNodeConnectors(sp);
}
Set<NodeConnector> sp = conf.getSubnetNodeConnectors();
subnet.addNodeConnectors(sp);
}
- boolean result = false;
+ boolean putNewSubnet = false;
if(subnetCurr == null) {
if(subnets.putIfAbsent(conf.getIPnum(), subnet) == null) {
if(subnetCurr == null) {
if(subnets.putIfAbsent(conf.getIPnum(), subnet) == null) {
- result = subnets.replace(conf.getIPnum(), subnetCurr, subnet);
+ putNewSubnet = subnets.replace(conf.getIPnum(), subnetCurr, subnet);
String msg = "Cluster conflict: Conflict while adding the subnet " + conf.getIPnum();
return new Status(StatusCode.CONFLICT, msg);
}
String msg = "Cluster conflict: Conflict while adding the subnet " + conf.getIPnum();
return new Status(StatusCode.CONFLICT, msg);
}
- } else { // This is the deletion of the whole subnet
+
+ // Subnet removal case
+ } else {
subnets.remove(conf.getIPnum());
}
return new Status(StatusCode.SUCCESS);
subnets.remove(conf.getIPnum());
}
return new Status(StatusCode.SUCCESS);
return new Status(StatusCode.SUCCESS);
}
return new Status(StatusCode.SUCCESS);
}
- private Status addRemoveSubnet(SubnetConfig conf, boolean add) {
+ private Status addRemoveSubnet(SubnetConfig conf, boolean isAdding) {
// Valid config check
if (!conf.isValidConfig()) {
String msg = "Invalid Subnet configuration";
// Valid config check
if (!conf.isValidConfig()) {
String msg = "Invalid Subnet configuration";
return new Status(StatusCode.BADREQUEST, msg);
}
return new Status(StatusCode.BADREQUEST, msg);
}
// Presence check
if (subnetsConfigList.containsKey(conf.getName())) {
return new Status(StatusCode.CONFLICT,
// Presence check
if (subnetsConfigList.containsKey(conf.getName())) {
return new Status(StatusCode.CONFLICT,
- "Same subnet config already exists");
+ "Subnet with the specified name already configured.");
Status rc = semanticCheck(conf);
if (!rc.isSuccess()) {
return rc;
Status rc = semanticCheck(conf);
if (!rc.isSuccess()) {
return rc;
- Status rc = updateDatabase(conf, add);
+ Status rc = updateDatabase(conf, isAdding);
if (rc.isSuccess()) {
// Update Configuration
if (rc.isSuccess()) {
// Update Configuration
- rc = updateConfig(conf, add);
+ rc = updateConfig(conf, isAdding);
- updateDatabase(conf, (!add));
+ updateDatabase(conf, (!isAdding));
Subnet sub = subCurr.clone();
Set<NodeConnector> sp = confCurr.getNodeConnectors(switchPorts);
sub.addNodeConnectors(sp);
Subnet sub = subCurr.clone();
Set<NodeConnector> sp = confCurr.getNodeConnectors(switchPorts);
sub.addNodeConnectors(sp);
- boolean subnetsReplace = subnets.replace(confCurr.getIPnum(), subCurr, sub);
- if (!subnetsReplace) {
+ boolean subnetsReplaced = subnets.replace(confCurr.getIPnum(), subCurr, sub);
+ if (!subnetsReplaced) {
String msg = "Cluster conflict: Conflict while adding ports to the subnet " + name;
return new Status(StatusCode.CONFLICT, msg);
}
String msg = "Cluster conflict: Conflict while adding ports to the subnet " + name;
return new Status(StatusCode.CONFLICT, msg);
}
// Update Configuration
SubnetConfig conf = confCurr.clone();
conf.addNodeConnectors(switchPorts);
// Update Configuration
SubnetConfig conf = confCurr.clone();
conf.addNodeConnectors(switchPorts);
- boolean result = subnetsConfigList.replace(name, confCurr, conf);
- if (!result) {
+ boolean configReplaced = subnetsConfigList.replace(name, confCurr, conf);
+ if (!configReplaced) {
// TODO: recovery using Transactionality
String msg = "Cluster conflict: Conflict while adding ports to the subnet " + name;
return new Status(StatusCode.CONFLICT, msg);
// TODO: recovery using Transactionality
String msg = "Cluster conflict: Conflict while adding ports to the subnet " + name;
return new Status(StatusCode.CONFLICT, msg);
package org.opendaylight.controller.switchmanager.internal;
package org.opendaylight.controller.switchmanager.internal;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.HashSet;
import java.util.Set;
SwitchManager switchmgr = new SwitchManager();
switchmgr.startUp();
SwitchManager switchmgr = new SwitchManager();
switchmgr.startUp();
- ArrayList<String> portList = new ArrayList<String>();
+ Set<String> portList = new HashSet<String>();
portList.add("1/1");
portList.add("1/2");
portList.add("1/3");
portList.add("1/1");
portList.add("1/2");
portList.add("1/3");
import java.util.ArrayList;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
SubnetConfig cfgObject = new SubnetConfig(gatewayName,
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
SubnetConfig cfgObject = new SubnetConfig(gatewayName,
- gatewayIPAddress, new ArrayList<String>());
+ gatewayIPAddress, new HashSet<String>());
Status result = switchManager.addSubnet(cfgObject);
if (result.isSuccess()) {
resultBean.setStatus(true);
Status result = switchManager.addSubnet(cfgObject);
if (result.isSuccess()) {
resultBean.setStatus(true);