use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project genius by opendaylight.
the class ArpUtilImpl method sendArpRequest.
@Override
public Future<RpcResult<Void>> sendArpRequest(SendArpRequestInput arpReqInput) {
LOG.trace("rpc sendArpRequest invoked for ip {}", arpReqInput.getIpaddress());
BigInteger dpnId;
byte[] payload;
String interfaceName = null;
byte[] srcIpBytes;
byte[] dstIpBytes;
byte[] srcMac;
RpcResultBuilder<Void> failureBuilder = RpcResultBuilder.failed();
RpcResultBuilder<Void> successBuilder = RpcResultBuilder.success();
try {
dstIpBytes = getIpAddressBytes(arpReqInput.getIpaddress());
} catch (UnknownHostException e) {
LOG.error("Cannot get IP address", e);
failureBuilder.withError(ErrorType.APPLICATION, ArpConstants.UNKNOWN_IP_ADDRESS_SUPPLIED);
return Futures.immediateFuture(failureBuilder.build());
}
int localErrorCount = 0;
for (InterfaceAddress interfaceAddress : arpReqInput.getInterfaceAddress()) {
try {
interfaceName = interfaceAddress.getInterface();
srcIpBytes = getIpAddressBytes(interfaceAddress.getIpAddress());
GetPortFromInterfaceOutput portResult = getPortFromInterface(interfaceName);
checkNotNull(portResult);
dpnId = portResult.getDpid();
Long portid = portResult.getPortno();
checkArgument(null != dpnId && !BigInteger.ZERO.equals(dpnId), ArpConstants.DPN_NOT_FOUND_ERROR, interfaceName);
NodeConnectorRef ref = MDSALUtil.getNodeConnRef(dpnId, portid.toString());
checkNotNull(ref, ArpConstants.NODE_CONNECTOR_NOT_FOUND_ERROR, interfaceName);
LOG.trace("sendArpRequest received dpnId {} out interface {}", dpnId, interfaceName);
if (interfaceAddress.getMacaddress() == null) {
srcMac = MDSALUtil.getMacAddressForNodeConnector(dataBroker, (InstanceIdentifier<NodeConnector>) ref.getValue());
} else {
String macAddr = interfaceAddress.getMacaddress().getValue();
srcMac = HexEncode.bytesFromHexString(macAddr);
}
checkNotNull(srcMac, ArpConstants.FAILED_TO_GET_SRC_MAC_FOR_INTERFACE, interfaceName, ref.getValue());
checkNotNull(srcIpBytes, ArpConstants.FAILED_TO_GET_SRC_IP_FOR_INTERFACE, interfaceName);
payload = ArpPacketUtil.getPayload(ArpConstants.ARP_REQUEST_OP, srcMac, srcIpBytes, ArpPacketUtil.ETHERNET_BROADCAST_DESTINATION, dstIpBytes);
List<Action> actions = getEgressAction(interfaceName);
sendPacketOutWithActions(dpnId, payload, ref, actions);
LOG.trace("sent arp request for {}", arpReqInput.getIpaddress());
} catch (UnknownHostException | PacketException | InterruptedException | ExecutionException | ReadFailedException e) {
LOG.trace("failed to send arp req for {} on interface {}", arpReqInput.getIpaddress(), interfaceName);
failureBuilder.withError(ErrorType.APPLICATION, ArpConstants.FAILED_TO_SEND_ARP_REQ_FOR_INTERFACE + interfaceName, e);
successBuilder.withError(ErrorType.APPLICATION, ArpConstants.FAILED_TO_SEND_ARP_REQ_FOR_INTERFACE + interfaceName, e);
localErrorCount++;
}
}
if (localErrorCount == arpReqInput.getInterfaceAddress().size()) {
// All the requests failed
return Futures.immediateFuture(failureBuilder.build());
}
return Futures.immediateFuture(successBuilder.build());
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project genius by opendaylight.
the class IdManagerTest method getUpdatedActualParentPool.
private IdPool getUpdatedActualParentPool() throws ReadFailedException {
IdPool idPoolParentFromDS = singleTxdataBroker.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(ID_POOL_NAME)).build());
List<ChildPools> childPool = idPoolParentFromDS.getChildPools();
List<ChildPools> updatedChildPool = childPool.stream().map(child -> new ChildPoolsBuilder(child).setLastAccessTime(0L).build()).collect(Collectors.toList());
List<IdEntries> idEntries = idPoolParentFromDS.getIdEntries();
IdPoolBuilder idPoolBuilder = new IdPoolBuilder(idPoolParentFromDS);
if (idEntries != null) {
List<IdEntries> sortedIdEntries = idEntries.stream().sorted(comparing(IdEntries::getIdKey)).collect(Collectors.toList());
idPoolBuilder.setIdEntries(sortedIdEntries);
}
IdPool actualIdPoolParent = idPoolBuilder.setChildPools(updatedChildPool).build();
return actualIdPoolParent;
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project genius by opendaylight.
the class ResourceBatchingManager method read.
/**
* Reads the identifier of the given resource type.
* Not to be used by the applications which uses their own resource queue
*
* @param resourceType resource type that was registered with batch manager
* @param identifier identifier to be read
* @return a CheckFuture containing the result of the read
*/
public <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(String resourceType, InstanceIdentifier<T> identifier) {
BlockingQueue<ActionableResource> queue = getQueue(resourceType);
if (queue != null) {
if (pendingModificationByResourceType.get(resourceType).contains(identifier)) {
SettableFuture<Optional<T>> readFuture = SettableFuture.create();
queue.add(new ActionableReadResource<>(identifier, readFuture));
return Futures.makeChecked(readFuture, ReadFailedException.MAPPER);
} else {
ResourceHandler resourceHandler = resourceHandlerMapper.get(resourceType).getRight();
try (ReadOnlyTransaction tx = resourceHandler.getResourceBroker().newReadOnlyTransaction()) {
return tx.read(resourceHandler.getDatastoreType(), identifier);
}
}
}
return Futures.immediateFailedCheckedFuture(new ReadFailedException("No batch handler was registered for resource " + resourceType));
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project controller by opendaylight.
the class TxchainBaRead method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
try (ReadOnlyTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
for (long l = 0; l < outerListElem; l++) {
InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey((int) l));
CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
try {
Optional<OuterList> optionalDataObject = submitFuture.checkedGet();
if (optionalDataObject != null && optionalDataObject.isPresent()) {
OuterList outerList = optionalDataObject.get();
String[] objectsArray = new String[outerList.getInnerList().size()];
for (InnerList innerList : outerList.getInnerList()) {
if (objectsArray[innerList.getName()] != null) {
LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue());
}
objectsArray[innerList.getName()] = innerList.getValue();
}
for (int i = 0; i < outerList.getInnerList().size(); i++) {
String itemStr = objectsArray[i];
if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
LOG.error("innerList: name: {}, value: {}", i, itemStr);
break;
}
}
txOk++;
} else {
txError++;
}
} catch (final ReadFailedException e) {
LOG.warn("failed to ....", e);
txError++;
}
}
}
}
use of org.opendaylight.controller.md.sal.common.api.data.ReadFailedException in project controller by opendaylight.
the class RemoteTransactionContext method executeRead.
@Override
public <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> returnFuture) {
LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(), readCmd.getPath());
final Throwable failure = failedModification;
if (failure != null) {
// If we know there was a previous modification failure, we must not send a read request, as it risks
// returning incorrect data. We check this before acquiring an operation simply because we want the app
// to complete this transaction as soon as possible.
returnFuture.setException(new ReadFailedException("Previous modification failed, cannot " + readCmd.getClass().getSimpleName() + " for path " + readCmd.getPath(), failure));
return;
}
// Send any batched modifications. This is necessary to honor the read uncommitted semantics of the
// public API contract.
final boolean havePermit = acquireOperation();
sendBatchedModifications();
OnComplete<Object> onComplete = new OnComplete<Object>() {
@Override
public void onComplete(Throwable failure, Object response) {
// We have previously acquired an operation, now release it, no matter what happened
if (havePermit) {
limiter.release();
}
if (failure != null) {
LOG.debug("Tx {} {} operation failed: {}", getIdentifier(), readCmd.getClass().getSimpleName(), failure);
returnFuture.setException(new ReadFailedException("Error checking " + readCmd.getClass().getSimpleName() + " for path " + readCmd.getPath(), failure));
} else {
LOG.debug("Tx {} {} operation succeeded", getIdentifier(), readCmd.getClass().getSimpleName());
readCmd.processResponse(response, returnFuture);
}
}
};
final Future<Object> future = actorContext.executeOperationAsync(getActor(), readCmd.asVersion(getTransactionVersion()).toSerializable(), actorContext.getOperationTimeout());
future.onComplete(onComplete, actorContext.getClientDispatcher());
}
Aggregations