Luca Prete

ONOS-4403 Remove intents using appId when apps get deactivated.

Change-Id: Ieaea8aeff2f2c29287a3e2eea33654fa22d38c09
......@@ -16,6 +16,7 @@
package org.onosproject.routing;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.intent.Intent;
/**
......@@ -48,4 +49,12 @@ public interface IntentSynchronizationService {
* @param intent intent to withdraw
*/
void withdraw(Intent intent);
/**
* Withdraws intents by app Id.
*
* @param applicationId the Id of the application that created the intents
* to be removed
*/
void removeIntentsByAppId(ApplicationId applicationId);
}
......
......@@ -143,6 +143,28 @@ public class IntentSynchronizer implements IntentSynchronizationService,
}
@Override
public void removeIntentsByAppId(ApplicationId appId) {
if (!isElectedLeader) {
// Only leader will withdraw intents
return;
}
log.debug("Withdrawing intents for app {}...",
appId);
intents.entrySet()
.stream()
.filter(intent -> intent.getValue().appId().equals(appId))
.forEach(intent -> {
log.debug("Intent Synchronizer withdrawing intent: {}",
intent);
intentService.withdraw(intent.getValue());
intents.remove(intent.getKey(), intent.getValue());
log.info("Tried to clean intents for app: {}", appId);
});
}
@Override
public void submit(Intent intent) {
synchronized (this) {
intents.put(intent.key(), intent);
......
......@@ -89,9 +89,9 @@ public class SdnIp {
interfaceService);
peerConnectivity.start();
// TODO fix removing intents
applicationService.registerDeactivateHook(appId,
intentSynchronizerAdmin::removeIntents);
applicationService.registerDeactivateHook(appId, () -> {
intentSynchronizer.removeIntentsByAppId(appId);
});
log.info("SDN-IP started");
}
......
......@@ -92,8 +92,9 @@ public class Vpls {
intentService,
intentSynchronizer);
applicationService.registerDeactivateHook(appId,
intentSynchronizerAdmin::removeIntents);
applicationService.registerDeactivateHook(appId, () -> {
intentSynchronizer.removeIntentsByAppId(appId);
});
hostService.addListener(hostListener);
interfaceService.addListener(interfaceListener);
......
......@@ -666,12 +666,14 @@ public class VplsTest {
@Override
public void modifyPrimary(boolean isPrimary) {
}
@Override
public void removeIntents() {
}
@Override
public void removeIntentsByAppId(ApplicationId applicationId) {
}
}
......