blob: 5e6fc96d9b784425d310b31f14ed1f9988f8c393 [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.
33 */
34@Beta
35public class RestProviderConfig extends Config<ApplicationId> {
36
37 public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
38 private static final String IP = "ip";
39 private static final int DEFAULT_HTTP_PORT = 80;
40 private static final String PORT = "port";
Andrea Campanella784ee0f2016-02-17 15:50:59 -080041 private static final String USERNAME = "username";
Andrea Campanella945ded22016-01-07 13:17:43 -080042 private static final String PASSWORD = "password";
43 private static final String PROTOCOL = "protocol";
Andrea Campanella2947e622016-01-27 09:23:46 -080044 private static final String URL = "url";
Michele Santuaric372c222017-01-12 09:41:25 +010045 private static final String TESTURL = "testUrl";
46 private static final String MANUFACTURER = "manufacturer";
47 private static final String HWVERSION = "hwVersion";
48 private static final String SWVERSION = "swVersion";
Andrea Campanella945ded22016-01-07 13:17:43 -080049
50 public Set<RestSBDevice> getDevicesAddresses() throws ConfigException {
51 Set<RestSBDevice> devicesAddresses = Sets.newHashSet();
52
53 try {
54 for (JsonNode node : array) {
55 String ip = node.path(IP).asText();
56 IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
57 int port = node.path(PORT).asInt(DEFAULT_HTTP_PORT);
Andrea Campanella784ee0f2016-02-17 15:50:59 -080058 String username = node.path(USERNAME).asText();
Andrea Campanella945ded22016-01-07 13:17:43 -080059 String password = node.path(PASSWORD).asText();
60 String protocol = node.path(PROTOCOL).asText();
Andrea Campanella2947e622016-01-27 09:23:46 -080061 String url = node.path(URL).asText();
Michele Santuaric372c222017-01-12 09:41:25 +010062 String testUrl = node.path(TESTURL).asText();
63 String manufacturer = node.path(MANUFACTURER).asText();
64 String hwVersion = node.path(HWVERSION).asText();
65 String swVersion = node.path(SWVERSION).asText();
66
Andrea Campanella784ee0f2016-02-17 15:50:59 -080067 devicesAddresses.add(new DefaultRestSBDevice(ipAddr, port, username,
Andrea Campanella2947e622016-01-27 09:23:46 -080068 password, protocol,
Michele Santuaric372c222017-01-12 09:41:25 +010069 url, false, testUrl, manufacturer,
70 hwVersion, swVersion));
Andrea Campanella945ded22016-01-07 13:17:43 -080071 }
72 } catch (IllegalArgumentException e) {
73 throw new ConfigException(CONFIG_VALUE_ERROR, e);
74 }
75
76 return devicesAddresses;
77 }
78
79}