Fix: make protocol field optional in kubevirt load balancer
Change-Id: I6c5368a8bd40df29c52c480af957b48abb240d1a
(cherry picked from commit 70d491cba5689d69708568f693b92432ebe52ba5)
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerRule.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerRule.java
index bd2f64a..4d8557c 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerRule.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerRule.java
@@ -26,7 +26,8 @@
*/
public final class DefaultKubevirtLoadBalancerRule implements KubevirtLoadBalancerRule {
private static final String NOT_NULL_MSG = "Load Balancer Rule % cannot be null";
- private static final String ICMP = "ICMP";
+ private static final String TCP = "TCP";
+ private static final String UDP = "UDP";
private final String protocol;
private final Integer portRangeMax;
@@ -110,7 +111,7 @@
public KubevirtLoadBalancerRule build() {
checkArgument(protocol != null, NOT_NULL_MSG, "protocol");
- if (!protocol.equalsIgnoreCase(ICMP)) {
+ if (protocol.equalsIgnoreCase(TCP) || protocol.equalsIgnoreCase(UDP)) {
checkArgument(portRangeMax != null, NOT_NULL_MSG, "portRangeMax");
checkArgument(portRangeMin != null, NOT_NULL_MSG, "portRangeMin");
}
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerRuleCodec.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerRuleCodec.java
index 613ac10..582d4d3 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerRuleCodec.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/codec/KubevirtLoadBalancerRuleCodec.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.kubevirtnetworking.codec;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
@@ -23,7 +24,6 @@
import org.slf4j.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.util.Tools.nullIsIllegal;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -36,7 +36,8 @@
private static final String PROTOCOL = "protocol";
private static final String PORT_RANGE_MAX = "portRangeMax";
private static final String PORT_RANGE_MIN = "portRangeMin";
- private static final String ICMP = "ICMP";
+ private static final String TCP = "TCP";
+ private static final String UDP = "UDP";
private static final String MISSING_MESSAGE = " is required in KubevirtLoadBalancerRule";
@@ -46,7 +47,7 @@
ObjectNode result = context.mapper().createObjectNode().put(PROTOCOL, rule.protocol());
- if (!rule.protocol().equalsIgnoreCase(ICMP)) {
+ if (rule.protocol().equalsIgnoreCase(TCP) || rule.protocol().equalsIgnoreCase(UDP)) {
result.put(PORT_RANGE_MAX, rule.portRangeMax()).put(PORT_RANGE_MIN, rule.portRangeMin());
}
return result;
@@ -60,11 +61,14 @@
KubevirtLoadBalancerRule.Builder builder = DefaultKubevirtLoadBalancerRule.builder();
- String protocol = nullIsIllegal(json.get(PROTOCOL).asText(), PROTOCOL + MISSING_MESSAGE);
-
+ JsonNode protocolJson = json.get(PROTOCOL);
+ String protocol = "";
+ if (protocolJson != null) {
+ protocol = protocolJson.asText();
+ }
builder.protocol(protocol);
- if (!protocol.equalsIgnoreCase(ICMP)) {
+ if (protocol.equalsIgnoreCase(TCP) || protocol.equalsIgnoreCase(UDP)) {
Integer portRangeMax = json.get(PORT_RANGE_MAX).asInt();
Integer portRangeMin = json.get(PORT_RANGE_MIN).asInt();
builder.portRangeMax(portRangeMax).portRangeMin(portRangeMin);