blob: 54accd351c0a452a176a2d48fa145373fbb9fc9e [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
slowr577f3222017-08-28 10:49:08 -07002 * Copyright 2016-present Open Networking Foundation
slowr13fa5b02017-08-08 16:32:31 -07003 *
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;
slowr577f3222017-08-28 10:49:08 -070026import org.onosproject.xran.rest.ResponseHelper.StatusCode;
slowr13fa5b02017-08-08 16:32:31 -070027import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
slowr13fa5b02017-08-08 16:32:31 -070030import javax.ws.rs.GET;
31import javax.ws.rs.Path;
32import javax.ws.rs.PathParam;
33import javax.ws.rs.Produces;
slowr577f3222017-08-28 10:49:08 -070034import javax.ws.rs.Consumes;
slowr13fa5b02017-08-08 16:32:31 -070035import 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 /**
slowr577f3222017-08-28 10:49:08 -070054 * Lists the cell with {cellid}.
slowr13fa5b02017-08-08 16:32:31 -070055 *
slowr577f3222017-08-28 10:49:08 -070056 * @param eciHex EutranCellIdentifier in binary
57 * @return Response
slowr13fa5b02017-08-08 16:32:31 -070058 */
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(),
slowr577f3222017-08-28 10:49:08 -070071 StatusCode.OK,
slowr60d4d102017-08-16 18:33:58 -070072 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(),
slowr577f3222017-08-28 10:49:08 -070082 StatusCode.INTERNAL_SERVER_ERROR,
slowr60d4d102017-08-16 18:33:58 -070083 "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(),
slowr577f3222017-08-28 10:49:08 -070091 StatusCode.NOT_FOUND,
slowr60d4d102017-08-16 18:33:58 -070092 "Not Found",
93 "Cell with " + eciHex + " was not found"
94 );
slowr13fa5b02017-08-08 16:32:31 -070095 }
96
97 /**
slowr577f3222017-08-28 10:49:08 -070098 * Modify the RRMConfig parameters of the cell.
slowr13fa5b02017-08-08 16:32:31 -070099 *
slowr577f3222017-08-28 10:49:08 -0700100 * @param eciHex EutranCellIdentifier in binary
101 * @param stream Parameters that you want to modify
102 * @return Response
slowr13fa5b02017-08-08 16:32:31 -0700103 */
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];
slowr577f3222017-08-28 10:49:08 -0700118 get(XranStore.class).modifycellrrmconf(cell, rrmConf);
slowr8ddc2b12017-08-14 14:13:38 -0700119
slowr577f3222017-08-28 10:49:08 -0700120 queue[0] = get(XranController.class).sendmodifiedrrmconf(cell.getRrmConfig(),
slowred74ec72017-08-17 11:25:01 -0700121 cell.getVersion() <= 3);
slowr577f3222017-08-28 10:49:08 -0700122 String poll = queue[0].poll(get(XranController.class)
123 .getNorthboundTimeout(), TimeUnit.MILLISECONDS);
slowr8ddc2b12017-08-14 14:13:38 -0700124
125 if (poll != null) {
slowr60d4d102017-08-16 18:33:58 -0700126 return ResponseHelper.getResponse(
127 mapper(),
slowr577f3222017-08-28 10:49:08 -0700128 StatusCode.OK,
slowr60d4d102017-08-16 18:33:58 -0700129 "Handoff Response",
130 poll
131 );
slowr8ddc2b12017-08-14 14:13:38 -0700132 } else {
slowr60d4d102017-08-16 18:33:58 -0700133 return ResponseHelper.getResponse(
134 mapper(),
slowr577f3222017-08-28 10:49:08 -0700135 StatusCode.REQUEST_TIMEOUT,
slowr60d4d102017-08-16 18:33:58 -0700136 "Handoff Timeout",
137 "eNodeB did not send a HOComplete/HOFailure on time"
138 );
slowr8ddc2b12017-08-14 14:13:38 -0700139 }
slowr67d05e42017-08-11 20:37:22 -0700140 }
slowrd19a83b2017-08-17 08:57:46 -0700141
142 return ResponseHelper.getResponse(
143 mapper(),
slowr577f3222017-08-28 10:49:08 -0700144 StatusCode.BAD_REQUEST,
slowr73b4eae2017-08-17 16:09:09 -0700145 "Bad Request",
slowrd19a83b2017-08-17 08:57:46 -0700146 "The command you specified is not implemented or doesn't exist. We support " +
147 "RRMConf commands."
148 );
slowr8ddc2b12017-08-14 14:13:38 -0700149 } catch (Exception e) {
slowr60d4d102017-08-16 18:33:58 -0700150 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
151 log.error(fullStackTrace);
slowr8ddc2b12017-08-14 14:13:38 -0700152 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -0700153
154 return ResponseHelper.getResponse(
155 mapper(),
slowr577f3222017-08-28 10:49:08 -0700156 StatusCode.INTERNAL_SERVER_ERROR,
slowr60d4d102017-08-16 18:33:58 -0700157 "Exception",
158 fullStackTrace
159 );
slowr13fa5b02017-08-08 16:32:31 -0700160 }
slowr13fa5b02017-08-08 16:32:31 -0700161 }
slowr8ddc2b12017-08-14 14:13:38 -0700162
slowr60d4d102017-08-16 18:33:58 -0700163 return ResponseHelper.getResponse(
164 mapper(),
slowr577f3222017-08-28 10:49:08 -0700165 StatusCode.NOT_FOUND,
slowr60d4d102017-08-16 18:33:58 -0700166 "Not Found",
167 "Cell " + eciHex + " was not found"
168 );
slowr13fa5b02017-08-08 16:32:31 -0700169 }
170
171}