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.codecs.api.ECGI; |
| 25 | import org.onosproject.xran.codecs.api.EUTRANCellIdentifier; |
| 26 | import org.onosproject.xran.controller.XranController; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 27 | import org.onosproject.xran.entities.RnibCell; |
| 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; |
| 38 | import java.io.IOException; |
| 39 | import java.io.InputStream; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame^] | 40 | import java.util.Optional; |
| 41 | import java.util.concurrent.SynchronousQueue; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Cell web resource. |
| 45 | */ |
| 46 | @Path("cell") |
| 47 | public class CellWebResource extends AbstractWebResource { |
| 48 | |
| 49 | private static final Logger log = |
| 50 | LoggerFactory.getLogger(CellWebResource.class); |
| 51 | |
| 52 | /** |
| 53 | * test. |
| 54 | * |
| 55 | * @param eciHex test |
| 56 | * @return test |
| 57 | */ |
| 58 | @GET |
| 59 | @Path("{cellid}") |
| 60 | @Produces(MediaType.APPLICATION_JSON) |
| 61 | public Response getCell(@PathParam("cellid") String eciHex) { |
| 62 | log.debug("GET CELLID {}", eciHex); |
| 63 | |
| 64 | RnibCell cell = get(XranStore.class).getCell(eciHex); |
| 65 | |
| 66 | ObjectNode rootNode = mapper().createObjectNode(); |
| 67 | |
| 68 | if (cell != null) { |
| 69 | try { |
| 70 | JsonNode jsonNode = mapper().readTree(cell.toString()); |
| 71 | rootNode.put("cell", jsonNode); |
| 72 | } catch (IOException e) { |
| 73 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 74 | e.printStackTrace(); |
| 75 | } |
| 76 | } else { |
| 77 | rootNode.put("error", "not found"); |
| 78 | } |
| 79 | |
| 80 | return ok(rootNode.toString()).build(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * test. |
| 85 | * |
| 86 | * @param eciHex test |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame^] | 87 | * @param stream test (body of request) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 88 | * @return test |
| 89 | */ |
| 90 | @Patch |
| 91 | @Path("{cellid}") |
| 92 | @Consumes(MediaType.APPLICATION_JSON) |
| 93 | public Response patchCell(@PathParam("cellid") String eciHex, InputStream stream) { |
| 94 | log.debug("PATCH CELLID {}", eciHex); |
| 95 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame^] | 96 | boolean b; |
| 97 | |
| 98 | RnibCell cell = get(XranStore.class).getCell(eciHex); |
| 99 | // Check if a cell with that ECI exists. If it does, then modify its contents. |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 100 | |
| 101 | try { |
| 102 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
| 103 | |
| 104 | JsonNode rrmConf = jsonTree.get("RRMConf"); |
| 105 | if (rrmConf != null) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame^] | 106 | final SynchronousQueue<String>[] queue = new SynchronousQueue[1]; |
| 107 | b = get(XranStore.class).modifyCellRrmConf(cell, rrmConf); |
| 108 | if (b) { |
| 109 | queue[0] = get(XranController.class).sendModifiedRRMConf(cell); |
| 110 | return Response.ok().entity(queue[0].take()).build(); |
| 111 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 112 | } |
| 113 | } catch (Exception e) { |
| 114 | log.error(ExceptionUtils.getFullStackTrace(e)); |
| 115 | e.printStackTrace(); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame^] | 116 | return Response.serverError().entity(ExceptionUtils.getFullStackTrace(e)).build(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 117 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame^] | 118 | return Response.noContent().build(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | } |