blob: 336f67a4ddc414a3009f708e0ec5f774127b212e [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;
slowr67d05e42017-08-11 20:37:22 -070024import org.onosproject.xran.codecs.api.ECGI;
25import org.onosproject.xran.codecs.api.EUTRANCellIdentifier;
26import org.onosproject.xran.controller.XranController;
slowr13fa5b02017-08-08 16:32:31 -070027import org.onosproject.xran.entities.RnibCell;
28import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
31import javax.ws.rs.Consumes;
32import javax.ws.rs.GET;
33import javax.ws.rs.Path;
34import javax.ws.rs.PathParam;
35import javax.ws.rs.Produces;
36import javax.ws.rs.core.MediaType;
37import javax.ws.rs.core.Response;
38import java.io.IOException;
39import java.io.InputStream;
slowr67d05e42017-08-11 20:37:22 -070040import java.util.Optional;
41import java.util.concurrent.SynchronousQueue;
slowr13fa5b02017-08-08 16:32:31 -070042
43/**
44 * Cell web resource.
45 */
46@Path("cell")
47public class CellWebResource extends AbstractWebResource {
48
49 private static final Logger log =
50 LoggerFactory.getLogger(CellWebResource.class);
51
52 /**
53 * test.
54 *
55 * @param eciHex test
56 * @return test
57 */
58 @GET
59 @Path("{cellid}")
60 @Produces(MediaType.APPLICATION_JSON)
61 public Response getCell(@PathParam("cellid") String eciHex) {
62 log.debug("GET CELLID {}", eciHex);
63
64 RnibCell cell = get(XranStore.class).getCell(eciHex);
65
66 ObjectNode rootNode = mapper().createObjectNode();
67
68 if (cell != null) {
69 try {
70 JsonNode jsonNode = mapper().readTree(cell.toString());
71 rootNode.put("cell", jsonNode);
72 } catch (IOException e) {
73 log.error(ExceptionUtils.getFullStackTrace(e));
74 e.printStackTrace();
75 }
76 } else {
77 rootNode.put("error", "not found");
78 }
79
80 return ok(rootNode.toString()).build();
81 }
82
83 /**
84 * test.
85 *
86 * @param eciHex test
slowr67d05e42017-08-11 20:37:22 -070087 * @param stream test (body of request)
slowr13fa5b02017-08-08 16:32:31 -070088 * @return test
89 */
90 @Patch
91 @Path("{cellid}")
92 @Consumes(MediaType.APPLICATION_JSON)
93 public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) {
94 log.debug("PATCH CELLID {}", eciHex);
95
slowr67d05e42017-08-11 20:37:22 -070096 boolean b;
97
98 RnibCell cell = get(XranStore.class).getCell(eciHex);
99 // Check if a cell with that ECI exists. If it does, then modify its contents.
slowr13fa5b02017-08-08 16:32:31 -0700100
101 try {
102 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
103
104 JsonNode rrmConf = jsonTree.get("RRMConf");
105 if (rrmConf != null) {
slowr67d05e42017-08-11 20:37:22 -0700106 final SynchronousQueue<String>[] queue = new SynchronousQueue[1];
107 b = get(XranStore.class).modifyCellRrmConf(cell, rrmConf);
108 if (b) {
109 queue[0] = get(XranController.class).sendModifiedRRMConf(cell);
110 return Response.ok().entity(queue[0].take()).build();
111 }
slowr13fa5b02017-08-08 16:32:31 -0700112 }
113 } catch (Exception e) {
114 log.error(ExceptionUtils.getFullStackTrace(e));
115 e.printStackTrace();
slowr67d05e42017-08-11 20:37:22 -0700116 return Response.serverError().entity(ExceptionUtils.getFullStackTrace(e)).build();
slowr13fa5b02017-08-08 16:32:31 -0700117 }
slowr67d05e42017-08-11 20:37:22 -0700118 return Response.noContent().build();
slowr13fa5b02017-08-08 16:32:31 -0700119 }
120
121}