use of org.opendaylight.openflowplugin.impl.role.RoleChangeException in project openflowplugin by opendaylight.
the class RoleService method getGenerationIdFromDevice.
public Future<BigInteger> getGenerationIdFromDevice(final Short version) {
LOG.info("getGenerationIdFromDevice called for device: {}", getDeviceInfo().getNodeId().getValue());
// send a dummy no-change role request to get the generation-id of the switch
final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
roleRequestInputBuilder.setRole(toOFJavaRole(OfpRole.NOCHANGE));
roleRequestInputBuilder.setVersion(version);
roleRequestInputBuilder.setGenerationId(BigInteger.ZERO);
final SettableFuture<BigInteger> finalFuture = SettableFuture.create();
final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture = handleServiceCall(roleRequestInputBuilder);
Futures.addCallback(genIdListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
@Override
public void onSuccess(@Nonnull final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
if (roleRequestOutputRpcResult.isSuccessful()) {
final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
if (roleRequestOutput != null) {
LOG.debug("roleRequestOutput.getGenerationId()={}", roleRequestOutput.getGenerationId());
finalFuture.set(roleRequestOutput.getGenerationId());
} else {
LOG.info("roleRequestOutput is null in getGenerationIdFromDevice");
finalFuture.setException(new RoleChangeException("Exception in getting generationId for device:" + getDeviceInfo().getNodeId().getValue()));
}
} else {
LOG.error("getGenerationIdFromDevice RPC error " + roleRequestOutputRpcResult.getErrors().iterator().next().getInfo());
finalFuture.setException(new RoleChangeException(ErrorUtil.errorsToString(roleRequestOutputRpcResult.getErrors())));
}
}
@Override
public void onFailure(final Throwable throwable) {
LOG.info("onFailure - getGenerationIdFromDevice RPC error {}", throwable);
finalFuture.setException(new ExecutionException(throwable));
}
}, MoreExecutors.directExecutor());
return finalFuture;
}
Aggregations