Search in sources :

Example 41 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project genius by opendaylight.

the class SingleTransactionDataBroker method syncUpdate.

public static <T extends DataObject> void syncUpdate(DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path, T data, int maxRetries) throws TransactionCommitFailedException {
    RetryingManagedNewTransactionRunner runner = new RetryingManagedNewTransactionRunner(broker, maxRetries);
    ListenableFutures.checkedGet(runner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.merge(datastoreType, path, data, true)), SUBMIT_MAPPER);
}
Also used : Logger(org.slf4j.Logger) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) LoggerFactory(org.slf4j.LoggerFactory) ReadTransaction(org.opendaylight.controller.md.sal.binding.api.ReadTransaction) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ListenableFutures(org.opendaylight.infrautils.utils.concurrent.ListenableFutures) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(com.google.common.base.Optional) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Objects.requireNonNull(java.util.Objects.requireNonNull) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Nonnull(javax.annotation.Nonnull) SUBMIT_MAPPER(org.opendaylight.genius.datastoreutils.TransactionCommitFailedExceptionMapper.SUBMIT_MAPPER) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner)

Example 42 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project genius by opendaylight.

the class SingleTransactionDataBroker method syncDelete.

public static <T extends DataObject> void syncDelete(DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path, int maxRetries) throws TransactionCommitFailedException {
    RetryingManagedNewTransactionRunner runner = new RetryingManagedNewTransactionRunner(broker, maxRetries);
    ListenableFutures.checkedGet(runner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.delete(datastoreType, path)), SUBMIT_MAPPER);
}
Also used : Logger(org.slf4j.Logger) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) LoggerFactory(org.slf4j.LoggerFactory) ReadTransaction(org.opendaylight.controller.md.sal.binding.api.ReadTransaction) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ListenableFutures(org.opendaylight.infrautils.utils.concurrent.ListenableFutures) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(com.google.common.base.Optional) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Objects.requireNonNull(java.util.Objects.requireNonNull) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Nonnull(javax.annotation.Nonnull) SUBMIT_MAPPER(org.opendaylight.genius.datastoreutils.TransactionCommitFailedExceptionMapper.SUBMIT_MAPPER) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner)

Example 43 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project genius by opendaylight.

the class SingleTransactionDataBroker method syncWrite.

public static <T extends DataObject> void syncWrite(DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path, T data, int maxRetries) throws TransactionCommitFailedException {
    RetryingManagedNewTransactionRunner runner = new RetryingManagedNewTransactionRunner(broker, maxRetries);
    ListenableFutures.checkedGet(runner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.put(datastoreType, path, data, true)), SUBMIT_MAPPER);
}
Also used : Logger(org.slf4j.Logger) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) LoggerFactory(org.slf4j.LoggerFactory) ReadTransaction(org.opendaylight.controller.md.sal.binding.api.ReadTransaction) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ListenableFutures(org.opendaylight.infrautils.utils.concurrent.ListenableFutures) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(com.google.common.base.Optional) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Objects.requireNonNull(java.util.Objects.requireNonNull) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Nonnull(javax.annotation.Nonnull) SUBMIT_MAPPER(org.opendaylight.genius.datastoreutils.TransactionCommitFailedExceptionMapper.SUBMIT_MAPPER) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner)

Example 44 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject 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);
    }
}
Also used : VtepsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsBuilder) TransportZoneBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder) SubnetsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsBuilder) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) LoggerFactory(org.slf4j.LoggerFactory) TepTypeInternal(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeInternal) VtepsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey) CommandSession(org.apache.felix.service.command.CommandSession) StringUtils(org.apache.commons.lang3.StringUtils) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) TransportZonesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZonesBuilder) PreDestroy(javax.annotation.PreDestroy) DataStoreCache(org.opendaylight.genius.utils.cache.DataStoreCache) TunnelMonitoringTypeLldp(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeLldp) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Optional(com.google.common.base.Optional) Map(java.util.Map) TunnelTypeGre(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre) BigInteger(java.math.BigInteger) TunnelTypeLogicalGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeLogicalGroup) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ItmConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) Collection(java.util.Collection) TunnelTypeMplsOverGre(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) List(java.util.List) IpPrefixBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder) TunnelTypeBase(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase) TunnelOperStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus) SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) TunnelMonitoringTypeBfd(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBfd) Inject(javax.inject.Inject) TunnelMonitorIntervalBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorIntervalBuilder) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) TunnelMonitoringTypeBase(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase) TunnelMonitorParamsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParamsBuilder) TunnelMonitorParams(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams) Logger(org.slf4j.Logger) TunnelMonitorInterval(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorInterval) ListenableFutures(org.opendaylight.infrautils.utils.concurrent.ListenableFutures) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) ITMConstants(org.opendaylight.genius.itm.globals.ITMConstants) Preconditions(com.google.common.base.Preconditions) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets) Collections(java.util.Collections) ItmUtils(org.opendaylight.genius.itm.impl.ItmUtils) SubnetUtils(org.apache.commons.net.util.SubnetUtils) IpAddressBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder) ArrayList(java.util.ArrayList) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets) Vteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones)

Aggregations

DataObject (org.opendaylight.yangtools.yang.binding.DataObject)44 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)24 Test (org.junit.Test)14 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)11 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)10 Optional (com.google.common.base.Optional)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)6 AbstractDataChangeListenerTest (org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)6 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)6 Collection (java.util.Collection)5 Nonnull (javax.annotation.Nonnull)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 TopLevelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey)5 DataObjectModification (org.opendaylight.controller.md.sal.binding.api.DataObjectModification)4