blob: d72614304046b06e48fcf6039e336280e26e91f6 [file] [log] [blame]
Andrea Campanella945ded22016-01-07 13:17:43 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Andrea Campanella945ded22016-01-07 13:17:43 -08003 *
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
17package org.onosproject.provider.rest.device.impl;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.google.common.annotations.Beta;
21import com.google.common.collect.Sets;
22import org.onlab.packet.IpAddress;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.incubator.net.config.basics.ConfigException;
25import org.onosproject.net.config.Config;
26import org.onosproject.protocol.rest.DefaultRestSBDevice;
27import org.onosproject.protocol.rest.RestSBDevice;
28
Andrea Campanella945ded22016-01-07 13:17:43 -080029import java.util.Set;
30
31/**
32 * Configuration for RestSB provider.
Andrea Campanella59b549d2017-04-14 21:58:16 +020033 * @deprecated 1.10.0 Kingfisher. Please Use RestDeviceConfig
Andrea Campanella945ded22016-01-07 13:17:43 -080034 */
Andrea Campanella59b549d2017-04-14 21:58:16 +020035@Deprecated
Andrea Campanella945ded22016-01-07 13:17:43 -080036@Beta
37public 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 Campanella784ee0f2016-02-17 15:50:59 -080043 private static final String USERNAME = "username";
Andrea Campanella945ded22016-01-07 13:17:43 -080044 private static final String PASSWORD = "password";
45 private static final String PROTOCOL = "protocol";
Andrea Campanella2947e622016-01-27 09:23:46 -080046 private static final String URL = "url";
Michele Santuaric372c222017-01-12 09:41:25 +010047 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 Campanella945ded22016-01-07 13:17:43 -080051
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 Campanella784ee0f2016-02-17 15:50:59 -080060 String username = node.path(USERNAME).asText();
Andrea Campanella945ded22016-01-07 13:17:43 -080061 String password = node.path(PASSWORD).asText();
62 String protocol = node.path(PROTOCOL).asText();
Andrea Campanella2947e622016-01-27 09:23:46 -080063 String url = node.path(URL).asText();
Michele Santuaric372c222017-01-12 09:41:25 +010064 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 Campanella784ee0f2016-02-17 15:50:59 -080069 devicesAddresses.add(new DefaultRestSBDevice(ipAddr, port, username,
Andrea Campanella2947e622016-01-27 09:23:46 -080070 password, protocol,
Michele Santuaric372c222017-01-12 09:41:25 +010071 url, false, testUrl, manufacturer,
72 hwVersion, swVersion));
Andrea Campanella945ded22016-01-07 13:17:43 -080073 }
74 } catch (IllegalArgumentException e) {
75 throw new ConfigException(CONFIG_VALUE_ERROR, e);
76 }
77
78 return devicesAddresses;
79 }
80
81}