Pingping Lin
Committed by Gerrit Code Review

when deactivate sdn-ip, also delete all relative intents

Change-Id: I7a6bd64b5a9525dc49ca2b9353fcc45dc9a16288
......@@ -15,24 +15,25 @@
*/
package org.onosproject.sdnip;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.Key;
import org.onosproject.routing.IntentSynchronizationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.Key;
import org.onosproject.routing.IntentSynchronizationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Synchronizes intents between the in-memory intent store and the
......@@ -97,55 +98,30 @@ public class IntentSynchronizer implements IntentSynchronizationService {
synchronized (this) {
// Stop the thread(s)
intentsSynchronizerExecutor.shutdownNow();
log.info("Intents Synchronizer Executor shutdown completed");
//
// Withdraw all app related intents
//
if (!isElectedLeader) {
return; // Nothing to do: not the leader anymore
}
}
}
//
// NOTE: We don't withdraw the intents during shutdown, because
// it creates flux in the data plane during switchover.
//
/*
//
// Build a batch operation to withdraw all intents from this
// application.
//
log.debug("Intent Synchronizer shutdown: " +
"withdrawing all intents...");
IntentOperations.Builder builder = IntentOperations.builder(appId);
for (Intent intent : intentService.getIntents()) {
// Skip the intents from other applications
if (!intent.appId().equals(appId)) {
continue;
}
/**
* Withdraws all intents.
*/
public void removeIntents() {
if (!isElectedLeader) {
// only leader will withdraw intents
return;
}
// Skip the intents that are already withdrawn
IntentState intentState =
intentService.getIntentState(intent.id());
if ((intentState == null) ||
intentState.equals(IntentState.WITHDRAWING) ||
intentState.equals(IntentState.WITHDRAWN)) {
continue;
}
log.debug("Intent Synchronizer shutdown: withdrawing all intents...");
log.trace("Intent Synchronizer withdrawing intent: {}",
intent);
builder.addWithdrawOperation(intent.id());
}
IntentOperations intentOperations = builder.build();
intentService.execute(intentOperations);
leaderChanged(false);
peerIntents.clear();
routeIntents.clear();
log.debug("Intent Synchronizer shutdown completed");
*/
for (Entry<Key, Intent> entry : intents.entrySet()) {
intentService.withdraw(entry.getValue());
log.debug("Intent Synchronizer withdrawing intent: {}",
entry.getValue());
}
intents.clear();
log.info("Tried to clean all intents");
}
@Override
......@@ -261,5 +237,4 @@ public class IntentSynchronizer implements IntentSynchronizationService {
}
log.debug("Intent synchronization completed");
}
}
......
......@@ -15,12 +15,17 @@
*/
package org.onosproject.sdnip;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Objects;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.app.ApplicationService;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.LeadershipEvent;
......@@ -28,8 +33,8 @@ import org.onosproject.cluster.LeadershipEventListener;
import org.onosproject.cluster.LeadershipService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.host.HostService;
import org.onosproject.net.intent.IntentService;
import org.onosproject.routing.IntentSynchronizationService;
......@@ -38,10 +43,6 @@ import org.onosproject.routing.SdnIpService;
import org.onosproject.routing.config.RoutingConfigurationService;
import org.slf4j.Logger;
import java.util.Objects;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Component for the SDN-IP peering application.
*/
......@@ -59,6 +60,9 @@ public class SdnIp implements SdnIpService {
protected IntentService intentService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ApplicationService applicationService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -84,7 +88,7 @@ public class SdnIp implements SdnIpService {
private SdnIpFib fib;
private LeadershipEventListener leadershipEventListener =
new InnerLeadershipEventListener();
new InnerLeadershipEventListener();
private ApplicationId appId;
private ControllerNode localControllerNode;
......@@ -113,6 +117,10 @@ public class SdnIp implements SdnIpService {
leadershipService.addListener(leadershipEventListener);
leadershipService.runForLeadership(appId.name());
applicationService.registerDeactivateHook(appId,
intentSynchronizer::removeIntents);
}
@Deactivate
......