blob: 65772f0d04b9f04fec2fc2b360687452bd82bf04 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
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.xran.rest;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import com.google.common.collect.Lists;
21import org.apache.commons.lang.exception.ExceptionUtils;
22import org.onosproject.rest.AbstractWebResource;
23import org.onosproject.xran.XranStore;
24import org.onosproject.xran.annotations.Patch;
25import org.onosproject.xran.entities.RnibLink;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29import javax.ws.rs.Consumes;
30import javax.ws.rs.DefaultValue;
31import javax.ws.rs.GET;
32import javax.ws.rs.POST;
33import javax.ws.rs.Path;
34import javax.ws.rs.PathParam;
35import javax.ws.rs.Produces;
36import javax.ws.rs.QueryParam;
37import javax.ws.rs.core.MediaType;
38import javax.ws.rs.core.Response;
39import java.io.IOException;
40import java.io.InputStream;
41import java.util.List;
42
43/**
44 * Link web resource.
45 */
46@Path("links")
47public class LinkWebResource extends AbstractWebResource {
48
49 private static final Logger log =
50 LoggerFactory.getLogger(LinkWebResource.class);
51
52 /**
53 * test.
54 *
55 * @param eciHex test
56 * @param ue test
57 * @return test
58 */
59 @GET
60 @Produces(MediaType.APPLICATION_JSON)
61 public Response getLinksBetween(@DefaultValue("") @QueryParam("cell") String eciHex,
62 @DefaultValue("-1") @QueryParam("ue") long ue) {
63 log.debug("GET LINKS CELL {} AND UE {}", eciHex, ue);
64
65 List<RnibLink> list = Lists.newArrayList();
66 if (!eciHex.isEmpty() && ue != -1) {
67 RnibLink link = get(XranStore.class).getLinkBetweenCellIdUeId(eciHex, ue);
68 if (link != null) {
69 list.add(link);
70 }
71 } else if (!eciHex.isEmpty()) {
72 list.addAll(get(XranStore.class).getLinksByCellId(eciHex));
73 } else if (ue != -1) {
74 list.addAll(get(XranStore.class).getLinksByUeId(ue));
75 } else {
76 list.addAll(get(XranStore.class).getLinks());
77 }
78
79 ObjectNode rootNode = mapper().createObjectNode();
80
81 try {
82 JsonNode jsonNode = mapper().readTree(list.toString());
83 rootNode.put("links", jsonNode);
84 } catch (IOException e) {
85 log.error(ExceptionUtils.getFullStackTrace(e));
86 e.printStackTrace();
87 }
88
89 return ok(rootNode.toString()).build();
90 }
91
92 /**
93 * test.
94 *
95 * @param src test
96 * @param dst test
97 * @param stream test
98 * @return test
99 */
100 @Patch
101 @Path("{src},{dst}")
102 @Consumes(MediaType.APPLICATION_JSON)
103 public Response patchLinks(@PathParam("src") String src, @PathParam("dst") long dst, InputStream stream) {
104 log.debug("Patch LINKS FROM {} to {}", src, dst);
105
106 boolean b = false;
107 try {
108 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
109
110 JsonNode type = jsonTree.get("type");
111 if (type != null) {
112
113 }
114
115 JsonNode trafficpercent = jsonTree.get("trafficpercent");
116 if (trafficpercent != null) {
117
118 }
119 } catch (Exception e) {
120 log.error(ExceptionUtils.getFullStackTrace(e));
121 e.printStackTrace();
122 }
123
124 return ok(b).build();
125 }
126
127 /**
128 * test.
129 *
130 * @param src test
131 * @param dst test
132 * @param stream test
133 * @return test
134 */
135 @POST
136 @Path("{src},{dst}")
137 @Consumes(MediaType.APPLICATION_JSON)
138 public Response postLinks(@PathParam("src") String src, @PathParam("dst") long dst, InputStream stream) {
139 log.debug("POST LINKS FROM {} to {}", src, dst);
140
141 boolean b = false;
142 try {
143 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
144
145 JsonNode type = jsonTree.get("type");
146
147 if (type != null) {
148 b = get(XranStore.class).createLinkBetweenCellIdUeId(src, dst, type.asText());
149 }
150 } catch (Exception e) {
151 log.error(ExceptionUtils.getFullStackTrace(e));
152 e.printStackTrace();
153 }
154
155 return ok(b).build();
156 }
157
158}