Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
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 | |
Konstantinos Kanonakis | 3cd8555 | 2016-11-17 10:11:13 -0600 | [diff] [blame] | 19 | import com.google.common.base.Objects; |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableList; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 21 | import org.onlab.packet.ChassisId; |
Yuta HIGUCHI | fc66705 | 2017-12-05 18:17:22 -0800 | [diff] [blame] | 22 | import org.onlab.util.SharedExecutors; |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 23 | import org.onlab.util.SharedScheduledExecutorService; |
| 24 | import org.onlab.util.SharedScheduledExecutors; |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 25 | import org.onlab.util.Tools; |
| 26 | import org.onosproject.cfg.ComponentConfigService; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.core.CoreService; |
Marc De Leenheer | b0d131c | 2016-03-01 20:34:59 -0800 | [diff] [blame] | 29 | import org.onosproject.net.AnnotationKeys; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 30 | import org.onosproject.net.DefaultAnnotations; |
| 31 | import org.onosproject.net.Device; |
| 32 | import org.onosproject.net.DeviceId; |
| 33 | import org.onosproject.net.MastershipRole; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 34 | import org.onosproject.net.PortNumber; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 35 | import org.onosproject.net.SparseAnnotations; |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 36 | import org.onosproject.net.behaviour.DevicesDiscovery; |
fahadnaeemkhan | 02ffa71 | 2017-12-01 19:49:45 -0800 | [diff] [blame] | 37 | import org.onosproject.net.behaviour.PortAdmin; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 38 | import org.onosproject.net.config.ConfigFactory; |
| 39 | import org.onosproject.net.config.NetworkConfigEvent; |
| 40 | import org.onosproject.net.config.NetworkConfigListener; |
| 41 | import org.onosproject.net.config.NetworkConfigRegistry; |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 42 | import org.onosproject.net.config.basics.SubjectFactories; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 43 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 44 | import org.onosproject.net.device.DeviceDescription; |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 45 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 46 | import org.onosproject.net.device.DeviceProvider; |
| 47 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 48 | import org.onosproject.net.device.DeviceProviderService; |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 49 | import org.onosproject.net.device.DeviceService; |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 50 | import org.onosproject.net.device.PortStatistics; |
| 51 | import org.onosproject.net.device.PortStatisticsDiscovery; |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 52 | import org.onosproject.net.driver.DefaultDriverData; |
| 53 | import org.onosproject.net.driver.DefaultDriverHandler; |
| 54 | import org.onosproject.net.driver.Driver; |
| 55 | import org.onosproject.net.driver.DriverData; |
| 56 | import org.onosproject.net.driver.DriverHandler; |
| 57 | import org.onosproject.net.driver.DriverService; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 58 | import org.onosproject.net.provider.AbstractProvider; |
| 59 | import org.onosproject.net.provider.ProviderId; |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 60 | import org.onosproject.protocol.rest.DefaultRestSBDevice; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 61 | import org.onosproject.protocol.rest.RestSBController; |
| 62 | import org.onosproject.protocol.rest.RestSBDevice; |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 63 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 64 | import org.osgi.service.component.annotations.Activate; |
| 65 | import org.osgi.service.component.annotations.Component; |
| 66 | import org.osgi.service.component.annotations.Deactivate; |
| 67 | import org.osgi.service.component.annotations.Modified; |
| 68 | import org.osgi.service.component.annotations.Reference; |
| 69 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 70 | import org.slf4j.Logger; |
| 71 | |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 72 | import javax.ws.rs.ProcessingException; |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 73 | import javax.ws.rs.core.MediaType; |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 74 | import java.util.Collection; |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 75 | import java.util.Dictionary; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 76 | import java.util.HashSet; |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 77 | import java.util.List; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 78 | import java.util.Set; |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 79 | import java.util.concurrent.Callable; |
fahadnaeemkhan | 02ffa71 | 2017-12-01 19:49:45 -0800 | [diff] [blame] | 80 | import java.util.concurrent.CompletableFuture; |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 81 | import java.util.concurrent.ExecutionException; |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 82 | import java.util.concurrent.ExecutorService; |
| 83 | import java.util.concurrent.Executors; |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 84 | import java.util.concurrent.Future; |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 85 | import java.util.concurrent.ScheduledFuture; |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 86 | import java.util.concurrent.TimeUnit; |
| 87 | import java.util.concurrent.TimeoutException; |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 88 | import java.util.stream.Collectors; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 89 | |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 90 | import static com.google.common.base.Preconditions.checkNotNull; |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 91 | import static org.onlab.util.Tools.groupedThreads; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 92 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_ADDED; |
Yuta HIGUCHI | fc66705 | 2017-12-05 18:17:22 -0800 | [diff] [blame] | 93 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_REMOVED; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 94 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UPDATED; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 95 | import static org.slf4j.LoggerFactory.getLogger; |
| 96 | |
| 97 | /** |
| 98 | * Provider for devices that use REST as means of configuration communication. |
| 99 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 100 | @Component(immediate = true, service = DeviceProvider.class) |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 101 | public class RestDeviceProvider extends AbstractProvider |
| 102 | implements DeviceProvider { |
| 103 | private static final String APP_NAME = "org.onosproject.restsb"; |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 104 | protected static final String REST = "rest"; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 105 | private static final String PROVIDER = "org.onosproject.provider.rest.device"; |
| 106 | private static final String IPADDRESS = "ipaddress"; |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 107 | private static final String ISNOTNULL = "Rest device is not null"; |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 108 | private static final String UNKNOWN = "unknown"; |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 109 | private static final String POLL_FREQUENCY = "pollFrequency"; |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 110 | private static final int REST_TIMEOUT_SEC = 5; |
Georgios Katsikas | 6a4d166 | 2017-07-27 13:22:31 +0200 | [diff] [blame] | 111 | private static final int EXECUTOR_THREAD_POOL_SIZE = 8; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 112 | private final Logger log = getLogger(getClass()); |
| 113 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 115 | protected DeviceProviderRegistry providerRegistry; |
| 116 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 117 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 118 | protected RestSBController controller; |
| 119 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 121 | protected NetworkConfigRegistry netCfgService; |
| 122 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 123 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 124 | protected ComponentConfigService compCfgService; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 125 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 126 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 127 | protected CoreService coreService; |
| 128 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 129 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 130 | protected DeviceService deviceService; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 131 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 132 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 133 | protected DriverService driverService; |
| 134 | |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 135 | private static final int DEFAULT_POLL_FREQUENCY_SECONDS = 30; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 136 | //@Property(name = POLL_FREQUENCY, intValue = DEFAULT_POLL_FREQUENCY_SECONDS, |
| 137 | // label = "Configure poll frequency for port status and statistics; " + |
| 138 | // "default is 30 seconds") |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 139 | private int pollFrequency = DEFAULT_POLL_FREQUENCY_SECONDS; |
| 140 | |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 141 | private DeviceProviderService providerService; |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 142 | private ApplicationId appId; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 143 | |
Michal Mach | 13072e2 | 2017-06-21 09:12:24 +0200 | [diff] [blame] | 144 | private ExecutorService executor; |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 145 | private final SharedScheduledExecutorService portStatisticsExecutor = |
| 146 | SharedScheduledExecutors.getPoolThreadExecutor(); |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 147 | |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 148 | private final List<ConfigFactory> factories = ImmutableList.of( |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 149 | new ConfigFactory<DeviceId, RestDeviceConfig>(SubjectFactories.DEVICE_SUBJECT_FACTORY, |
| 150 | RestDeviceConfig.class, |
| 151 | REST) { |
| 152 | @Override |
| 153 | public RestDeviceConfig createConfig() { |
| 154 | return new RestDeviceConfig(); |
| 155 | } |
| 156 | }); |
| 157 | |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 158 | private final NetworkConfigListener configListener = new InternalNetworkConfigListener(); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 159 | |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 160 | private ScheduledFuture<?> scheduledTask; |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 161 | |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 162 | |
| 163 | @Activate |
| 164 | public void activate() { |
| 165 | appId = coreService.registerApplication(APP_NAME); |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 166 | compCfgService.registerProperties(getClass()); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 167 | providerService = providerRegistry.register(this); |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 168 | factories.forEach(netCfgService::registerConfigFactory); |
Georgios Katsikas | 6a4d166 | 2017-07-27 13:22:31 +0200 | [diff] [blame] | 169 | executor = Executors.newFixedThreadPool( |
| 170 | EXECUTOR_THREAD_POOL_SIZE, groupedThreads("onos/restsbprovider", "device-installer-%d", log) |
| 171 | ); |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 172 | netCfgService.addListener(configListener); |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 173 | executor.execute(RestDeviceProvider.this::createAndConnectDevices); |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 174 | scheduledTask = schedulePolling(); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 175 | log.info("Started"); |
| 176 | } |
| 177 | |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 178 | @Modified |
| 179 | public void modified(ComponentContext context) { |
| 180 | int previousPollFrequency = pollFrequency; |
| 181 | |
| 182 | if (context != null) { |
| 183 | Dictionary<?, ?> properties = context.getProperties(); |
| 184 | pollFrequency = Tools.getIntegerProperty(properties, POLL_FREQUENCY, |
| 185 | DEFAULT_POLL_FREQUENCY_SECONDS); |
| 186 | log.info("Configured. Poll frequency is configured to {} seconds", pollFrequency); |
| 187 | } |
| 188 | |
| 189 | // Re-schedule only if frequency has changed |
| 190 | if (!scheduledTask.isCancelled() && (previousPollFrequency != pollFrequency)) { |
| 191 | log.info("Re-scheduling port statistics task with frequency {} seconds", pollFrequency); |
| 192 | scheduledTask.cancel(true); |
| 193 | scheduledTask = schedulePolling(); |
| 194 | } |
| 195 | } |
| 196 | |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 197 | @Deactivate |
| 198 | public void deactivate() { |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 199 | compCfgService.unregisterProperties(getClass(), false); |
| 200 | netCfgService.removeListener(configListener); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 201 | providerRegistry.unregister(this); |
| 202 | providerService = null; |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 203 | factories.forEach(netCfgService::unregisterConfigFactory); |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 204 | scheduledTask.cancel(true); |
Lukasz Ryba | 4da35c5 | 2017-06-20 09:14:11 +0200 | [diff] [blame] | 205 | executor.shutdown(); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 206 | log.info("Stopped"); |
| 207 | } |
| 208 | |
| 209 | public RestDeviceProvider() { |
| 210 | super(new ProviderId(REST, PROVIDER)); |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void triggerProbe(DeviceId deviceId) { |
| 215 | // TODO: This will be implemented later. |
| 216 | log.info("Triggering probe on device {}", deviceId); |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public void roleChanged(DeviceId deviceId, MastershipRole newRole) { |
| 221 | // TODO: This will be implemented later. |
| 222 | } |
| 223 | |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 224 | @Override |
| 225 | public boolean isReachable(DeviceId deviceId) { |
| 226 | RestSBDevice restDevice = controller.getDevice(deviceId); |
| 227 | if (restDevice == null) { |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 228 | restDevice = controller.getProxySBDevice(deviceId); |
| 229 | if (restDevice == null) { |
| 230 | log.debug("the requested device id: " + |
| 231 | deviceId.toString() + |
| 232 | " is not associated to any REST or REST " + |
| 233 | "proxy Device"); |
| 234 | return false; |
| 235 | } |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 236 | } |
| 237 | return restDevice.isActive(); |
| 238 | } |
| 239 | |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 240 | private void deviceAdded(RestSBDevice restSBDev) { |
| 241 | checkNotNull(restSBDev, ISNOTNULL); |
| 242 | |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 243 | Driver driver = driverService.getDriver(restSBDev.manufacturer().get(), |
| 244 | restSBDev.hwVersion().get(), |
| 245 | restSBDev.swVersion().get()); |
| 246 | |
| 247 | // Check if the server is controlling a single or multiple devices |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 248 | if (restSBDev.isProxy()) { |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 249 | if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) { |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 250 | DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver); |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 251 | Set<DeviceId> deviceIds = devicesDiscovery.deviceIds(); |
| 252 | restSBDev.setActive(true); |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 253 | deviceIds.forEach(deviceId -> { |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 254 | controller.addProxiedDevice(deviceId, restSBDev); |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 255 | DeviceDescription devDesc = devicesDiscovery.deviceDetails(deviceId); |
| 256 | checkNotNull(devDesc, "DeviceDescription cannot be null"); |
| 257 | providerService.deviceConnected(deviceId, mergeAnn(restSBDev.deviceId(), devDesc)); |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 258 | |
| 259 | if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) { |
| 260 | DriverHandler h = driverService.createHandler(deviceId); |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 261 | DeviceDescriptionDiscovery devDisc = h.behaviour(DeviceDescriptionDiscovery.class); |
| 262 | providerService.updatePorts(deviceId, devDisc.discoverPortDetails()); |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | checkAndUpdateDevice(deviceId); |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 266 | }); |
| 267 | } else { |
| 268 | log.warn("Driver not found for {}", restSBDev); |
| 269 | } |
| 270 | } else { |
| 271 | DeviceId deviceId = restSBDev.deviceId(); |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 272 | if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) { |
| 273 | restSBDev.setActive(true); |
| 274 | DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver); |
| 275 | DeviceDescription deviceDescription = devicesDiscovery.deviceDetails(deviceId); |
| 276 | checkNotNull(deviceDescription, "DeviceDescription cannot be null"); |
| 277 | providerService.deviceConnected(deviceId, deviceDescription); |
| 278 | |
| 279 | if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) { |
| 280 | DriverHandler h = driverService.createHandler(deviceId); |
| 281 | DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class); |
| 282 | providerService.updatePorts(deviceId, deviceDiscovery.discoverPortDetails()); |
| 283 | } |
| 284 | } else { |
| 285 | ChassisId cid = new ChassisId(); |
| 286 | String ipAddress = restSBDev.ip().toString(); |
| 287 | SparseAnnotations annotations = DefaultAnnotations.builder() |
| 288 | .set(IPADDRESS, ipAddress) |
| 289 | .set(AnnotationKeys.PROTOCOL, REST.toUpperCase()) |
| 290 | .build(); |
| 291 | DeviceDescription deviceDescription = new DefaultDeviceDescription( |
| 292 | deviceId.uri(), |
| 293 | Device.Type.SWITCH, |
| 294 | UNKNOWN, UNKNOWN, |
| 295 | UNKNOWN, UNKNOWN, |
| 296 | cid, |
| 297 | annotations); |
| 298 | restSBDev.setActive(true); |
| 299 | providerService.deviceConnected(deviceId, deviceDescription); |
| 300 | } |
| 301 | |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 302 | checkAndUpdateDevice(deviceId); |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | private DefaultDeviceDescription mergeAnn(DeviceId devId, DeviceDescription desc) { |
| 307 | return new DefaultDeviceDescription( |
| 308 | desc, |
| 309 | DefaultAnnotations.merge( |
| 310 | DefaultAnnotations.builder() |
| 311 | .set(AnnotationKeys.PROTOCOL, REST.toUpperCase()) |
| 312 | // The rest server added as annotation to the device |
| 313 | .set(AnnotationKeys.REST_SERVER, devId.toString()) |
| 314 | .build(), |
| 315 | desc.annotations())); |
| 316 | } |
| 317 | |
| 318 | private DevicesDiscovery devicesDiscovery(RestSBDevice restSBDevice, Driver driver) { |
| 319 | DriverData driverData = new DefaultDriverData(driver, restSBDevice.deviceId()); |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 320 | DevicesDiscovery devicesDiscovery = driver.createBehaviour(driverData, DevicesDiscovery.class); |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 321 | devicesDiscovery.setHandler(new DefaultDriverHandler(driverData)); |
| 322 | return devicesDiscovery; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Konstantinos Kanonakis | 3cd8555 | 2016-11-17 10:11:13 -0600 | [diff] [blame] | 325 | private void checkAndUpdateDevice(DeviceId deviceId) { |
| 326 | if (deviceService.getDevice(deviceId) == null) { |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 327 | log.warn("Device {} has not been added to store, maybe due to a problem in connectivity", deviceId); |
Konstantinos Kanonakis | 3cd8555 | 2016-11-17 10:11:13 -0600 | [diff] [blame] | 328 | } else { |
| 329 | boolean isReachable = isReachable(deviceId); |
| 330 | if (isReachable && deviceService.isAvailable(deviceId)) { |
| 331 | Device device = deviceService.getDevice(deviceId); |
| 332 | if (device.is(DeviceDescriptionDiscovery.class)) { |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 333 | DeviceDescriptionDiscovery deviceDescriptionDiscovery = |
| 334 | device.as(DeviceDescriptionDiscovery.class); |
| 335 | DeviceDescription updatedDeviceDescription = |
| 336 | deviceDescriptionDiscovery.discoverDeviceDetails(); |
| 337 | if (updatedDeviceDescription != null && |
| 338 | !descriptionEquals(device, updatedDeviceDescription)) { |
| 339 | providerService.deviceConnected( |
| 340 | deviceId, |
| 341 | new DefaultDeviceDescription( |
| 342 | updatedDeviceDescription, true, |
| 343 | updatedDeviceDescription.annotations())); |
Konstantinos Kanonakis | 3cd8555 | 2016-11-17 10:11:13 -0600 | [diff] [blame] | 344 | //if ports are not discovered, retry the discovery |
| 345 | if (deviceService.getPorts(deviceId).isEmpty()) { |
| 346 | discoverPorts(deviceId); |
| 347 | } |
| 348 | } |
| 349 | } else { |
| 350 | log.warn("No DeviceDescriptionDiscovery behaviour for device {}", deviceId); |
| 351 | } |
| 352 | } else if (!isReachable && deviceService.isAvailable(deviceId)) { |
| 353 | providerService.deviceDisconnected(deviceId); |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | private boolean descriptionEquals(Device device, DeviceDescription updatedDeviceDescription) { |
Michele Santuari | d2c8f21 | 2017-01-09 18:23:45 +0100 | [diff] [blame] | 359 | return Objects.equal(device.id().uri(), updatedDeviceDescription.deviceUri()) |
Konstantinos Kanonakis | 3cd8555 | 2016-11-17 10:11:13 -0600 | [diff] [blame] | 360 | && Objects.equal(device.type(), updatedDeviceDescription.type()) |
| 361 | && Objects.equal(device.manufacturer(), updatedDeviceDescription.manufacturer()) |
| 362 | && Objects.equal(device.hwVersion(), updatedDeviceDescription.hwVersion()) |
| 363 | && Objects.equal(device.swVersion(), updatedDeviceDescription.swVersion()) |
| 364 | && Objects.equal(device.serialNumber(), updatedDeviceDescription.serialNumber()) |
| 365 | && Objects.equal(device.chassisId(), updatedDeviceDescription.chassisId()) |
| 366 | && Objects.equal(device.annotations(), updatedDeviceDescription.annotations()); |
| 367 | } |
| 368 | |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 369 | private void deviceRemoved(DeviceId deviceId) { |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 370 | checkNotNull(deviceId, ISNOTNULL); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 371 | providerService.deviceDisconnected(deviceId); |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 372 | controller.getProxiedDevices(deviceId).forEach(device -> { |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 373 | controller.removeProxiedDevice(device); |
| 374 | providerService.deviceDisconnected(device); |
| 375 | }); |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 376 | controller.removeDevice(deviceId); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 379 | //Method to connect devices provided via net-cfg under devices/ tree |
| 380 | private void createAndConnectDevices() { |
| 381 | Set<DeviceId> deviceSubjects = |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 382 | netCfgService.getSubjects(DeviceId.class, RestDeviceConfig.class); |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 383 | connectDevices(deviceSubjects.stream() |
fahadnaeemkhan | 02ffa71 | 2017-12-01 19:49:45 -0800 | [diff] [blame] | 384 | .filter(deviceId -> deviceService.getDevice(deviceId) == null) |
| 385 | .map(deviceId -> { |
| 386 | RestDeviceConfig config = |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 387 | netCfgService.getConfig(deviceId, RestDeviceConfig.class); |
Yuta HIGUCHI | fc66705 | 2017-12-05 18:17:22 -0800 | [diff] [blame] | 388 | return toInactiveRestSBDevice(config); |
fahadnaeemkhan | 02ffa71 | 2017-12-01 19:49:45 -0800 | [diff] [blame] | 389 | }).collect(Collectors.toSet())); |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 390 | } |
| 391 | |
Yuta HIGUCHI | fc66705 | 2017-12-05 18:17:22 -0800 | [diff] [blame] | 392 | private RestSBDevice toInactiveRestSBDevice(RestDeviceConfig config) { |
| 393 | return new DefaultRestSBDevice(config.ip(), |
| 394 | config.port(), |
| 395 | config.username(), |
| 396 | config.password(), |
| 397 | config.protocol(), |
| 398 | config.url(), |
| 399 | false, |
| 400 | config.testUrl(), |
| 401 | config.manufacturer(), |
| 402 | config.hwVersion(), |
| 403 | config.swVersion(), |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 404 | config.isProxy(), |
Yuta HIGUCHI | fc66705 | 2017-12-05 18:17:22 -0800 | [diff] [blame] | 405 | config.authenticationScheme(), |
| 406 | config.token() |
| 407 | ); |
| 408 | } |
| 409 | |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 410 | private void connectDevices(Set<RestSBDevice> devices) { |
| 411 | //Precomputing the devices to be removed |
| 412 | Set<RestSBDevice> toBeRemoved = new HashSet<>(controller.getDevices().values()); |
| 413 | toBeRemoved.removeAll(devices); |
| 414 | //Adding new devices |
| 415 | devices.stream() |
| 416 | .filter(device -> { |
| 417 | device.setActive(false); |
| 418 | controller.addDevice(device); |
| 419 | return testDeviceConnection(device); |
| 420 | }) |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 421 | .forEach(this::deviceAdded); |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 422 | //Removing devices not wanted anymore |
| 423 | toBeRemoved.forEach(device -> deviceRemoved(device.deviceId())); |
| 424 | } |
| 425 | |
Yuta HIGUCHI | fc66705 | 2017-12-05 18:17:22 -0800 | [diff] [blame] | 426 | private void connectDevice(RestSBDevice device) { |
| 427 | // TODO borrowed from above, |
| 428 | // not sure why setting it to inactive |
| 429 | device.setActive(false); |
| 430 | controller.addDevice(device); |
| 431 | if (testDeviceConnection(device)) { |
| 432 | deviceAdded(device); |
| 433 | } |
| 434 | } |
| 435 | |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 436 | private ScheduledFuture schedulePolling() { |
| 437 | return portStatisticsExecutor.scheduleAtFixedRate(this::executePortStatisticsUpdate, |
Georgios Katsikas | 0f12bc6 | 2018-07-06 09:06:42 +0200 | [diff] [blame] | 438 | pollFrequency / 2, pollFrequency, |
Michal Mach | d809974 | 2017-06-19 14:32:35 +0200 | [diff] [blame] | 439 | TimeUnit.SECONDS); |
| 440 | } |
| 441 | |
| 442 | private void executePortStatisticsUpdate() { |
| 443 | controller.getDevices().keySet().forEach(this::updatePortStatistics); |
| 444 | } |
| 445 | |
| 446 | private void updatePortStatistics(DeviceId deviceId) { |
| 447 | Device device = deviceService.getDevice(deviceId); |
| 448 | checkNotNull(device, "device cannot be null"); |
| 449 | |
| 450 | if (device.is(PortStatisticsDiscovery.class)) { |
| 451 | PortStatisticsDiscovery portStatisticsDiscovery = device.as(PortStatisticsDiscovery.class); |
| 452 | Collection<PortStatistics> portStatistics = portStatisticsDiscovery.discoverPortStatistics(); |
| 453 | if (portStatistics != null && !portStatistics.isEmpty()) { |
| 454 | providerService.updatePortStatistics(deviceId, portStatistics); |
| 455 | } |
| 456 | } else { |
| 457 | log.debug("No port statistics getter behaviour for device {}", deviceId); |
| 458 | } |
| 459 | } |
| 460 | |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 461 | private void discoverPorts(DeviceId deviceId) { |
| 462 | Device device = deviceService.getDevice(deviceId); |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 463 | DeviceDescriptionDiscovery deviceDescriptionDiscovery = device.as(DeviceDescriptionDiscovery.class); |
Ray Milkey | 640fedd | 2018-02-08 09:02:26 -0800 | [diff] [blame] | 464 | providerService.updatePorts(deviceId, deviceDescriptionDiscovery.discoverPortDetails()); |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 467 | private boolean testDeviceConnection(RestSBDevice dev) { |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 468 | try { |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 469 | Callable<Boolean> connectionSuccess; |
| 470 | |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 471 | if (dev.testUrl().isPresent()) { |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 472 | connectionSuccess = () -> |
| 473 | controller.get(dev.deviceId(), dev.testUrl().get(), MediaType.APPLICATION_JSON_TYPE) != null; |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 474 | } else { |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 475 | connectionSuccess = () -> |
| 476 | controller.get(dev.deviceId(), "", MediaType.APPLICATION_JSON_TYPE) != null; |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 477 | } |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 478 | |
| 479 | Future<Boolean> future = executor.submit(connectionSuccess); |
| 480 | try { |
Michal Mach | 67acb69 | 2017-06-21 12:05:36 +0200 | [diff] [blame] | 481 | return future.get(REST_TIMEOUT_SEC, TimeUnit.SECONDS); |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 482 | } catch (TimeoutException ex) { |
Sean Condon | e45e12c | 2018-05-04 16:27:07 +0100 | [diff] [blame] | 483 | log.warn("Connection to device {} timed out: {}", dev.deviceId(), ex.getMessage()); |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 484 | return false; |
| 485 | } catch (InterruptedException ex) { |
Sean Condon | e45e12c | 2018-05-04 16:27:07 +0100 | [diff] [blame] | 486 | log.warn("Connection to device {} interrupted: {}", dev.deviceId(), ex.getMessage()); |
Ray Milkey | 5c7d488 | 2018-02-05 14:50:39 -0800 | [diff] [blame] | 487 | Thread.currentThread().interrupt(); |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 488 | return false; |
| 489 | } catch (ExecutionException ex) { |
Sean Condon | e45e12c | 2018-05-04 16:27:07 +0100 | [diff] [blame] | 490 | log.warn("Connection to device {} had an execution exception.", dev.deviceId(), ex); |
Palash Kala | 4c71ee7 | 2017-05-24 17:43:59 +0900 | [diff] [blame] | 491 | return false; |
| 492 | } |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 493 | |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 494 | } catch (ProcessingException e) { |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 495 | log.warn("Cannot connect to device {}", dev, e); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 496 | } |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 501 | @Override |
| 502 | public void event(NetworkConfigEvent event) { |
Georgios Katsikas | 15841e2 | 2018-07-28 14:27:28 +0200 | [diff] [blame] | 503 | if (!isRelevant(event)) { |
| 504 | log.warn("Irrelevant network configuration event: {}", event); |
| 505 | return; |
| 506 | } |
| 507 | |
Yuta HIGUCHI | fc66705 | 2017-12-05 18:17:22 -0800 | [diff] [blame] | 508 | ExecutorService bg = SharedExecutors.getSingleThreadExecutor(); |
| 509 | if (event.type() == CONFIG_REMOVED) { |
| 510 | DeviceId did = (DeviceId) event.subject(); |
| 511 | bg.execute(() -> deviceRemoved(did)); |
| 512 | } else { |
| 513 | // CONFIG_ADDED or CONFIG_UPDATED |
| 514 | RestDeviceConfig cfg = (RestDeviceConfig) event.config().get(); |
| 515 | RestSBDevice restSBDevice = toInactiveRestSBDevice(cfg); |
| 516 | bg.execute(() -> connectDevice(restSBDevice)); |
| 517 | } |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | @Override |
| 521 | public boolean isRelevant(NetworkConfigEvent event) { |
Yuta HIGUCHI | 872fdbe | 2017-12-05 15:34:28 -0800 | [diff] [blame] | 522 | return event.configClass().equals(RestDeviceConfig.class) && |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 523 | (event.type() == CONFIG_ADDED || |
Yuta HIGUCHI | fc66705 | 2017-12-05 18:17:22 -0800 | [diff] [blame] | 524 | event.type() == CONFIG_UPDATED || |
| 525 | event.type() == CONFIG_REMOVED); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 526 | } |
| 527 | } |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 528 | |
| 529 | @Override |
| 530 | public void changePortState(DeviceId deviceId, PortNumber portNumber, |
| 531 | boolean enable) { |
fahadnaeemkhan | 482951f | 2017-08-24 16:35:17 -0700 | [diff] [blame] | 532 | Device device = deviceService.getDevice(deviceId); |
| 533 | if (device != null) { |
| 534 | if (device.is(PortAdmin.class)) { |
| 535 | PortAdmin portAdmin = device.as(PortAdmin.class); |
| 536 | CompletableFuture<Boolean> modified; |
| 537 | if (enable) { |
| 538 | modified = portAdmin.enable(portNumber); |
| 539 | } else { |
| 540 | modified = portAdmin.disable(portNumber); |
| 541 | } |
| 542 | modified.thenAcceptAsync(result -> { |
| 543 | if (!result) { |
| 544 | log.warn("Device {} port {} state can't be changed to {}", |
| 545 | deviceId, portNumber, enable); |
| 546 | } |
| 547 | }); |
| 548 | |
| 549 | } else { |
| 550 | log.warn("Device {} does not support PortAdmin behavior", deviceId); |
| 551 | } |
| 552 | } else { |
| 553 | log.warn("unable to get the device {}, port {} state can't be changed to {}", |
| 554 | deviceId, portNumber, enable); |
| 555 | } |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 556 | } |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 557 | } |