Search in sources :

Example 1 with RoleChangeException

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;
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RoleChangeException(org.opendaylight.openflowplugin.impl.role.RoleChangeException) RoleRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) BigInteger(java.math.BigInteger) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BigInteger (java.math.BigInteger)1 ExecutionException (java.util.concurrent.ExecutionException)1 RoleChangeException (org.opendaylight.openflowplugin.impl.role.RoleChangeException)1 RoleRequestInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder)1 RoleRequestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1