use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project genius by opendaylight.
the class TepCommandHelper method deleteOnCommit.
@SuppressWarnings("checkstyle:IllegalCatch")
public <T extends DataObject> void deleteOnCommit() {
List<InstanceIdentifier<T>> vtepPaths = new ArrayList<>();
List<InstanceIdentifier<T>> subnetPaths = new ArrayList<>();
List<InstanceIdentifier<T>> tzPaths = new ArrayList<>();
List<Subnets> subDelList = new ArrayList<>();
List<TransportZone> tzDelList = new ArrayList<>();
List<Vteps> vtepDelList = new ArrayList<>();
List<InstanceIdentifier<T>> allPaths = new ArrayList<>();
try {
if (vtepDelCommitList != null && !vtepDelCommitList.isEmpty()) {
InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
if (transportZonesOptional.isPresent()) {
TransportZones transportZones = transportZonesOptional.get();
for (TransportZone tz : transportZones.getTransportZone()) {
if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
continue;
}
for (Subnets sub : tz.getSubnets()) {
vtepDelList.addAll(vtepDelCommitList);
for (Vteps vtep : vtepDelList) {
InstanceIdentifier<T> vpath = (InstanceIdentifier<T>) InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, tz.getKey()).child(Subnets.class, sub.getKey()).child(Vteps.class, vtep.getKey()).build();
if (sub.getVteps().remove(vtep)) {
vtepPaths.add(vpath);
if (sub.getVteps().size() == 0 || sub.getVteps() == null) {
subDelList.add(sub);
}
}
}
}
}
for (TransportZone tz : transportZones.getTransportZone()) {
if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
continue;
}
for (Subnets sub : subDelList) {
if (tz.getSubnets().remove(sub)) {
InstanceIdentifier<T> spath = (InstanceIdentifier<T>) InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, tz.getKey()).child(Subnets.class, sub.getKey()).build();
subnetPaths.add(spath);
if (tz.getSubnets() == null || tz.getSubnets().size() == 0) {
tzDelList.add(tz);
}
}
}
}
for (TransportZone tz : tzDelList) {
if (transportZones.getTransportZone().remove(tz)) {
InstanceIdentifier<T> tpath = (InstanceIdentifier<T>) InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, tz.getKey()).build();
tzPaths.add(tpath);
if (transportZones.getTransportZone() == null || transportZones.getTransportZone().size() == 0) {
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.delete(LogicalDatastoreType.CONFIGURATION, path)), LOG, "Error deleting {}", path);
return;
}
}
}
allPaths.addAll(vtepPaths);
allPaths.addAll(subnetPaths);
allPaths.addAll(tzPaths);
ItmUtils.asyncBulkRemove(dataBroker, LogicalDatastoreType.CONFIGURATION, allPaths, ItmUtils.DEFAULT_CALLBACK);
}
vtepPaths.clear();
subnetPaths.clear();
tzPaths.clear();
allPaths.clear();
vtepDelCommitList.clear();
}
} catch (RuntimeException e) {
LOG.error("Unexpected error", e);
}
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project genius by opendaylight.
the class TepDeleteDatastore method doExecute.
@Override
protected Object doExecute() {
final DataBroker dataBroker = itmProvider.getDataBroker();
InstanceIdentifier<TransportZones> itmConfigPath = InstanceIdentifier.builder(TransportZones.class).build();
InstanceIdentifier<Interfaces> interfacesConfigPath = InstanceIdentifier.builder(Interfaces.class).build();
final InstanceIdentifier<InterfacesState> ifStateOpPath = InstanceIdentifier.builder(InterfacesState.class).build();
InstanceIdentifier<Nodes> frmConfigPath = InstanceIdentifier.builder(Nodes.class).build();
List<InstanceIdentifier<T>> allConfigPaths = new ArrayList<>();
allConfigPaths.add((InstanceIdentifier<T>) itmConfigPath);
allConfigPaths.add((InstanceIdentifier<T>) interfacesConfigPath);
allConfigPaths.add((InstanceIdentifier<T>) frmConfigPath);
// allConfigPaths.add((InstanceIdentifier<T>) tunnelsConfigPath);
ItmUtils.asyncBulkRemove(dataBroker, LogicalDatastoreType.CONFIGURATION, allConfigPaths, ItmUtils.DEFAULT_CALLBACK);
List<InstanceIdentifier<T>> allOperationalPaths = new ArrayList<>();
// allOperationalPaths.add((InstanceIdentifier<T>) tnStateOpPath);
allOperationalPaths.add((InstanceIdentifier<T>) ifStateOpPath);
ItmUtils.asyncBulkRemove(dataBroker, LogicalDatastoreType.OPERATIONAL, allOperationalPaths, ItmUtils.DEFAULT_CALLBACK);
return null;
}
Aggregations