daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 16 | package org.onosproject.openstacknetworkingui.web; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.SerializationFeature; |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | import org.onlab.osgi.DefaultServiceDirectory; |
| 22 | import org.onosproject.openstacknetworkingui.OpenstackNetworkingUiService; |
| 23 | import org.onosproject.rest.AbstractWebResource; |
| 24 | |
| 25 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; |
| 27 | |
| 28 | import javax.ws.rs.Consumes; |
| 29 | import javax.ws.rs.POST; |
| 30 | import javax.ws.rs.Path; |
| 31 | import javax.ws.rs.Produces; |
| 32 | import javax.ws.rs.core.Context; |
| 33 | import javax.ws.rs.core.MediaType; |
| 34 | import javax.ws.rs.core.Response; |
| 35 | import javax.ws.rs.core.UriInfo; |
| 36 | import java.io.IOException; |
| 37 | import java.io.InputStream; |
| 38 | |
| 39 | import static javax.ws.rs.core.Response.status; |
Ray Milkey | 86ee5e8 | 2018-04-02 15:33:07 -0700 | [diff] [blame^] | 40 | import static org.onlab.util.Tools.readTreeFromStream; |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Handles REST API from monitoring server. |
| 44 | */ |
| 45 | |
| 46 | @Path("result") |
| 47 | public class FlowTraceWebResource extends AbstractWebResource { |
| 48 | protected final Logger log = LoggerFactory.getLogger(getClass()); |
| 49 | private final OpenstackNetworkingUiService uiService = |
| 50 | DefaultServiceDirectory.getService(OpenstackNetworkingUiService.class); |
| 51 | |
| 52 | private static final String FLOW_TRACE_RESULT = "flowTraceResult"; |
| 53 | |
| 54 | @Context |
| 55 | private UriInfo uriInfo; |
| 56 | |
| 57 | @POST |
| 58 | @Consumes(MediaType.APPLICATION_JSON) |
| 59 | @Produces(MediaType.APPLICATION_JSON) |
| 60 | public Response flowTraceResponse(InputStream inputStream) throws IOException { |
| 61 | try { |
Ray Milkey | 86ee5e8 | 2018-04-02 15:33:07 -0700 | [diff] [blame^] | 62 | JsonNode jsonNode = readTreeFromStream(mapper().enable(SerializationFeature.INDENT_OUTPUT), inputStream); |
daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 63 | ObjectNode objectNode = jsonNode.deepCopy(); |
| 64 | |
| 65 | log.debug("FlowTraceResponse: {}", jsonNode.toString()); |
| 66 | |
| 67 | uiService.sendMessage(FLOW_TRACE_RESULT, objectNode); |
| 68 | |
| 69 | } catch (IOException e) { |
| 70 | log.error("Exception occured because of {}", e.toString()); |
| 71 | } |
| 72 | |
| 73 | return status(Response.Status.OK).build(); |
| 74 | } |
| 75 | |
| 76 | } |