3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.topology.northbound;
12 import java.util.ArrayList;
13 import java.util.List;
17 import javax.ws.rs.GET;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.PathParam;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.core.MediaType;
23 import org.codehaus.enunciate.jaxrs.ResponseCode;
24 import org.codehaus.enunciate.jaxrs.StatusCodes;
25 import org.codehaus.enunciate.jaxrs.TypeHint;
26 import org.opendaylight.controller.northbound.commons.RestMessages;
27 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
28 import org.opendaylight.controller.sal.core.Edge;
29 import org.opendaylight.controller.sal.core.Property;
30 import org.opendaylight.controller.sal.utils.ServiceHelper;
31 import org.opendaylight.controller.topologymanager.ITopologyManager;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Topology Northbound REST API
39 * Authentication scheme : <b>HTTP Basic</b><br>
40 * Authentication realm : <b>opendaylight</b><br>
41 * Transport : <b>HTTP and HTTPS</b><br>
43 * HTTPS Authentication is disabled by default. Administrator can enable it in tomcat-server.xml after adding
44 * a proper keystore / SSL certificate from a trusted authority.<br>
45 * More info : http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
49 public class TopologyNorthboundJAXRS {
50 private static Logger logger = LoggerFactory
51 .getLogger(TopologyNorthboundJAXRS.class);
55 * Retrieve the Topology for the
57 * @param containerName The container for which we want to retrieve the topology
59 * @return A List of EdgeProps each EdgeProp represent an Edge of
60 * the grap with the corresponding properties attached to it.
62 @Path("/{containerName}")
64 @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
65 @TypeHint(Topology.class)
66 @StatusCodes( { @ResponseCode(code = 404, condition = "The containerName passed was not found") })
67 public Topology getTopology(
68 @PathParam("containerName") String containerName) {
69 ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
70 .getInstance(ITopologyManager.class, containerName, this);
71 if (topologyManager == null) {
72 throw new ResourceNotFoundException(RestMessages.NOCONTAINER
76 Map<Edge, Set<Property>> topo = topologyManager.getEdges();
78 List<EdgeProperties> res = new ArrayList<EdgeProperties>();
79 for (Map.Entry<Edge, Set<Property>> entry : topo.entrySet()) {
80 EdgeProperties el = new EdgeProperties(entry.getKey(), entry.getValue());
83 return new Topology(res);