blob: 21d9774225330978df0868cb3daa1d1809f3bded [file] [log] [blame]
Andrea Campanella945ded22016-01-07 13:17:43 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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;
Andrea Campanella945ded22016-01-07 13:17:43 -080024import org.onosproject.net.config.Config;
fahadnaeemkhan02ffa712017-12-01 19:49:45 -080025import org.onosproject.net.config.ConfigException;
Andrea Campanella945ded22016-01-07 13:17:43 -080026import org.onosproject.protocol.rest.DefaultRestSBDevice;
27import org.onosproject.protocol.rest.RestSBDevice;
fahadnaeemkhan02ffa712017-12-01 19:49:45 -080028import org.onosproject.protocol.rest.RestSBDevice.AuthenticationScheme;
Andrea Campanella945ded22016-01-07 13:17:43 -080029
Andrea Campanella945ded22016-01-07 13:17:43 -080030import java.util.Set;
31
32/**
33 * Configuration for RestSB provider.
fahadnaeemkhan02ffa712017-12-01 19:49:45 -080034 *
Andrea Campanella59b549d2017-04-14 21:58:16 +020035 * @deprecated 1.10.0 Kingfisher. Please Use RestDeviceConfig
Andrea Campanella945ded22016-01-07 13:17:43 -080036 */
Andrea Campanella59b549d2017-04-14 21:58:16 +020037@Deprecated
Andrea Campanella945ded22016-01-07 13:17:43 -080038@Beta
39public class RestProviderConfig extends Config<ApplicationId> {
40
41 public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
42 private static final String IP = "ip";
43 private static final int DEFAULT_HTTP_PORT = 80;
44 private static final String PORT = "port";
Andrea Campanella784ee0f2016-02-17 15:50:59 -080045 private static final String USERNAME = "username";
Andrea Campanella945ded22016-01-07 13:17:43 -080046 private static final String PASSWORD = "password";
47 private static final String PROTOCOL = "protocol";
Andrea Campanella2947e622016-01-27 09:23:46 -080048 private static final String URL = "url";
Michele Santuaric372c222017-01-12 09:41:25 +010049 private static final String TESTURL = "testUrl";
50 private static final String MANUFACTURER = "manufacturer";
51 private static final String HWVERSION = "hwVersion";
52 private static final String SWVERSION = "swVersion";
fahadnaeemkhan02ffa712017-12-01 19:49:45 -080053 private static final String AUTHENTICATION_SCHEME = "authenticationScheme";
54 private static final String TOKEN = "token";
Andrea Campanella945ded22016-01-07 13:17:43 -080055
56 public Set<RestSBDevice> getDevicesAddresses() throws ConfigException {
57 Set<RestSBDevice> devicesAddresses = Sets.newHashSet();
58
59 try {
60 for (JsonNode node : array) {
61 String ip = node.path(IP).asText();
62 IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
63 int port = node.path(PORT).asInt(DEFAULT_HTTP_PORT);
Andrea Campanella784ee0f2016-02-17 15:50:59 -080064 String username = node.path(USERNAME).asText();
Andrea Campanella945ded22016-01-07 13:17:43 -080065 String password = node.path(PASSWORD).asText();
66 String protocol = node.path(PROTOCOL).asText();
Andrea Campanella2947e622016-01-27 09:23:46 -080067 String url = node.path(URL).asText();
Michele Santuaric372c222017-01-12 09:41:25 +010068 String testUrl = node.path(TESTURL).asText();
69 String manufacturer = node.path(MANUFACTURER).asText();
70 String hwVersion = node.path(HWVERSION).asText();
71 String swVersion = node.path(SWVERSION).asText();
fahadnaeemkhan02ffa712017-12-01 19:49:45 -080072 AuthenticationScheme authenticationScheme = AuthenticationScheme.valueOf(node.path(
73 AUTHENTICATION_SCHEME).asText().toUpperCase());
74 String token = node.path(TOKEN).asText();
Michele Santuaric372c222017-01-12 09:41:25 +010075
Andrea Campanella784ee0f2016-02-17 15:50:59 -080076 devicesAddresses.add(new DefaultRestSBDevice(ipAddr, port, username,
fahadnaeemkhan02ffa712017-12-01 19:49:45 -080077 password, protocol,
78 url, false, testUrl, manufacturer,
79 hwVersion, swVersion, authenticationScheme, token));
Andrea Campanella945ded22016-01-07 13:17:43 -080080 }
81 } catch (IllegalArgumentException e) {
82 throw new ConfigException(CONFIG_VALUE_ERROR, e);
83 }
84
85 return devicesAddresses;
86 }
87
88}