blob: 36b5bd3631189a9b7a4134195a67873e35b3b83e [file] [log] [blame]
daniel park128c52c2017-09-04 13:15:51 +09001/*
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 */
16package org.onosproject.openstacknetworkingui.web;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.SerializationFeature;
20import com.fasterxml.jackson.databind.node.ObjectNode;
21import org.onlab.osgi.DefaultServiceDirectory;
22import org.onosproject.openstacknetworkingui.OpenstackNetworkingUiService;
23import org.onosproject.rest.AbstractWebResource;
24
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28import javax.ws.rs.Consumes;
29import javax.ws.rs.POST;
30import javax.ws.rs.Path;
31import javax.ws.rs.Produces;
32import javax.ws.rs.core.Context;
33import javax.ws.rs.core.MediaType;
34import javax.ws.rs.core.Response;
35import javax.ws.rs.core.UriInfo;
36import java.io.IOException;
37import java.io.InputStream;
38
39import static javax.ws.rs.core.Response.status;
Ray Milkey86ee5e82018-04-02 15:33:07 -070040import static org.onlab.util.Tools.readTreeFromStream;
daniel park128c52c2017-09-04 13:15:51 +090041
42/**
43 * Handles REST API from monitoring server.
44 */
45
46@Path("result")
47public 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 Milkey86ee5e82018-04-02 15:33:07 -070062 JsonNode jsonNode = readTreeFromStream(mapper().enable(SerializationFeature.INDENT_OUTPUT), inputStream);
daniel park128c52c2017-09-04 13:15:51 +090063 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}