Bug 3412 - Device should not be propagated if initial stats collection fails
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsManagerImpl.java
index 1ed062f97daa81f0c3a4a114e12f3f6d09842f72..9ab662d529b5df1cd60d9f4dce2558d643c25a74 100644 (file)
@@ -66,10 +66,17 @@ public class StatisticsManagerImpl implements StatisticsManager {
                     contexts.put(deviceContext, statisticsContext);
                     final TimeCounter timeCounter = new TimeCounter();
                     scheduleNextPolling(deviceContext, statisticsContext, timeCounter);
+                    LOG.trace("Device dynamic info collecting done. Going to announce raise to next level.");
+                    deviceInitPhaseHandler.onDeviceContextLevelUp(deviceContext);
+                    deviceContext.getDeviceState().setDeviceSynchronized(true);
+                } else {
+                    final String deviceAdress = deviceContext.getPrimaryConnectionContext().getConnectionAdapter().getRemoteAddress().toString();
+                    try {
+                        deviceContext.close();
+                    } catch (Exception e) {
+                        LOG.info("Statistics for device {} could not be gathered. Closing its device context.", deviceAdress);
+                    }
                 }
-                LOG.trace("Device dynamic info collecting done. Going to announce raise to next level.");
-                deviceInitPhaseHandler.onDeviceContextLevelUp(deviceContext);
-                deviceContext.getDeviceState().setDeviceSynchronized(true);
             }
 
             @Override