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();
}
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();
}
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();
}
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());
}
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;
}
Aggregations