Search in sources :

Example 61 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project lispflowmapping by opendaylight.

the class VppNetconfTrasaction method read.

public static synchronized <T extends DataObject> Optional<T> read(DataBroker dataBroker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> instanceIdentifier) {
    LOG.trace("Started Netconf transaction on VPP Node");
    Preconditions.checkNotNull(dataBroker);
    Optional<T> returnData;
    int retryCounter = RETRY_COUNT;
    while (retryCounter > 0) {
        ReadOnlyTransaction readTransaction = dataBroker.newReadOnlyTransaction();
        try {
            returnData = readTransaction(instanceIdentifier, datastoreType, readTransaction);
            LOG.trace("Netconf READ transaction SUCCESSFUL. Data present: {}", returnData.isPresent());
            readTransaction.close();
            return returnData;
        } catch (IllegalStateException e) {
            LOG.warn("Assuming that netconf read-transaction failed, retrying. Retry Count: " + retryCounter, e.getMessage());
            readTransaction.close();
        } catch (InterruptedException | ExecutionException e) {
            LOG.warn("Exception while reading data. Retry Aborted.", e.getMessage());
            readTransaction.close();
            break;
        }
        retryCounter--;
    }
    return Optional.absent();
}
Also used : ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ExecutionException(java.util.concurrent.ExecutionException)

Example 62 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project lispflowmapping by opendaylight.

the class DataStoreBackEndTest method getAllMappingsTest.

/**
 * Tests {@link DataStoreBackEnd#getAllMappings} method.
 */
@Test
@SuppressWarnings("unchecked")
public void getAllMappingsTest() throws ReadFailedException {
    final ReadOnlyTransaction rTxMock = Mockito.mock(ReadOnlyTransaction.class);
    final CheckedFuture<Optional<MappingDatabase>, ReadFailedException> readFutureMock = Mockito.mock(CheckedFuture.class);
    final Optional<MappingDatabase> optionalMock = Mockito.mock(Optional.class);
    Mockito.when(txChainMock.newReadOnlyTransaction()).thenReturn(rTxMock);
    Mockito.when(rTxMock.read(LogicalDatastoreType.CONFIGURATION, DATABASE_ROOT)).thenReturn(readFutureMock);
    Mockito.when(rTxMock.read(LogicalDatastoreType.OPERATIONAL, DATABASE_ROOT)).thenReturn(readFutureMock);
    Mockito.when(readFutureMock.checkedGet()).thenReturn(optionalMock);
    Mockito.when(optionalMock.isPresent()).thenReturn(true);
    Mockito.when(optionalMock.get()).thenReturn(getDefaultMappingDatabase().build());
    assertEquals(8, dataStoreBackEnd.getAllMappings().size());
    Mockito.verify(optionalMock, Mockito.times(2)).get();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) MappingDatabase(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase) Optional(com.google.common.base.Optional) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 63 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project lispflowmapping by opendaylight.

the class DataStoreBackEndTest method getAllAuthenticationKeysTest.

/**
 * Tests {@link DataStoreBackEnd#getAllAuthenticationKeys} method.
 */
@Test
@SuppressWarnings("unchecked")
public void getAllAuthenticationKeysTest() throws ReadFailedException {
    final ReadOnlyTransaction rTxMock = Mockito.mock(ReadOnlyTransaction.class);
    final CheckedFuture<Optional<MappingDatabase>, ReadFailedException> readFutureMock = Mockito.mock(CheckedFuture.class);
    final Optional<MappingDatabase> optionalMock = Mockito.mock(Optional.class);
    Mockito.when(txChainMock.newReadOnlyTransaction()).thenReturn(rTxMock);
    Mockito.when(rTxMock.read(LogicalDatastoreType.CONFIGURATION, DATABASE_ROOT)).thenReturn(readFutureMock);
    Mockito.when(readFutureMock.checkedGet()).thenReturn(optionalMock);
    Mockito.when(optionalMock.isPresent()).thenReturn(true);
    Mockito.when(optionalMock.get()).thenReturn(getDefaultMappingDatabase().build());
    assertEquals(4, dataStoreBackEnd.getAllAuthenticationKeys().size());
    Mockito.verify(optionalMock).get();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) MappingDatabase(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase) Optional(com.google.common.base.Optional) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 64 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project genius by opendaylight.

the class AlivenessMonitor method resumeMonitoring.

