blob: ac2806db160679f0df4ef27c8e499b03ea356cb2 [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
slowr60d4d102017-08-16 18:33:58 -070018import com.fasterxml.jackson.annotation.JsonInclude;
slowr13fa5b02017-08-08 16:32:31 -070019import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.node.ObjectNode;
21import org.apache.commons.lang.exception.ExceptionUtils;
22import org.onosproject.rest.AbstractWebResource;
23import org.onosproject.xran.XranStore;
24import org.onosproject.xran.annotations.Patch;
slowr67d05e42017-08-11 20:37:22 -070025import org.onosproject.xran.controller.XranController;
slowr13fa5b02017-08-08 16:32:31 -070026import org.onosproject.xran.entities.RnibCell;
slowr60d4d102017-08-16 18:33:58 -070027import org.onosproject.xran.rest.ResponseHelper.statusCode;
slowr13fa5b02017-08-08 16:32:31 -070028import 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;
slowr13fa5b02017-08-08 16:32:31 -070038import java.io.InputStream;
slowr67d05e42017-08-11 20:37:22 -070039import java.util.concurrent.SynchronousQueue;
slowr8ddc2b12017-08-14 14:13:38 -070040import java.util.concurrent.TimeUnit;
slowr13fa5b02017-08-08 16:32:31 -070041
42/**
43 * Cell web resource.
44 */
45@Path("cell")
46public class CellWebResource extends AbstractWebResource {
47
48 private static final Logger log =
49 LoggerFactory.getLogger(CellWebResource.class);
50
slowr60d4d102017-08-16 18:33:58 -070051 public CellWebResource() {
52 }
53
slowr13fa5b02017-08-08 16:32:31 -070054 /**
55 * test.
56 *
57 * @param eciHex test
58 * @return test
59 */
60 @GET
61 @Path("{cellid}")
62 @Produces(MediaType.APPLICATION_JSON)
63 public Response getCell(@PathParam("cellid") String eciHex) {
slowr13fa5b02017-08-08 16:32:31 -070064 RnibCell cell = get(XranStore.class).getCell(eciHex);
65
slowr13fa5b02017-08-08 16:32:31 -070066 if (cell != null) {
67 try {
slowr60d4d102017-08-16 18:33:58 -070068 JsonNode jsonNode = mapper().valueToTree(cell);
slowr8ddc2b12017-08-14 14:13:38 -070069
slowr60d4d102017-08-16 18:33:58 -070070 return ResponseHelper.getResponse(
71 mapper(),
72 statusCode.OK,
73 jsonNode
74 );
75
76 } catch (Exception e) {
77 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
78 log.error(fullStackTrace);
slowr13fa5b02017-08-08 16:32:31 -070079 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -070080
81 return ResponseHelper.getResponse(
82 mapper(),
83 statusCode.INTERNAL_SERVER_ERROR,
84 "Exception",
85 fullStackTrace
86 );
slowr13fa5b02017-08-08 16:32:31 -070087 }
slowr13fa5b02017-08-08 16:32:31 -070088 }
89
slowr60d4d102017-08-16 18:33:58 -070090 return ResponseHelper.getResponse(
91 mapper(),
92 statusCode.NOT_FOUND,
93 "Not Found",
94 "Cell with " + eciHex + " was not found"
95 );
slowr13fa5b02017-08-08 16:32:31 -070096 }
97
98 /**
99 * test.
100 *
101 * @param eciHex test
slowr67d05e42017-08-11 20:37:22 -0700102 * @param stream test (body of request)
slowr13fa5b02017-08-08 16:32:31 -0700103 * @return test
104 */
105 @Patch
106 @Path("{cellid}")
107 @Consumes(MediaType.APPLICATION_JSON)
slowr60d4d102017-08-16 18:33:58 -0700108 @Produces(MediaType.APPLICATION_JSON)
slowr13fa5b02017-08-08 16:32:31 -0700109 public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) {
slowr67d05e42017-08-11 20:37:22 -0700110 RnibCell cell = get(XranStore.class).getCell(eciHex);
slowr13fa5b02017-08-08 16:32:31 -0700111
slowr8ddc2b12017-08-14 14:13:38 -0700112 if (cell != null) {
113 try {
114 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
slowr13fa5b02017-08-08 16:32:31 -0700115
slowr89c2ac12017-08-15 16:20:06 -0700116 JsonNode rrmConf = jsonTree.path("RRMConf");
117 if (!rrmConf.isMissingNode()) {
slowr8ddc2b12017-08-14 14:13:38 -0700118 final SynchronousQueue<String>[] queue = new SynchronousQueue[1];
119 get(XranStore.class).modifyCellRrmConf(cell, rrmConf);
120
121 queue[0] = get(XranController.class).sendModifiedRRMConf(cell.getRrmConfig(),
122 cell.getVersion().equals("3"));
123 String poll = queue[0].poll(5, TimeUnit.SECONDS);
124
125 if (poll != null) {
slowr60d4d102017-08-16 18:33:58 -0700126 return ResponseHelper.getResponse(
127 mapper(),
128 statusCode.OK,
129 "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(),
135 statusCode.REQUEST_TIMEOUT,
136 "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 }
slowr8ddc2b12017-08-14 14:13:38 -0700141 } catch (Exception e) {
slowr60d4d102017-08-16 18:33:58 -0700142 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
143 log.error(fullStackTrace);
slowr8ddc2b12017-08-14 14:13:38 -0700144 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -0700145
146 return ResponseHelper.getResponse(
147 mapper(),
148 statusCode.INTERNAL_SERVER_ERROR,
149 "Exception",
150 fullStackTrace
151 );
slowr13fa5b02017-08-08 16:32:31 -0700152 }
slowr13fa5b02017-08-08 16:32:31 -0700153 }
slowr8ddc2b12017-08-14 14:13:38 -0700154
slowr60d4d102017-08-16 18:33:58 -0700155 return ResponseHelper.getResponse(
156 mapper(),
157 statusCode.NOT_FOUND,
158 "Not Found",
159 "Cell " + eciHex + " was not found"
160 );
slowr13fa5b02017-08-08 16:32:31 -0700161 }
162
163}