Make timeout and max attempts configurable
- Resolve ONOS-472
- Define instance variables for timeout and max attemps
- Add a constructor that initializes the added instance variables
Change-Id: Ia70421122cd6042b01850eabec9f249e7cea5e88
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
index 389a7be..78ebbf3 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
@@ -52,6 +52,7 @@
import org.onosproject.net.intent.IntentStoreDelegate;
import org.slf4j.Logger;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
@@ -743,13 +744,17 @@
private class IntentInstallMonitor implements Runnable {
- // TODO make this configurable
+ // TODO make this configurable through a configuration file using @Property mechanism
+ // These fields needs to be moved to the enclosing class and configurable through a configuration file
private static final int TIMEOUT_PER_OP = 500; // ms
private static final int MAX_ATTEMPTS = 3;
private final IntentOperations ops;
private final List<IntentUpdate> intentUpdates = Lists.newArrayList();
+ private final Duration timeoutPerOperation;
+ private final int maxAttempts;
+
// future holding current FlowRuleBatch installation result
private Future<CompletedBatchOperation> future;
private long startTime = System.currentTimeMillis();
@@ -757,14 +762,22 @@
private int installAttempt;
public IntentInstallMonitor(IntentOperations ops) {
+ this(ops, Duration.ofMillis(TIMEOUT_PER_OP), MAX_ATTEMPTS);
+ }
+
+ public IntentInstallMonitor(IntentOperations ops, Duration timeoutPerOperation, int maxAttempts) {
this.ops = checkNotNull(ops);
+ this.timeoutPerOperation = checkNotNull(timeoutPerOperation);
+ checkArgument(maxAttempts > 0, "maxAttempts must be larger than 0, but %s", maxAttempts);
+ this.maxAttempts = maxAttempts;
+
resetTimeoutLimit();
}
private void resetTimeoutLimit() {
// FIXME compute reasonable timeouts
this.endTime = System.currentTimeMillis()
- + ops.operations().size() * TIMEOUT_PER_OP;
+ + ops.operations().size() * timeoutPerOperation.toMillis();
}
private void buildIntentUpdates() {
@@ -880,12 +893,12 @@
// reset the timer
resetTimeoutLimit();
installAttempt++;
- if (installAttempt == MAX_ATTEMPTS) {
+ if (installAttempt == maxAttempts) {
log.warn("Install request timed out: {}", ops);
for (IntentUpdate update : intentUpdates) {
update.batchFailed();
}
- } else if (installAttempt > MAX_ATTEMPTS) {
+ } else if (installAttempt > maxAttempts) {
abandonShip();
return;
} // else just resubmit the work