blob: 58b4bef54c24a4c73714a601affcf0d2b0004a8f [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;
slowr13fa5b02017-08-08 16:32:31 -070020import org.apache.commons.lang.exception.ExceptionUtils;
21import org.onosproject.rest.AbstractWebResource;
22import org.onosproject.xran.XranStore;
23import org.onosproject.xran.entities.RnibSlice;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26
27import javax.ws.rs.Consumes;
28import javax.ws.rs.GET;
29import javax.ws.rs.POST;
30import javax.ws.rs.Path;
31import javax.ws.rs.PathParam;
32import javax.ws.rs.Produces;
33import javax.ws.rs.core.MediaType;
34import javax.ws.rs.core.Response;
35import java.io.IOException;
36import java.io.InputStream;
37
38/**
39 * Slice web resource.
40 */
41@Path("slice")
42public class SliceWebResource extends AbstractWebResource {
43
44 private static final Logger log =
45 LoggerFactory.getLogger(SliceWebResource.class);
46
slowr60d4d102017-08-16 18:33:58 -070047 public SliceWebResource() {
48
49 }
50
slowr13fa5b02017-08-08 16:32:31 -070051 /**
52 * test.
53 *
54 * @param sliceid test
55 * @return test
56 */
57 @GET
58 @Path("{sliceid}")
59 @Produces(MediaType.APPLICATION_JSON)
60 public Response getSlice(@PathParam("sliceid") long sliceid) {
slowr13fa5b02017-08-08 16:32:31 -070061 RnibSlice slice = get(XranStore.class).getSlice(sliceid);
62
slowr13fa5b02017-08-08 16:32:31 -070063 if (slice != null) {
64 try {
slowr60d4d102017-08-16 18:33:58 -070065 JsonNode jsonNode = mapper().valueToTree(slice);
66
67 return ResponseHelper.getResponse(
68 mapper(),
69 ResponseHelper.statusCode.OK,
70 jsonNode
71 );
72 } catch (Exception e) {
73 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
74 log.error(fullStackTrace);
slowr13fa5b02017-08-08 16:32:31 -070075 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -070076
77 return ResponseHelper.getResponse(
78 mapper(),
79 ResponseHelper.statusCode.INTERNAL_SERVER_ERROR,
80 "Exception",
81 fullStackTrace
82 );
slowr13fa5b02017-08-08 16:32:31 -070083 }
slowr13fa5b02017-08-08 16:32:31 -070084 }
85
slowr60d4d102017-08-16 18:33:58 -070086 return ResponseHelper.getResponse(
87 mapper(),
88 ResponseHelper.statusCode.NOT_FOUND,
89 "Not Found",
90 "Slice " + sliceid + " not found"
91 );
slowr13fa5b02017-08-08 16:32:31 -070092 }
93
94 /**
95 * test.
96 *
97 * @param stream test
98 * @return test
99 */
100 @POST
101 @Consumes(MediaType.APPLICATION_JSON)
slowr60d4d102017-08-16 18:33:58 -0700102 @Produces(MediaType.APPLICATION_JSON)
slowr13fa5b02017-08-08 16:32:31 -0700103 public Response postSlice(InputStream stream) {
slowr13fa5b02017-08-08 16:32:31 -0700104 try {
slowr60d4d102017-08-16 18:33:58 -0700105// ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
106// get(XranStore.class).createSlice(jsonTree);
slowr13fa5b02017-08-08 16:32:31 -0700107
slowr60d4d102017-08-16 18:33:58 -0700108 // FIXME: change when implemented
109 return ResponseHelper.getResponse(
110 mapper(),
111 ResponseHelper.statusCode.NOT_IMPLEMENTED,
112 "Not Implemented",
113 "POST Slice not implemented"
114 );
slowr13fa5b02017-08-08 16:32:31 -0700115 } catch (Exception e) {
slowr60d4d102017-08-16 18:33:58 -0700116 String fullStackTrace = ExceptionUtils.getFullStackTrace(e);
117 log.error(fullStackTrace);
slowr13fa5b02017-08-08 16:32:31 -0700118 e.printStackTrace();
slowr60d4d102017-08-16 18:33:58 -0700119
120 return ResponseHelper.getResponse(
121 mapper(),
122 ResponseHelper.statusCode.INTERNAL_SERVER_ERROR,
123 "Exception",
124 fullStackTrace
125 );
slowr13fa5b02017-08-08 16:32:31 -0700126 }
slowr13fa5b02017-08-08 16:32:31 -0700127 }
128
129}