Fix for propeties that need to have the same name as the used variable.

Enabling rest reply timout to be configured

Change-Id: I4435c1d359a47b64d861c9a1be7ec1008371ba2b
This commit is contained in:
Andrea Campanella 2019-03-18 16:57:27 -07:00 committed by Ray Milkey
parent 40259008bd
commit 02f86c84a0
4 changed files with 35 additions and 25 deletions

View File

@ -109,7 +109,7 @@ import static org.slf4j.LoggerFactory.getLogger;
*/ */
@Component(immediate = true, @Component(immediate = true,
property = { property = {
POLL_FREQUENCY_SECONDS_DEFAULT + ":Integer=" + POLL_FREQUENCY_SECONDS_DEFAULT, POLL_FREQUENCY_SECONDS + ":Integer=" + POLL_FREQUENCY_SECONDS_DEFAULT,
MAX_RETRIES + ":Integer=" + MAX_RETRIES_DEFAULT, MAX_RETRIES + ":Integer=" + MAX_RETRIES_DEFAULT,
}) })
public class NetconfDeviceProvider extends AbstractProvider public class NetconfDeviceProvider extends AbstractProvider

View File

@ -457,7 +457,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
private int portStatsPollFrequency = POLL_FREQ_DEFAULT; private int portStatsPollFrequency = POLL_FREQ_DEFAULT;
/** It indicates frequency must be used instead of wavelength for port tuning. */ /** It indicates frequency must be used instead of wavelength for port tuning. */
private static boolean propFreq = PROP_FREQ_DEFAULT; private static boolean propertyFrequency = PROP_FREQ_DEFAULT;
private final Timer timer = new Timer("onos-openflow-portstats-collector"); private final Timer timer = new Timer("onos-openflow-portstats-collector");
@ -655,12 +655,12 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
private static String freqLmdaToAnnotation(long freqLmda, boolean useFreq) { private static String freqLmdaToAnnotation(long freqLmda, boolean useFreq) {
if (useFreq) { if (useFreq) {
if (propFreq) { if (propertyFrequency) {
mhzToAnnotation(freqLmda); mhzToAnnotation(freqLmda);
} else { } else {
mhzToAnnotationNm(freqLmda); mhzToAnnotationNm(freqLmda);
} }
} else if (propFreq) { } else if (propertyFrequency) {
lambdaToAnnotationHz(freqLmda); lambdaToAnnotationHz(freqLmda);
} }
return Double.toString(freqLmda / 100.0); return Double.toString(freqLmda / 100.0);
@ -709,11 +709,11 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
long txOffset = optical.get().getTxOffset(); long txOffset = optical.get().getTxOffset();
long txGridSpan = optical.get().getTxGridSpan(); long txGridSpan = optical.get().getTxGridSpan();
annotations.set(AK_TX_TUNE_FEATURE, ((flags & txTune) != 0) ? "enabled" : "disabled"); annotations.set(AK_TX_TUNE_FEATURE, ((flags & txTune) != 0) ? "enabled" : "disabled");
annotations.set(propFreq ? AK_TX_FREQ_HZ : AK_TX_LMDA_NM, annotations.set(propertyFrequency ? AK_TX_FREQ_HZ : AK_TX_LMDA_NM,
freqLmdaToAnnotation(txFreq, useFreq)); freqLmdaToAnnotation(txFreq, useFreq));
annotations.set(propFreq ? AK_TX_OFFSET_HZ : AK_TX_OFFSET_LMDA_NM, annotations.set(propertyFrequency ? AK_TX_OFFSET_HZ : AK_TX_OFFSET_LMDA_NM,
freqLmdaToAnnotation(txOffset, useFreq)); freqLmdaToAnnotation(txOffset, useFreq));
annotations.set(propFreq ? AK_TX_GRID_SPAN_HZ : AK_TX_GRID_SPAN_LMDA_NM, annotations.set(propertyFrequency ? AK_TX_GRID_SPAN_HZ : AK_TX_GRID_SPAN_LMDA_NM,
freqLmdaToAnnotation(txGridSpan, useFreq)); freqLmdaToAnnotation(txGridSpan, useFreq));
int rxTune = OFPortStatsOpticalFlagsSerializerVer14.RX_TUNE_VAL; int rxTune = OFPortStatsOpticalFlagsSerializerVer14.RX_TUNE_VAL;
@ -721,11 +721,11 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
long rxOffset = optical.get().getRxOffset(); long rxOffset = optical.get().getRxOffset();
long rxGridSpan = optical.get().getRxGridSpan(); long rxGridSpan = optical.get().getRxGridSpan();
annotations.set(AK_RX_TUNE_FEATURE, ((flags & rxTune) != 0) ? "enabled" : "disabled"); annotations.set(AK_RX_TUNE_FEATURE, ((flags & rxTune) != 0) ? "enabled" : "disabled");
annotations.set(propFreq ? AK_RX_FREQ_HZ : AK_RX_LMDA_NM, annotations.set(propertyFrequency ? AK_RX_FREQ_HZ : AK_RX_LMDA_NM,
freqLmdaToAnnotation(rxFreq, useFreq)); freqLmdaToAnnotation(rxFreq, useFreq));
annotations.set(propFreq ? AK_RX_OFFSET_HZ : AK_RX_OFFSET_LMDA_NM, annotations.set(propertyFrequency ? AK_RX_OFFSET_HZ : AK_RX_OFFSET_LMDA_NM,
freqLmdaToAnnotation(rxOffset, useFreq)); freqLmdaToAnnotation(rxOffset, useFreq));
annotations.set(propFreq ? AK_RX_GRID_SPAN_HZ : AK_RX_GRID_SPAN_LMDA_NM, annotations.set(propertyFrequency ? AK_RX_GRID_SPAN_HZ : AK_RX_GRID_SPAN_LMDA_NM,
freqLmdaToAnnotation(rxGridSpan, useFreq)); freqLmdaToAnnotation(rxGridSpan, useFreq));
int txPwrVal = OFPortStatsOpticalFlagsSerializerVer14.TX_PWR_VAL; int txPwrVal = OFPortStatsOpticalFlagsSerializerVer14.TX_PWR_VAL;
@ -1234,32 +1234,32 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
boolean useFreq = (supported & OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL) != 0; boolean useFreq = (supported & OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL) != 0;
annotations.set(AK_USE_FREQ_FEATURE, useFreq ? "enabled" : "disabled"); annotations.set(AK_USE_FREQ_FEATURE, useFreq ? "enabled" : "disabled");
annotations.set(propFreq ? AK_RX_MIN_FREQ_HZ : AK_RX_MIN_LMDA_NM, annotations.set(propertyFrequency ? AK_RX_MIN_FREQ_HZ : AK_RX_MIN_LMDA_NM,
freqLmdaToAnnotation(rxMin, useFreq)); freqLmdaToAnnotation(rxMin, useFreq));
annotations.set(propFreq ? AK_RX_MAX_FREQ_HZ : AK_RX_MAX_LMDA_NM, annotations.set(propertyFrequency ? AK_RX_MAX_FREQ_HZ : AK_RX_MAX_LMDA_NM,
freqLmdaToAnnotation(rxMax, useFreq)); freqLmdaToAnnotation(rxMax, useFreq));
annotations.set(propFreq ? AK_RX_GRID_HZ : AK_RX_GRID_LMDA_NM, annotations.set(propertyFrequency ? AK_RX_GRID_HZ : AK_RX_GRID_LMDA_NM,
freqLmdaToAnnotation(rxGrid, useFreq)); freqLmdaToAnnotation(rxGrid, useFreq));
annotations.set(propFreq ? AK_TX_MIN_FREQ_HZ : AK_TX_MIN_LMDA_NM, annotations.set(propertyFrequency ? AK_TX_MIN_FREQ_HZ : AK_TX_MIN_LMDA_NM,
freqLmdaToAnnotation(txMin, useFreq)); freqLmdaToAnnotation(txMin, useFreq));
annotations.set(propFreq ? AK_TX_MAX_FREQ_HZ : AK_TX_MAX_LMDA_NM, annotations.set(propertyFrequency ? AK_TX_MAX_FREQ_HZ : AK_TX_MAX_LMDA_NM,
freqLmdaToAnnotation(txMax, useFreq)); freqLmdaToAnnotation(txMax, useFreq));
annotations.set(propFreq ? AK_TX_GRID_HZ : AK_TX_GRID_LMDA_NM, annotations.set(propertyFrequency ? AK_TX_GRID_HZ : AK_TX_GRID_LMDA_NM,
freqLmdaToAnnotation(txGrid, useFreq)); freqLmdaToAnnotation(txGrid, useFreq));
// FIXME pretty confident this is not going to happen // FIXME pretty confident this is not going to happen
// unless Device models Tx/Rx ports as separate port // unless Device models Tx/Rx ports as separate port
if (rxMin == txMin) { if (rxMin == txMin) {
annotations.set(propFreq ? AK_MIN_FREQ_HZ : AK_MIN_LMDA_NM, annotations.set(propertyFrequency ? AK_MIN_FREQ_HZ : AK_MIN_LMDA_NM,
freqLmdaToAnnotation(rxMin, useFreq)); freqLmdaToAnnotation(rxMin, useFreq));
} }
if (rxMax == txMax) { if (rxMax == txMax) {
annotations.set(propFreq ? AK_MAX_FREQ_HZ : AK_MAX_LMDA_NM, annotations.set(propertyFrequency ? AK_MAX_FREQ_HZ : AK_MAX_LMDA_NM,
freqLmdaToAnnotation(rxMax, useFreq)); freqLmdaToAnnotation(rxMax, useFreq));
} }
if (rxGrid == txGrid) { if (rxGrid == txGrid) {
annotations.set(propFreq ? AK_GRID_HZ : AK_GRID_LMDA_NM, annotations.set(propertyFrequency ? AK_GRID_HZ : AK_GRID_LMDA_NM,
freqLmdaToAnnotation(rxGrid, useFreq)); freqLmdaToAnnotation(rxGrid, useFreq));
} }

View File

@ -26,4 +26,7 @@ public final class OsgiPropertyConstants {
public static final String POLL_FREQUENCY = "pollFrequency"; public static final String POLL_FREQUENCY = "pollFrequency";
public static final int POLL_FREQUENCY_DEFAULT = 30; public static final int POLL_FREQUENCY_DEFAULT = 30;
public static final String TIMEOUT = "replyTimeout";
public static final int TIMEOUT_DEFAULT = 5;
} }

View File

@ -95,14 +95,17 @@ import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_REMOVED;
import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UPDATED; import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UPDATED;
import static org.onosproject.provider.rest.device.impl.OsgiPropertyConstants.POLL_FREQUENCY; import static org.onosproject.provider.rest.device.impl.OsgiPropertyConstants.POLL_FREQUENCY;
import static org.onosproject.provider.rest.device.impl.OsgiPropertyConstants.POLL_FREQUENCY_DEFAULT; import static org.onosproject.provider.rest.device.impl.OsgiPropertyConstants.POLL_FREQUENCY_DEFAULT;
import static org.onosproject.provider.rest.device.impl.OsgiPropertyConstants.TIMEOUT;
import static org.onosproject.provider.rest.device.impl.OsgiPropertyConstants.TIMEOUT_DEFAULT;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
/** /**
* Provider for devices that use REST as means of configuration communication. * Provider for devices that use REST as means of configuration communication.
*/ */
@Component(immediate = true, service = DeviceProvider.class, @Component(immediate = true,
property = { property = {
POLL_FREQUENCY + ":Integer=" + POLL_FREQUENCY_DEFAULT, POLL_FREQUENCY + ":Integer=" + POLL_FREQUENCY_DEFAULT,
TIMEOUT + ":Integer=" + TIMEOUT_DEFAULT,
}) })
public class RestDeviceProvider extends AbstractProvider public class RestDeviceProvider extends AbstractProvider
implements DeviceProvider { implements DeviceProvider {
@ -113,9 +116,7 @@ public class RestDeviceProvider extends AbstractProvider
private static final String DEVICENULL = "Rest device is null"; private static final String DEVICENULL = "Rest device is null";
private static final String DRIVERNULL = "Driver is null"; private static final String DRIVERNULL = "Driver is null";
private static final String UNKNOWN = "unknown"; private static final String UNKNOWN = "unknown";
private static final int REST_TIMEOUT_SEC = 5;
private static final int EXECUTOR_THREAD_POOL_SIZE = 8; private static final int EXECUTOR_THREAD_POOL_SIZE = 8;
private static final int DEVICE_POLL_SEC = 30;
private final Logger log = getLogger(getClass()); private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY) @Reference(cardinality = ReferenceCardinality.MANDATORY)
@ -142,6 +143,9 @@ public class RestDeviceProvider extends AbstractProvider
/** Configure poll frequency for port status and statistics; default is 30 seconds. */ /** Configure poll frequency for port status and statistics; default is 30 seconds. */
private int pollFrequency = POLL_FREQUENCY_DEFAULT; private int pollFrequency = POLL_FREQUENCY_DEFAULT;
/** Configure timeout for a device reply; default is 5 seconds. */
private int replyTimeout = TIMEOUT_DEFAULT;
private DeviceProviderService providerService; private DeviceProviderService providerService;
private ApplicationId appId; private ApplicationId appId;
@ -191,7 +195,10 @@ public class RestDeviceProvider extends AbstractProvider
Dictionary<?, ?> properties = context.getProperties(); Dictionary<?, ?> properties = context.getProperties();
pollFrequency = Tools.getIntegerProperty(properties, POLL_FREQUENCY, pollFrequency = Tools.getIntegerProperty(properties, POLL_FREQUENCY,
POLL_FREQUENCY_DEFAULT); POLL_FREQUENCY_DEFAULT);
log.info("Configured. Poll frequency is configured to {} seconds", pollFrequency); replyTimeout = Tools.getIntegerProperty(properties, TIMEOUT,
TIMEOUT_DEFAULT);
log.info("Configured. Poll frequency = {} seconds, reply timeout = {} seconds ",
pollFrequency, replyTimeout);
} }
// Re-schedule only if frequency has changed // Re-schedule only if frequency has changed
@ -265,7 +272,7 @@ public class RestDeviceProvider extends AbstractProvider
} catch (Exception e) { } catch (Exception e) {
log.error("Exception at schedule Device polling", e); log.error("Exception at schedule Device polling", e);
} }
}, 1, DEVICE_POLL_SEC, TimeUnit.SECONDS); }, 1, pollFrequency, TimeUnit.SECONDS);
} }
private DeviceDescription getDesc(RestSBDevice restSBDev) { private DeviceDescription getDesc(RestSBDevice restSBDev) {
@ -562,7 +569,7 @@ public class RestDeviceProvider extends AbstractProvider
Future<Boolean> future = executor.submit(connectionSuccess); Future<Boolean> future = executor.submit(connectionSuccess);
try { try {
return future.get(REST_TIMEOUT_SEC, TimeUnit.SECONDS); return future.get(replyTimeout, TimeUnit.SECONDS);
} catch (TimeoutException ex) { } catch (TimeoutException ex) {
log.warn("Connection to device {} timed out: {}", dev.deviceId(), ex.getMessage()); log.warn("Connection to device {} timed out: {}", dev.deviceId(), ex.getMessage());
return false; return false;