Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -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 | */ |
| 16 | |
| 17 | package org.onosproject.provider.rest.device.impl; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.google.common.annotations.Beta; |
| 21 | import com.google.common.collect.Sets; |
| 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.incubator.net.config.basics.ConfigException; |
| 25 | import org.onosproject.net.config.Config; |
| 26 | import org.onosproject.protocol.rest.DefaultRestSBDevice; |
| 27 | import org.onosproject.protocol.rest.RestSBDevice; |
| 28 | |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 29 | import java.util.Set; |
| 30 | |
| 31 | /** |
| 32 | * Configuration for RestSB provider. |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame^] | 33 | * @deprecated 1.10.0 Kingfisher. Please Use RestDeviceConfig |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 34 | */ |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame^] | 35 | @Deprecated |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 36 | @Beta |
| 37 | public class RestProviderConfig extends Config<ApplicationId> { |
| 38 | |
| 39 | public static final String CONFIG_VALUE_ERROR = "Error parsing config value"; |
| 40 | private static final String IP = "ip"; |
| 41 | private static final int DEFAULT_HTTP_PORT = 80; |
| 42 | private static final String PORT = "port"; |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 43 | private static final String USERNAME = "username"; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 44 | private static final String PASSWORD = "password"; |
| 45 | private static final String PROTOCOL = "protocol"; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 46 | private static final String URL = "url"; |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 47 | private static final String TESTURL = "testUrl"; |
| 48 | private static final String MANUFACTURER = "manufacturer"; |
| 49 | private static final String HWVERSION = "hwVersion"; |
| 50 | private static final String SWVERSION = "swVersion"; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 51 | |
| 52 | public Set<RestSBDevice> getDevicesAddresses() throws ConfigException { |
| 53 | Set<RestSBDevice> devicesAddresses = Sets.newHashSet(); |
| 54 | |
| 55 | try { |
| 56 | for (JsonNode node : array) { |
| 57 | String ip = node.path(IP).asText(); |
| 58 | IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip); |
| 59 | int port = node.path(PORT).asInt(DEFAULT_HTTP_PORT); |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 60 | String username = node.path(USERNAME).asText(); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 61 | String password = node.path(PASSWORD).asText(); |
| 62 | String protocol = node.path(PROTOCOL).asText(); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 63 | String url = node.path(URL).asText(); |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 64 | String testUrl = node.path(TESTURL).asText(); |
| 65 | String manufacturer = node.path(MANUFACTURER).asText(); |
| 66 | String hwVersion = node.path(HWVERSION).asText(); |
| 67 | String swVersion = node.path(SWVERSION).asText(); |
| 68 | |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 69 | devicesAddresses.add(new DefaultRestSBDevice(ipAddr, port, username, |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 70 | password, protocol, |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 71 | url, false, testUrl, manufacturer, |
| 72 | hwVersion, swVersion)); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 73 | } |
| 74 | } catch (IllegalArgumentException e) { |
| 75 | throw new ConfigException(CONFIG_VALUE_ERROR, e); |
| 76 | } |
| 77 | |
| 78 | return devicesAddresses; |
| 79 | } |
| 80 | |
| 81 | } |