blob: 7d08f88a04d8cfc9ff8010eb96cff9002d9e3d4c [file] [log] [blame]
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Phaneendra Manda8db7d092016-06-04 00:17:24 +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 static org.onlab.util.Tools.nullIsNotFound;
19
20import javax.ws.rs.Consumes;
21import javax.ws.rs.GET;
22import javax.ws.rs.Path;
23import javax.ws.rs.PathParam;
24import javax.ws.rs.Produces;
25import javax.ws.rs.core.MediaType;
26import javax.ws.rs.core.Response;
27
28import org.onosproject.rest.AbstractWebResource;
29import org.onosproject.vtnrsc.PortChainId;
30import org.onosproject.vtnrsc.ServiceFunctionGroup;
31import org.onosproject.vtnrsc.portchainsfmap.PortChainSfMapService;
32
33import com.fasterxml.jackson.databind.node.ArrayNode;
34import com.fasterxml.jackson.databind.node.ObjectNode;
35
36/**
37 * Query service function and load details by port chain.
38 */
39
40@Path("portChainSfMap")
41public class PortChainSfMapWebResource extends AbstractWebResource {
42
43 public static final String PORT_CHAIN_NOT_FOUND = "Port chain not found";
44 public static final String PORT_CHAIN_ID_EXIST = "Port chain exists";
45 public static final String PORT_CHAIN_ID_NOT_EXIST = "Port chain does not exist with identifier";
46
47 /**
48 * Get service function details of a specified port chain id.
49 *
50 * @param id port chain id
51 * @return 200 OK, 404 if given identifier does not exist
52 */
53 @GET
54 @Path("{chainId}")
55 @Produces(MediaType.APPLICATION_JSON)
56 @Consumes(MediaType.APPLICATION_JSON)
57 public Response getPortChainSfMap(@PathParam("chainId") String id) {
58
59 Iterable<ServiceFunctionGroup> serviceFunctionGroups = nullIsNotFound(get(PortChainSfMapService.class)
60 .getServiceFunctions(PortChainId.of(id)),
61 PORT_CHAIN_NOT_FOUND);
62 ObjectNode result = mapper().createObjectNode();
63 ArrayNode portChainSfMap = result.putArray("portChainSfMap");
64 if (serviceFunctionGroups != null) {
65 for (final ServiceFunctionGroup serviceFunctionGroup : serviceFunctionGroups) {
66 portChainSfMap.add(codec(ServiceFunctionGroup.class).encode(serviceFunctionGroup, this));
67 }
68 }
69 return ok(result.toString()).build();
70 }
71}