Use ID to preserve the uniqueness for kubevirt router and lb
Change-Id: I0893f8dcfb713115cee9df5a78fc8823e198a17c
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancer.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancer.java
index bf4a21d..f186c53 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancer.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancer.java
@@ -31,6 +31,7 @@
private static final String NOT_NULL_MSG = "Loadbalancer % cannot be null";
+ private final String id;
private final String name;
private final String description;
private final String networkId;
@@ -41,6 +42,7 @@
/**
* Default constructor.
*
+ * @param id load balancer id
* @param name load balancer name
* @param description load balancer description
* @param networkId load balancer network identifier
@@ -48,9 +50,11 @@
* @param members load balancer members
* @param rules load balancer rules
*/
- public DefaultKubevirtLoadBalancer(String name, String description, String networkId,
- IpAddress vip, Set<IpAddress> members,
+ public DefaultKubevirtLoadBalancer(String id, String name, String description,
+ String networkId, IpAddress vip,
+ Set<IpAddress> members,
Set<KubevirtLoadBalancerRule> rules) {
+ this.id = id;
this.name = name;
this.description = description;
this.networkId = networkId;
@@ -60,6 +64,11 @@
}
@Override
+ public String id() {
+ return id;
+ }
+
+ @Override
public String name() {
return name;
}
@@ -106,19 +115,21 @@
return false;
}
DefaultKubevirtLoadBalancer that = (DefaultKubevirtLoadBalancer) o;
- return name.equals(that.name) && Objects.equals(description, that.description) &&
+ return id.equals(that.id) && name.equals(that.name) &&
+ Objects.equals(description, that.description) &&
networkId.equals(that.networkId) && vip.equals(that.vip) &&
Objects.equals(members, that.members) && Objects.equals(rules, that.rules);
}
@Override
public int hashCode() {
- return Objects.hash(name, description, networkId, vip, members, rules);
+ return Objects.hash(id, name, description, networkId, vip, members, rules);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
+ .add("id", id)
.add("name", name)
.add("description", description)
.add("networkId", networkId)
@@ -134,6 +145,7 @@
public static final class Builder implements KubevirtLoadBalancer.Builder {
+ private String id;
private String name;
private String description;
private String networkId;
@@ -147,11 +159,18 @@
@Override
public KubevirtLoadBalancer build() {
+ checkArgument(id != null, NOT_NULL_MSG, "id");
checkArgument(networkId != null, NOT_NULL_MSG, "networkId");
checkArgument(name != null, NOT_NULL_MSG, "name");
checkArgument(vip != null, NOT_NULL_MSG, "vip");
- return new DefaultKubevirtLoadBalancer(name, description, networkId, vip, members, rules);
+ return new DefaultKubevirtLoadBalancer(id, name, description, networkId, vip, members, rules);
+ }
+
+ @Override
+ public Builder id(String id) {
+ this.id = id;
+ return this;
}
@Override
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouter.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouter.java
index 43c9c88..80948db 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouter.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouter.java
@@ -35,6 +35,7 @@
private static final String NOT_NULL_MSG = "Router % cannot be null";
+ private final String id;
private final String name;
private final String description;
private final boolean enableSnat;
@@ -47,6 +48,7 @@
/**
* A default constructor.
*
+ * @param id router id
* @param name router name
* @param description router description
* @param enableSnat snat use indicator
@@ -56,12 +58,13 @@
* @param peerRouter external peer router
* @param gateway elected gateway node id
*/
- public DefaultKubevirtRouter(String name, String description,
+ public DefaultKubevirtRouter(String id, String name, String description,
boolean enableSnat, MacAddress mac,
Set<String> internal,
Map<String, String> external,
KubevirtPeerRouter peerRouter,
String gateway) {
+ this.id = id;
this.name = name;
this.description = description;
this.enableSnat = enableSnat;
@@ -73,6 +76,11 @@
}
@Override
+ public String id() {
+ return id;
+ }
+
+ @Override
public String name() {
return name;
}
@@ -123,6 +131,7 @@
@Override
public KubevirtRouter updatePeerRouter(KubevirtPeerRouter updated) {
return DefaultKubevirtRouter.builder()
+ .id(id)
.name(name)
.enableSnat(enableSnat)
.description(description)
@@ -137,6 +146,7 @@
@Override
public KubevirtRouter updatedElectedGateway(String updated) {
return DefaultKubevirtRouter.builder()
+ .id(id)
.name(name)
.enableSnat(enableSnat)
.description(description)
@@ -157,7 +167,7 @@
return false;
}
DefaultKubevirtRouter that = (DefaultKubevirtRouter) o;
- return enableSnat == that.enableSnat && name.equals(that.name) &&
+ return id.equals(that.id) && enableSnat == that.enableSnat && name.equals(that.name) &&
description.equals(that.description) && mac.equals(that.mac) &&
internal.equals(that.internal) && external.equals(that.external) &&
peerRouter.equals(that.peerRouter) && gateway.equals(that.electedGateway());
@@ -165,12 +175,13 @@
@Override
public int hashCode() {
- return Objects.hash(name, description, mac);
+ return Objects.hash(id, name, description, mac);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
+ .add("id", id)
.add("name", name)
.add("description", description)
.add("enableSnat", enableSnat)
@@ -193,6 +204,7 @@
public static final class Builder implements KubevirtRouter.Builder {
+ private String id;
private String name;
private String description;
private boolean enableSnat;
@@ -204,10 +216,17 @@
@Override
public KubevirtRouter build() {
+ checkArgument(id != null, NOT_NULL_MSG, "id");
checkArgument(name != null, NOT_NULL_MSG, "name");
- return new DefaultKubevirtRouter(name, description, enableSnat, mac,
- internal, external, peerRouter, gateway);
+ return new DefaultKubevirtRouter(id, name, description, enableSnat,
+ mac, internal, external, peerRouter, gateway);
+ }
+
+ @Override
+ public Builder id(String id) {
+ this.id = id;
+ return this;
}
@Override
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancer.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancer.java
index 7547547..382b9f6 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancer.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancer.java
@@ -25,6 +25,13 @@
public interface KubevirtLoadBalancer {
/**
+ * Returns the load balancer id.
+ *
+ * @return load balancer id
+ */
+ String id();
+
+ /**
* Returns the load balancer name.
*
* @return load balancer name
@@ -78,6 +85,14 @@
KubevirtLoadBalancer build();
/**
+ * Returns kubevirt load balancer builder with supplied load balancer id.
+ *
+ * @param id load balancer id
+ * @return load balancer builder
+ */
+ Builder id(String id);
+
+ /**
* Returns kubevirt load balancer builder with supplied load balancer name.
*
* @param name load balancer name
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.java
index db62c77..f129fe1 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.java
@@ -26,6 +26,13 @@
public interface KubevirtRouter {
/**
+ * Return the router id.
+ *
+ * @return router id
+ */
+ String id();
+
+ /**
* Returns the router name.
*
* @return router name
@@ -109,6 +116,14 @@
KubevirtRouter build();
/**
+ * Returns kubevirt router builder with supplied router id.
+ *
+ * @param id router id
+ * @return router builder
+ */
+ Builder id(String id);
+
+ /**
* Returns kubevirt router builder with supplied router name.
*
* @param name router name
diff --git a/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerTest.java b/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerTest.java
index e9ec471..691cf5f 100644
--- a/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerTest.java
+++ b/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerTest.java
@@ -31,6 +31,8 @@
*/
public class DefaultKubevirtLoadBalancerTest {
+ private static final String ID_1 = "26fcc876-f39a-459f-801d-75dcd3654ab8";
+ private static final String ID_2 = "1c14194b-04ca-4c79-b0c7-2d8bb964133f";
private static final String NAME_1 = "lb-1";
private static final String NAME_2 = "lb-2";
private static final String DESCRIPTION_1 = "dummy lb 1";
@@ -84,6 +86,7 @@
@Before
public void setUp() {
lb1 = DefaultKubevirtLoadBalancer.builder()
+ .id(ID_1)
.name(NAME_1)
.description(DESCRIPTION_1)
.networkId(NETWORK_ID_1)
@@ -93,6 +96,7 @@
.build();
sameAsLb1 = DefaultKubevirtLoadBalancer.builder()
+ .id(ID_1)
.name(NAME_1)
.description(DESCRIPTION_1)
.networkId(NETWORK_ID_1)
@@ -102,6 +106,7 @@
.build();
lb2 = DefaultKubevirtLoadBalancer.builder()
+ .id(ID_2)
.name(NAME_2)
.description(DESCRIPTION_2)
.networkId(NETWORK_ID_2)
@@ -128,6 +133,7 @@
public void testConstruction() {
KubevirtLoadBalancer lb = lb1;
+ assertEquals(ID_1, lb.id());
assertEquals(NAME_1, lb.name());
assertEquals(DESCRIPTION_1, lb.description());
assertEquals(NETWORK_ID_1, lb.networkId());
diff --git a/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouterTest.java b/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouterTest.java
index 644b839..30c2341 100644
--- a/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouterTest.java
+++ b/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouterTest.java
@@ -33,6 +33,8 @@
*/
public class DefaultKubevirtRouterTest {
+ private static final String ID_1 = "26fcc876-f39a-459f-801d-75dcd3654ab8";
+ private static final String ID_2 = "1c14194b-04ca-4c79-b0c7-2d8bb964133f";
private static final String NAME_1 = "router-1";
private static final String NAME_2 = "router-2";
private static final String DESCRIPTION_1 = "dummy router 1";
@@ -73,6 +75,7 @@
@Before
public void setUp() {
router1 = DefaultKubevirtRouter.builder()
+ .id(ID_1)
.name(NAME_1)
.description(DESCRIPTION_1)
.enableSnat(ENABLE_SNAT_1)
@@ -83,6 +86,7 @@
.electedGateway(GATEWAY_HOST_1)
.build();
sameAsRouter1 = DefaultKubevirtRouter.builder()
+ .id(ID_1)
.name(NAME_1)
.description(DESCRIPTION_1)
.enableSnat(ENABLE_SNAT_1)
@@ -93,6 +97,7 @@
.electedGateway(GATEWAY_HOST_1)
.build();
router2 = DefaultKubevirtRouter.builder()
+ .id(ID_2)
.name(NAME_2)
.description(DESCRIPTION_2)
.enableSnat(ENABLE_SNAT_2)
@@ -121,6 +126,7 @@
public void testConstruction() {
KubevirtRouter router = router1;
+ assertEquals(ID_1, router.id());
assertEquals(NAME_1, router.name());
assertEquals(DESCRIPTION_1, router.description());
assertEquals(ENABLE_SNAT_1, router.enableSnat());
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListLoadBalancerCommand.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListLoadBalancerCommand.java
index 94bf069..f35c093 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListLoadBalancerCommand.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListLoadBalancerCommand.java
@@ -29,6 +29,7 @@
import java.util.Comparator;
import java.util.List;
+import static org.onosproject.kubevirtnetworking.api.Constants.CLI_ID_LENGTH;
import static org.onosproject.kubevirtnetworking.api.Constants.CLI_IP_ADDRESSES_LENGTH;
import static org.onosproject.kubevirtnetworking.api.Constants.CLI_IP_ADDRESS_LENGTH;
import static org.onosproject.kubevirtnetworking.api.Constants.CLI_MARGIN_LENGTH;
@@ -49,16 +50,18 @@
List<KubevirtLoadBalancer> lbs = Lists.newArrayList(service.loadBalancers());
lbs.sort(Comparator.comparing(KubevirtLoadBalancer::name));
- String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_NAME_LENGTH,
+ String format = genFormatString(ImmutableList.of(CLI_ID_LENGTH, CLI_NAME_LENGTH, CLI_NAME_LENGTH,
CLI_IP_ADDRESS_LENGTH, CLI_IP_ADDRESSES_LENGTH));
if (outputJson()) {
print("%s", json(lbs));
} else {
- print(format, "Name", "NetworkId", "Virtual IP", "Members");
+ print(format, "ID", "Name", "NetworkId", "Virtual IP", "Members");
for (KubevirtLoadBalancer lb : lbs) {
print(format,
+ StringUtils.substring(lb.id(),
+ 0, CLI_ID_LENGTH - CLI_MARGIN_LENGTH),
StringUtils.substring(lb.name(),
0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH),
StringUtils.substring(lb.networkId(),
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListRouterCommand.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListRouterCommand.java
index dd08419..4081dbb 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListRouterCommand.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListRouterCommand.java
@@ -31,6 +31,7 @@
import java.util.Set;
import static org.onosproject.kubevirtnetworking.api.Constants.CLI_FLAG_LENGTH;
+import static org.onosproject.kubevirtnetworking.api.Constants.CLI_ID_LENGTH;
import static org.onosproject.kubevirtnetworking.api.Constants.CLI_IP_ADDRESSES_LENGTH;
import static org.onosproject.kubevirtnetworking.api.Constants.CLI_IP_ADDRESS_LENGTH;
import static org.onosproject.kubevirtnetworking.api.Constants.CLI_MARGIN_LENGTH;
@@ -52,13 +53,13 @@
List<KubevirtRouter> routers = Lists.newArrayList(service.routers());
routers.sort(Comparator.comparing(KubevirtRouter::name));
- String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH,
+ String format = genFormatString(ImmutableList.of(CLI_ID_LENGTH, CLI_NAME_LENGTH,
CLI_FLAG_LENGTH, CLI_IP_ADDRESSES_LENGTH, CLI_IP_ADDRESS_LENGTH, CLI_NAME_LENGTH));
if (outputJson()) {
print("%s", json(routers));
} else {
- print(format, "Name", "SNAT", "Internal", "External", "GatewayNode");
+ print(format, "ID", "Name", "SNAT", "Internal", "External", "GatewayNode");
for (KubevirtRouter router : routers) {
Set<String> internalNetworks = router.internal();
@@ -69,7 +70,9 @@
String external = externalNetwork == null ? "[]" : externalNetwork;
String gwNode = router.electedGateway() == null ? "N/A" : router.electedGateway();
- print(format, StringUtils.substring(router.name(), 0,
+ print(format, StringUtils.substring(router.id(), 0,
+ CLI_ID_LENGTH - CLI_MARGIN_LENGTH),
+ StringUtils.substring(router.name(), 0,
CLI_NAME_LENGTH - CLI_MARGIN_LENGTH),
StringUtils.substring(String.valueOf(router.enableSnat()), 0,
CLI_FLAG_LENGTH - CLI_MARGIN_LENGTH),
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtSyncStateCommand.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtSyncStateCommand.java
index 5c51008..46ee569 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtSyncStateCommand.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtSyncStateCommand.java
@@ -162,7 +162,7 @@
KubevirtRouterAdminService routerService = get(KubevirtRouterAdminService.class);
Set<KubevirtRouter> existingRouters = routerService.routers();
Set<String> existingRouterNames = existingRouters.stream()
- .map(KubevirtRouter::name).collect(Collectors.toSet());
+ .map(KubevirtRouter::id).collect(Collectors.toSet());
Map<String, Object> refRouters = client.customResource(routerCrdCxt).list();
ObjectMapper mapper = new ObjectMapper();
@@ -174,9 +174,9 @@
for (JsonValue item : items) {
KubevirtRouter router = parseKubevirtRouter(routerService, item.toString());
if (router != null) {
- if (existingRouterNames.contains(router.name())) {
+ if (existingRouterNames.contains(router.id())) {
- KubevirtPeerRouter oldPeerRouter = routerService.router(router.name()).peerRouter();
+ KubevirtPeerRouter oldPeerRouter = routerService.router(router.id()).peerRouter();
if (oldPeerRouter != null
&& Objects.equals(oldPeerRouter.ipAddress(), router.peerRouter().ipAddress())
&& oldPeerRouter.macAddress() != null
@@ -233,7 +233,7 @@
KubevirtSecurityGroupAdminService sgService = get(KubevirtSecurityGroupAdminService.class);
Set<KubevirtSecurityGroup> existingSgs = sgService.securityGroups();
Set<String> existingSgNames = existingSgs.stream()
- .map(KubevirtSecurityGroup::name).collect(Collectors.toSet());
+ .map(KubevirtSecurityGroup::id).collect(Collectors.toSet());
Map<String, Object> refSgs = client.customResource(securityGroupCrdCxt).list();
ObjectMapper mapper = new ObjectMapper();
@@ -244,7 +244,7 @@
for (JsonValue item : items) {
KubevirtSecurityGroup sg = parseSecurityGroup(item.toString());
if (sg != null) {
- if (existingSgNames.contains(sg.name())) {
+ if (existingSgNames.contains(sg.id())) {
KubevirtSecurityGroup orig = sgService.securityGroup(sg.id());
if (orig != null) {
@@ -299,7 +299,7 @@
KubevirtLoadBalancerAdminService lbService = get(KubevirtLoadBalancerAdminService.class);
Set<KubevirtLoadBalancer> existingLbs = lbService.loadBalancers();
Set<String> existingLbNames = existingLbs.stream()
- .map(KubevirtLoadBalancer::name).collect(Collectors.toSet());
+ .map(KubevirtLoadBalancer::id).collect(Collectors.toSet());
Map<String, Object> refLbs = client.customResource(lbCrdCxt).list();
ObjectMapper mapper = new ObjectMapper();
@@ -311,7 +311,7 @@
for (JsonValue item : items) {
KubevirtLoadBalancer lb = parseKubevirtLoadBalancer(item.toString());
if (lb != null) {
- if (existingLbNames.contains(lb.name())) {
+ if (existingLbNames.contains(lb.id())) {
lbService.updateLoadBalancer(lb);
} else {
lbService.createLoadBalancer(lb);
@@ -334,7 +334,7 @@
ObjectNode spec = (ObjectNode) json.get(SPEC);
KubevirtRouter router = codec(KubevirtRouter.class).decode(spec, this);
- KubevirtRouter existing = service.router(router.name());
+ KubevirtRouter existing = service.router(router.id());
if (existing == null) {
return router;
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/DistributedKubevirtLoadBalancerStore.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/DistributedKubevirtLoadBalancerStore.java
index 1c045f3..e873a9c 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/DistributedKubevirtLoadBalancerStore.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/DistributedKubevirtLoadBalancerStore.java
@@ -117,8 +117,8 @@
@Override
public void createLoadBalancer(KubevirtLoadBalancer lb) {
- loadBalancerStore.compute(lb.name(), (name, existing) -> {
- final String error = lb.name() + ERR_DUPLICATE;
+ loadBalancerStore.compute(lb.id(), (id, existing) -> {
+ final String error = lb.id() + ERR_DUPLICATE;
checkArgument(existing == null, error);
return lb;
});
@@ -126,26 +126,26 @@
@Override
public void updateLoadBalancer(KubevirtLoadBalancer lb) {
- loadBalancerStore.compute(lb.name(), (name, existing) -> {
- final String error = lb.name() + ERR_NOT_FOUND;
+ loadBalancerStore.compute(lb.id(), (id, existing) -> {
+ final String error = lb.id() + ERR_NOT_FOUND;
checkArgument(existing != null, error);
return lb;
});
}
@Override
- public KubevirtLoadBalancer removeLoadBalancer(String name) {
- Versioned<KubevirtLoadBalancer> lb = loadBalancerStore.remove(name);
+ public KubevirtLoadBalancer removeLoadBalancer(String id) {
+ Versioned<KubevirtLoadBalancer> lb = loadBalancerStore.remove(id);
if (lb == null) {
- final String error = name + ERR_NOT_FOUND;
+ final String error = id + ERR_NOT_FOUND;
throw new IllegalArgumentException(error);
}
return lb.value();
}
@Override
- public KubevirtLoadBalancer loadBalancer(String name) {
- return loadBalancerStore.asJavaMap().get(name);
+ public KubevirtLoadBalancer loadBalancer(String id) {
+ return loadBalancerStore.asJavaMap().get(id);
}
@Override
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/DistributedKubevirtRouterStore.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/DistributedKubevirtRouterStore.java
index 4b982aa..008c93f 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/DistributedKubevirtRouterStore.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/DistributedKubevirtRouterStore.java
@@ -156,8 +156,8 @@
@Override
public void createRouter(KubevirtRouter router) {
- routerStore.compute(router.name(), (name, existing) -> {
- final String error = router.name() + ERR_DUPLICATE;
+ routerStore.compute(router.id(), (id, existing) -> {
+ final String error = router.id() + ERR_DUPLICATE;
checkArgument(existing == null, error);
return router;
});
@@ -165,26 +165,26 @@
@Override
public void updateRouter(KubevirtRouter router) {
- routerStore.compute(router.name(), (name, existing) -> {
- final String error = router.name() + ERR_NOT_FOUND;
+ routerStore.compute(router.id(), (id, existing) -> {
+ final String error = router.id() + ERR_NOT_FOUND;
checkArgument(existing != null, error);
return router;
});
}
@Override
- public KubevirtRouter removeRouter(String name) {
- Versioned<KubevirtRouter> router = routerStore.remove(name);
+ public KubevirtRouter removeRouter(String id) {
+ Versioned<KubevirtRouter> router = routerStore.remove(id);
if (router == null) {
- final String error = name + ERR_NOT_FOUND;
+ final String error = id + ERR_NOT_FOUND;
throw new IllegalArgumentException(error);
}
return router.value();
}
@Override
- public KubevirtRouter router(String name) {
- return routerStore.asJavaMap().get(name);
+ public KubevirtRouter router(String id) {
+ return routerStore.asJavaMap().get(id);
}
@Override
@@ -270,9 +270,9 @@
KUBEVIRT_ROUTER_UPDATED, event.newValue().value())));
KubevirtRouter router = Strings.isNullOrEmpty(
- event.newValue().value().name()) ?
+ event.newValue().value().id()) ?
null :
- router(event.newValue().value().name());
+ router(event.newValue().value().id());
KubevirtRouter oldValue = event.oldValue().value();
KubevirtRouter newValue = event.newValue().value();
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtLoadBalancerWatcher.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtLoadBalancerWatcher.java
index 77d31a7..b662a86 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtLoadBalancerWatcher.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtLoadBalancerWatcher.java
@@ -215,7 +215,7 @@
KubevirtLoadBalancer lb = parseKubevirtLoadBalancer(resource);
if (lb != null) {
- if (adminService.loadBalancer(lb.name()) == null) {
+ if (adminService.loadBalancer(lb.id()) == null) {
adminService.createLoadBalancer(lb);
}
}
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterWatcher.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterWatcher.java
index 13bce6b..a52eaab 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterWatcher.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterWatcher.java
@@ -139,7 +139,7 @@
JsonNode json = mapper.readTree(resource);
ObjectNode spec = (ObjectNode) json.get("spec");
KubevirtRouter router = codec(KubevirtRouter.class).decode(spec, this);
- KubevirtRouter existing = routerService.router(router.name());
+ KubevirtRouter existing = routerService.router(router.id());
if (existing == null) {
return router;
@@ -221,14 +221,14 @@
return;
}
- String name = parseResourceName(resource);
+ String id = parseResourceName(resource);
log.trace("Process Virtual Router {} creating event from API server.",
- name);
+ id);
KubevirtRouter router = parseKubevirtRouter(resource);
if (router != null) {
- if (adminService.router(router.name()) == null) {
+ if (adminService.router(router.id()) == null) {
adminService.createRouter(router);
}
}
@@ -239,14 +239,14 @@
return;
}
- String name = parseResourceName(resource);
+ String id = parseResourceName(resource);
log.trace("Process Virtual Router {} updating event from API server.",
- name);
+ id);
KubevirtRouter router = parseKubevirtRouter(resource);
- KubevirtPeerRouter oldPeerRouter = adminService.router(router.name()).peerRouter();
+ KubevirtPeerRouter oldPeerRouter = adminService.router(router.id()).peerRouter();
if (oldPeerRouter != null
&& Objects.equals(oldPeerRouter.ipAddress(), router.peerRouter().ipAddress())
&& oldPeerRouter.macAddress() != null
@@ -265,12 +265,12 @@
return;
}
- String name = parseResourceName(resource);
+ String id = parseResourceName(resource);
log.trace("Process Virtual Router {} removal event from API server.",
- name);
+ id);
- adminService.removeRouter(name);
+ adminService.removeRouter(id);
}
private boolean isMaster() {
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingSnatHandler.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingSnatHandler.java
index 716ec9c..003b581 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingSnatHandler.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingSnatHandler.java
@@ -696,7 +696,8 @@
if (!isRelevantHelper()) {
return;
}
- if (router.enableSnat() && !router.external().isEmpty() && router.peerRouter() != null) {
+ if (router.enableSnat() && !router.external().isEmpty() && router.peerRouter() != null &&
+ router.electedGateway() != null) {
initGatewayNodeSnatForRouter(router, router.electedGateway(), true);
KubevirtNode gatewayNode = kubevirtNodeService.node(router.electedGateway());
diff --git a/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtLoadBalancerManagerTest.java b/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtLoadBalancerManagerTest.java
index 73e1c35..99b90e6 100644
--- a/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtLoadBalancerManagerTest.java
+++ b/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtLoadBalancerManagerTest.java
@@ -49,12 +49,14 @@
private static final ApplicationId TEST_APP_ID = new DefaultApplicationId(1, "test");
+ private static final String LB_ID = "26fcc876-f39a-459f-801d-75dcd3654ab8";
private static final String LB_NAME = "lb-1";
private static final String NETWORK_NAME = "vxlan-1";
private static final String UPDATED_DESCRIPTION = "lb-updated";
private static final String UNKNOWN_ID = "unknown";
private static final KubevirtLoadBalancer LB = DefaultKubevirtLoadBalancer.builder()
+ .id(LB_ID)
.name(LB_NAME)
.description(LB_NAME)
.networkId(NETWORK_NAME)
@@ -64,6 +66,7 @@
.build();
private static final KubevirtLoadBalancer LB_UPDATED = DefaultKubevirtLoadBalancer.builder()
+ .id(LB_ID)
.name(LB_NAME)
.description(UPDATED_DESCRIPTION)
.networkId(NETWORK_NAME)
@@ -73,6 +76,7 @@
.build();
private static final KubevirtLoadBalancer LB_WITH_MEMBERS = DefaultKubevirtLoadBalancer.builder()
+ .id(LB_ID)
.name(LB_NAME)
.description(LB_NAME)
.networkId(NETWORK_NAME)
@@ -124,9 +128,9 @@
* Tests if getting a load balancer with ID returns the correct load balancer.
*/
@Test
- public void testGetLoadBalancerByName() {
+ public void testGetLoadBalancerById() {
createBasicLoadBalancers();
- assertNotNull("Load balancer did not match", target.loadBalancer(LB_NAME));
+ assertNotNull("Load balancer did not match", target.loadBalancer(LB_ID));
assertNull("Load balancer did not match", target.loadBalancer(UNKNOWN_ID));
}
@@ -137,11 +141,11 @@
public void testCreateAndRemoveLoadBalancer() {
target.createLoadBalancer(LB);
assertEquals("Number of load balancers did not match", 1, target.loadBalancers().size());
- assertNotNull("Load balancer was not created", target.loadBalancer(LB_NAME));
+ assertNotNull("Load balancer was not created", target.loadBalancer(LB_ID));
- target.removeLoadBalancer(LB_NAME);
+ target.removeLoadBalancer(LB_ID);
assertEquals("Number of load balancers did not match", 0, target.loadBalancers().size());
- assertNull("Load balancer was not removed", target.loadBalancer(LB_NAME));
+ assertNull("Load balancer was not removed", target.loadBalancer(LB_ID));
validateEvents(KUBEVIRT_LOAD_BALANCER_CREATED, KUBEVIRT_LOAD_BALANCER_REMOVED);
}
@@ -153,11 +157,11 @@
public void testCreateAndUpdateLoadBalancer() {
target.createLoadBalancer(LB);
assertEquals("Number of load balancers did not match", 1, target.loadBalancers().size());
- assertEquals("Load balancer did not match", LB_NAME, target.loadBalancer(LB_NAME).name());
+ assertEquals("Load balancer did not match", LB_ID, target.loadBalancer(LB_ID).id());
target.updateLoadBalancer(LB_UPDATED);
assertEquals("Number of load balancers did not match", 1, target.loadBalancers().size());
- assertEquals("Load balancer did not match", LB_NAME, target.loadBalancer(LB_NAME).name());
+ assertEquals("Load balancer did not match", LB_ID, target.loadBalancer(LB_ID).id());
validateEvents(KUBEVIRT_LOAD_BALANCER_CREATED, KUBEVIRT_LOAD_BALANCER_UPDATED);
}
diff --git a/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterManagerTest.java b/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterManagerTest.java
index 26d7088..4241bf8 100644
--- a/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterManagerTest.java
+++ b/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterManagerTest.java
@@ -69,6 +69,7 @@
private static final ApplicationId TEST_APP_ID = new DefaultApplicationId(1, "test");
+ private static final String ROUTER_ID = "26fcc876-f39a-459f-801d-75dcd3654ab8";
private static final String ROUTER_NAME = "router-1";
private static final String POD_NAME = "pod-1";
private static final String NETWORK_NAME = "flat-1";
@@ -79,6 +80,7 @@
private static final String UNKNOWN_ID = "unknown";
private static final KubevirtRouter ROUTER = DefaultKubevirtRouter.builder()
+ .id(ROUTER_ID)
.name(ROUTER_NAME)
.description(ROUTER_NAME)
.internal(ImmutableSet.of())
@@ -87,6 +89,7 @@
.build();
private static final KubevirtRouter ROUTER_UPDATED = DefaultKubevirtRouter.builder()
+ .id(ROUTER_ID)
.name(ROUTER_NAME)
.description(UPDATED_DESCRIPTION)
.internal(ImmutableSet.of())
@@ -95,6 +98,7 @@
.build();
private static final KubevirtRouter ROUTER_WITH_INTERNAL = DefaultKubevirtRouter.builder()
+ .id(ROUTER_ID)
.name(ROUTER_NAME)
.description(ROUTER_NAME)
.internal(ImmutableSet.of("vxlan-1", "vxlan-2"))
@@ -103,6 +107,7 @@
.build();
private static final KubevirtRouter ROUTER_WITH_SINGLE_INTERNAL = DefaultKubevirtRouter.builder()
+ .id(ROUTER_ID)
.name(ROUTER_NAME)
.description(ROUTER_NAME)
.internal(ImmutableSet.of("vxlan-1"))
@@ -111,6 +116,7 @@
.build();
private static final KubevirtRouter ROUTER_WITH_EXTERNAL = DefaultKubevirtRouter.builder()
+ .id(ROUTER_ID)
.name(ROUTER_NAME)
.description(ROUTER_NAME)
.internal(ImmutableSet.of())
@@ -122,14 +128,14 @@
private static final KubevirtFloatingIp FLOATING_IP_DISASSOCIATED = DefaultKubevirtFloatingIp.builder()
.id(FLOATING_IP_ID)
- .routerName(ROUTER_NAME)
+ .routerName(ROUTER_ID)
.networkName(NETWORK_NAME)
.floatingIp(IpAddress.valueOf("10.10.10.10"))
.build();
private static final KubevirtFloatingIp FLOATING_IP_ASSOCIATED = DefaultKubevirtFloatingIp.builder()
.id(FLOATING_IP_ID)
- .routerName(ROUTER_NAME)
+ .routerName(ROUTER_ID)
.networkName(NETWORK_NAME)
.floatingIp(IpAddress.valueOf("10.10.10.10"))
.fixedIp(IpAddress.valueOf("20.20.20.20"))
@@ -182,7 +188,7 @@
@Test
public void testGetRouterByName() {
createBasicRouters();
- assertNotNull("Router did not match", target.router(ROUTER_NAME));
+ assertNotNull("Router did not match", target.router(ROUTER_ID));
}
/**
@@ -192,11 +198,11 @@
public void testCreateAndRemoveRouter() {
target.createRouter(ROUTER);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertNotNull("Router was not created", target.router(ROUTER_NAME));
+ assertNotNull("Router was not created", target.router(ROUTER_ID));
- target.removeRouter(ROUTER_NAME);
+ target.removeRouter(ROUTER_ID);
assertEquals("Number of router did not match", 0, target.routers().size());
- assertNull("Router was not created", target.router(ROUTER_NAME));
+ assertNull("Router was not created", target.router(ROUTER_ID));
validateEvents(KUBEVIRT_ROUTER_CREATED, KUBEVIRT_ROUTER_REMOVED);
}
@@ -211,7 +217,7 @@
target.updateRouter(ROUTER_UPDATED);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertEquals("Router did not match", UPDATED_DESCRIPTION, target.router(ROUTER_NAME).description());
+ assertEquals("Router did not match", UPDATED_DESCRIPTION, target.router(ROUTER_ID).description());
validateEvents(KUBEVIRT_ROUTER_CREATED, KUBEVIRT_ROUTER_UPDATED);
}
@@ -223,9 +229,9 @@
public void testPeerRouterMacUpdate() {
target.createRouter(ROUTER_WITH_EXTERNAL);
- target.updatePeerRouterMac(ROUTER_NAME, UPDATED_MAC);
+ target.updatePeerRouterMac(ROUTER_ID, UPDATED_MAC);
assertEquals("MAC address was not updated", UPDATED_MAC,
- target.router(ROUTER_NAME).peerRouter().macAddress());
+ target.router(ROUTER_ID).peerRouter().macAddress());
validateEvents(KUBEVIRT_ROUTER_CREATED, KUBEVIRT_ROUTER_UPDATED);
}
@@ -237,15 +243,15 @@
public void testRouterInternalAttachedAndDetached() {
target.createRouter(ROUTER);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertEquals("Router internal did not match", 0, target.router(ROUTER_NAME).internal().size());
+ assertEquals("Router internal did not match", 0, target.router(ROUTER_ID).internal().size());
target.updateRouter(ROUTER_WITH_INTERNAL);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertEquals("Router internal did not match", 2, target.router(ROUTER_NAME).internal().size());
+ assertEquals("Router internal did not match", 2, target.router(ROUTER_ID).internal().size());
target.updateRouter(ROUTER);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertEquals("Router internal did not match", 0, target.router(ROUTER_NAME).internal().size());
+ assertEquals("Router internal did not match", 0, target.router(ROUTER_ID).internal().size());
validateEvents(KUBEVIRT_ROUTER_CREATED, KUBEVIRT_ROUTER_UPDATED,
KUBEVIRT_ROUTER_INTERNAL_NETWORKS_ATTACHED, KUBEVIRT_ROUTER_UPDATED,
@@ -256,11 +262,11 @@
public void testRouterInternalShrink() {
target.createRouter(ROUTER_WITH_INTERNAL);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertEquals("Router internal did not match", 2, target.router(ROUTER_NAME).internal().size());
+ assertEquals("Router internal did not match", 2, target.router(ROUTER_ID).internal().size());
target.updateRouter(ROUTER_WITH_SINGLE_INTERNAL);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertEquals("Router internal did not match", 1, target.router(ROUTER_NAME).internal().size());
+ assertEquals("Router internal did not match", 1, target.router(ROUTER_ID).internal().size());
validateEvents(KUBEVIRT_ROUTER_CREATED, KUBEVIRT_ROUTER_UPDATED,
KUBEVIRT_ROUTER_INTERNAL_NETWORKS_DETACHED);
@@ -275,18 +281,18 @@
public void testRouterExternalAttachedAndDetached() {
target.createRouter(ROUTER);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertNull(target.router(ROUTER_NAME).peerRouter());
- assertEquals(0, target.router(ROUTER_NAME).external().size());
+ assertNull(target.router(ROUTER_ID).peerRouter());
+ assertEquals(0, target.router(ROUTER_ID).external().size());
target.updateRouter(ROUTER_WITH_EXTERNAL);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertNotNull(target.router(ROUTER_NAME).peerRouter());
- assertEquals(1, target.router(ROUTER_NAME).external().size());
+ assertNotNull(target.router(ROUTER_ID).peerRouter());
+ assertEquals(1, target.router(ROUTER_ID).external().size());
target.updateRouter(ROUTER);
assertEquals("Number of router did not match", 1, target.routers().size());
- assertNull(target.router(ROUTER_NAME).peerRouter());
- assertEquals(0, target.router(ROUTER_NAME).external().size());
+ assertNull(target.router(ROUTER_ID).peerRouter());
+ assertEquals(0, target.router(ROUTER_ID).external().size());
validateEvents(KUBEVIRT_ROUTER_CREATED, KUBEVIRT_ROUTER_UPDATED,
KUBEVIRT_ROUTER_EXTERNAL_NETWORK_ATTACHED, KUBEVIRT_ROUTER_UPDATED,
@@ -362,7 +368,7 @@
public void testGetFloatingIpsByRouterName() {
createBasicFloatingIpDisassociated();
assertEquals("Number of floating IPs did not match", 1,
- target.floatingIpsByRouter(ROUTER_NAME).size());
+ target.floatingIpsByRouter(ROUTER_ID).size());
}
/**
diff --git a/apps/kubevirt-networking/web/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerCodec.java b/apps/kubevirt-networking/web/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerCodec.java
index c11d829..0e80b0d 100644
--- a/apps/kubevirt-networking/web/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerCodec.java
+++ b/apps/kubevirt-networking/web/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerCodec.java
@@ -38,6 +38,7 @@
private final Logger log = getLogger(getClass());
+ private static final String ID = "id";
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String VIP = "vip";
@@ -52,6 +53,7 @@
checkNotNull(lb, "Kubevirt load balancer cannot be null");
ObjectNode result = context.mapper().createObjectNode()
+ .put(ID, lb.id())
.put(NAME, lb.name())
.put(VIP, lb.vip().toString())
.put(NETWORK_ID, lb.networkId());
@@ -87,6 +89,7 @@
return null;
}
+ String id = nullIsIllegal(json.get(ID).asText(), ID + MISSING_MESSAGE);
String name = nullIsIllegal(json.get(NAME).asText(), NAME + MISSING_MESSAGE);
IpAddress vip = IpAddress.valueOf(nullIsIllegal(json.get(VIP).asText(),
VIP + MISSING_MESSAGE));
@@ -94,6 +97,7 @@
NETWORK_ID + MISSING_MESSAGE);
KubevirtLoadBalancer.Builder builder = DefaultKubevirtLoadBalancer.builder()
+ .id(id)
.name(name)
.vip(vip)
.networkId(networkId);
diff --git a/apps/kubevirt-networking/web/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterCodec.java b/apps/kubevirt-networking/web/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterCodec.java
index 5ca4ab6..3bfb44d 100644
--- a/apps/kubevirt-networking/web/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterCodec.java
+++ b/apps/kubevirt-networking/web/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterCodec.java
@@ -43,6 +43,7 @@
private final Logger log = getLogger(getClass());
+ private static final String ID = "id";
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String ENABLE_SNAT = "enableSnat";
@@ -61,6 +62,7 @@
checkNotNull(router, "Kubevirt router cannot be null");
ObjectNode result = context.mapper().createObjectNode()
+ .put(ID, router.id())
.put(NAME, router.name())
.put(ENABLE_SNAT, router.enableSnat())
.put(MAC_ADDRESS, router.mac().toString());
@@ -111,6 +113,9 @@
return null;
}
+ String id = nullIsIllegal(json.get(ID).asText(),
+ ID + MISSING_MESSAGE);
+
String name = nullIsIllegal(json.get(NAME).asText(),
NAME + MISSING_MESSAGE);
@@ -118,6 +123,7 @@
MAC_ADDRESS + MISSING_MESSAGE);
KubevirtRouter.Builder builder = DefaultKubevirtRouter.builder()
+ .id(id)
.name(name)
.mac(MacAddress.valueOf(vrouterMac));
diff --git a/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtFloatingIps.json b/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtFloatingIps.json
index 07a45e2..43d1dd1 100644
--- a/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtFloatingIps.json
+++ b/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtFloatingIps.json
@@ -30,7 +30,7 @@
},
"routerName": {
"type": "string",
- "example": "router-1",
+ "example": "26fcc876-f39a-459f-801d-75dcd3654ab8",
"description": "Name of router."
},
"networkName": {
diff --git a/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtLoadBalancers.json b/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtLoadBalancers.json
index f06aedf..9695249 100644
--- a/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtLoadBalancers.json
+++ b/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtLoadBalancers.json
@@ -15,6 +15,7 @@
"type": "object",
"description": "A load balancer object.",
"required": [
+ "id",
"name",
"description",
"networkId",
@@ -23,6 +24,11 @@
"rules"
],
"properties": {
+ "id": {
+ "type": "string",
+ "example": "26fcc876-f39a-459f-801d-75dcd3654ab8",
+ "description": "The ID of load balancer."
+ },
"name": {
"type": "string",
"example": "lb-1",
diff --git a/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtRouters.json b/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtRouters.json
index 835dfea..db64213 100644
--- a/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtRouters.json
+++ b/apps/kubevirt-networking/web/src/main/resources/definitions/KubevirtRouters.json
@@ -15,6 +15,7 @@
"type": "object",
"description": "A router object.",
"required": [
+ "id",
"name",
"enableSnat",
"mac",
@@ -23,6 +24,11 @@
"peerRouter"
],
"properties": {
+ "id": {
+ "type": "string",
+ "example": "26fcc876-f39a-459f-801d-75dcd3654ab8",
+ "description": "The ID of router."
+ },
"name": {
"type": "string",
"example": "router-1",
diff --git a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerCodecTest.java b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerCodecTest.java
index cd86402..d15a38d 100644
--- a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerCodecTest.java
+++ b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerCodecTest.java
@@ -96,6 +96,7 @@
@Test
public void testKubevirtLoadBalancerEncode() {
KubevirtLoadBalancer lb = DefaultKubevirtLoadBalancer.builder()
+ .id("26fcc876-f39a-459f-801d-75dcd3654ab8")
.name("lb-1")
.networkId("net-1")
.vip(IpAddress.valueOf("10.10.10.10"))
@@ -116,6 +117,7 @@
public void testKubevirtLoadBalancerDecode() throws IOException {
KubevirtLoadBalancer lb = getKubevirtLoadBalancer("KubevirtLoadBalancer.json");
+ assertThat(lb.id(), is("26fcc876-f39a-459f-801d-75dcd3654ab8"));
assertThat(lb.name(), is("lb-1"));
assertThat(lb.description(), is("Example Load Balancer"));
assertThat(lb.networkId(), is("net-1"));
diff --git a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerJsonMatcher.java b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerJsonMatcher.java
index 9122bd0..5a75b2b 100644
--- a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerJsonMatcher.java
+++ b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerJsonMatcher.java
@@ -28,6 +28,7 @@
*/
public final class KubevirtLoadBalancerJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+ private static final String ID = "id";
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String VIP = "vip";
@@ -43,6 +44,14 @@
@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+ // check ID
+ String jsonId = jsonNode.get(ID).asText();
+ String id = lb.id();
+ if (!jsonId.equals(id)) {
+ description.appendText("ID was " + jsonId);
+ return false;
+ }
+
// check name
String jsonName = jsonNode.get(NAME).asText();
String name = lb.name();
diff --git a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterCodecTest.java b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterCodecTest.java
index 1ff8951..104833c 100644
--- a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterCodecTest.java
+++ b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterCodecTest.java
@@ -77,6 +77,7 @@
MacAddress.valueOf("11:22:33:44:55:66"));
KubevirtRouter router = DefaultKubevirtRouter.builder()
+ .id("26fcc876-f39a-459f-801d-75dcd3654ab8")
.name("router-1")
.enableSnat(true)
.mac(MacAddress.valueOf("11:22:33:44:55:66"))
@@ -95,6 +96,7 @@
public void testKubevirtRouterDecode() throws IOException {
KubevirtRouter router = getKubevirtRouter("KubevirtRouter.json");
+ assertEquals("26fcc876-f39a-459f-801d-75dcd3654ab8", router.id());
assertEquals("router-1", router.name());
assertEquals("Example Virtual Router", router.description());
assertTrue(router.enableSnat());
diff --git a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterJsonMatcher.java b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterJsonMatcher.java
index a855f42..dcbd193 100644
--- a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterJsonMatcher.java
+++ b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/codec/KubevirtRouterJsonMatcher.java
@@ -28,6 +28,8 @@
public final class KubevirtRouterJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
private final KubevirtRouter router;
+
+ private static final String ID = "id";
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String ENABLE_SNAT = "enableSnat";
@@ -44,6 +46,13 @@
@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+ // check ID
+ String jsonId = jsonNode.get(ID).asText();
+ String id = router.id();
+ if (!jsonId.equals(id)) {
+ description.appendText("ID was " + jsonId);
+ return false;
+ }
// check name
String jsonName = jsonNode.get(NAME).asText();
diff --git a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResourceTest.java b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResourceTest.java
index c1415fd..8dafe86 100644
--- a/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResourceTest.java
+++ b/apps/kubevirt-networking/web/src/test/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResourceTest.java
@@ -66,6 +66,7 @@
private static final String VR_STATUS_PATH = "api/mm5/v1/status/vr/";
private static final String NETWORK_PATH = "api/mm5/v1/network";
+ private static final String ROUTER_ID = "26fcc876-f39a-459f-801d-75dcd3654ab8";
private static final String ROUTER_NAME = "router1";
private static final String HOST_NAME = "hostname1";
@@ -94,6 +95,7 @@
private static final KubevirtRouter ROUTER_1 = DefaultKubevirtRouter.builder()
+ .id(ROUTER_ID)
.name(ROUTER_NAME).build();
/**
diff --git a/apps/kubevirt-networking/web/src/test/resources/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancer.json b/apps/kubevirt-networking/web/src/test/resources/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancer.json
index 806fd73..77b9385 100644
--- a/apps/kubevirt-networking/web/src/test/resources/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancer.json
+++ b/apps/kubevirt-networking/web/src/test/resources/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancer.json
@@ -1,4 +1,5 @@
{
+ "id": "26fcc876-f39a-459f-801d-75dcd3654ab8",
"name": "lb-1",
"description": "Example Load Balancer",
"networkId": "net-1",
diff --git a/apps/kubevirt-networking/web/src/test/resources/org/onosproject/kubevirtnetworking/codec/KubevirtRouter.json b/apps/kubevirt-networking/web/src/test/resources/org/onosproject/kubevirtnetworking/codec/KubevirtRouter.json
index 5d9d53c..57a3b6c 100644
--- a/apps/kubevirt-networking/web/src/test/resources/org/onosproject/kubevirtnetworking/codec/KubevirtRouter.json
+++ b/apps/kubevirt-networking/web/src/test/resources/org/onosproject/kubevirtnetworking/codec/KubevirtRouter.json
@@ -1,4 +1,5 @@
{
+ "id": "26fcc876-f39a-459f-801d-75dcd3654ab8",
"name": "router-1",
"description": "Example Virtual Router",
"enableSnat": true,