Committed by
Ray Milkey
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
Showing
1 changed file
with
17 additions
and
4 deletions
| ... | @@ -52,6 +52,7 @@ import org.onosproject.net.intent.BatchWrite; | ... | @@ -52,6 +52,7 @@ import org.onosproject.net.intent.BatchWrite; |
| 52 | import org.onosproject.net.intent.IntentStoreDelegate; | 52 | import org.onosproject.net.intent.IntentStoreDelegate; |
| 53 | import org.slf4j.Logger; | 53 | import org.slf4j.Logger; |
| 54 | 54 | ||
| 55 | +import java.time.Duration; | ||
| 55 | import java.util.ArrayList; | 56 | import java.util.ArrayList; |
| 56 | import java.util.Collections; | 57 | import java.util.Collections; |
| 57 | import java.util.EnumSet; | 58 | import java.util.EnumSet; |
| ... | @@ -743,13 +744,17 @@ public class IntentManager | ... | @@ -743,13 +744,17 @@ public class IntentManager |
| 743 | 744 | ||
| 744 | private class IntentInstallMonitor implements Runnable { | 745 | private class IntentInstallMonitor implements Runnable { |
| 745 | 746 | ||
| 746 | - // TODO make this configurable | 747 | + // TODO make this configurable through a configuration file using @Property mechanism |
| 748 | + // These fields needs to be moved to the enclosing class and configurable through a configuration file | ||
| 747 | private static final int TIMEOUT_PER_OP = 500; // ms | 749 | private static final int TIMEOUT_PER_OP = 500; // ms |
| 748 | private static final int MAX_ATTEMPTS = 3; | 750 | private static final int MAX_ATTEMPTS = 3; |
| 749 | 751 | ||
| 750 | private final IntentOperations ops; | 752 | private final IntentOperations ops; |
| 751 | private final List<IntentUpdate> intentUpdates = Lists.newArrayList(); | 753 | private final List<IntentUpdate> intentUpdates = Lists.newArrayList(); |
| 752 | 754 | ||
| 755 | + private final Duration timeoutPerOperation; | ||
| 756 | + private final int maxAttempts; | ||
| 757 | + | ||
| 753 | // future holding current FlowRuleBatch installation result | 758 | // future holding current FlowRuleBatch installation result |
| 754 | private Future<CompletedBatchOperation> future; | 759 | private Future<CompletedBatchOperation> future; |
| 755 | private long startTime = System.currentTimeMillis(); | 760 | private long startTime = System.currentTimeMillis(); |
| ... | @@ -757,14 +762,22 @@ public class IntentManager | ... | @@ -757,14 +762,22 @@ public class IntentManager |
| 757 | private int installAttempt; | 762 | private int installAttempt; |
| 758 | 763 | ||
| 759 | public IntentInstallMonitor(IntentOperations ops) { | 764 | public IntentInstallMonitor(IntentOperations ops) { |
| 765 | + this(ops, Duration.ofMillis(TIMEOUT_PER_OP), MAX_ATTEMPTS); | ||
| 766 | + } | ||
| 767 | + | ||
| 768 | + public IntentInstallMonitor(IntentOperations ops, Duration timeoutPerOperation, int maxAttempts) { | ||
| 760 | this.ops = checkNotNull(ops); | 769 | this.ops = checkNotNull(ops); |
| 770 | + this.timeoutPerOperation = checkNotNull(timeoutPerOperation); | ||
| 771 | + checkArgument(maxAttempts > 0, "maxAttempts must be larger than 0, but %s", maxAttempts); | ||
| 772 | + this.maxAttempts = maxAttempts; | ||
| 773 | + | ||
| 761 | resetTimeoutLimit(); | 774 | resetTimeoutLimit(); |
| 762 | } | 775 | } |
| 763 | 776 | ||
| 764 | private void resetTimeoutLimit() { | 777 | private void resetTimeoutLimit() { |
| 765 | // FIXME compute reasonable timeouts | 778 | // FIXME compute reasonable timeouts |
| 766 | this.endTime = System.currentTimeMillis() | 779 | this.endTime = System.currentTimeMillis() |
| 767 | - + ops.operations().size() * TIMEOUT_PER_OP; | 780 | + + ops.operations().size() * timeoutPerOperation.toMillis(); |
| 768 | } | 781 | } |
| 769 | 782 | ||
| 770 | private void buildIntentUpdates() { | 783 | private void buildIntentUpdates() { |
| ... | @@ -880,12 +893,12 @@ public class IntentManager | ... | @@ -880,12 +893,12 @@ public class IntentManager |
| 880 | // reset the timer | 893 | // reset the timer |
| 881 | resetTimeoutLimit(); | 894 | resetTimeoutLimit(); |
| 882 | installAttempt++; | 895 | installAttempt++; |
| 883 | - if (installAttempt == MAX_ATTEMPTS) { | 896 | + if (installAttempt == maxAttempts) { |
| 884 | log.warn("Install request timed out: {}", ops); | 897 | log.warn("Install request timed out: {}", ops); |
| 885 | for (IntentUpdate update : intentUpdates) { | 898 | for (IntentUpdate update : intentUpdates) { |
| 886 | update.batchFailed(); | 899 | update.batchFailed(); |
| 887 | } | 900 | } |
| 888 | - } else if (installAttempt > MAX_ATTEMPTS) { | 901 | + } else if (installAttempt > maxAttempts) { |
| 889 | abandonShip(); | 902 | abandonShip(); |
| 890 | return; | 903 | return; |
| 891 | } // else just resubmit the work | 904 | } // else just resubmit the work | ... | ... |
-
Please register or login to post a comment