Search in sources :

Example 1 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class NodeConnectedHandlerTest method readNodes.

public void readNodes() throws Exception {
    ReadTransaction tx = getDataBroker().newReadOnlyTransaction();
    d1GlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d1NodePath, tx);
    d2GlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d2NodePath, tx);
    haGlobalOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, haNodePath, tx);
    d1PsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d1PsNodePath, tx);
    d2PsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, d2PsNodePath, tx);
    haPsOpNode = TestUtil.readNode(LogicalDatastoreType.OPERATIONAL, haPsNodePath, tx);
    haGlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, haNodePath, tx);
    d1GlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d1NodePath, tx);
    d2GlobalConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d2NodePath, tx);
    haPsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, haPsNodePath, tx);
    d1PsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d1PsNodePath, tx);
    d2PsConfigNode = TestUtil.readNode(LogicalDatastoreType.CONFIGURATION, d2PsNodePath, tx);
    tx.close();
}
Also used : ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction)

Example 2 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class StatisticsImpl method cleanAllElementCounterRequests.

@Override
public ListenableFuture<RpcResult<CleanAllElementCounterRequestsOutput>> cleanAllElementCounterRequests(CleanAllElementCounterRequestsInput input) {
    ReadTransaction tx = db.newReadOnlyTransaction();
    CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
    CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
    try {
        Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
        Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
        if (!iecrcOpt.isPresent() || !eecrcOpt.isPresent()) {
            LOG.warn("Couldn't read element counters config data from DB");
            statisticsCounters.failedReadingCounterDataFromConfig();
            return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>failed().withError(ErrorType.APPLICATION, "Couldn't read element counters config data from DB").buildFuture();
        }
        Set<String> idsToRelease = new HashSet<>();
        if (input.getPortId() != null && !input.getPortId().isEmpty()) {
            idsToRelease.addAll(getAllPortRequestsUniqueIds(input.getPortId(), iecrcOpt.get().getCounterRequests()));
            idsToRelease.addAll(getAllPortRequestsUniqueIds(input.getPortId(), eecrcOpt.get().getCounterRequests()));
            removeAllElementCounterRequestsOnPort(input.getPortId(), iecrcOpt.get().getCounterRequests());
            removeAllElementCounterRequestsOnPort(input.getPortId(), eecrcOpt.get().getCounterRequests());
        } else {
            idsToRelease.addAll(getAllRquestsUniqueIds(iecrcOpt.get().getCounterRequests()));
            idsToRelease.addAll(getAllRquestsUniqueIds(eecrcOpt.get().getCounterRequests()));
            removeAllElementCounterRequests(iecrcOpt.get().getCounterRequests());
            removeAllElementCounterRequests(eecrcOpt.get().getCounterRequests());
        }
        releaseIds(idsToRelease);
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
    } finally {
        tx.close();
    }
    return RpcResultBuilder.<CleanAllElementCounterRequestsOutput>success().buildFuture();
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) Optional(java.util.Optional) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) CleanAllElementCounterRequestsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.CleanAllElementCounterRequestsOutput) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 3 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class StatisticsImpl method handleInterfaceRemoval.

