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