blob: 8a40f51916f3daecd0d9a0f7066f3b6953895072 [file] [log] [blame]
Jian Li810f58c2021-02-27 01:10:50 +09001/*
2 * Copyright 2021-present Open Networking Foundation
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.kubevirtnetworking.web;
17
18import org.onosproject.kubevirtnetworking.api.KubevirtRouter;
19import org.onosproject.kubevirtnetworking.api.KubevirtRouterService;
20import org.onosproject.rest.AbstractWebResource;
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24import javax.ws.rs.GET;
25import javax.ws.rs.Path;
26import javax.ws.rs.Produces;
27import javax.ws.rs.core.MediaType;
28import javax.ws.rs.core.Response;
29
30/**
31 * Handles REST API call for kubevirt router.
32 */
33@Path("router")
34public class KubevirtRouterWebResource extends AbstractWebResource {
35
36 protected final Logger log = LoggerFactory.getLogger(getClass());
Jian Li1c10cf22021-03-05 01:32:04 +090037 private static final String ROUTERS = "routers";
Jian Li810f58c2021-02-27 01:10:50 +090038
39 /**
40 * Returns set of all routers.
41 *
42 * @return 200 OK with set of all routers
43 * @onos.rsModel KubevirtRouters
44 */
45 @GET
46 @Produces(MediaType.APPLICATION_JSON)
47 public Response getRouters() {
48 KubevirtRouterService service = get(KubevirtRouterService.class);
49 final Iterable<KubevirtRouter> routers = service.routers();
Jian Li1c10cf22021-03-05 01:32:04 +090050 return ok(encodeArray(KubevirtRouter.class, ROUTERS, routers)).build();
Jian Li810f58c2021-02-27 01:10:50 +090051 }
52}