* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.impl.role.RoleChangeException;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.impl.role.RoleChangeException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder, RoleRequestOutput> {
private static final Logger LOG = LoggerFactory.getLogger(RoleService.class);
private final DeviceContext deviceContext;
public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder, RoleRequestOutput> {
private static final Logger LOG = LoggerFactory.getLogger(RoleService.class);
private final DeviceContext deviceContext;
- protected RoleService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final Class<RoleRequestOutput> clazz) {
+ public RoleService(final RequestContextStack requestContextStack,
+ final DeviceContext deviceContext,
+ final Class<RoleRequestOutput> clazz) {
super(requestContextStack, deviceContext, clazz);
this.deviceContext = deviceContext;
}
super(requestContextStack, deviceContext, clazz);
this.deviceContext = deviceContext;
}
- public Future<BigInteger> getGenerationIdFromDevice(final Short version) {
- LOG.info("getGenerationIdFromDevice called for device:{}", getDeviceInfo().getNodeId().getValue());
+ public ListenableFuture<Uint64> getGenerationIdFromDevice(final Uint8 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);
// 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);
- final SettableFuture<BigInteger> finalFuture = SettableFuture.create();
- final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture = handleServiceCall(roleRequestInputBuilder);
+ final SettableFuture<Uint64> finalFuture = SettableFuture.create();
+ final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture =
+ handleServiceCall(roleRequestInputBuilder);
Futures.addCallback(genIdListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
@Override
public void onSuccess(final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
Futures.addCallback(genIdListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
@Override
public void onSuccess(final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
finalFuture.set(roleRequestOutput.getGenerationId());
} else {
LOG.info("roleRequestOutput is null in getGenerationIdFromDevice");
finalFuture.set(roleRequestOutput.getGenerationId());
} else {
LOG.info("roleRequestOutput is null in getGenerationIdFromDevice");
- public Future<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Short version, final BigInteger generationId) {
+ public ListenableFuture<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Uint8 version,
+ final Uint64 generationId) {
LOG.info("submitRoleChange called for device:{}, role:{}",
getDeviceInfo().getNodeId(), ofpRole);
final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
LOG.info("submitRoleChange called for device:{}, role:{}",
getDeviceInfo().getNodeId(), ofpRole);
final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
final SettableFuture<RpcResult<SetRoleOutput>> finalFuture = SettableFuture.create();
Futures.addCallback(roleListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
final SettableFuture<RpcResult<SetRoleOutput>> finalFuture = SettableFuture.create();
Futures.addCallback(roleListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
final Collection<RpcError> rpcErrors = roleRequestOutputRpcResult.getErrors();
if (roleRequestOutput != null) {
final SetRoleOutputBuilder setRoleOutputBuilder = new SetRoleOutputBuilder();
final Collection<RpcError> rpcErrors = roleRequestOutputRpcResult.getErrors();
if (roleRequestOutput != null) {
final SetRoleOutputBuilder setRoleOutputBuilder = new SetRoleOutputBuilder();
- setRoleOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(roleRequestOutput.getXid())));
- finalFuture.set(RpcResultBuilder.<SetRoleOutput>success().withResult(setRoleOutputBuilder.build()).build());
+ setRoleOutputBuilder
+ .setTransactionId(new TransactionId(Uint64.valueOf(roleRequestOutput.getXid())));
+ finalFuture.set(RpcResultBuilder.<SetRoleOutput>success()
+ .withResult(setRoleOutputBuilder.build()).build());
} else if (rpcErrors != null) {
LOG.trace("roleRequestOutput is null , rpcErrors={}", rpcErrors);
} else if (rpcErrors != null) {
LOG.trace("roleRequestOutput is null , rpcErrors={}", rpcErrors);
getDeviceInfo().getNodeId(), ofpRole, throwable);
finalFuture.setException(throwable);
}
getDeviceInfo().getNodeId(), ofpRole, throwable);
finalFuture.setException(throwable);
}