Hyunsun Moon
Committed by Gerrit Code Review

Fix to update gateway group only if new gateway is added

Also implemented equals, hashCode, and toString for GatewayNode.

Change-Id: I4c487cafa263833701c5790b2057c1d9c23e33bf
......@@ -15,9 +15,12 @@
*/
package org.onosproject.scalablegateway.api;
import com.google.common.base.MoreObjects;
import org.onlab.packet.Ip4Address;
import org.onosproject.net.DeviceId;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
......@@ -62,6 +65,40 @@ public final class GatewayNode {
return dataIpAddress;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof GatewayNode) {
GatewayNode that = (GatewayNode) obj;
if (Objects.equals(gatewayDeviceId, that.gatewayDeviceId) &&
Objects.equals(gatewayExternalInterfaceName,
that.gatewayExternalInterfaceName) &&
Objects.equals(dataIpAddress, that.dataIpAddress)) {
return true;
}
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(gatewayDeviceId,
gatewayExternalInterfaceName,
dataIpAddress);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("deviceId", gatewayDeviceId)
.add("externalPort", gatewayExternalInterfaceName)
.add("dataIp", dataIpAddress)
.toString();
}
/**
* Returns GatewayNode builder object.
*
......
......@@ -203,9 +203,15 @@ public class ScalableGatewayManager implements ScalableGatewayService {
@Override
public boolean addGatewayNode(GatewayNode gatewayNode) {
gatewayNodeMap.putIfAbsent(gatewayNode.getGatewayDeviceId(), gatewayNode);
updateGatewayLoadBalance(gatewayNode, true);
return true;
Versioned<GatewayNode> existingNode = gatewayNodeMap.putIfAbsent(
gatewayNode.getGatewayDeviceId(), gatewayNode);
if (existingNode == null) {
updateGatewayLoadBalance(gatewayNode, true);
log.info("Added {} to gateway pool", gatewayNode);
return true;
} else {
return false;
}
}
@Override
......