Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 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 | */ |
Jonathan Hart | 9bb32ab | 2015-05-05 18:17:31 -0700 | [diff] [blame] | 16 | package org.onosproject.rest.resources; |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 18 | import javax.ws.rs.GET; |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 19 | import javax.ws.rs.Path; |
| 20 | import javax.ws.rs.PathParam; |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 21 | import javax.ws.rs.Produces; |
| 22 | import javax.ws.rs.core.MediaType; |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 23 | import javax.ws.rs.core.Response; |
Jordan Halterman | 2ac98b9 | 2018-10-11 14:48:55 -0700 | [diff] [blame] | 24 | |
| 25 | import org.onosproject.cluster.ClusterService; |
| 26 | import org.onosproject.cluster.ControllerNode; |
| 27 | import org.onosproject.cluster.NodeId; |
| 28 | import org.onosproject.rest.AbstractWebResource; |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 29 | |
Thomas Vachuska | f8cac48 | 2015-04-08 19:40:12 -0700 | [diff] [blame] | 30 | import static org.onlab.util.Tools.nullIsNotFound; |
| 31 | |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 32 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 33 | * Manage cluster of ONOS instances. |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 34 | */ |
| 35 | @Path("cluster") |
| 36 | public class ClusterWebResource extends AbstractWebResource { |
| 37 | |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 38 | private static final String NODE_NOT_FOUND = "Node is not found"; |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 39 | |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Get all cluster nodes. |
| 42 | * Returns array of all cluster nodes. |
| 43 | * |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 44 | * @return 200 OK with a collection of cluster nodes |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 45 | * @onos.rsModel Cluster |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 46 | */ |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 47 | @GET |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 48 | @Produces(MediaType.APPLICATION_JSON) |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 49 | public Response getClusterNodes() { |
| 50 | Iterable<ControllerNode> nodes = get(ClusterService.class).getNodes(); |
| 51 | return ok(encodeArray(ControllerNode.class, "nodes", nodes)).build(); |
| 52 | } |
| 53 | |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 54 | /** |
| 55 | * Get cluster node details. |
| 56 | * Returns details of the specified cluster node. |
| 57 | * |
| 58 | * @param id cluster node identifier |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 59 | * @return 200 OK with a cluster node |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 60 | * @onos.rsModel ClusterNode |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 61 | */ |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 62 | @GET |
| 63 | @Path("{id}") |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 64 | @Produces(MediaType.APPLICATION_JSON) |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 65 | 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 Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 70 | } |