slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.xran.rest; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import org.apache.commons.lang.exception.ExceptionUtils; |
| 21 | import org.onosproject.rest.AbstractWebResource; |
| 22 | import org.onosproject.xran.XranStore; |
| 23 | import org.onosproject.xran.annotations.Patch; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 24 | import org.onosproject.xran.controller.XranController; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 25 | import org.onosproject.xran.entities.RnibCell; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 26 | import org.onosproject.xran.rest.ResponseHelper.StatusCode; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 27 | import org.slf4j.Logger; |
| 28 | import org.slf4j.LoggerFactory; |
| 29 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 30 | import javax.ws.rs.GET; |
| 31 | import javax.ws.rs.Path; |
| 32 | import javax.ws.rs.PathParam; |
| 33 | import javax.ws.rs.Produces; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 34 | import javax.ws.rs.Consumes; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 35 | import javax.ws.rs.core.MediaType; |
| 36 | import javax.ws.rs.core.Response; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 37 | import java.io.InputStream; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 38 | import java.util.concurrent.SynchronousQueue; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 39 | import java.util.concurrent.TimeUnit; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Cell web resource. |
| 43 | */ |
| 44 | @Path("cell") |
| 45 | public class CellWebResource extends AbstractWebResource { |
| 46 | |
| 47 | private static final Logger log = |
| 48 | LoggerFactory.getLogger(CellWebResource.class); |
| 49 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 50 | public CellWebResource() { |
| 51 | } |
| 52 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 53 | /** |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 54 | * Lists the cell with {cellid}. |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 55 | * |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 56 | * @param eciHex EutranCellIdentifier in binary |
| 57 | * @return Response |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 58 | */ |
| 59 | @GET |
| 60 | @Path("{cellid}") |
| 61 | @Produces(MediaType.APPLICATION_JSON) |
| 62 | public Response getCell(@PathParam("cellid") String eciHex) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 63 | RnibCell cell = get(XranStore.class).getCell(eciHex); |
| 64 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 65 | if (cell != null) { |
| 66 | try { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 67 | JsonNode jsonNode = mapper().valueToTree(cell); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 68 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 69 | return ResponseHelper.getResponse( |
| 70 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 71 | StatusCode.OK, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 72 | jsonNode |
| 73 | ); |
| 74 | |
| 75 | } catch (Exception e) { |
| 76 | String fullStackTrace = ExceptionUtils.getFullStackTrace(e); |
| 77 | log.error(fullStackTrace); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 78 | e.printStackTrace(); |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 79 | |
| 80 | return ResponseHelper.getResponse( |
| 81 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 82 | StatusCode.INTERNAL_SERVER_ERROR, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 83 | "Exception", |
| 84 | fullStackTrace |
| 85 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 86 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 87 | } |
| 88 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 89 | return ResponseHelper.getResponse( |
| 90 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 91 | StatusCode.NOT_FOUND, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 92 | "Not Found", |
| 93 | "Cell with " + eciHex + " was not found" |
| 94 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 98 | * Modify the RRMConfig parameters of the cell. |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 99 | * |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 100 | * @param eciHex EutranCellIdentifier in binary |
| 101 | * @param stream Parameters that you want to modify |
| 102 | * @return Response |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 103 | */ |
| 104 | @Patch |
| 105 | @Path("{cellid}") |
| 106 | @Consumes(MediaType.APPLICATION_JSON) |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 107 | @Produces(MediaType.APPLICATION_JSON) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 108 | public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 109 | RnibCell cell = get(XranStore.class).getCell(eciHex); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 110 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 111 | if (cell != null) { |
| 112 | try { |
| 113 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 114 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 115 | JsonNode rrmConf = jsonTree.path("RRMConf"); |
| 116 | if (!rrmConf.isMissingNode()) { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 117 | final SynchronousQueue<String>[] queue = new SynchronousQueue[1]; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 118 | get(XranStore.class).modifycellrrmconf(cell, rrmConf); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 119 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 120 | queue[0] = get(XranController.class).sendmodifiedrrmconf(cell.getRrmConfig(), |
slowr | ed74ec7 | 2017-08-17 11:25:01 -0700 | [diff] [blame] | 121 | cell.getVersion() <= 3); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 122 | String poll = queue[0].poll(get(XranController.class) |
| 123 | .getNorthboundTimeout(), TimeUnit.MILLISECONDS); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 124 | |
| 125 | if (poll != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 126 | return ResponseHelper.getResponse( |
| 127 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 128 | StatusCode.OK, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 129 | "Handoff Response", |
| 130 | poll |
| 131 | ); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 132 | } else { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 133 | return ResponseHelper.getResponse( |
| 134 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 135 | StatusCode.REQUEST_TIMEOUT, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 136 | "Handoff Timeout", |
| 137 | "eNodeB did not send a HOComplete/HOFailure on time" |
| 138 | ); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 139 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 140 | } |
slowr | d19a83b | 2017-08-17 08:57:46 -0700 | [diff] [blame] | 141 | |
| 142 | return ResponseHelper.getResponse( |
| 143 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 144 | StatusCode.BAD_REQUEST, |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 145 | "Bad Request", |
slowr | d19a83b | 2017-08-17 08:57:46 -0700 | [diff] [blame] | 146 | "The command you specified is not implemented or doesn't exist. We support " + |
| 147 | "RRMConf commands." |
| 148 | ); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 149 | } catch (Exception e) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 150 | String fullStackTrace = ExceptionUtils.getFullStackTrace(e); |
| 151 | log.error(fullStackTrace); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 152 | e.printStackTrace(); |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 153 | |
| 154 | return ResponseHelper.getResponse( |
| 155 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 156 | StatusCode.INTERNAL_SERVER_ERROR, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 157 | "Exception", |
| 158 | fullStackTrace |
| 159 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 160 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 161 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 162 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 163 | return ResponseHelper.getResponse( |
| 164 | mapper(), |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame^] | 165 | StatusCode.NOT_FOUND, |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 166 | "Not Found", |
| 167 | "Cell " + eciHex + " was not found" |
| 168 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | } |