ONOS-5182 Simplified OpenStack networking application structure
Change-Id: Ic7941f2c9a2febec4f24745278c4c305a3937097
diff --git a/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpensatckRouterWebResource.java b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpensatckRouterWebResource.java
new file mode 100644
index 0000000..c39afd6
--- /dev/null
+++ b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpensatckRouterWebResource.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.openstacknetworking.web;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.openstackinterface.OpenstackRouter;
+import org.onosproject.openstackinterface.OpenstackRouterInterface;
+import org.onosproject.openstackinterface.web.OpenstackRouterCodec;
+import org.onosproject.openstackinterface.web.OpenstackRouterInterfaceCodec;
+import org.onosproject.openstacknetworking.api.OpenstackRoutingService;
+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.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.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Handles REST API call of Neturon L3 plugin.
+ */
+
+@Path("routers")
+public class OpensatckRouterWebResource extends AbstractWebResource {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final OpenstackRouterInterfaceCodec ROUTER_INTERFACE_CODEC
+ = new OpenstackRouterInterfaceCodec();
+ private static final OpenstackRouterCodec ROUTER_CODEC
+ = new OpenstackRouterCodec();
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createRouter(InputStream input) {
+ checkNotNull(input);
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode routerNode = (ObjectNode) mapper.readTree(input);
+
+ OpenstackRouter openstackRouter
+ = ROUTER_CODEC.decode(routerNode, this);
+
+ OpenstackRoutingService routingService
+ = getService(OpenstackRoutingService.class);
+ routingService.createRouter(openstackRouter);
+
+ log.debug("REST API CREATE router is called {}", input.toString());
+ return Response.status(Response.Status.OK).build();
+ } catch (Exception e) {
+ log.error("Create Router failed because of exception {}",
+ e.toString());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
+ .build();
+ }
+ }
+
+ @PUT
+ @Path("{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateRouter(@PathParam("id") String id, InputStream input) {
+ checkNotNull(input);
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode routerNode = (ObjectNode) mapper.readTree(input);
+
+ OpenstackRouter or = ROUTER_CODEC.decode(routerNode, this);
+
+ OpenstackRouter.Builder osBuilder = new OpenstackRouter.Builder()
+ .tenantId(or.tenantId())
+ .id(id)
+ .name(or.name())
+ .status(OpenstackRouter.RouterStatus.ACTIVE)
+ .adminStateUp(Boolean.valueOf(or.adminStateUp()))
+ .gatewayExternalInfo(or.gatewayExternalInfo());
+
+ OpenstackRoutingService routingService
+ = getService(OpenstackRoutingService.class);
+ routingService.updateRouter(osBuilder.build());
+
+ log.debug("REST API UPDATE router is called from router {}", input.toString());
+ return Response.status(Response.Status.OK).build();
+ } catch (Exception e) {
+ log.error("Updates Router failed because of exception {}",
+ e.toString());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
+ .build();
+ }
+ }
+
+ @PUT
+ @Path("{id}/add_router_interface")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response addRouterInterface(@PathParam("id") String id, InputStream input) {
+ checkNotNull(input);
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode routerIfNode = (ObjectNode) mapper.readTree(input);
+
+ OpenstackRouterInterface openstackRouterInterface
+ = ROUTER_INTERFACE_CODEC.decode(routerIfNode, this);
+
+ OpenstackRoutingService routingService
+ = getService(OpenstackRoutingService.class);
+ routingService.addRouterInterface(openstackRouterInterface);
+
+ log.debug("REST API AddRouterInterface is called from router {} portId: {}, subnetId: {}, tenantId: {}",
+ openstackRouterInterface.id(), openstackRouterInterface.portId(),
+ openstackRouterInterface.subnetId(), openstackRouterInterface.tenantId());
+
+ return Response.status(Response.Status.OK).build();
+ } catch (Exception e) {
+ log.error("AddRouterInterface failed because of exception {}",
+ e.toString());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
+ .build();
+ }
+ }
+
+ @DELETE
+ @Path("{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response deleteRouter(@PathParam("id") String id) {
+ checkNotNull(id);
+ OpenstackRoutingService routingService
+ = getService(OpenstackRoutingService.class);
+ routingService.removeRouter(id);
+
+ log.debug("REST API DELETE routers is called {}", id);
+ return Response.noContent().build();
+ }
+
+ @PUT
+ @Path("{id}/remove_router_interface")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response removeRouterInterface(@PathParam("id") String id, InputStream input) {
+ checkNotNull(id);
+ checkNotNull(input);
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode routerIfNode = (ObjectNode) mapper.readTree(input);
+
+ OpenstackRouterInterface openstackRouterInterface
+ = ROUTER_INTERFACE_CODEC.decode(routerIfNode, this);
+
+ OpenstackRoutingService routingService
+ = getService(OpenstackRoutingService.class);
+ routingService.removeRouterInterface(openstackRouterInterface);
+
+ log.debug("REST API RemoveRouterInterface is called from router {} portId: {}, subnetId: {}," +
+ "tenantId: {}", openstackRouterInterface.id(), openstackRouterInterface.portId(),
+ openstackRouterInterface.subnetId(), openstackRouterInterface.tenantId());
+
+ return Response.status(Response.Status.OK).build();
+ } catch (Exception e) {
+ log.error("RemoveRouterInterface failed because of exception {}",
+ e.toString());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
+ .build();
+ }
+ }
+}
diff --git a/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackFloatingIpWebResource.java b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackFloatingIpWebResource.java
new file mode 100644
index 0000000..a6880fd
--- /dev/null
+++ b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackFloatingIpWebResource.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.openstacknetworking.web;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.openstackinterface.OpenstackFloatingIP;
+import org.onosproject.openstackinterface.web.OpenstackFloatingIpCodec;
+import org.onosproject.openstacknetworking.api.OpenstackFloatingIpService;
+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.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.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Handles REST API call of Neutron L3 plugin.
+ */
+@Path("floatingips")
+public class OpenstackFloatingIpWebResource extends AbstractWebResource {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final OpenstackFloatingIpCodec FLOATING_IP_CODEC = new OpenstackFloatingIpCodec();
+
+ /**
+ * Create FloatingIP.
+ *
+ * @param input JSON data describing FloatingIP
+ * @return 200 OK
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createFloatingIp(InputStream input) {
+ checkNotNull(input);
+
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input);
+
+ OpenstackFloatingIP osFloatingIp = FLOATING_IP_CODEC.decode(floatingIpNode, this);
+ OpenstackFloatingIpService floatingIpService =
+ getService(OpenstackFloatingIpService.class);
+ floatingIpService.createFloatingIp(osFloatingIp);
+
+ log.debug("REST API CREATE floatingip called");
+ return Response.status(Response.Status.OK).build();
+ } catch (Exception e) {
+ log.error("createFloatingIp failed with {}", e.toString());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
+ .build();
+ }
+ }
+
+ /**
+ * Update FloatingIP.
+ *
+ * @param id FloatingIP identifier
+ * @param input JSON data describing FloatingIP
+ * @return 200 OK
+ */
+ @PUT
+ @Path("{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateFloatingIp(@PathParam("id") String id, InputStream input) {
+ checkNotNull(id);
+ checkNotNull(input);
+
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input);
+
+ OpenstackFloatingIP osFloatingIp = FLOATING_IP_CODEC.decode(floatingIpNode, this);
+ OpenstackFloatingIpService floatingIpService =
+ getService(OpenstackFloatingIpService.class);
+ floatingIpService.updateFloatingIp(osFloatingIp);
+
+ log.debug("REST API UPDATE floatingip called {}", id);
+ return Response.status(Response.Status.OK).build();
+ } catch (Exception e) {
+ log.error("updateFloatingIp failed with {}", e.toString());
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
+ .build();
+ }
+ }
+
+ /**
+ * Delete FloatingIP.
+ *
+ * @param id FloatingIP identifier
+ * @return 204 OK
+ */
+ @DELETE
+ @Path("{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response deleteFloatingIp(@PathParam("id") String id) {
+ checkNotNull(id);
+
+ OpenstackFloatingIpService floatingIpService =
+ getService(OpenstackFloatingIpService.class);
+ floatingIpService.deleteFloatingIp(id);
+
+ log.debug("REST API DELETE floatingip is called {}", id);
+ return Response.noContent().build();
+ }
+
+}
diff --git a/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackNetworkWebResource.java b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackNetworkWebResource.java
new file mode 100644
index 0000000..c547b2e
--- /dev/null
+++ b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackNetworkWebResource.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.openstacknetworking.web;
+
+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.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+
+/**
+ * Handles REST API call of Neutron ML2 plugin.
+ */
+@Path("networks")
+public class OpenstackNetworkWebResource extends AbstractWebResource {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createNetwork(InputStream input) {
+ log.debug("REST API networks is called {}", input.toString());
+ return Response.status(Response.Status.OK).build();
+ }
+
+ @PUT
+ @Path("{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateNetwork(InputStream input) {
+ log.debug("REST API networks is called {}", input.toString());
+ return Response.status(Response.Status.OK).build();
+ }
+
+ @DELETE
+ @Path("{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response deleteNetwork(InputStream input) {
+ log.debug("REST API networks is called {}", input.toString());
+ return Response.noContent().build();
+ }
+}
diff --git a/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackPortWebResource.java b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackPortWebResource.java
new file mode 100644
index 0000000..7683b0c
--- /dev/null
+++ b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackPortWebResource.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.openstacknetworking.web;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.openstackinterface.OpenstackPort;
+import org.onosproject.openstackinterface.web.OpenstackPortCodec;
+import org.onosproject.openstacknetworking.api.OpenstackSecurityGroupService;
+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.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.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Handles Rest API call from Neutron ML2 plugin.
+ */
+@Path("ports")
+public class OpenstackPortWebResource extends AbstractWebResource {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private static final OpenstackPortCodec PORT_CODEC
+ = new OpenstackPortCodec();
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createPorts(InputStream input) {
+ return Response.status(Response.Status.OK).build();
+ }
+
+ @Path("{portUUID}")
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response deletePorts(@PathParam("portUUID") String id) {
+ return Response.noContent().build();
+ }
+
+ @PUT
+ @Path("{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updatePorts(@PathParam("id") String id, InputStream input) {
+ checkNotNull(input);
+ checkNotNull(id);
+
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode portNode = (ObjectNode) mapper.readTree(input);
+ OpenstackPort osPort = PORT_CODEC.decode(portNode, this);
+
+ OpenstackSecurityGroupService sgService
+ = getService(OpenstackSecurityGroupService.class);
+ sgService.updateSecurityGroup(osPort);
+
+ return Response.status(Response.Status.OK).build();
+ } catch (IOException e) {
+ log.error("UpdatePort post process failed due to {}", e.getMessage());
+
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage())
+ .build();
+ }
+ }
+}
diff --git a/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSubnetWebResource.java b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSubnetWebResource.java
new file mode 100644
index 0000000..ca9f3ab
--- /dev/null
+++ b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSubnetWebResource.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.openstacknetworking.web;
+
+/**
+ * Handles Rest API call from Neutron ML2 plugin.
+ */
+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.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.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+
+@Path("subnets")
+public class OpenstackSubnetWebResource extends AbstractWebResource {
+ protected static final Logger log = LoggerFactory
+ .getLogger(OpenstackSubnetWebResource.class);
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createSubnet(InputStream input) {
+ return Response.status(Response.Status.OK).build();
+ }
+
+
+ @PUT
+ @Path("{subnetId}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response updateSubnet(@PathParam("subnetId") String id,
+ final InputStream input) {
+ return Response.status(Response.Status.OK).build();
+ }
+
+ @DELETE
+ @Path("{subnetId}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteSubnet(@PathParam("subnetId") String id) {
+ return Response.noContent().build();
+ }
+}
diff --git a/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/package-info.java b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/package-info.java
new file mode 100644
index 0000000..9f1e043
--- /dev/null
+++ b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/web/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/**
+ * OpenStack networking implementation.
+ */
+package org.onosproject.openstacknetworking.web;