@Override
public void handleInterfaceRemoval(String interfaceId) {
    CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc;
    CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc;
    try (ReadTransaction tx = db.newReadOnlyTransaction()) {
        iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
        eecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
    }
    try {
        Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
        Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
        if (!iecrcOpt.isPresent() || !eecrcOpt.isPresent()) {
            LOG.warn("Couldn't read element counters config data from DB");
            statisticsCounters.failedReadingCounterDataFromConfig();
            return;
        }
        removeAllElementCounterRequestsOnPort(interfaceId, iecrcOpt.get().getCounterRequests());
        removeAllElementCounterRequestsOnPort(interfaceId, eecrcOpt.get().getCounterRequests());
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        statisticsCounters.failedGettingCounterResultsPortRemoval();
        return;
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) Optional(java.util.Optional) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class DhcpExternalTunnelManager method createRemoteMcastMac.

@Nullable
public RemoteMcastMacs createRemoteMcastMac(Node dstDevice, String logicalSwitchName, IpAddress internalTunnelIp) {
    Set<LocatorSet> locators = new HashSet<>();
    TerminationPointKey terminationPointKey = HwvtepSouthboundUtils.getTerminationPointKey(internalTunnelIp.getIpv4Address().getValue());
    HwvtepPhysicalLocatorRef phyLocRef = new HwvtepPhysicalLocatorRef(HwvtepSouthboundUtils.createInstanceIdentifier(dstDevice.getNodeId()).child(TerminationPoint.class, terminationPointKey));
    locators.add(new LocatorSetBuilder().setLocatorRef(phyLocRef).build());
    HwvtepLogicalSwitchRef lsRef = new HwvtepLogicalSwitchRef(HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(dstDevice.getNodeId(), new HwvtepNodeName(logicalSwitchName)));
    RemoteMcastMacs remoteMcastMacs = new RemoteMcastMacsBuilder().setMacEntryKey(new MacAddress(UNKNOWN_DMAC)).setLogicalSwitchRef(lsRef).build();
    InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(dstDevice.getNodeId(), remoteMcastMacs.key());
    ReadTransaction transaction = broker.newReadOnlyTransaction();
    try {
        // TODO do async mdsal read
        remoteMcastMacs = transaction.read(LogicalDatastoreType.CONFIGURATION, iid).get().get();
        locators.addAll(remoteMcastMacs.getLocatorSet());
        return new RemoteMcastMacsBuilder(remoteMcastMacs).setLocatorSet(new ArrayList<>(locators)).build();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Failed to read the macs {}", iid);
    } finally {
        transaction.close();
    }
    return null;
}
Also used : LocatorSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet) HwvtepPhysicalLocatorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef) TerminationPointKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey) ArrayList(java.util.ArrayList) HwvtepLogicalSwitchRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) LocatorSetBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSetBuilder) RemoteMcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) HwvtepNodeName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName) ExecutionException(java.util.concurrent.ExecutionException) RemoteMcastMacsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsBuilder) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) HashSet(java.util.HashSet) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 5 with ReadTransaction

use of org.opendaylight.mdsal.binding.api.ReadTransaction in project netvirt by opendaylight.

the class DhcpSubnetListener method getSubnetMapBuilder.

private SubnetmapBuilder getSubnetMapBuilder(DataBroker broker, Uuid subnetId) {
    SubnetmapBuilder builder = null;
    InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
    ReadTransaction tx = broker.newReadOnlyTransaction();
    Optional<Subnetmap> sn;
    try {
        sn = tx.read(LogicalDatastoreType.CONFIGURATION, id).get();
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    } finally {
        tx.close();
    }
    if (sn.isPresent()) {
        builder = new SubnetmapBuilder(sn.get());
    } else {
        builder = new SubnetmapBuilder().withKey(new SubnetmapKey(subnetId)).setId(subnetId);
    }
    return builder;
}
Also used : ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ExecutionException(java.util.concurrent.ExecutionException) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)

Aggregations

ReadTransaction (org.opendaylight.mdsal.binding.api.ReadTransaction)11 ExecutionException (java.util.concurrent.ExecutionException)7 Optional (java.util.Optional)6 ArrayList (java.util.ArrayList)4 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)4 HashSet (java.util.HashSet)2 List (java.util.List)2 EgressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig)2 IngressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig)2 Nullable (org.eclipse.jdt.annotation.Nullable)1 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)1 IdPools (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools)1 IdPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool)1 IdPoolKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey)1 ExternalTunnelList (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList)1 DcGatewayIpList (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList)1 Group (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group)1 VrfTables (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)1 EvpnRdToNetwork (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.evpn.rd.to.networks.EvpnRdToNetwork)1 EvpnRdToNetworkKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.evpn.rd.to.networks.EvpnRdToNetworkKey)1