blob: 25825a9cd19180953c5098c24683d3e604469501 [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.controller.XranController;
slowr13fa5b02017-08-08 16:32:31 -070025import org.onosproject.xran.entities.RnibCell;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29import javax.ws.rs.Consumes;
30import javax.ws.rs.GET;
31import javax.ws.rs.Path;
32import javax.ws.rs.PathParam;
33import javax.ws.rs.Produces;
34import javax.ws.rs.core.MediaType;
35import javax.ws.rs.core.Response;
36import java.io.IOException;
37import java.io.InputStream;
slowr67d05e42017-08-11 20:37:22 -070038import java.util.concurrent.SynchronousQueue;
slowr8ddc2b12017-08-14 14:13:38 -070039import java.util.concurrent.TimeUnit;
slowr13fa5b02017-08-08 16:32:31 -070040
41/**
42 * Cell web resource.
43 */
44@Path("cell")
45public class CellWebResource extends AbstractWebResource {
46
47 private static final Logger log =
48 LoggerFactory.getLogger(CellWebResource.class);
49
50 /**
51 * test.
52 *
53 * @param eciHex test
54 * @return test
55 */
56 @GET
57 @Path("{cellid}")
58 @Produces(MediaType.APPLICATION_JSON)
59 public Response getCell(@PathParam("cellid") String eciHex) {
slowr13fa5b02017-08-08 16:32:31 -070060 RnibCell cell = get(XranStore.class).getCell(eciHex);
61
slowr13fa5b02017-08-08 16:32:31 -070062 if (cell != null) {
63 try {
slowr8ddc2b12017-08-14 14:13:38 -070064 ObjectNode rootNode = mapper().createObjectNode();
65
slowr13fa5b02017-08-08 16:32:31 -070066 JsonNode jsonNode = mapper().readTree(cell.toString());
67 rootNode.put("cell", jsonNode);
68 } catch (IOException e) {
69 log.error(ExceptionUtils.getFullStackTrace(e));
70 e.printStackTrace();
slowr8ddc2b12017-08-14 14:13:38 -070071 return Response.serverError()
72 .entity(ExceptionUtils.getFullStackTrace(e))
73 .build();
slowr13fa5b02017-08-08 16:32:31 -070074 }
slowr13fa5b02017-08-08 16:32:31 -070075 }
76
slowr8ddc2b12017-08-14 14:13:38 -070077 return Response.serverError().entity("cell not found").build();
slowr13fa5b02017-08-08 16:32:31 -070078 }
79
80 /**
81 * test.
82 *
83 * @param eciHex test
slowr67d05e42017-08-11 20:37:22 -070084 * @param stream test (body of request)
slowr13fa5b02017-08-08 16:32:31 -070085 * @return test
86 */
87 @Patch
88 @Path("{cellid}")
89 @Consumes(MediaType.APPLICATION_JSON)
90 public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) {
slowr67d05e42017-08-11 20:37:22 -070091 RnibCell cell = get(XranStore.class).getCell(eciHex);
slowr13fa5b02017-08-08 16:32:31 -070092
slowr8ddc2b12017-08-14 14:13:38 -070093 if (cell != null) {
94 try {
95 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
slowr13fa5b02017-08-08 16:32:31 -070096
slowr89c2ac12017-08-15 16:20:06 -070097 JsonNode rrmConf = jsonTree.path("RRMConf");
98 if (!rrmConf.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -070099 final SynchronousQueue<String>[] queue = new SynchronousQueue[1];
100 get(XranStore.class).modifyCellRrmConf(cell, rrmConf);
101
102 queue[0] = get(XranController.class).sendModifiedRRMConf(cell.getRrmConfig(),
103 cell.getVersion().equals("3"));
104 String poll = queue[0].poll(5, TimeUnit.SECONDS);
105
106 if (poll != null) {
107 return Response.ok()
108 .entity(poll)
109 .build();
110 } else {
111 return Response.serverError()
112 .entity("did not receive response in time")
113 .build();
114 }
slowr67d05e42017-08-11 20:37:22 -0700115 }
slowr8ddc2b12017-08-14 14:13:38 -0700116 } catch (Exception e) {
117 log.error(ExceptionUtils.getFullStackTrace(e));
118 e.printStackTrace();
119 return Response.serverError()
120 .entity(ExceptionUtils.getFullStackTrace(e))
121 .build();
slowr13fa5b02017-08-08 16:32:31 -0700122 }
slowr13fa5b02017-08-08 16:32:31 -0700123 }
slowr8ddc2b12017-08-14 14:13:38 -0700124
slowr89c2ac12017-08-15 16:20:06 -0700125 return Response.serverError()
126 .entity("cell not found")
127 .build();
slowr13fa5b02017-08-08 16:32:31 -0700128 }
129
130}