use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class VirtualNetworkIntentManager method withdraw.
@Override
public void withdraw(Intent intent) {
checkNotNull(intent, INTENT_NULL);
IntentData data = IntentData.withdraw(intent);
intentStore.addPending(networkId, data);
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class VirtualNetworkIntentManager method createInitialPhase.
private VirtualIntentProcessPhase createInitialPhase(IntentData data) {
IntentData pending = intentStore.getPendingData(networkId, data.key());
if (pending == null || pending.version().isNewerThan(data.version())) {
/*
If the pending map is null, then this intent was compiled by a
previous batch iteration, so we can skip it.
If the pending map has a newer request, it will get compiled as
part of the next batch, so we can skip it.
*/
return VirtualIntentSkipped.getPhase();
}
IntentData current = intentStore.getIntentData(networkId, data.key());
return newInitialPhase(networkId, processor, data, current);
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class VirtualIntentPurgeRequest method shouldAcceptPurge.
private boolean shouldAcceptPurge() {
if (!stored.isPresent()) {
log.info("Purge for intent {}, but intent is not present", data.key());
return true;
}
IntentData storedData = stored.get();
if (storedData.state() == IntentState.WITHDRAWN || storedData.state() == IntentState.FAILED) {
return true;
}
log.info("Purge for intent {} is rejected because intent state is {}", data.key(), storedData.state());
return false;
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class VirtualIntentInstallCoordinator method finish.
/**
* Completed the installation context and update the Intent store.
*
* @param intentInstallationContext the installation context
*/
private void finish(IntentInstallationContext intentInstallationContext) {
Set<IntentOperationContext> errCtxs = intentInstallationContext.errorContexts();
Optional<IntentData> toUninstall = intentInstallationContext.toUninstall();
Optional<IntentData> toInstall = intentInstallationContext.toInstall();
// Intent install success
if (errCtxs == null || errCtxs.isEmpty()) {
if (toInstall.isPresent()) {
IntentData installData = toInstall.get();
log.debug("Completed installing: {}", installData.key());
installData = IntentData.compiled(installData, installData.installables());
installData.setState(INSTALLED);
intentStore.write(networkId, installData);
} else if (toUninstall.isPresent()) {
IntentData uninstallData = toUninstall.get();
uninstallData = IntentData.compiled(uninstallData, Collections.emptyList());
log.debug("Completed withdrawing: {}", uninstallData.key());
switch(uninstallData.request()) {
case INSTALL_REQ:
log.warn("{} was requested to withdraw during installation?", uninstallData.intent());
uninstallData.setState(FAILED);
break;
case WITHDRAW_REQ:
default:
// TODO "default" case should not happen
uninstallData.setState(WITHDRAWN);
break;
}
// Intent has been withdrawn; we can clear the installables
intentStore.write(networkId, uninstallData);
}
} else {
// if toInstall was cause of error, then recompile (manage/increment counter, when exceeded -> CORRUPT)
if (toInstall.isPresent()) {
IntentData installData = toInstall.get();
installData.setState(CORRUPT);
installData.incrementErrorCount();
intentStore.write(networkId, installData);
}
// if toUninstall was cause of error, then CORRUPT (another job will clean this up)
if (toUninstall.isPresent()) {
IntentData uninstallData = toUninstall.get();
uninstallData.setState(CORRUPT);
uninstallData.incrementErrorCount();
intentStore.write(networkId, uninstallData);
}
}
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class SimpleVirtualIntentStore method write.
@Override
public void write(NetworkId networkId, IntentData newData) {
checkNotNull(newData);
synchronized (this) {
// TODO this could be refactored/cleaned up
IntentData currentData = getCurrentMap(networkId).get(newData.key());
IntentData pendingData = getPendingMap(networkId).get(newData.key());
if (IntentData.isUpdateAcceptable(currentData, newData)) {
if (pendingData != null) {
if (pendingData.state() == PURGE_REQ) {
getCurrentMap(networkId).remove(newData.key(), newData);
} else {
getCurrentMap(networkId).put(newData.key(), IntentData.copy(newData));
}
if (pendingData.version().compareTo(newData.version()) <= 0) {
// pendingData version is less than or equal to newData's
// Note: a new update for this key could be pending (it's version will be greater)
getPendingMap(networkId).remove(newData.key());
}
}
IntentEvent.getEvent(newData).ifPresent(e -> notifyDelegate(networkId, e));
}
}
}
Aggregations