slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 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 | 60d4d10 | 2017-08-16 18:33:58 -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 | |
| 30 | import javax.ws.rs.Consumes; |
| 31 | import javax.ws.rs.GET; |
| 32 | import javax.ws.rs.Path; |
| 33 | import javax.ws.rs.PathParam; |
| 34 | import javax.ws.rs.Produces; |
| 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 | /** |
| 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) { |
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(), |
| 71 | statusCode.OK, |
| 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(), |
| 82 | statusCode.INTERNAL_SERVER_ERROR, |
| 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(), |
| 91 | statusCode.NOT_FOUND, |
| 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 | /** |
| 98 | * test. |
| 99 | * |
| 100 | * @param eciHex test |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 101 | * @param stream test (body of request) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 102 | * @return test |
| 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]; |
| 118 | get(XranStore.class).modifyCellRrmConf(cell, rrmConf); |
| 119 | |
| 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 | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 122 | String poll = queue[0].poll(5, TimeUnit.SECONDS); |
| 123 | |
| 124 | if (poll != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 125 | return ResponseHelper.getResponse( |
| 126 | mapper(), |
| 127 | statusCode.OK, |
| 128 | "Handoff Response", |
| 129 | poll |
| 130 | ); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 131 | } else { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 132 | return ResponseHelper.getResponse( |
| 133 | mapper(), |
| 134 | statusCode.REQUEST_TIMEOUT, |
| 135 | "Handoff Timeout", |
| 136 | "eNodeB did not send a HOComplete/HOFailure on time" |
| 137 | ); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 138 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 139 | } |
slowr | d19a83b | 2017-08-17 08:57:46 -0700 | [diff] [blame] | 140 | |
| 141 | return ResponseHelper.getResponse( |
| 142 | mapper(), |
slowr | 73b4eae | 2017-08-17 16:09:09 -0700 | [diff] [blame] | 143 | ResponseHelper.statusCode.BAD_REQUEST, |
| 144 | "Bad Request", |
slowr | d19a83b | 2017-08-17 08:57:46 -0700 | [diff] [blame] | 145 | "The command you specified is not implemented or doesn't exist. We support " + |
| 146 | "RRMConf commands." |
| 147 | ); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 148 | } catch (Exception e) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 149 | String fullStackTrace = ExceptionUtils.getFullStackTrace(e); |
| 150 | log.error(fullStackTrace); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 151 | e.printStackTrace(); |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 152 | |
| 153 | return ResponseHelper.getResponse( |
| 154 | mapper(), |
| 155 | statusCode.INTERNAL_SERVER_ERROR, |
| 156 | "Exception", |
| 157 | fullStackTrace |
| 158 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 159 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 160 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 161 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 162 | return ResponseHelper.getResponse( |
| 163 | mapper(), |
| 164 | statusCode.NOT_FOUND, |
| 165 | "Not Found", |
| 166 | "Cell " + eciHex + " was not found" |
| 167 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | } |