Implement kubevirt loadbalancer service with unit tests
Change-Id: I1c29e75aa5196b497f8f12f1d182788e3d173244
(cherry picked from commit 870abf8c7a7904c5953e20807ee7c681d8b5cd0b)
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
new file mode 100644
index 0000000..453610e
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerRule.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2021-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.kubevirtnetworking.api;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default implementation class of kubevirt load balancer rule.
+ */
+public final class DefaultKubevirtLoadBalancerRule implements KubevirtLoadBalancerRule {
+ private static final String NOT_NULL_MSG = "Load Balancer Rule % cannot be null";
+
+ private final String protocol;
+ private final Integer portRangeMax;
+ private final Integer portRangeMin;
+
+ /**
+ * A default constructor.
+ *
+ * @param protocol protocol
+ * @param portRangeMax port range max
+ * @param portRangeMin port range min
+ */
+ public DefaultKubevirtLoadBalancerRule(String protocol,
+ Integer portRangeMax,
+ Integer portRangeMin) {
+ this.protocol = protocol;
+ this.portRangeMax = portRangeMax;
+ this.portRangeMin = portRangeMin;
+ }
+
+ @Override
+ public String protocol() {
+ return protocol;
+ }
+
+ @Override
+ public Integer portRangeMax() {
+ return portRangeMax;
+ }
+
+ @Override
+ public Integer portRangeMin() {
+ return portRangeMin;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ DefaultKubevirtLoadBalancerRule that = (DefaultKubevirtLoadBalancerRule) o;
+ return protocol.equals(that.protocol) &&
+ portRangeMax.equals(that.portRangeMax) &&
+ portRangeMin.equals(that.portRangeMin);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(protocol, portRangeMax, portRangeMin);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("protocol", protocol)
+ .add("portRangeMax", portRangeMax)
+ .add("portRangeMin", portRangeMin)
+ .toString();
+ }
+
+ /**
+ * Returns new builder instance.
+ *
+ * @return kubevirt load balancer rule builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder implements KubevirtLoadBalancerRule.Builder {
+
+ private String protocol;
+ private Integer portRangeMax;
+ private Integer portRangeMin;
+
+ @Override
+ public KubevirtLoadBalancerRule build() {
+ checkArgument(protocol != null, NOT_NULL_MSG, "protocol");
+ checkArgument(portRangeMax != null, NOT_NULL_MSG, "portRangeMax");
+ checkArgument(portRangeMin != null, NOT_NULL_MSG, "portRangeMin");
+
+ return new DefaultKubevirtLoadBalancerRule(protocol, portRangeMax, portRangeMin);
+ }
+
+ @Override
+ public Builder portRangeMax(Integer portRangeMax) {
+ this.portRangeMax = portRangeMax;
+ return this;
+ }
+
+ @Override
+ public Builder portRangeMin(Integer portRangeMin) {
+ this.portRangeMin = portRangeMin;
+ return this;
+ }
+
+ @Override
+ public Builder protocol(String protocol) {
+ this.protocol = protocol;
+ return this;
+ }
+ }
+}