Supports Mm5 Interface in KubevirtNode app.
- Adds datacenter and cluster id parameter to KubevirtApiConfig
- Implements related REST API web resource
Change-Id: Ib1b6cbc1dbbe11def4d97d78c2e74b5eeec560dc
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResource.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResource.java
new file mode 100644
index 0000000..ef8f707
--- /dev/null
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResource.java
@@ -0,0 +1,485 @@
+/*
+ * Copyright 2022-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.web;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp;
+import org.onosproject.kubevirtnetworking.api.KubevirtInstance;
+import org.onosproject.kubevirtnetworking.api.KubevirtInstanceService;
+import org.onosproject.kubevirtnetworking.api.KubevirtLoadBalancer;
+import org.onosproject.kubevirtnetworking.api.KubevirtLoadBalancerService;
+import org.onosproject.kubevirtnetworking.api.KubevirtNetwork;
+import org.onosproject.kubevirtnetworking.api.KubevirtNetworkService;
+import org.onosproject.kubevirtnetworking.api.KubevirtRouter;
+import org.onosproject.kubevirtnetworking.api.KubevirtRouterService;
+import org.onosproject.kubevirtnode.api.KubevirtNode;
+import org.onosproject.kubevirtnode.api.KubevirtNodeService;
+import org.onosproject.rest.AbstractWebResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.io.InputStream;
+
+/**
+ * Handles REST API for communication with MEC Orchestrator.
+ */
+@Path("api/mm5/v1")
+public class KubevirtMm5WebResource extends AbstractWebResource {
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final String RECEIVED_REQUEST = "Received %s request";
+ private static final String QUERY_STATUS_LEG = "LEG status query";
+ private static final String QUERY_STATUS_VR = "VR status query";
+
+ private static final String QUERY_GET_NETWORK = "get network query";
+ private static final String QUERY_CREATE_NETWORK = "create network query";
+ private static final String QUERY_UPDATE_NETWORK = "update network query";
+ private static final String QUERY_DELETE_NETWORK = "delete network query";
+
+ private static final String QUERY_GET_VR = "get virtual router query";
+ private static final String QUERY_CREATE_VR = "create virtual router query";
+ private static final String QUERY_UPDATE_VR = "update virtual router query";
+ private static final String QUERY_DELETE_VR = "delete virtual router query";
+
+ private static final String QUERY_GET_FIP = "get floating ip query";
+ private static final String QUERY_CREATE_FIP = "create floating ip query";
+ private static final String QUERY_UPDATE_FIP = "update floating ip query";
+ private static final String QUERY_DELETE_FIP = "delete floating ip query";
+
+ private static final String QUERY_GET_LB = "get LoadBalancer query";
+ private static final String QUERY_CREATE_LB = "create LoadBalancer query";
+ private static final String QUERY_UPDATE_LB = "update LoadBalancer query";
+ private static final String QUERY_DELETE_LB = "delete LoadBalancer query";
+
+ private static final String QUERY_GET_INSTANCE = "get instance query";
+ private static final String QUERY_CREATE_INSTANCE = "create instance query";
+ private static final String QUERY_UPDATE_INSTANCE = "update floating ip query";
+ private static final String QUERY_DELETE_INSTANCE = "delete floating ip query";
+
+ private static final String NODE_NAME = "nodeName";
+ private static final String STATE = "state";
+ private static final String ACTIVE = "ACTIVE";
+ private static final String INACTIVE = "INACTIVE";
+
+ private static final String NETWORKS = "networks";
+ private static final String INSTANCES = "instances";
+ private static final String VIRTUAL_ROUTERS = "virtualRouters";
+ private static final String LOAD_BALANCERS = "loadBalancers";
+ private static final String FLOATING_IPS = "floatingIps";
+
+ private static final String UP = "up";
+ private static final String DOWN = "down";
+ private static final String NONE = "none";
+
+ private static final String VR_NAME = "vrName";
+
+ @Context
+ private UriInfo uriInfo;
+
+ /**
+ * Obtains the status of the virtual router.
+ *
+ * @param vrName virtual router name
+ * @return the state of the virtual router in Json
+ */
+ @GET
+ @Path("status/vr/{vrName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response vrStatus(@PathParam(VR_NAME) String vrName) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_STATUS_VR));
+
+ KubevirtRouterService service = get(KubevirtRouterService.class);
+
+ KubevirtRouter router = service.routers().stream()
+ .filter(r -> r.name().equals(vrName))
+ .findAny().orElse(null);
+
+ if (router == null) {
+ return Response.status(Response.Status.NOT_FOUND).build();
+ } else {
+ ObjectNode jsonResult = mapper().createObjectNode();
+
+ jsonResult.put(VR_NAME, router.name());
+
+ if (router.electedGateway() == null) {
+ jsonResult.put("merName", NONE);
+ jsonResult.put("status", DOWN);
+ } else {
+ jsonResult.put("merName", router.electedGateway());
+ jsonResult.put("status", UP);
+ }
+
+ jsonResult.put("timeUpdated", System.currentTimeMillis());
+ return ok(jsonResult).build();
+ }
+ }
+
+ /**
+ * Obtains the state of the leg node.
+ *
+ * @param nodeName leg host name
+ * @return the state of the leg node in Json
+ */
+ @PUT
+ @Path("state/mer/{nodeName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response legStatus(@PathParam("nodeName") String nodeName) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_STATUS_LEG));
+
+ KubevirtNodeService service = get(KubevirtNodeService.class);
+
+ ObjectNode jsonResult = mapper().createObjectNode();
+ jsonResult.put(NODE_NAME, nodeName);
+
+ boolean isActive = service.completeNodes().stream()
+ .anyMatch(node -> node.type().equals(KubevirtNode.Type.GATEWAY) &&
+ node.hostname().equals(nodeName));
+ if (isActive) {
+ jsonResult.put(STATE, ACTIVE);
+ } else {
+ jsonResult.put(STATE, INACTIVE);
+ }
+ return ok(jsonResult).build();
+ }
+
+ /**
+ * Obtains the network information in Json Array.
+ *
+ * @return network information in Json
+ */
+ @GET
+ @Path("network")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getNetwork() {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_GET_NETWORK));
+
+ KubevirtNetworkService service = get(KubevirtNetworkService.class);
+ final Iterable<KubevirtNetwork> networks = service.networks();
+ return ok(encodeArray(KubevirtNetwork.class, NETWORKS, networks)).build();
+ }
+
+ /**
+ * Creates the kubevirt network with specified input stream.
+ *
+ * @param inputStream network Json input stream
+ * @return 200 OK if succeeded
+ */
+ @POST
+ @Path("network")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createNetwork(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_CREATE_NETWORK));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Updates the kubevirt network with the specified input stream.
+ *
+ * @param inputStream network Json input stream
+ * @return 200 OK if succeeded
+ */
+ @PUT
+ @Path("network/{networkName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateNetwork(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_UPDATE_NETWORK));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Deletes the kubevirt network with the specified input stream.
+ *
+ * @param inputStream network Json input stream
+ * @return 200 OK if succeeded
+ */
+ @DELETE
+ @Path("network/{networkName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteNetwork(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_DELETE_NETWORK));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Obtains the instance information in Json Array.
+ *
+ * @return instance information in Json
+ */
+ @GET
+ @Path("instance")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getInstance() {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_GET_INSTANCE));
+
+ KubevirtInstanceService service = get(KubevirtInstanceService.class);
+ final Iterable<KubevirtInstance> instances = service.instances();
+ return ok(encodeArray(KubevirtInstance.class, INSTANCES, instances)).build();
+ }
+
+ /**
+ * Creates the instance with specified input stream.
+ *
+ * @param inputStream instance Json insput stream
+ * @return 200 OK if succeeded
+ */
+ @POST
+ @Path("instance")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createInstance(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_CREATE_INSTANCE));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Updates the instance with specified input stream.
+ *
+ * @param inputStream instance Json insput stream
+ * @return 200 OK if succeeded
+ */
+ @PUT
+ @Path("instance/{instanceName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateInstance(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_UPDATE_INSTANCE));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Deletes the instance with specified input stream.
+ *
+ * @param inputStream inputStream instance Json insput stream
+ * @return 200 OK if succeeded
+ */
+ @DELETE
+ @Path("instance/{instanceName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteInstance(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_DELETE_INSTANCE));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Obtains the virtual router in Json array.
+ *
+ * @return virtual router information in Json
+ */
+ @GET
+ @Path("vr")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getVirtualRouter() {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_GET_VR));
+
+ KubevirtRouterService service = get(KubevirtRouterService.class);
+ final Iterable<KubevirtRouter> routers = service.routers();
+ return ok(encodeArray(KubevirtRouter.class, VIRTUAL_ROUTERS, routers)).build();
+ }
+
+ /**
+ * Creates the virtual router with specified input stream.
+ *
+ * @param inputStream virtual router Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @POST
+ @Path("vr")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createVirtualRouter(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_CREATE_VR));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Updates the virtual router with specified input stream.
+ *
+ * @param inputStream virtual router Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @PUT
+ @Path("vr/{vrName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateVirtualRouter(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_UPDATE_VR));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Deletes the virtual router with specified input stream.
+ *
+ * @param inputStream virtual router Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @DELETE
+ @Path("vr/{vrName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteVirtualRouter(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_DELETE_VR));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Obtains the floating ip in Json array.
+ *
+ * @return floating ip information in Json
+ */
+ @GET
+ @Path("fip")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getFloatingIp() {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_GET_FIP));
+
+ KubevirtRouterService service = get(KubevirtRouterService.class);
+ final Iterable<KubevirtFloatingIp> fips = service.floatingIps();
+ return ok(encodeArray(KubevirtFloatingIp.class, FLOATING_IPS, fips)).build();
+ }
+
+ /**
+ * Creates the floating ip with specified input stream.
+ *
+ * @param inputStream floating ip Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @POST
+ @Path("fip")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createFloatingIp(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_CREATE_FIP));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Updates the floating ip with specified input stream.
+ *
+ * @param inputStream floating ip Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @PUT
+ @Path("fip/{fipName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateFloatingIp(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_UPDATE_FIP));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Deletes the floating ip with specified input stream.
+ *
+ * @param inputStream floating ip Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @DELETE
+ @Path("fip/{fipName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteFloatingIp(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_DELETE_FIP));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Obtains the loadbalaner in Json array.
+ *
+ * @return loadbalancer information in Json
+ */
+ @GET
+ @Path("lb")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getLoadBalancer() {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_GET_LB));
+
+ KubevirtLoadBalancerService service = get(KubevirtLoadBalancerService.class);
+ final Iterable<KubevirtLoadBalancer> lbs = service.loadBalancers();
+ return ok(encodeArray(KubevirtLoadBalancer.class, LOAD_BALANCERS, lbs)).build();
+ }
+
+ /**
+ * Creates the loadbalander with specified input stream.
+ *
+ * @param inputStream loadbalancer Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @POST
+ @Path("lb")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createLoadBalancer(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_CREATE_LB));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Updates the loadbalander with specified input stream.
+ *
+ * @param inputStream loadbalancer Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @PUT
+ @Path("lb/{lbName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateLoadBalancer(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_UPDATE_LB));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+
+ /**
+ * Deletes the loadbalander with specified input stream.
+ *
+ * @param inputStream loadbalancer Json inputstream
+ * @return 200 OK if succeeded
+ */
+ @DELETE
+ @Path("lb/{lbName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteLoadBalancer(InputStream inputStream) {
+ log.trace(String.format(RECEIVED_REQUEST, QUERY_DELETE_LB));
+ //Just sends 200 OK for now.
+ return ok(mapper().createObjectNode()).build();
+ }
+}
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/web/KubevirtNetworkingWebApplication.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/web/KubevirtNetworkingWebApplication.java
index 1345f95..dc2afbc 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/web/KubevirtNetworkingWebApplication.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/web/KubevirtNetworkingWebApplication.java
@@ -30,7 +30,8 @@
KubevirtRouterWebResource.class,
KubevirtFloatingIpsWebResource.class,
KubevirtSecurityGroupWebResource.class,
- KubevirtLoadBalancerWebResource.class
+ KubevirtLoadBalancerWebResource.class,
+ KubevirtMm5WebResource.class
);
}
}
diff --git a/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResourceTest.java b/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResourceTest.java
new file mode 100644
index 0000000..c1415fd
--- /dev/null
+++ b/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/web/KubevirtMm5WebResourceTest.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2022-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.web;
+
+import com.eclipsesource.json.Json;
+import com.eclipsesource.json.JsonArray;
+import com.eclipsesource.json.JsonObject;
+import com.google.common.collect.ImmutableSet;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.osgi.ServiceDirectory;
+import org.onlab.osgi.TestServiceDirectory;
+import org.onlab.packet.IpAddress;
+import org.onosproject.codec.CodecService;
+import org.onosproject.codec.impl.CodecManager;
+import org.onosproject.kubevirtnetworking.api.DefaultKubevirtNetwork;
+import org.onosproject.kubevirtnetworking.api.DefaultKubevirtRouter;
+import org.onosproject.kubevirtnetworking.api.KubevirtHostRoute;
+import org.onosproject.kubevirtnetworking.api.KubevirtIpPool;
+import org.onosproject.kubevirtnetworking.api.KubevirtNetwork;
+import org.onosproject.kubevirtnetworking.api.KubevirtNetworkService;
+import org.onosproject.kubevirtnetworking.api.KubevirtRouter;
+import org.onosproject.kubevirtnetworking.api.KubevirtRouterService;
+import org.onosproject.kubevirtnetworking.codec.KubevirtHostRouteCodec;
+import org.onosproject.kubevirtnetworking.codec.KubevirtIpPoolCodec;
+import org.onosproject.kubevirtnetworking.codec.KubevirtNetworkCodec;
+import org.onosproject.kubevirtnode.api.DefaultKubevirtNode;
+import org.onosproject.kubevirtnode.api.KubevirtNode;
+import org.onosproject.kubevirtnode.api.KubevirtNodeService;
+import org.onosproject.kubevirtnode.api.KubevirtNodeState;
+import org.onosproject.net.DeviceId;
+import org.onosproject.rest.resources.ResourceTest;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+public class KubevirtMm5WebResourceTest extends ResourceTest {
+
+ final KubevirtRouterService mockRouterService = createMock(KubevirtRouterService.class);
+ final KubevirtNodeService mockNodeService = createMock(KubevirtNodeService.class);
+ final KubevirtNetworkService mockNetworkService = createMock(KubevirtNetworkService.class);
+
+ 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_NAME = "router1";
+ private static final String HOST_NAME = "hostname1";
+
+
+ private static final KubevirtNetwork NETWORK_1 = DefaultKubevirtNetwork.builder()
+ .networkId("network")
+ .name("network")
+ .type(KubevirtNetwork.Type.FLAT)
+ .cidr("10.10.10.0/24")
+ .mtu(1500)
+ .gatewayIp(IpAddress.valueOf("10.10.10.1"))
+ .defaultRoute(true)
+ .ipPool(new KubevirtIpPool(IpAddress.valueOf("10.10.10.100"),
+ IpAddress.valueOf("10.10.10.200")))
+ .build();
+
+ private static final KubevirtNode NODE_1 = DefaultKubevirtNode.builder()
+ .hostname(HOST_NAME)
+ .type(KubevirtNode.Type.GATEWAY)
+ .dataIp(IpAddress.valueOf("10.134.34.222"))
+ .managementIp(IpAddress.valueOf("10.134.231.30"))
+ .intgBridge(DeviceId.deviceId("of:00000000000000a1"))
+ .tunBridge(DeviceId.deviceId("of:00000000000000a2"))
+ .state(KubevirtNodeState.COMPLETE)
+ .build();
+
+
+ private static final KubevirtRouter ROUTER_1 = DefaultKubevirtRouter.builder()
+ .name(ROUTER_NAME).build();
+
+ /**
+ * Constructs a kubevirt mm5 resource test instance.
+ */
+ public KubevirtMm5WebResourceTest() {
+ super(ResourceConfig.forApplicationClass(KubevirtNetworkingWebApplication.class));
+ }
+
+ /**
+ * Sets up the global values for all the tests.
+ */
+ @Before
+ public void setUpTest() {
+ final CodecManager codecService = new CodecManager();
+ codecService.activate();
+ codecService.registerCodec(KubevirtNetwork.class, new KubevirtNetworkCodec());
+ codecService.registerCodec(KubevirtHostRoute.class, new KubevirtHostRouteCodec());
+ codecService.registerCodec(KubevirtIpPool.class, new KubevirtIpPoolCodec());
+
+ ServiceDirectory testDirectory =
+ new TestServiceDirectory()
+ .add(KubevirtNodeService.class, mockNodeService)
+ .add(KubevirtNetworkService.class, mockNetworkService)
+ .add(KubevirtRouterService.class, mockRouterService)
+ .add(CodecService.class, codecService);
+
+ setServiceDirectory(testDirectory);
+ }
+
+ @Test
+ public void testVrStatusWithExistingRouterOperation() {
+ expect(mockRouterService.routers()).andReturn(ImmutableSet.of(ROUTER_1)).anyTimes();
+ replay(mockRouterService);
+
+ final WebTarget wt = target();
+
+ final String stringResponse = wt.path(VR_STATUS_PATH + ROUTER_NAME).request().get(String.class);
+ final Response response = wt.path(VR_STATUS_PATH + ROUTER_NAME).request().get();
+
+ final JsonObject result = Json.parse(stringResponse).asObject();
+
+ assertThat(result, notNullValue());
+ assertThat(result.names(), hasSize(4));
+ assertThat(response.getStatus(), is(200));
+
+ verify(mockRouterService);
+ }
+
+ @Test
+ public void testVrStatusWithNonRouterOperation() {
+ expect(mockRouterService.routers()).andReturn(ImmutableSet.of(ROUTER_1)).anyTimes();
+ replay(mockRouterService);
+
+ final WebTarget wt = target();
+
+ final Response response = wt.path(VR_STATUS_PATH + "anyRouter").request().get();
+ assertThat(response.getStatus(), is(404));
+
+ verify(mockRouterService);
+ }
+
+ @Test
+ public void testGetNetworkOperation() {
+ expect(mockNetworkService.networks()).andReturn(ImmutableSet.of(NETWORK_1)).anyTimes();
+ replay(mockNetworkService);
+
+ final WebTarget wt = target();
+
+ final String response = wt.path(NETWORK_PATH).request().get(String.class);
+ final JsonObject result = Json.parse(response).asObject();
+
+ assertThat(result, notNullValue());
+ assertThat(result.names(), hasSize(1));
+ assertThat(result.names().get(0), is("networks"));
+
+ final JsonArray jsonNodes = result.get("networks").asArray();
+ assertThat(jsonNodes, notNullValue());
+ assertThat(jsonNodes.size(), is(1));
+
+ verify(mockNetworkService);
+ }
+}
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/DefaultKubevirtApiConfig.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/DefaultKubevirtApiConfig.java
index 1cf58ed..753d360 100644
--- a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/DefaultKubevirtApiConfig.java
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/DefaultKubevirtApiConfig.java
@@ -41,6 +41,8 @@
private final String serviceFqdn;
private final String apiServerFqdn;
private final IpAddress controllerIp;
+ private final String datacenterId;
+ private final String clusterId;
/**
* Default constructor for Kubevirt API config.
@@ -56,13 +58,15 @@
* @param serviceFqdn service FQDN
* @param apiServerFqdn API server FQDN
* @param controllerIp controller IP address
+ * @param datacenterId datacenter Id
+ * @param clusterId cluster Id
*/
private DefaultKubevirtApiConfig(Scheme scheme, IpAddress ipAddress,
- int port, State state,
- String token, String caCertData,
- String clientCertData, String clientKeyData,
- String serviceFqdn, String apiServerFqdn,
- IpAddress controllerIp) {
+ int port, State state,
+ String token, String caCertData,
+ String clientCertData, String clientKeyData,
+ String serviceFqdn, String apiServerFqdn,
+ IpAddress controllerIp, String datacenterId, String clusterId) {
this.scheme = scheme;
this.ipAddress = ipAddress;
this.port = port;
@@ -74,6 +78,8 @@
this.serviceFqdn = serviceFqdn;
this.apiServerFqdn = apiServerFqdn;
this.controllerIp = controllerIp;
+ this.datacenterId = datacenterId;
+ this.clusterId = clusterId;
}
@Override
@@ -110,6 +116,8 @@
.serviceFqdn(serviceFqdn)
.apiServerFqdn(apiServerFqdn)
.controllerIp(controllerIp)
+ .datacenterId(datacenterId)
+ .clusterId(clusterId)
.build();
}
@@ -127,6 +135,8 @@
.serviceFqdn(serviceFqdn)
.apiServerFqdn(apiServerFqdn)
.controllerIp(controllerIp)
+ .datacenterId(datacenterId)
+ .clusterId(clusterId)
.build();
}
@@ -144,6 +154,8 @@
.serviceFqdn(serviceFqdn)
.apiServerFqdn(apiServerFqdn)
.controllerIp(controllerIp)
+ .datacenterId(datacenterId)
+ .clusterId(clusterId)
.build();
}
@@ -183,6 +195,16 @@
}
@Override
+ public String datacenterId() {
+ return datacenterId;
+ }
+
+ @Override
+ public String clusterId() {
+ return clusterId;
+ }
+
+ @Override
public boolean equals(Object o) {
if (this == o) {
return true;
@@ -198,14 +220,16 @@
clientKeyData.equals(that.clientKeyData) &&
Objects.equals(serviceFqdn, that.serviceFqdn) &&
Objects.equals(apiServerFqdn, that.apiServerFqdn) &&
- Objects.equals(controllerIp, that.controllerIp);
+ Objects.equals(controllerIp, that.controllerIp) &&
+ Objects.equals(datacenterId, that.datacenterId) &&
+ Objects.equals(clusterId, that.clusterId);
}
@Override
public int hashCode() {
return Objects.hash(scheme, ipAddress, port, state, token,
caCertData, clientCertData, clientKeyData, serviceFqdn,
- apiServerFqdn, controllerIp);
+ apiServerFqdn, controllerIp, datacenterId, clusterId);
}
@Override
@@ -222,6 +246,8 @@
.add("serviceFqdn", serviceFqdn)
.add("apiServerFqdn", apiServerFqdn)
.add("controllerIp", controllerIp)
+ .add("datacenterId", datacenterId)
+ .add("clusterId", clusterId)
.toString();
}
@@ -247,6 +273,8 @@
private String serviceFqdn;
private String apiServerFqdn;
private IpAddress controllerIp;
+ private String datacenterId;
+ private String clusterId;
@Override
public KubevirtApiConfig build() {
@@ -262,7 +290,7 @@
return new DefaultKubevirtApiConfig(scheme, ipAddress, port, state,
token, caCertData, clientCertData, clientKeyData, serviceFqdn,
- apiServerFqdn, controllerIp);
+ apiServerFqdn, controllerIp, datacenterId, clusterId);
}
@Override
@@ -330,5 +358,17 @@
this.controllerIp = controllerIp;
return this;
}
+
+ @Override
+ public Builder datacenterId(String datacenterId) {
+ this.datacenterId = datacenterId;
+ return this;
+ }
+
+ @Override
+ public Builder clusterId(String clusterId) {
+ this.clusterId = clusterId;
+ return this;
+ }
}
}
diff --git a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtApiConfig.java b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtApiConfig.java
index 74ad4cb..c56c9b6 100644
--- a/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtApiConfig.java
+++ b/apps/kubevirt-node/api/src/main/java/org/onosproject/kubevirtnode/api/KubevirtApiConfig.java
@@ -154,6 +154,20 @@
IpAddress controllerIp();
/**
+ * Returns the datacenter id.
+ *
+ * @return datacenter id.
+ */
+ String datacenterId();
+
+ /**
+ * Returns the cluster id.
+ *
+ * @return cluster id.
+ */
+ String clusterId();
+
+ /**
* Builder of new API config entity.
*/
interface Builder {
@@ -252,5 +266,21 @@
* @return Kubevirt API config builder
*/
Builder controllerIp(IpAddress controllerIp);
+
+ /**
+ * Returns kubevirt API server config builder with the supplied datacenter id.
+ *
+ * @param datacenteId datacenter id
+ * @return Kubevirt API config builder
+ */
+ Builder datacenterId(String datacenteId);
+
+ /**
+ * Returns kubevirt API server config builder with the supplied cluster id.
+ *
+ * @param clusterId cluster id
+ * @return Kubevirt API config builder
+ */
+ Builder clusterId(String clusterId);
}
}
diff --git a/apps/kubevirt-node/api/src/test/java/org/onosproject/kubevirtnode/api/DefaultKubevirtApiConfigTest.java b/apps/kubevirt-node/api/src/test/java/org/onosproject/kubevirtnode/api/DefaultKubevirtApiConfigTest.java
index 7b98323..486e0dc 100644
--- a/apps/kubevirt-node/api/src/test/java/org/onosproject/kubevirtnode/api/DefaultKubevirtApiConfigTest.java
+++ b/apps/kubevirt-node/api/src/test/java/org/onosproject/kubevirtnode/api/DefaultKubevirtApiConfigTest.java
@@ -62,6 +62,13 @@
private static final IpAddress CONTROLLER_IP_1 = IpAddress.valueOf("127.0.0.1");
private static final IpAddress CONTROLLER_IP_2 = IpAddress.valueOf("169.254.169.254");
+ private static final String DATACENTER_ID_1 = "BD";
+ private static final String DATACENTER_ID_2 = "SS";
+
+ private static final String CLUSTER_ID_1 = "BD-CT-01";
+ private static final String CLUSTER_ID_2 = "SS-CT-01";
+
+
private KubevirtApiConfig config1;
private KubevirtApiConfig sameAsConfig1;
private KubevirtApiConfig config2;
@@ -91,6 +98,8 @@
.serviceFqdn(SERVICE_FQDN_1)
.apiServerFqdn(API_SERVER_FQDN_1)
.controllerIp(CONTROLLER_IP_1)
+ .datacenterId(DATACENTER_ID_1)
+ .clusterId(CLUSTER_ID_1)
.build();
sameAsConfig1 = DefaultKubevirtApiConfig.builder()
@@ -105,6 +114,8 @@
.serviceFqdn(SERVICE_FQDN_1)
.apiServerFqdn(API_SERVER_FQDN_1)
.controllerIp(CONTROLLER_IP_1)
+ .datacenterId(DATACENTER_ID_1)
+ .clusterId(CLUSTER_ID_1)
.build();
config2 = DefaultKubevirtApiConfig.builder()
@@ -119,6 +130,8 @@
.serviceFqdn(SERVICE_FQDN_2)
.apiServerFqdn(API_SERVER_FQDN_2)
.controllerIp(CONTROLLER_IP_2)
+ .datacenterId(DATACENTER_ID_2)
+ .clusterId(CLUSTER_ID_2)
.build();
}
@@ -150,5 +163,7 @@
assertEquals(SERVICE_FQDN_1, config.serviceFqdn());
assertEquals(API_SERVER_FQDN_1, config.apiServerFqdn());
assertEquals(CONTROLLER_IP_1, config.controllerIp());
+ assertEquals(DATACENTER_ID_1, config.datacenterId());
+ assertEquals(CLUSTER_ID_1, config.clusterId());
}
}
diff --git a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtListApiConfigsCommand.java b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtListApiConfigsCommand.java
index 5b9c268..75d4ced 100644
--- a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtListApiConfigsCommand.java
+++ b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtListApiConfigsCommand.java
@@ -33,7 +33,7 @@
description = "Lists all KubeVirt API server configs registered to the service")
public class KubevirtListApiConfigsCommand extends AbstractShellCommand {
- private static final String FORMAT = "%-10s%-20s%-10s%-25s%-10s";
+ private static final String FORMAT = "%-10s%-20s%-10s%-25s%-10s%-20s%-20s";
@Override
protected void doExecute() throws Exception {
@@ -43,14 +43,14 @@
if (outputJson()) {
print("%s", json(config));
} else {
- print(FORMAT, "Scheme", "Server IP", "Port", "Controller IP", "State");
+ print(FORMAT, "Scheme", "Server IP", "Port", "Controller IP", "State", "Datacenter ID", "Cluster ID");
String controllerIp = "N/A";
if (config != null) {
if (config.controllerIp() != null) {
controllerIp = config.controllerIp().toString();
}
print(FORMAT, config.scheme().name(), config.ipAddress().toString(),
- config.port(), controllerIp, config.state().name());
+ config.port(), controllerIp, config.state().name(), config.datacenterId(), config.clusterId());
} else {
print("Kubevirt config not found!");
}
diff --git a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodec.java b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodec.java
index 9fc2099..e79843f 100644
--- a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodec.java
+++ b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodec.java
@@ -44,6 +44,8 @@
private static final String SERVICE_FQDN = "serviceFqdn";
private static final String API_SERVER_FQDN = "apiServerFqdn";
private static final String CONTROLLER_IP = "controllerIp";
+ private static final String DATACENTER_ID = "datacenterId";
+ private static final String CLUSTER_ID = "clusterId";
private static final String MISSING_MESSAGE = " is required in KubevirtApiConfig";
@@ -53,7 +55,9 @@
.put(SCHEME, entity.scheme().name())
.put(IP_ADDRESS, entity.ipAddress().toString())
.put(PORT, entity.port())
- .put(STATE, entity.state().name());
+ .put(STATE, entity.state().name())
+ .put(DATACENTER_ID, entity.datacenterId())
+ .put(CLUSTER_ID, entity.clusterId());
if (entity.scheme() == HTTPS) {
node.put(CA_CERT_DATA, entity.caCertData())
@@ -122,6 +126,8 @@
JsonNode serviceFqdn = json.get(SERVICE_FQDN);
JsonNode apiServerFqdn = json.get(API_SERVER_FQDN);
JsonNode controllerIp = json.get(CONTROLLER_IP);
+ JsonNode datacenterId = json.get(DATACENTER_ID);
+ JsonNode clusterId = json.get(CLUSTER_ID);
String token = "";
String caCertData = "";
@@ -186,6 +192,14 @@
builder.controllerIp(IpAddress.valueOf(controllerIp.asText()));
}
+ if (datacenterId != null) {
+ builder.datacenterId(datacenterId.asText());
+ }
+
+ if (clusterId != null) {
+ builder.clusterId(clusterId.asText());
+ }
+
return builder.build();
}
}
diff --git a/apps/kubevirt-node/app/src/main/resources/definitions/KubevirtApiConfig.json b/apps/kubevirt-node/app/src/main/resources/definitions/KubevirtApiConfig.json
index 4e0800d..88c5520 100644
--- a/apps/kubevirt-node/app/src/main/resources/definitions/KubevirtApiConfig.json
+++ b/apps/kubevirt-node/app/src/main/resources/definitions/KubevirtApiConfig.json
@@ -5,7 +5,9 @@
"segmentId",
"scheme",
"ipAddress",
- "port"
+ "port",
+ "datacenterId",
+ "clusterId"
],
"properties": {
"clusterName": {
@@ -27,6 +29,14 @@
"port": {
"type": "integer",
"example": 6443
+ },
+ "datacenterId": {
+ "type": "string",
+ "example": "BD"
+ },
+ "clusterId": {
+ "type": "string",
+ "example": "BD-MEH-CT01"
}
}
}
\ No newline at end of file
diff --git a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodecTest.java b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodecTest.java
index 16af906..06dfd48 100644
--- a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodecTest.java
+++ b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodecTest.java
@@ -89,7 +89,10 @@
.serviceFqdn("kubevirt.edgestack.svc.cluster.local")
.apiServerFqdn("kubernetes.default.svc.cluster.local")
.controllerIp(IpAddress.valueOf("127.0.0.1"))
+ .datacenterId("BD")
+ .clusterId("BD-MEH-CT01")
.build();
+
ObjectNode configJson = kubevirtApiConfigCodec.encode(config, context);
assertThat(configJson, matchesKubevirtApiConfig(config));
}
@@ -113,6 +116,9 @@
assertEquals("kubevirt.edgestack.svc.cluster.local", config.serviceFqdn());
assertEquals("kubernetes.default.svc.cluster.local", config.apiServerFqdn());
assertEquals("127.0.0.1", config.controllerIp().toString());
+ assertEquals("BD", config.datacenterId());
+ assertEquals("BD-MEH-CT01", config.clusterId());
+
}
private KubevirtApiConfig getKubevirtApiConfig(String resourceName) throws IOException {
diff --git a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/impl/KubevirtApiConfigManagerTest.java b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/impl/KubevirtApiConfigManagerTest.java
index 0e5db34..98a6b1e 100644
--- a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/impl/KubevirtApiConfigManagerTest.java
+++ b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/impl/KubevirtApiConfigManagerTest.java
@@ -74,12 +74,16 @@
.ipAddress(IpAddress.valueOf("10.10.10.2"))
.port(6443)
.state(DISCONNECTED)
+ .datacenterId("BD")
+ .clusterId("BD-MEH-CT01")
.build();
apiConfig2 = DefaultKubevirtApiConfig.builder()
.scheme(KubevirtApiConfig.Scheme.HTTP)
.ipAddress(IpAddress.valueOf("10.10.10.3"))
.port(6443)
.state(DISCONNECTED)
+ .datacenterId("BD")
+ .clusterId("BD-MEH-CT01")
.build();
configStore = new DistributedKubevirtApiConfigStore();
diff --git a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtApiConfigWebResourceTest.java b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtApiConfigWebResourceTest.java
index e6d1034..5a72b49 100644
--- a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtApiConfigWebResourceTest.java
+++ b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtApiConfigWebResourceTest.java
@@ -87,6 +87,8 @@
.caCertData("caCertData")
.clientCertData("clientCertData")
.clientKeyData("clientKeyData")
+ .datacenterId("DB")
+ .clusterId("BD-MEH-CT01")
.build();
}
diff --git a/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/codec/KubevirtApiConfig.json b/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/codec/KubevirtApiConfig.json
index b95c29a..5f48d0a 100644
--- a/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/codec/KubevirtApiConfig.json
+++ b/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/codec/KubevirtApiConfig.json
@@ -8,5 +8,7 @@
"clientKeyData": "clientKeyData",
"serviceFqdn": "kubevirt.edgestack.svc.cluster.local",
"apiServerFqdn": "kubernetes.default.svc.cluster.local",
- "controllerIp": "127.0.0.1"
+ "controllerIp": "127.0.0.1",
+ "datacenterId": "BD",
+ "clusterId": "BD-MEH-CT01"
}
\ No newline at end of file
diff --git a/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/web/kubevirt-api-config.json b/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/web/kubevirt-api-config.json
index 7a5c5f5..b256cc4 100644
--- a/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/web/kubevirt-api-config.json
+++ b/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/web/kubevirt-api-config.json
@@ -6,5 +6,7 @@
"caCertData": "caCertData",
"clientCertData": "clientCertData",
"clientKeyData": "clientKeyData",
- "controllerIp": "127.0.0.1"
+ "controllerIp": "127.0.0.1",
+ "datacenterId": "BD",
+ "clusterId": "BD-MEH-CT01"
}
\ No newline at end of file