Implement kubevirt node service, expose it through REST API and CLI
Change-Id: Ieebd2652af31344df3a7c91d3669a2ba150cb57f
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/DefaultKubevirtNode.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/DefaultKubevirtNode.java
index cd653ce..3815ff3 100644
--- a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/DefaultKubevirtNode.java
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/DefaultKubevirtNode.java
@@ -125,6 +125,20 @@
}
@Override
+ public KubevirtNode updateIntgBridge(DeviceId deviceId) {
+ return new Builder()
+ .hostname(hostname)
+ .clusterName(clusterName)
+ .type(type)
+ .intgBridge(deviceId)
+ .managementIp(managementIp)
+ .dataIp(dataIp)
+ .state(state)
+ .phyIntfs(phyIntfs)
+ .build();
+ }
+
+ @Override
public Collection<KubevirtPhyInterface> phyIntfs() {
if (phyIntfs == null) {
return new ArrayList<>();
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNode.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNode.java
index 544c76b..402d0f9 100644
--- a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNode.java
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNode.java
@@ -100,11 +100,19 @@
* Returns new kubevirt node instance with given state.
*
* @param newState updated state
- * @return updated kubernetes node
+ * @return updated kubevirt node
*/
KubevirtNode updateState(KubevirtNodeState newState);
/**
+ * Returns new kubevirt node instance with given integration bridge.
+ *
+ * @param deviceId integration bridge device ID
+ * @return updated kubevirt node
+ */
+ KubevirtNode updateIntgBridge(DeviceId deviceId);
+
+ /**
* Returns a collection of physical interfaces.
*
* @return physical interfaces
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeAdminService.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeAdminService.java
new file mode 100644
index 0000000..424a422
--- /dev/null
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeAdminService.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2020-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.kubevirtnode.api;
+
+/**
+ * Service for administering inventory of {@link KubevirtNode}.
+ */
+public interface KubevirtNodeAdminService extends KubevirtNodeService {
+
+ /**
+ * Creates a new node.
+ *
+ * @param node kubevirt node
+ */
+ void createNode(KubevirtNode node);
+
+ /**
+ * Updates the node.
+ *
+ * @param node kubevirt node
+ */
+ void updateNode(KubevirtNode node);
+
+ /**
+ * Removes the node.
+ *
+ * @param hostname kubevirt node hostname
+ * @return removed node; null if the node does not exist
+ */
+ KubevirtNode removeNode(String hostname);
+}
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeEvent.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeEvent.java
new file mode 100644
index 0000000..742c0d7
--- /dev/null
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeEvent.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2020-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.kubevirtnode.api;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes Kubevirt node init state event.
+ */
+public class KubevirtNodeEvent extends AbstractEvent<KubevirtNodeEvent.Type, KubevirtNode> {
+
+ /**
+ * List of kubevirt node event types.
+ */
+ public enum Type {
+
+ /**
+ * Signifies that new node is created.
+ */
+ KUBEVIRT_NODE_CREATED,
+
+ /**
+ * Signifies that the node state is updated.
+ */
+ KUBEVIRT_NODE_UPDATED,
+
+ /**
+ * Signifies that the node state is complete.
+ */
+ KUBEVIRT_NODE_COMPLETE,
+
+ /**
+ * Signifies that the node state is removed.
+ */
+ KUBEVIRT_NODE_REMOVED,
+
+ /**
+ * Signifies that the node state is changed to incomplete.
+ */
+ KUBEVIRT_NODE_INCOMPLETE
+ }
+
+ public KubevirtNodeEvent(Type type, KubevirtNode subject) {
+ super(type, subject);
+ }
+}
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeListener.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeListener.java
new file mode 100644
index 0000000..c5cff24
--- /dev/null
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeListener.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2020-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.kubevirtnode.api;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener for KubevirtNode event.
+ */
+public interface KubevirtNodeListener extends EventListener<KubevirtNodeEvent> {
+}
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeService.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeService.java
new file mode 100644
index 0000000..e032ba3
--- /dev/null
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeService.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2020-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.kubevirtnode.api;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.event.ListenerService;
+import org.onosproject.net.DeviceId;
+
+import java.util.Set;
+
+/**
+ * Service for interfacing with the inventory of {@link KubevirtNode}.
+ */
+public interface KubevirtNodeService extends ListenerService<KubevirtNodeEvent, KubevirtNodeListener> {
+
+ String APP_ID = "org.onosproject.kubevirtnode";
+
+ /**
+ * Returns all registered nodes.
+ *
+ * @return set of kubevirt nodes
+ */
+ Set<KubevirtNode> nodes();
+
+ /**
+ * Returns all nodes with the specified type.
+ *
+ * @param type node type
+ * @return set of kubevirt nodes
+ */
+ Set<KubevirtNode> nodes(KubevirtNode.Type type);
+
+ /**
+ * Returns all nodes with complete state.
+ *
+ * @return set of kubevirt nodes
+ */
+ Set<KubevirtNode> completeNodes();
+
+ /**
+ * Returns all nodes with complete state and the specified type.
+ *
+ * @param type node type
+ * @return set of kubevirt nodes
+ */
+ Set<KubevirtNode> completeNodes(KubevirtNode.Type type);
+
+ /**
+ * Returns the node with the specified hostname.
+ *
+ * @param hostname hostname
+ * @return kubevirt node
+ */
+ KubevirtNode node(String hostname);
+
+ /**
+ * Returns the node with the specified device ID.
+ * The device ID can be any one of integration bridge or ovsdb device.
+ *
+ * @param deviceId device id
+ * @return kubevirt node
+ */
+ KubevirtNode node(DeviceId deviceId);
+
+ /**
+ * Returns the node with the specified management IP address.
+ *
+ * @param mgmtIp management IP
+ * @return kubevirt node
+ */
+ KubevirtNode node(IpAddress mgmtIp);
+}
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeStore.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeStore.java
new file mode 100644
index 0000000..b6a9f03
--- /dev/null
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeStore.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2020-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.kubevirtnode.api;
+
+import org.onosproject.store.Store;
+
+import java.util.Set;
+
+/**
+ * Manages inventory of KubevirtNode; not intended for direct use.
+ */
+public interface KubevirtNodeStore extends Store<KubevirtNodeEvent, KubevirtNodeStoreDelegate> {
+
+ /**
+ * Creates a new node.
+ *
+ * @param node kubevirt node
+ */
+ void createNode(KubevirtNode node);
+
+ /**
+ * Updates the node.
+ *
+ * @param node kubevirt node
+ */
+ void updateNode(KubevirtNode node);
+
+ /**
+ * Removes the node.
+ *
+ * @param hostname kubevirt node hostname
+ * @return removed kubevirt node; null if no node mapped for the hostname
+ */
+ KubevirtNode removeNode(String hostname);
+
+ /**
+ * Returns all registered nodes.
+ *
+ * @return set of kubevirt nodes
+ */
+ Set<KubevirtNode> nodes();
+
+ /**
+ * Returns the node with the specified hostname.
+ *
+ * @param hostname hostname
+ * @return kubevirt node
+ */
+ KubevirtNode node(String hostname);
+}
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeStoreDelegate.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeStoreDelegate.java
new file mode 100644
index 0000000..5e87855
--- /dev/null
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtNodeStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2020-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.kubevirtnode.api;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * KubevirtNode store delegate.
+ */
+public interface KubevirtNodeStoreDelegate extends StoreDelegate<KubevirtNodeEvent> {
+}