Support to store and monitor kubevirt POD resource
Change-Id: I2b484a806549620c5b1352da63061cd850b0284c
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/Constants.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/Constants.java
index 7a5d873..0ff5fec 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/Constants.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/Constants.java
@@ -63,6 +63,7 @@
public static final int CLI_MAC_ADDRESS_LENGTH = 25;
public static final int CLI_PORTS_LENGTH = 20;
public static final int CLI_NAMESPACE_LENGTH = 15;
+ public static final int CLI_STATUS_LENGTH = 15;
public static final int CLI_PHASE_LENGTH = 15;
public static final int CLI_TYPE_LENGTH = 15;
public static final int CLI_TYPES_LENGTH = 30;
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodAdminService.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodAdminService.java
new file mode 100644
index 0000000..668081a
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodAdminService.java
@@ -0,0 +1,50 @@
+/*
+ * 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 io.fabric8.kubernetes.api.model.Pod;
+
+/**
+ * Service for administering the inventory of kubevirt service.
+ */
+public interface KubevirtPodAdminService extends KubevirtPodService {
+
+ /**
+ * Creates a kubevirt service with the given information.
+ *
+ * @param pod the new kubevirt pod
+ */
+ void createPod(Pod pod);
+
+ /**
+ * Updates the kubevirt pod with the given information.
+ *
+ * @param pod the updated kubevirt pod
+ */
+ void updatePod(Pod pod);
+
+ /**
+ * Removes the kubevirt pod.
+ *
+ * @param uid kubevirt pod UID
+ */
+ void removePod(String uid);
+
+ /**
+ * Clears the existing pods.
+ */
+ void clear();
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodEvent.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodEvent.java
new file mode 100644
index 0000000..a1f5b83
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodEvent.java
@@ -0,0 +1,92 @@
+/*
+ * 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 io.fabric8.kubernetes.api.model.Pod;
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Kubevirt pod event class.
+ */
+public class KubevirtPodEvent extends AbstractEvent<KubevirtPodEvent.Type, Pod> {
+
+ /**
+ * Creates an event of a given type for the specified kubevirt pod.
+ *
+ * @param type kubevirt pod event type
+ * @param subject kubevirt pod
+ */
+ public KubevirtPodEvent(Type type, Pod subject) {
+ super(type, subject);
+ }
+
+ public enum Type {
+ /**
+ * Signifies that a new kubevirt pod is created.
+ */
+ KUBEVIRT_POD_CREATED,
+
+ /**
+ * Signifies that the kubevirt pod is updated.
+ */
+ KUBEVIRT_POD_UPDATED,
+
+ /**
+ * Signifies that the kubevirt pod is in Pending phase.
+ */
+ KUBEVIRT_POD_PENDING,
+
+ /**
+ * Signifies that the kubevirt pod is in Running phase.
+ */
+ KUBEVIRT_POD_RUNNING,
+
+ /**
+ * Signifies that the kubevirt pod is in Succeeded phase.
+ */
+ KUBEVIRT_POD_SUCCEEDED,
+
+ /**
+ * Signifies that the kubevirt pod is in Failed phase.
+ */
+ KUBEVIRT_POD_FAILED,
+
+ /**
+ * Signifies that the kubevirt pod is in Unknown phase.
+ */
+ KUBEVIRT_POD_UNKNOWN,
+
+ /**
+ * Signifies that the kubevirt pod is in Completed phase.
+ */
+ KUBEVIRT_POD_COMPLETED,
+
+ /**
+ * Signifies that the kubevirt pod is in CrashLoopBackOff phase.
+ */
+ KUBEVIRT_POD_CRASH_LOOP_BACK_OFF,
+
+ /**
+ * Signifies that the kubevirt pod annotation is added.
+ */
+ KUBEVIRT_POD_ANNOTATION_ADDED,
+
+ /**
+ * Signifies that the kubevirt pod is removed.
+ */
+ KUBEVIRT_POD_REMOVED,
+ }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodListener.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodListener.java
new file mode 100644
index 0000000..5f980b6
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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 org.onosproject.event.EventListener;
+
+/**
+ * Listener for kubevirt pod event.
+ */
+public interface KubevirtPodListener extends EventListener<KubevirtPodEvent> {
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodService.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodService.java
new file mode 100644
index 0000000..5c99d5c
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodService.java
@@ -0,0 +1,43 @@
+/*
+ * 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 io.fabric8.kubernetes.api.model.Pod;
+import org.onosproject.event.ListenerService;
+
+import java.util.Set;
+
+/**
+ * Service for interacting with the inventory of kubevirt service.
+ */
+public interface KubevirtPodService
+ extends ListenerService<KubevirtPodEvent, KubevirtPodListener> {
+
+ /**
+ * Returns the kubevirt pod with the supplied pod UID.
+ *
+ * @param uid pod UID
+ * @return kubevirt pod
+ */
+ Pod pod(String uid);
+
+ /**
+ * Returns all kubevirt pods registered.
+ *
+ * @return set of kubevirt pods
+ */
+ Set<Pod> pods();
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodStore.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodStore.java
new file mode 100644
index 0000000..6376f3e
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodStore.java
@@ -0,0 +1,69 @@
+/*
+ * 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 io.fabric8.kubernetes.api.model.Pod;
+import org.onosproject.store.Store;
+
+import java.util.Set;
+
+/**
+ * Manages inventory of kubevirt pod; not intended for direct use.
+ */
+public interface KubevirtPodStore extends Store<KubevirtPodEvent, KubevirtPodStoreDelegate> {
+
+ /**
+ * Creates the new kubevirt pod.
+ *
+ * @param pod kubevirt pod
+ */
+ void createPod(Pod pod);
+
+ /**
+ * Updates the kubevirt pod.
+ *
+ * @param pod kubevirt pod
+ */
+ void updatePod(Pod pod);
+
+ /**
+ * Removes the kubevirt pod with the given pod UID.
+ *
+ * @param uid kubevirt pod UID
+ * @return removed kubevirt pod; null if failed
+ */
+ Pod removePod(String uid);
+
+ /**
+ * Returns the kubevirt pod with the given pod UID.
+ *
+ * @param uid kubevirt pod UID
+ * @return kubevirt pod; null if not found
+ */
+ Pod pod(String uid);
+
+ /**
+ * Returns all kubevirt pods.
+ *
+ * @return set of kubevirt pods
+ */
+ Set<Pod> pods();
+
+ /**
+ * Removes all kubevirt pods.
+ */
+ void clear();
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodStoreDelegate.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodStoreDelegate.java
new file mode 100644
index 0000000..5eb7f0d
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPodStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * 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 org.onosproject.store.StoreDelegate;
+
+/**
+ * Kubevirt pod store delegate abstraction.
+ */
+public interface KubevirtPodStoreDelegate extends StoreDelegate<KubevirtPodEvent> {
+}