Ayaka Koshibe
Committed by Gerrit Code Review

remove dependency on Devices for handling MastershipEvents

Change-Id: Ie1670e77d3eee5dbd597f574ebe16d687e7b551e
......@@ -358,7 +358,7 @@ public class OpticalConfigProvider extends AbstractProvider implements DevicePro
}
@Override
public void triggerProbe(Device device) {
public void triggerProbe(DeviceId deviceId) {
// TODO We may want to consider re-reading config files and publishing them based on this event.
}
......
......@@ -15,7 +15,6 @@
*/
package org.onlab.onos.net.device;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.provider.Provider;
......@@ -35,9 +34,9 @@ public interface DeviceProvider extends Provider {
* {@link org.onlab.onos.net.device.DeviceProviderService#deviceDisconnected}
* at some later point in time.
*
* @param device device to be probed
* @param deviceId ID of device to be probed
*/
void triggerProbe(Device device);
void triggerProbe(DeviceId deviceId);
/**
* Notifies the provider of a mastership role change for the specified
......
......@@ -182,6 +182,9 @@ public class DeviceManager
// Check a device for control channel connectivity.
private boolean isReachable(DeviceId deviceId) {
if (deviceId == null) {
return false;
}
DeviceProvider provider = getProvider(deviceId);
if (provider != null) {
return provider.isReachable(deviceId);
......@@ -370,7 +373,6 @@ public class DeviceManager
checkNotNull(portDescriptions,
"Port descriptions list cannot be null");
checkValidity();
if (!deviceClockProviderService.isTimestampAvailable(deviceId)) {
// Never been a master for this device
// any update will be ignored.
......@@ -475,15 +477,7 @@ public class DeviceManager
return true;
}
Device device = store.getDevice(deviceId);
// FIXME: Device might not be there yet. (eventual consistent)
// FIXME relinquish role
if (device == null) {
log.warn("{} was not there. Cannot apply role {}", deviceId, newRole);
return false;
}
DeviceProvider provider = getProvider(device.providerId());
DeviceProvider provider = getProvider(deviceId);
if (provider == null) {
log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
return false;
......@@ -492,10 +486,7 @@ public class DeviceManager
if (newRole.equals(MastershipRole.MASTER)) {
// only trigger event when request was sent to provider
// TODO: consider removing this from Device event type?
post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
provider.triggerProbe(device);
provider.triggerProbe(deviceId);
}
return true;
}
......
......@@ -259,7 +259,7 @@ public class DeviceManagerTest {
}
@Override
public void triggerProbe(Device device) {
public void triggerProbe(DeviceId deviceId) {
}
@Override
......
......@@ -235,7 +235,10 @@ public class SimpleDeviceStore
DeviceId deviceId,
List<PortDescription> portDescriptions) {
Device device = devices.get(deviceId);
checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
if (device == null) {
log.debug("Device {} doesn't exist or hasn't been initialized yet", deviceId);
return Collections.emptyList();
}
Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId);
checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId);
......
......@@ -57,7 +57,7 @@ class RoleManager implements RoleHandler {
private static Logger log = LoggerFactory.getLogger(RoleManager.class);
// The time until cached XID is evicted. Arbitray for now.
// The time until cached XID is evicted. Arbitrary for now.
private final int pendingXidTimeoutSeconds = 60;
// The cache for pending expected RoleReplies keyed on expected XID
......
......@@ -127,17 +127,16 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
}
@Override
public void triggerProbe(Device device) {
final DeviceId deviceId = device.id();
public void triggerProbe(DeviceId deviceId) {
LOG.info("Triggering probe on device {}", deviceId);
final Dpid dpid = dpid(deviceId.uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null || !sw.isConnected()) {
LOG.error("Failed to probe device {} on sw={}", device, sw);
LOG.error("Failed to probe device {} on sw={}", deviceId, sw);
providerService.deviceDisconnected(deviceId);
} else {
LOG.trace("Confirmed device {} connection", device);
LOG.trace("Confirmed device {} connection", deviceId);
// FIXME require something like below to match javadoc description
// but this starts infinite loop with current DeviceManager
// final ChassisId cId = new ChassisId(dpid.value());
......
......@@ -240,7 +240,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
}
@Override
public void triggerProbe(Device device) {
public void triggerProbe(DeviceId deviceId) {
}
@Override
......