blob: 47570c91fd60a317a296f99b237758b02cd77b05 [file] [log] [blame]
Thomas Vachuskade563cf2015-04-01 00:28:50 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskade563cf2015-04-01 00:28:50 -07003 *
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 */
Jonathan Hart9bb32ab2015-05-05 18:17:31 -070016package org.onosproject.rest.resources;
Thomas Vachuskade563cf2015-04-01 00:28:50 -070017
Thomas Vachuskade563cf2015-04-01 00:28:50 -070018import javax.ws.rs.GET;
Thomas Vachuskade563cf2015-04-01 00:28:50 -070019import javax.ws.rs.Path;
20import javax.ws.rs.PathParam;
Jian Licc730a62016-05-10 16:36:16 -070021import javax.ws.rs.Produces;
22import javax.ws.rs.core.MediaType;
Thomas Vachuskade563cf2015-04-01 00:28:50 -070023import javax.ws.rs.core.Response;
Jordan Halterman2ac98b92018-10-11 14:48:55 -070024
25import org.onosproject.cluster.ClusterService;
26import org.onosproject.cluster.ControllerNode;
27import org.onosproject.cluster.NodeId;
28import org.onosproject.rest.AbstractWebResource;
Thomas Vachuskade563cf2015-04-01 00:28:50 -070029
Thomas Vachuskaf8cac482015-04-08 19:40:12 -070030import static org.onlab.util.Tools.nullIsNotFound;
31
Thomas Vachuskade563cf2015-04-01 00:28:50 -070032/**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070033 * Manage cluster of ONOS instances.
Thomas Vachuskade563cf2015-04-01 00:28:50 -070034 */
35@Path("cluster")
36public class ClusterWebResource extends AbstractWebResource {
37
Jian Licc730a62016-05-10 16:36:16 -070038 private static final String NODE_NOT_FOUND = "Node is not found";
Thomas Vachuskade563cf2015-04-01 00:28:50 -070039
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070040 /**
41 * Get all cluster nodes.
42 * Returns array of all cluster nodes.
43 *
Jian Licc730a62016-05-10 16:36:16 -070044 * @return 200 OK with a collection of cluster nodes
Andrea Campanella10c4adc2015-12-03 15:27:54 -080045 * @onos.rsModel Cluster
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070046 */
Thomas Vachuskade563cf2015-04-01 00:28:50 -070047 @GET
Jian Licc730a62016-05-10 16:36:16 -070048 @Produces(MediaType.APPLICATION_JSON)
Thomas Vachuskade563cf2015-04-01 00:28:50 -070049 public Response getClusterNodes() {
50 Iterable<ControllerNode> nodes = get(ClusterService.class).getNodes();
51 return ok(encodeArray(ControllerNode.class, "nodes", nodes)).build();
52 }
53
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070054 /**
55 * Get cluster node details.
56 * Returns details of the specified cluster node.
57 *
58 * @param id cluster node identifier
Jian Licc730a62016-05-10 16:36:16 -070059 * @return 200 OK with a cluster node
Andrea Campanella10c4adc2015-12-03 15:27:54 -080060 * @onos.rsModel ClusterNode
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070061 */
Thomas Vachuskade563cf2015-04-01 00:28:50 -070062 @GET
63 @Path("{id}")
Jian Licc730a62016-05-10 16:36:16 -070064 @Produces(MediaType.APPLICATION_JSON)
Thomas Vachuskade563cf2015-04-01 00:28:50 -070065 public Response getClusterNode(@PathParam("id") String id) {
66 ControllerNode node = nullIsNotFound(get(ClusterService.class).getNode(new NodeId(id)),
67 NODE_NOT_FOUND);
68 return ok(codec(ControllerNode.class).encode(node, this)).build();
69 }
Thomas Vachuskade563cf2015-04-01 00:28:50 -070070}