private void resumeMonitoring(final long monitorId) {
    final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
    ListenableFuture<Optional<MonitoringInfo>> readInfoResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
    Futures.addCallback(readInfoResult, new FutureCallback<Optional<MonitoringInfo>>() {

        @Override
        public void onFailure(Throwable error) {
            String msg = String.format("Unable to read monitoring info associated with monitor id %d", monitorId);
            LOG.error("Monitor resume Failed. {}", msg, error);
            tx.close();
        }

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringInfo> optInfo) {
            if (optInfo.isPresent()) {
                final MonitoringInfo info = optInfo.get();
                ListenableFuture<Optional<MonitorProfile>> readProfile = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(info.getProfileId()));
                Futures.addCallback(readProfile, new FutureCallback<Optional<MonitorProfile>>() {

                    @Override
                    public void onFailure(Throwable error) {
                        String msg = String.format("Unable to read Monitoring profile associated with id %d", info.getProfileId());
                        LOG.warn("Monitor resume Failed. {}", msg, error);
                        tx.close();
                    }

                    @Override
                    public void onSuccess(@Nonnull Optional<MonitorProfile> optProfile) {
                        tx.close();
                        if (optProfile.isPresent()) {
                            updateMonitorStatusTo(monitorId, MonitorStatus.Started, currentStatus -> currentStatus != MonitorStatus.Started);
                            MonitorProfile profile = optProfile.get();
                            LOG.debug("Monitor Resume - Scheduling monitoring task for Id: {}", monitorId);
                            scheduleMonitoringTask(info, profile.getMonitorInterval());
                        } else {
                            String msg = String.format("Monitoring profile associated with id %d is not present", info.getProfileId());
                            LOG.warn("Monitor resume Failed. {}", msg);
                        }
                    }
                }, MoreExecutors.directExecutor());
            } else {
                tx.close();
                String msg = String.format("Monitoring info associated with id %d is not present", monitorId);
                LOG.warn("Monitor resume Failed. {}", msg);
            }
        }
    }, MoreExecutors.directExecutor());
}
Also used : Optional(com.google.common.base.Optional) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Nonnull(javax.annotation.Nonnull) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 65 with ReadOnlyTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction in project genius by opendaylight.

the class AlivenessMonitor method monitorUnpause.

@Override
public Future<RpcResult<Void>> monitorUnpause(MonitorUnpauseInput input) {
    LOG.debug("Monitor Unpause operation invoked for monitor id: {}", input.getMonitorId());
    final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    final Long monitorId = input.getMonitorId();
    final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
    ListenableFuture<Optional<MonitoringInfo>> readInfoResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
    Futures.addCallback(readInfoResult, new FutureCallback<Optional<MonitoringInfo>>() {

        @Override
        public void onFailure(Throwable error) {
            tx.close();
            String msg = String.format("Unable to read monitoring info associated with monitor id %d", monitorId);
            LOG.error("Monitor unpause Failed. {}", msg, error);
            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
        }

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringInfo> optInfo) {
            if (optInfo.isPresent()) {
                final MonitoringInfo info = optInfo.get();
                ListenableFuture<Optional<MonitorProfile>> readProfile = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(info.getProfileId()));
                Futures.addCallback(readProfile, new FutureCallback<Optional<MonitorProfile>>() {

                    @Override
                    public void onFailure(Throwable error) {
                        tx.close();
                        String msg = String.format("Unable to read Monitoring profile associated with id %d", info.getProfileId());
                        LOG.warn("Monitor unpause Failed. {}", msg, error);
                        result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
                    }

                    @Override
                    public void onSuccess(@Nonnull Optional<MonitorProfile> optProfile) {
                        tx.close();
                        if (optProfile.isPresent()) {
                            updateMonitorStatusTo(monitorId, MonitorStatus.Started, currentStatus -> (currentStatus == MonitorStatus.Paused || currentStatus == MonitorStatus.Stopped));
                            MonitorProfile profile = optProfile.get();
                            LOG.debug("Monitor Resume - Scheduling monitoring task with Id: {}", monitorId);
                            EtherTypes protocolType = profile.getProtocolType();
                            if (protocolType == EtherTypes.Bfd) {
                                LOG.debug("disabling bfd for hwvtep tunnel montior id {}", monitorId);
                                ((HwVtepTunnelsStateHandler) alivenessProtocolHandlerRegistry.get(protocolType)).resetMonitoringTask(true);
                            } else {
                                scheduleMonitoringTask(info, profile.getMonitorInterval());
                            }
                            result.set(RpcResultBuilder.<Void>success().build());
                        } else {
                            String msg = String.format("Monitoring profile associated with id %d is not present", info.getProfileId());
                            LOG.warn("Monitor unpause Failed. {}", msg);
                            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg).build());
                        }
                    }
                }, callbackExecutorService);
            } else {
                tx.close();
                String msg = String.format("Monitoring info associated with id %d is not present", monitorId);
                LOG.warn("Monitor unpause Failed. {}", msg);
                result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg).build());
            }
        }
    }, callbackExecutorService);
    return result;
}
Also used : Optional(com.google.common.base.Optional) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Nonnull(javax.annotation.Nonnull) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)65 Optional (com.google.common.base.Optional)27 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)23 ExecutionException (java.util.concurrent.ExecutionException)17 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)16 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)16 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)13 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)12 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)8 ArrayList (java.util.ArrayList)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)7 List (java.util.List)6 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)6 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)6 Test (org.junit.Test)5 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)5 Nonnull (javax.annotation.Nonnull)4 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)4 CacheBuilder (com.google.common.cache.CacheBuilder)3