blob: a2b0eac42c7df5a7f3258b6162282cb21576cd89 [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 org.apache.commons.lang.exception.ExceptionUtils;
21import org.onosproject.rest.AbstractWebResource;
22import org.onosproject.xran.XranStore;
23import org.onosproject.xran.annotations.Patch;
24import org.onosproject.xran.entities.RnibCell;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28import javax.ws.rs.Consumes;
29import javax.ws.rs.GET;
30import javax.ws.rs.Path;
31import javax.ws.rs.PathParam;
32import javax.ws.rs.Produces;
33import javax.ws.rs.core.MediaType;
34import javax.ws.rs.core.Response;
35import java.io.IOException;
36import java.io.InputStream;
37
38/**
39 * Cell web resource.
40 */
41@Path("cell")
42public class CellWebResource extends AbstractWebResource {
43
44 private static final Logger log =
45 LoggerFactory.getLogger(CellWebResource.class);
46
47 /**
48 * test.
49 *
50 * @param eciHex test
51 * @return test
52 */
53 @GET
54 @Path("{cellid}")
55 @Produces(MediaType.APPLICATION_JSON)
56 public Response getCell(@PathParam("cellid") String eciHex) {
57 log.debug("GET CELLID {}", eciHex);
58
59 RnibCell cell = get(XranStore.class).getCell(eciHex);
60
61 ObjectNode rootNode = mapper().createObjectNode();
62
63 if (cell != null) {
64 try {
65 JsonNode jsonNode = mapper().readTree(cell.toString());
66 rootNode.put("cell", jsonNode);
67 } catch (IOException e) {
68 log.error(ExceptionUtils.getFullStackTrace(e));
69 e.printStackTrace();
70 }
71 } else {
72 rootNode.put("error", "not found");
73 }
74
75 return ok(rootNode.toString()).build();
76 }
77
78 /**
79 * test.
80 *
81 * @param eciHex test
82 * @param stream test
83 * @return test
84 */
85 @Patch
86 @Path("{cellid}")
87 @Consumes(MediaType.APPLICATION_JSON)
88 public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) {
89 log.debug("PATCH CELLID {}", eciHex);
90
91 boolean b = false;
92
93 try {
94 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
95
96 JsonNode rrmConf = jsonTree.get("RRMConf");
97 if (rrmConf != null) {
98 b = get(XranStore.class).modifyCellRrmConf(eciHex, rrmConf);
99 }
100 } catch (Exception e) {
101 log.error(ExceptionUtils.getFullStackTrace(e));
102 e.printStackTrace();
103 }
104
105
106 return ok(b).build();
107 }
108
109}