Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [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; |
| 17 | |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
Jian Li | 43c956b | 2015-11-26 03:02:46 -0800 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
Jonathan Hart | 9bb32ab | 2015-05-05 18:17:31 -0700 | [diff] [blame] | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Charles Chan | 6285113 | 2020-01-14 16:29:43 -0800 | [diff] [blame^] | 21 | import org.onlab.packet.EthType; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.VlanId; |
| 25 | import org.onosproject.net.ConnectPoint; |
| 26 | import org.onosproject.net.DefaultAnnotations; |
Jonathan Hart | 9bb32ab | 2015-05-05 18:17:31 -0700 | [diff] [blame] | 27 | import org.onosproject.net.Host; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 28 | import org.onosproject.net.HostId; |
| 29 | import org.onosproject.net.HostLocation; |
| 30 | import org.onosproject.net.SparseAnnotations; |
| 31 | import org.onosproject.net.host.DefaultHostDescription; |
Thomas Vachuska | 58a7c34 | 2016-12-13 01:10:56 -0800 | [diff] [blame] | 32 | import org.onosproject.net.host.HostAdminService; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 33 | import org.onosproject.net.host.HostProvider; |
| 34 | import org.onosproject.net.host.HostProviderRegistry; |
| 35 | import org.onosproject.net.host.HostProviderService; |
Jonathan Hart | 9bb32ab | 2015-05-05 18:17:31 -0700 | [diff] [blame] | 36 | import org.onosproject.net.host.HostService; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 37 | import org.onosproject.net.provider.ProviderId; |
Jonathan Hart | 9bb32ab | 2015-05-05 18:17:31 -0700 | [diff] [blame] | 38 | import org.onosproject.rest.AbstractWebResource; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 39 | |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 40 | import javax.ws.rs.Consumes; |
Thomas Vachuska | 58a7c34 | 2016-12-13 01:10:56 -0800 | [diff] [blame] | 41 | import javax.ws.rs.DELETE; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 42 | import javax.ws.rs.GET; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 43 | import javax.ws.rs.POST; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 44 | import javax.ws.rs.Path; |
| 45 | import javax.ws.rs.PathParam; |
| 46 | import javax.ws.rs.Produces; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 47 | import javax.ws.rs.core.Context; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 48 | import javax.ws.rs.core.MediaType; |
| 49 | import javax.ws.rs.core.Response; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 50 | import javax.ws.rs.core.UriBuilder; |
| 51 | import javax.ws.rs.core.UriInfo; |
| 52 | import java.io.IOException; |
| 53 | import java.io.InputStream; |
| 54 | import java.net.URI; |
| 55 | import java.util.HashSet; |
| 56 | import java.util.Iterator; |
Jian Li | 43c956b | 2015-11-26 03:02:46 -0800 | [diff] [blame] | 57 | import java.util.Map; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 58 | import java.util.Set; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 59 | |
Thomas Vachuska | f8cac48 | 2015-04-08 19:40:12 -0700 | [diff] [blame] | 60 | import static org.onlab.util.Tools.nullIsNotFound; |
Ray Milkey | 86ee5e8 | 2018-04-02 15:33:07 -0700 | [diff] [blame] | 61 | import static org.onlab.util.Tools.readTreeFromStream; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 62 | import static org.onosproject.net.HostId.hostId; |
| 63 | |
| 64 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 65 | * Manage inventory of end-station hosts. |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 66 | */ |
| 67 | @Path("hosts") |
| 68 | public class HostsWebResource extends AbstractWebResource { |
| 69 | |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 70 | @Context |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 71 | private UriInfo uriInfo; |
| 72 | private static final String HOST_NOT_FOUND = "Host is not found"; |
Charles Chan | 6285113 | 2020-01-14 16:29:43 -0800 | [diff] [blame^] | 73 | private static final String[] REMOVAL_KEYS = {"mac", "vlan", "locations", "ipAddresses", "innerVlan", "outerTpid"}; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 74 | |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Get all end-station hosts. |
| 77 | * Returns array of all known end-station hosts. |
| 78 | * |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 79 | * @return 200 OK with array of all known end-station hosts. |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 80 | * @onos.rsModel Hosts |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 81 | */ |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 82 | @GET |
| 83 | @Produces(MediaType.APPLICATION_JSON) |
| 84 | public Response getHosts() { |
| 85 | final Iterable<Host> hosts = get(HostService.class).getHosts(); |
| 86 | final ObjectNode root = encodeArray(Host.class, "hosts", hosts); |
Ray Milkey | 3f02569 | 2015-01-26 11:15:41 -0800 | [diff] [blame] | 87 | return ok(root).build(); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 90 | /** |
| 91 | * Get details of end-station host. |
| 92 | * Returns detailed properties of the specified end-station host. |
| 93 | * |
| 94 | * @param id host identifier |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 95 | * @return 200 OK with detailed properties of the specified end-station host |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 96 | * @onos.rsModel Host |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 97 | */ |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 98 | @GET |
| 99 | @Produces(MediaType.APPLICATION_JSON) |
| 100 | @Path("{id}") |
| 101 | public Response getHostById(@PathParam("id") String id) { |
| 102 | final Host host = nullIsNotFound(get(HostService.class).getHost(hostId(id)), |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 103 | HOST_NOT_FOUND); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 104 | final ObjectNode root = codec(Host.class).encode(host, this); |
Ray Milkey | 3f02569 | 2015-01-26 11:15:41 -0800 | [diff] [blame] | 105 | return ok(root).build(); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Get details of end-station host with MAC/VLAN. |
| 110 | * Returns detailed properties of the specified end-station host. |
| 111 | * |
| 112 | * @param mac host MAC address |
| 113 | * @param vlan host VLAN identifier |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 114 | * @return 200 OK with detailed properties of the specified end-station host |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 115 | * @onos.rsModel Host |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 116 | */ |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 117 | @GET |
| 118 | @Produces(MediaType.APPLICATION_JSON) |
| 119 | @Path("{mac}/{vlan}") |
| 120 | public Response getHostByMacAndVlan(@PathParam("mac") String mac, |
| 121 | @PathParam("vlan") String vlan) { |
| 122 | final Host host = nullIsNotFound(get(HostService.class).getHost(hostId(mac + "/" + vlan)), |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 123 | HOST_NOT_FOUND); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 124 | final ObjectNode root = codec(Host.class).encode(host, this); |
Ray Milkey | 3f02569 | 2015-01-26 11:15:41 -0800 | [diff] [blame] | 125 | return ok(root).build(); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 126 | } |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * Creates a new host based on JSON input and adds it to the current |
| 130 | * host inventory. |
| 131 | * |
| 132 | * @param stream input JSON |
| 133 | * @return status of the request - CREATED if the JSON is correct, |
| 134 | * BAD_REQUEST if the JSON is invalid |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 135 | * @onos.rsModel HostPut |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 136 | */ |
| 137 | @POST |
| 138 | @Consumes(MediaType.APPLICATION_JSON) |
| 139 | @Produces(MediaType.APPLICATION_JSON) |
| 140 | public Response createAndAddHost(InputStream stream) { |
| 141 | URI location; |
| 142 | try { |
| 143 | // Parse the input stream |
Ray Milkey | 86ee5e8 | 2018-04-02 15:33:07 -0700 | [diff] [blame] | 144 | ObjectNode root = readTreeFromStream(mapper(), stream); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 145 | |
| 146 | HostProviderRegistry hostProviderRegistry = get(HostProviderRegistry.class); |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 147 | InternalHostProvider hostProvider = new InternalHostProvider(); |
| 148 | HostProviderService hostProviderService = hostProviderRegistry.register(hostProvider); |
| 149 | hostProvider.setHostProviderService(hostProviderService); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 150 | HostId hostId = hostProvider.parseHost(root); |
| 151 | |
| 152 | UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() |
| 153 | .path("hosts") |
| 154 | .path(hostId.mac().toString()) |
| 155 | .path(hostId.vlanId().toString()); |
| 156 | location = locationBuilder.build(); |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 157 | hostProviderRegistry.unregister(hostProvider); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 158 | |
| 159 | } catch (IOException ex) { |
Ray Milkey | 5d915f4 | 2015-08-13 10:27:53 -0700 | [diff] [blame] | 160 | throw new IllegalArgumentException(ex); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 161 | } |
| 162 | return Response |
| 163 | .created(location) |
| 164 | .build(); |
| 165 | } |
| 166 | |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 167 | /** |
Thomas Vachuska | 58a7c34 | 2016-12-13 01:10:56 -0800 | [diff] [blame] | 168 | * Removes infrastructure device. |
| 169 | * Administratively deletes the specified device from the inventory of |
| 170 | * known devices. |
| 171 | * |
| 172 | * @param mac host MAC address |
| 173 | * @param vlan host VLAN identifier |
| 174 | * @return 204 OK |
| 175 | * @onos.rsModel Host |
| 176 | */ |
| 177 | @DELETE |
| 178 | @Path("{mac}/{vlan}") |
| 179 | @Produces(MediaType.APPLICATION_JSON) |
| 180 | public Response removeHost(@PathParam("mac") String mac, |
| 181 | @PathParam("vlan") String vlan) { |
| 182 | get(HostAdminService.class).removeHost(hostId(mac + "/" + vlan)); |
| 183 | return Response.noContent().build(); |
| 184 | } |
| 185 | |
| 186 | /** |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 187 | * Internal host provider that provides host events. |
| 188 | */ |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 189 | private final class InternalHostProvider implements HostProvider { |
| 190 | private final ProviderId providerId = |
| 191 | new ProviderId("host", "org.onosproject.rest", true); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 192 | private HostProviderService hostProviderService; |
| 193 | |
Jian Li | cc730a6 | 2016-05-10 16:36:16 -0700 | [diff] [blame] | 194 | /** |
| 195 | * Prevents from instantiation. |
| 196 | */ |
Ray Milkey | 5d915f4 | 2015-08-13 10:27:53 -0700 | [diff] [blame] | 197 | private InternalHostProvider() { |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Ray Milkey | 5d915f4 | 2015-08-13 10:27:53 -0700 | [diff] [blame] | 200 | public void triggerProbe(Host host) { |
| 201 | // Not implemented since there is no need to check for hosts on network |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 204 | public void setHostProviderService(HostProviderService service) { |
| 205 | this.hostProviderService = service; |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Ray Milkey | 5d915f4 | 2015-08-13 10:27:53 -0700 | [diff] [blame] | 208 | /* |
| 209 | * Return the ProviderId of "this" |
| 210 | */ |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 211 | public ProviderId id() { |
| 212 | return providerId; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Creates and adds new host based on given data and returns its host ID. |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 217 | * |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 218 | * @param node JsonNode containing host information |
| 219 | * @return host ID of new host created |
| 220 | */ |
| 221 | private HostId parseHost(JsonNode node) { |
| 222 | MacAddress mac = MacAddress.valueOf(node.get("mac").asText()); |
Ray Milkey | 5d915f4 | 2015-08-13 10:27:53 -0700 | [diff] [blame] | 223 | VlanId vlanId = VlanId.vlanId((short) node.get("vlan").asInt(VlanId.UNTAGGED)); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 224 | |
Charles Chan | 6285113 | 2020-01-14 16:29:43 -0800 | [diff] [blame^] | 225 | // Parse locations |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 226 | Iterator<JsonNode> locationNodes = node.get("locations").elements(); |
| 227 | Set<HostLocation> locations = new HashSet<>(); |
| 228 | while (locationNodes.hasNext()) { |
| 229 | JsonNode locationNode = locationNodes.next(); |
| 230 | String deviceAndPort = locationNode.get("elementId").asText() + "/" + |
| 231 | locationNode.get("port").asText(); |
| 232 | HostLocation hostLocation = new HostLocation(ConnectPoint.deviceConnectPoint(deviceAndPort), 0); |
| 233 | locations.add(hostLocation); |
| 234 | } |
| 235 | |
Charles Chan | 6285113 | 2020-01-14 16:29:43 -0800 | [diff] [blame^] | 236 | // Parse ipAddresses |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 237 | Iterator<JsonNode> ipNodes = node.get("ipAddresses").elements(); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 238 | Set<IpAddress> ips = new HashSet<>(); |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 239 | while (ipNodes.hasNext()) { |
| 240 | ips.add(IpAddress.valueOf(ipNodes.next().asText())); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 241 | } |
Jian Li | 43c956b | 2015-11-26 03:02:46 -0800 | [diff] [blame] | 242 | |
Charles Chan | 6285113 | 2020-01-14 16:29:43 -0800 | [diff] [blame^] | 243 | // Parse innerVlan |
| 244 | JsonNode innerVlanNode = node.get("innerVlan"); |
| 245 | VlanId innerVlan = (null == innerVlanNode) ? VlanId.NONE : VlanId.vlanId(innerVlanNode.asText()); |
| 246 | |
| 247 | // Parse outerTpid |
| 248 | JsonNode outerTpidNode = node.get("outerTpid"); |
| 249 | EthType outerTpid = (null == outerTpidNode) ? EthType.EtherType.UNKNOWN.ethType() : |
| 250 | EthType.EtherType.lookup((short) (Integer.decode(outerTpidNode.asText()) & 0xFFFF)).ethType(); |
| 251 | |
Jian Li | 43c956b | 2015-11-26 03:02:46 -0800 | [diff] [blame] | 252 | // try to remove elements from json node after reading them |
| 253 | SparseAnnotations annotations = annotations(removeElements(node, REMOVAL_KEYS)); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 254 | // Update host inventory |
| 255 | |
| 256 | HostId hostId = HostId.hostId(mac, vlanId); |
Charles Chan | 6285113 | 2020-01-14 16:29:43 -0800 | [diff] [blame^] | 257 | DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, locations, |
| 258 | ips, innerVlan, outerTpid, true, annotations); |
Ray Milkey | dc08344 | 2016-02-22 11:27:57 -0800 | [diff] [blame] | 259 | hostProviderService.hostDetected(hostId, desc, false); |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 260 | return hostId; |
| 261 | } |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 262 | |
| 263 | /** |
Jian Li | 43c956b | 2015-11-26 03:02:46 -0800 | [diff] [blame] | 264 | * Remove a set of elements from JsonNode by specifying keys. |
| 265 | * |
| 266 | * @param node JsonNode containing host information |
| 267 | * @param removalKeys key of elements that need to be removed |
| 268 | * @return removal keys |
| 269 | */ |
| 270 | private JsonNode removeElements(JsonNode node, String[] removalKeys) { |
| 271 | ObjectMapper mapper = new ObjectMapper(); |
| 272 | Map<String, Object> map = mapper.convertValue(node, Map.class); |
| 273 | for (String key : removalKeys) { |
| 274 | map.remove(key); |
| 275 | } |
| 276 | return mapper.convertValue(map, JsonNode.class); |
| 277 | } |
| 278 | |
| 279 | /** |
Kedar Gupta | 7c4d196 | 2015-08-03 10:46:04 -0700 | [diff] [blame] | 280 | * Produces annotations from specified JsonNode. Copied from the ConfigProvider |
| 281 | * class for use in the POST method. |
| 282 | * |
| 283 | * @param node node to be annotated |
| 284 | * @return SparseAnnotations object with information about node |
| 285 | */ |
| 286 | private SparseAnnotations annotations(JsonNode node) { |
| 287 | if (node == null) { |
| 288 | return DefaultAnnotations.EMPTY; |
| 289 | } |
| 290 | |
| 291 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 292 | Iterator<String> it = node.fieldNames(); |
| 293 | while (it.hasNext()) { |
| 294 | String k = it.next(); |
| 295 | builder.set(k, node.get(k).asText()); |
| 296 | } |
| 297 | return builder.build(); |
| 298 | } |
| 299 | |
Kedar Gupta | 47bd480 | 2015-07-15 09:43:26 -0700 | [diff] [blame] | 300 | } |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 301 | } |
| 302 | |