blob: c738b401a66afbfa9c33260f84b028fd9ef90568 [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;
slowr60d4d102017-08-16 18:33:58 -070026import org.onosproject.xran.rest.ResponseHelper.statusCode;
slowr13fa5b02017-08-08 16:32:31 -070027import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
30import javax.ws.rs.Consumes;
31import javax.ws.rs.GET;
32import javax.ws.rs.Path;
33import javax.ws.rs.PathParam;
34import javax.ws.rs.Produces;
35import javax.ws.rs.core.MediaType;
36import javax.ws.rs.core.Response;
slowr13fa5b02017-08-08 16:32:31 -070037import 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
slowr60d4d102017-08-16 18:33:58 -070050 public CellWebResource() {
51 }
52
slowr13fa5b02017-08-08 16:32:31 -070053 /**
54 * test.
55 *
56 * @param eciHex test
57 * @return test
58 */
59 @GET
60 @Path("{cellid}")
61 @Produces(MediaType.APPLICATION_JSON)
62 public Response getCell(@PathParam("cellid") String eciHex) {
slowr13fa5b02017-08-08 16:32:31 -070063 RnibCell cell = get(XranStore.class).getCell(eciHex);
64
slowr13fa5b02017-08-08 16:32:31 -070065 if (cell != null) {
66 try {
slowr60d4d102017-08-16 18:33:58 -070067 JsonNode jsonNode = mapper().valueToTree(cell);
slowr8ddc2b12017-08-14 14:13:38 -070068
slowr60d4d102017-08-16 18:33:58 -070069 return ResponseHelper.getResponse(
70 mapper(),
71 statusCode.OK,
72 jsonNode
73 );
74
75 } catch (Exception e) {
76 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
77 log.error(fullStackTrace);
slowr13fa5b02017-08-08 16:32:31 -070078 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -070079
80 return ResponseHelper.getResponse(
81 mapper(),
82 statusCode.INTERNAL_SERVER_ERROR,
83 "Exception",
84 fullStackTrace
85 );
slowr13fa5b02017-08-08 16:32:31 -070086 }
slowr13fa5b02017-08-08 16:32:31 -070087 }
88
slowr60d4d102017-08-16 18:33:58 -070089 return ResponseHelper.getResponse(
90 mapper(),
91 statusCode.NOT_FOUND,
92 "Not Found",
93 "Cell with " + eciHex + " was not found"
94 );
slowr13fa5b02017-08-08 16:32:31 -070095 }
96
97 /**
98 * test.
99 *
100 * @param eciHex test
slowr67d05e42017-08-11 20:37:22 -0700101 * @param stream test (body of request)
slowr13fa5b02017-08-08 16:32:31 -0700102 * @return test
103 */
104 @Patch
105 @Path("{cellid}")
106 @Consumes(MediaType.APPLICATION_JSON)
slowr60d4d102017-08-16 18:33:58 -0700107 @Produces(MediaType.APPLICATION_JSON)
slowr13fa5b02017-08-08 16:32:31 -0700108 public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) {
slowr67d05e42017-08-11 20:37:22 -0700109 RnibCell cell = get(XranStore.class).getCell(eciHex);
slowr13fa5b02017-08-08 16:32:31 -0700110
slowr8ddc2b12017-08-14 14:13:38 -0700111 if (cell != null) {
112 try {
113 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
slowr13fa5b02017-08-08 16:32:31 -0700114
slowr89c2ac12017-08-15 16:20:06 -0700115 JsonNode rrmConf = jsonTree.path("RRMConf");
116 if (!rrmConf.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700117 final SynchronousQueue<String>[] queue = new SynchronousQueue[1];
118 get(XranStore.class).modifyCellRrmConf(cell, rrmConf);
119
120 queue[0] = get(XranController.class).sendModifiedRRMConf(cell.getRrmConfig(),
slowred74ec72017-08-17 11:25:01 -0700121 cell.getVersion() <= 3);
slowr8ddc2b12017-08-14 14:13:38 -0700122 String poll = queue[0].poll(5, TimeUnit.SECONDS);
123
124 if (poll != null) {
slowr60d4d102017-08-16 18:33:58 -0700125 return ResponseHelper.getResponse(
126 mapper(),
127 statusCode.OK,
128 "Handoff Response",
129 poll
130 );
slowr8ddc2b12017-08-14 14:13:38 -0700131 } else {
slowr60d4d102017-08-16 18:33:58 -0700132 return ResponseHelper.getResponse(
133 mapper(),
134 statusCode.REQUEST_TIMEOUT,
135 "Handoff Timeout",
136 "eNodeB did not send a HOComplete/HOFailure on time"
137 );
slowr8ddc2b12017-08-14 14:13:38 -0700138 }
slowr67d05e42017-08-11 20:37:22 -0700139 }
slowrd19a83b2017-08-17 08:57:46 -0700140
141 return ResponseHelper.getResponse(
142 mapper(),
slowr73b4eae2017-08-17 16:09:09 -0700143 ResponseHelper.statusCode.BAD_REQUEST,
144 "Bad Request",
slowrd19a83b2017-08-17 08:57:46 -0700145 "The command you specified is not implemented or doesn't exist. We support " +
146 "RRMConf commands."
147 );
slowr8ddc2b12017-08-14 14:13:38 -0700148 } catch (Exception e) {
slowr60d4d102017-08-16 18:33:58 -0700149 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
150 log.error(fullStackTrace);
slowr8ddc2b12017-08-14 14:13:38 -0700151 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -0700152
153 return ResponseHelper.getResponse(
154 mapper(),
155 statusCode.INTERNAL_SERVER_ERROR,
156 "Exception",
157 fullStackTrace
158 );
slowr13fa5b02017-08-08 16:32:31 -0700159 }
slowr13fa5b02017-08-08 16:32:31 -0700160 }
slowr8ddc2b12017-08-14 14:13:38 -0700161
slowr60d4d102017-08-16 18:33:58 -0700162 return ResponseHelper.getResponse(
163 mapper(),
164 statusCode.NOT_FOUND,
165 "Not Found",
166 "Cell " + eciHex + " was not found"
167 );
slowr13fa5b02017-08-08 16:32:31 -0700168 }
169
170}