sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 16 | package org.onosproject.openstacknetworking.web; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 17 | |
sangho | c853a72 | 2016-07-04 21:10:42 +0900 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import org.onosproject.openstackinterface.OpenstackPort; |
| 21 | import org.onosproject.openstackinterface.web.OpenstackPortCodec; |
Hyunsun Moon | 0540087 | 2017-02-07 17:11:25 +0900 | [diff] [blame^] | 22 | import org.onosproject.openstacknetworking.api.OpenstackSecurityGroupService; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 23 | import org.onosproject.rest.AbstractWebResource; |
sangho | c853a72 | 2016-07-04 21:10:42 +0900 | [diff] [blame] | 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 26 | |
| 27 | import javax.ws.rs.Consumes; |
| 28 | import javax.ws.rs.DELETE; |
| 29 | import javax.ws.rs.POST; |
| 30 | import javax.ws.rs.PUT; |
| 31 | import javax.ws.rs.Path; |
sanghoshin | 65723ae | 2015-11-17 22:07:21 +0900 | [diff] [blame] | 32 | import javax.ws.rs.PathParam; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 33 | import javax.ws.rs.Produces; |
| 34 | import javax.ws.rs.core.MediaType; |
| 35 | import javax.ws.rs.core.Response; |
sangho | c853a72 | 2016-07-04 21:10:42 +0900 | [diff] [blame] | 36 | import java.io.IOException; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 37 | import java.io.InputStream; |
| 38 | |
sangho | c853a72 | 2016-07-04 21:10:42 +0900 | [diff] [blame] | 39 | import static com.google.common.base.Preconditions.checkNotNull; |
| 40 | |
sanghoshin | f25d2e0 | 2015-11-11 23:07:17 +0900 | [diff] [blame] | 41 | /** |
| 42 | * Handles Rest API call from Neutron ML2 plugin. |
| 43 | */ |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 44 | @Path("ports") |
| 45 | public class OpenstackPortWebResource extends AbstractWebResource { |
sangho | c853a72 | 2016-07-04 21:10:42 +0900 | [diff] [blame] | 46 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 47 | |
| 48 | private static final OpenstackPortCodec PORT_CODEC |
| 49 | = new OpenstackPortCodec(); |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 50 | |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 51 | @POST |
| 52 | @Consumes(MediaType.APPLICATION_JSON) |
| 53 | @Produces(MediaType.APPLICATION_JSON) |
| 54 | public Response createPorts(InputStream input) { |
Hyunsun Moon | b974fca | 2016-06-30 21:20:39 -0700 | [diff] [blame] | 55 | return Response.status(Response.Status.OK).build(); |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 56 | } |
| 57 | |
sanghoshin | 65723ae | 2015-11-17 22:07:21 +0900 | [diff] [blame] | 58 | @Path("{portUUID}") |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 59 | @DELETE |
jskim | 3d66aca | 2016-09-22 16:45:10 +0900 | [diff] [blame] | 60 | @Consumes(MediaType.APPLICATION_JSON) |
sanghoshin | 65723ae | 2015-11-17 22:07:21 +0900 | [diff] [blame] | 61 | public Response deletePorts(@PathParam("portUUID") String id) { |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 62 | return Response.noContent().build(); |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @PUT |
| 66 | @Path("{id}") |
| 67 | @Consumes(MediaType.APPLICATION_JSON) |
| 68 | @Produces(MediaType.APPLICATION_JSON) |
sangho | c853a72 | 2016-07-04 21:10:42 +0900 | [diff] [blame] | 69 | public Response updatePorts(@PathParam("id") String id, InputStream input) { |
| 70 | checkNotNull(input); |
| 71 | checkNotNull(id); |
| 72 | |
| 73 | try { |
| 74 | ObjectMapper mapper = new ObjectMapper(); |
| 75 | ObjectNode portNode = (ObjectNode) mapper.readTree(input); |
| 76 | OpenstackPort osPort = PORT_CODEC.decode(portNode, this); |
| 77 | |
| 78 | OpenstackSecurityGroupService sgService |
| 79 | = getService(OpenstackSecurityGroupService.class); |
| 80 | sgService.updateSecurityGroup(osPort); |
| 81 | |
| 82 | return Response.status(Response.Status.OK).build(); |
sangho | c853a72 | 2016-07-04 21:10:42 +0900 | [diff] [blame] | 83 | } catch (IOException e) { |
| 84 | log.error("UpdatePort post process failed due to {}", e.getMessage()); |
| 85 | |
| 86 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()) |
| 87 | .build(); |
| 88 | } |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 89 | } |
| 90 | } |