blob: d4fbf28a2ba17feec924b4475bc12d6fe9214faa [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;
40
41/**
42 * Handles REST API from monitoring server.
43 */
44
45@Path("result")
46public class FlowTraceWebResource extends AbstractWebResource {
47 protected final Logger log = LoggerFactory.getLogger(getClass());
48 private final OpenstackNetworkingUiService uiService =
49 DefaultServiceDirectory.getService(OpenstackNetworkingUiService.class);
50
51 private static final String FLOW_TRACE_RESULT = "flowTraceResult";
52
53 @Context
54 private UriInfo uriInfo;
55
56 @POST
57 @Consumes(MediaType.APPLICATION_JSON)
58 @Produces(MediaType.APPLICATION_JSON)
59 public Response flowTraceResponse(InputStream inputStream) throws IOException {
60 try {
61 JsonNode jsonNode = mapper().enable(SerializationFeature.INDENT_OUTPUT).readTree(inputStream);
62 ObjectNode objectNode = jsonNode.deepCopy();
63
64 log.debug("FlowTraceResponse: {}", jsonNode.toString());
65
66 uiService.sendMessage(FLOW_TRACE_RESULT, objectNode);
67
68 } catch (IOException e) {
69 log.error("Exception occured because of {}", e.toString());
70 }
71
72 return status(Response.Status.OK).build();
73 }
74
75}