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 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 18 | import com.fasterxml.jackson.annotation.JsonInclude; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | import org.apache.commons.lang.exception.ExceptionUtils; |
| 22 | import org.onosproject.rest.AbstractWebResource; |
| 23 | import org.onosproject.xran.XranStore; |
| 24 | import org.onosproject.xran.annotations.Patch; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 25 | import org.onosproject.xran.controller.XranController; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 26 | import org.onosproject.xran.entities.RnibCell; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 27 | import org.onosproject.xran.rest.ResponseHelper.statusCode; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 28 | import org.slf4j.Logger; |
| 29 | import org.slf4j.LoggerFactory; |
| 30 | |
| 31 | import javax.ws.rs.Consumes; |
| 32 | import javax.ws.rs.GET; |
| 33 | import javax.ws.rs.Path; |
| 34 | import javax.ws.rs.PathParam; |
| 35 | import javax.ws.rs.Produces; |
| 36 | import javax.ws.rs.core.MediaType; |
| 37 | import javax.ws.rs.core.Response; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 38 | import java.io.InputStream; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 39 | import java.util.concurrent.SynchronousQueue; |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 40 | import java.util.concurrent.TimeUnit; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Cell web resource. |
| 44 | */ |
| 45 | @Path("cell") |
| 46 | public class CellWebResource extends AbstractWebResource { |
| 47 | |
| 48 | private static final Logger log = |
| 49 | LoggerFactory.getLogger(CellWebResource.class); |
| 50 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 51 | public CellWebResource() { |
| 52 | } |
| 53 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 54 | /** |
| 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) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 64 | RnibCell cell = get(XranStore.class).getCell(eciHex); |
| 65 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 66 | if (cell != null) { |
| 67 | try { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 68 | JsonNode jsonNode = mapper().valueToTree(cell); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 69 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 70 | 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); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 79 | e.printStackTrace(); |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 80 | |
| 81 | return ResponseHelper.getResponse( |
| 82 | mapper(), |
| 83 | statusCode.INTERNAL_SERVER_ERROR, |
| 84 | "Exception", |
| 85 | fullStackTrace |
| 86 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 87 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 88 | } |
| 89 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 90 | return ResponseHelper.getResponse( |
| 91 | mapper(), |
| 92 | statusCode.NOT_FOUND, |
| 93 | "Not Found", |
| 94 | "Cell with " + eciHex + " was not found" |
| 95 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
| 99 | * test. |
| 100 | * |
| 101 | * @param eciHex test |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 102 | * @param stream test (body of request) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 103 | * @return test |
| 104 | */ |
| 105 | @Patch |
| 106 | @Path("{cellid}") |
| 107 | @Consumes(MediaType.APPLICATION_JSON) |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 108 | @Produces(MediaType.APPLICATION_JSON) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 109 | public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 110 | RnibCell cell = get(XranStore.class).getCell(eciHex); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 111 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 112 | if (cell != null) { |
| 113 | try { |
| 114 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 115 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 116 | JsonNode rrmConf = jsonTree.path("RRMConf"); |
| 117 | if (!rrmConf.isMissingNode()) { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 118 | 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) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 126 | return ResponseHelper.getResponse( |
| 127 | mapper(), |
| 128 | statusCode.OK, |
| 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(), |
| 135 | statusCode.REQUEST_TIMEOUT, |
| 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(), |
| 144 | ResponseHelper.statusCode.NOT_IMPLEMENTED, |
| 145 | "Not Implemented", |
| 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(), |
| 156 | statusCode.INTERNAL_SERVER_ERROR, |
| 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(), |
| 165 | statusCode.NOT_FOUND, |
| 166 | "Not Found", |
| 167 | "Cell " + eciHex + " was not found" |
| 168 | ); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | } |