blob: 991f0fc1bb6f9f58b1dc61ee29d99692b463264e [file] [log] [blame]
SureshBR0bc64992015-12-03 16:38:02 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
SureshBR0bc64992015-12-03 16:38:02 +05303 *
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.vtnweb.resources;
17
18import javax.ws.rs.GET;
19import javax.ws.rs.Path;
20import javax.ws.rs.Produces;
Wu wenbind0b119f2016-05-11 18:03:41 +080021import javax.ws.rs.Consumes;
SureshBR0bc64992015-12-03 16:38:02 +053022import javax.ws.rs.core.MediaType;
23import javax.ws.rs.core.Response;
24
25import org.onosproject.net.DeviceId;
26import org.onosproject.rest.AbstractWebResource;
27import org.onosproject.vtnrsc.classifier.ClassifierService;
28import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
31import com.fasterxml.jackson.databind.node.ArrayNode;
32import com.fasterxml.jackson.databind.node.ObjectNode;
33
34/**
35 * Query and program classifiers.
36 */
37@Path("classifiers")
38public class ClassifierWebResource extends AbstractWebResource {
39
40 private final Logger log = LoggerFactory.getLogger(ClassifierWebResource.class);
41
42 /**
43 * Get the list of classifier devices.
44 *
45 * @return 200 OK
46 */
47 @GET
48 @Produces(MediaType.APPLICATION_JSON)
Wu wenbind0b119f2016-05-11 18:03:41 +080049 @Consumes(MediaType.APPLICATION_JSON)
SureshBR0bc64992015-12-03 16:38:02 +053050 public Response getClassifiers() {
51
52 ObjectNode result = mapper().createObjectNode();
53
54 Iterable<DeviceId> classifierDevices = get(ClassifierService.class).getClassifiers();
55 ArrayNode classifier = result.putArray("classifiers");
56 if (classifierDevices != null) {
57 for (final DeviceId deviceId : classifierDevices) {
58 ObjectNode dev = mapper().createObjectNode()
59 .put("DeviceId", deviceId.toString());
60 classifier.add(dev);
61 }
62 }
63 return ok(result.toString()).build();
64 }
65}