mirror of
				https://github.com/opennetworkinglab/onos.git
				synced 2025-11-04 02:01:11 +01:00 
			
		
		
		
	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
This commit is contained in:
		
							parent
							
								
									51fc40b05b
								
							
						
					
					
						commit
						8cd9fb8ad5
					
				@ -52,6 +52,7 @@ import org.onosproject.net.intent.BatchWrite;
 | 
				
			|||||||
import org.onosproject.net.intent.IntentStoreDelegate;
 | 
					import org.onosproject.net.intent.IntentStoreDelegate;
 | 
				
			||||||
import org.slf4j.Logger;
 | 
					import org.slf4j.Logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.time.Duration;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.Collections;
 | 
					import java.util.Collections;
 | 
				
			||||||
import java.util.EnumSet;
 | 
					import java.util.EnumSet;
 | 
				
			||||||
@ -743,13 +744,17 @@ public class IntentManager
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private class IntentInstallMonitor implements Runnable {
 | 
					    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 TIMEOUT_PER_OP = 500; // ms
 | 
				
			||||||
        private static final int MAX_ATTEMPTS = 3;
 | 
					        private static final int MAX_ATTEMPTS = 3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private final IntentOperations ops;
 | 
					        private final IntentOperations ops;
 | 
				
			||||||
        private final List<IntentUpdate> intentUpdates = Lists.newArrayList();
 | 
					        private final List<IntentUpdate> intentUpdates = Lists.newArrayList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private final Duration timeoutPerOperation;
 | 
				
			||||||
 | 
					        private final int maxAttempts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // future holding current FlowRuleBatch installation result
 | 
					        // future holding current FlowRuleBatch installation result
 | 
				
			||||||
        private Future<CompletedBatchOperation> future;
 | 
					        private Future<CompletedBatchOperation> future;
 | 
				
			||||||
        private long startTime = System.currentTimeMillis();
 | 
					        private long startTime = System.currentTimeMillis();
 | 
				
			||||||
@ -757,14 +762,22 @@ public class IntentManager
 | 
				
			|||||||
        private int installAttempt;
 | 
					        private int installAttempt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public IntentInstallMonitor(IntentOperations ops) {
 | 
					        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.ops = checkNotNull(ops);
 | 
				
			||||||
 | 
					            this.timeoutPerOperation = checkNotNull(timeoutPerOperation);
 | 
				
			||||||
 | 
					            checkArgument(maxAttempts > 0, "maxAttempts must be larger than 0, but %s", maxAttempts);
 | 
				
			||||||
 | 
					            this.maxAttempts = maxAttempts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            resetTimeoutLimit();
 | 
					            resetTimeoutLimit();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void resetTimeoutLimit() {
 | 
					        private void resetTimeoutLimit() {
 | 
				
			||||||
            // FIXME compute reasonable timeouts
 | 
					            // FIXME compute reasonable timeouts
 | 
				
			||||||
            this.endTime = System.currentTimeMillis()
 | 
					            this.endTime = System.currentTimeMillis()
 | 
				
			||||||
                           + ops.operations().size() * TIMEOUT_PER_OP;
 | 
					                           + ops.operations().size() * timeoutPerOperation.toMillis();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void buildIntentUpdates() {
 | 
					        private void buildIntentUpdates() {
 | 
				
			||||||
@ -880,12 +893,12 @@ public class IntentManager
 | 
				
			|||||||
                // reset the timer
 | 
					                // reset the timer
 | 
				
			||||||
                resetTimeoutLimit();
 | 
					                resetTimeoutLimit();
 | 
				
			||||||
                installAttempt++;
 | 
					                installAttempt++;
 | 
				
			||||||
                if (installAttempt == MAX_ATTEMPTS) {
 | 
					                if (installAttempt == maxAttempts) {
 | 
				
			||||||
                    log.warn("Install request timed out: {}", ops);
 | 
					                    log.warn("Install request timed out: {}", ops);
 | 
				
			||||||
                    for (IntentUpdate update : intentUpdates) {
 | 
					                    for (IntentUpdate update : intentUpdates) {
 | 
				
			||||||
                        update.batchFailed();
 | 
					                        update.batchFailed();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                } else if (installAttempt > MAX_ATTEMPTS) {
 | 
					                } else if (installAttempt > maxAttempts) {
 | 
				
			||||||
                    abandonShip();
 | 
					                    abandonShip();
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                } // else just resubmit the work
 | 
					                } // else just resubmit the work
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user