Bump odlparent to 5.0.0
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / RoleService.java
index de1ad3efea2b1e887d0f349537aa839348573fdf..ff642d73668bce060a3476cca708e96477e3c24a 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.impl.services;
 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.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import java.math.BigInteger;
 import java.util.Collection;
@@ -19,6 +20,7 @@ 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.impl.util.ErrorUtil;
 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;
@@ -33,15 +35,14 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- * Created by kramesha on 8/24/15.
- */
 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;
     }
@@ -62,7 +63,8 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
         roleRequestInputBuilder.setGenerationId(BigInteger.ZERO);
 
         final SettableFuture<BigInteger> finalFuture = SettableFuture.create();
-        final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture = handleServiceCall(roleRequestInputBuilder);
+        final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture =
+                handleServiceCall(roleRequestInputBuilder);
         Futures.addCallback(genIdListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
             @Override
             public void onSuccess(final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
@@ -73,28 +75,31 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
                         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()));
+                        finalFuture.setException(new RoleChangeException("Exception in getting generationId for device:"
+                                + getDeviceInfo().getNodeId().getValue()));
                     }
 
                 } else {
-                    LOG.error("getGenerationIdFromDevice RPC error " +
+                    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);
+                LOG.info("onFailure - getGenerationIdFromDevice RPC error", throwable);
                 finalFuture.setException(new ExecutionException(throwable));
             }
-        });
+        }, MoreExecutors.directExecutor());
         return finalFuture;
     }
 
 
-    public Future<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Short version, final BigInteger generationId) {
+    public Future<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole,
+                                                             final Short version,
+                                                             final BigInteger generationId) {
         LOG.info("submitRoleChange called for device:{}, role:{}",
                 getDeviceInfo().getNodeId(), ofpRole);
         final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
@@ -102,7 +107,8 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
         roleRequestInputBuilder.setVersion(version);
         roleRequestInputBuilder.setGenerationId(generationId);
 
-        final ListenableFuture<RpcResult<RoleRequestOutput>> roleListenableFuture = handleServiceCall(roleRequestInputBuilder);
+        final ListenableFuture<RpcResult<RoleRequestOutput>> roleListenableFuture =
+                handleServiceCall(roleRequestInputBuilder);
 
         final SettableFuture<RpcResult<SetRoleOutput>> finalFuture = SettableFuture.create();
         Futures.addCallback(roleListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
@@ -114,8 +120,10 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
                 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(BigInteger.valueOf(roleRequestOutput.getXid())));
+                    finalFuture.set(RpcResultBuilder.<SetRoleOutput>success()
+                            .withResult(setRoleOutputBuilder.build()).build());
 
                 } else if (rpcErrors != null) {
                     LOG.trace("roleRequestOutput is null , rpcErrors={}", rpcErrors);
@@ -134,7 +142,7 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
                         getDeviceInfo().getNodeId(), ofpRole, throwable);
                 finalFuture.setException(throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
         return finalFuture;
     }
 
@@ -157,6 +165,4 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
         }
         return ofJavaRole;
     }
-
-
 }