Bug 5596 Initial commit failed
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalGroupServiceImpl.java
index cdbc10b6f08f0083cf503a734154994c0ca60c6a..1e1ff0e9f5e53f2adb583902da28d68f488b4779 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
@@ -45,11 +46,11 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
     private final DeviceContext deviceContext;
     private ItemLifecycleListener itemLifecycleListener;
 
-    public SalGroupServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+    public SalGroupServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) {
         this.deviceContext = deviceContext;
-        addGroup = new GroupService<>(requestContextStack, deviceContext, AddGroupOutput.class);
-        updateGroup = new GroupService<>(requestContextStack, deviceContext, UpdateGroupOutput.class);
-        removeGroup = new GroupService<>(requestContextStack, deviceContext, RemoveGroupOutput.class);
+        addGroup = new GroupService<>(requestContextStack, deviceContext, AddGroupOutput.class, convertorExecutor);
+        updateGroup = new GroupService<>(requestContextStack, deviceContext, UpdateGroupOutput.class, convertorExecutor);
+        removeGroup = new GroupService<>(requestContextStack, deviceContext, RemoveGroupOutput.class, convertorExecutor);
     }
 
     @Override
@@ -59,7 +60,6 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
 
     @Override
     public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
-        addGroup.getDeviceRegistry().getDeviceGroupRegistry().store(input.getGroupId());
         final ListenableFuture<RpcResult<AddGroupOutput>> resultFuture = addGroup.handleServiceCall(input);
         Futures.addCallback(resultFuture, new FutureCallback<RpcResult<AddGroupOutput>>() {
             @Override
@@ -68,17 +68,17 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
                     if(LOG.isDebugEnabled()) {
                         LOG.debug("group add with id={} finished without error", input.getGroupId().getValue());
                     }
+                    deviceContext.getDeviceGroupRegistry().store(input.getGroupId());
                     addIfNecessaryToDS(input.getGroupId(), input);
                 } else {
-                LOG.error("group add with id={} failed, errors={}", input.getGroupId().getValue(),
-                        errorsToString(result.getErrors()));
-                 }
+                    LOG.error("group add with id={} failed, errors={}", input.getGroupId().getValue(),
+                            errorsToString(result.getErrors()));
+                }
             }
 
             @Override
             public void onFailure(Throwable t) {
-                LOG.error("Service call for group add failed for id={}. Exception: {}",
-                        input.getGroupId().getValue(), t);
+                LOG.error("Service call for group add failed for id={}. Exception: {}", input.getGroupId().getValue(), t);
             }
         });
 
@@ -115,7 +115,6 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
 
     @Override
     public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
-        removeGroup.getDeviceRegistry().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
         final ListenableFuture<RpcResult<RemoveGroupOutput>> resultFuture = removeGroup.handleServiceCall(input);
         Futures.addCallback(resultFuture, new FutureCallback<RpcResult<RemoveGroupOutput>>() {
             @Override
@@ -124,6 +123,7 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
                     if(LOG.isDebugEnabled()) {
                         LOG.debug("Group remove for id {} succeded", input.getGroupId().getValue());
                     }
+                    removeGroup.getDeviceRegistry().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
                     removeIfNecessaryFromDS(input.getGroupId());
                 }else{
                     LOG.error("group remove failed with id={}, errors={}", input.getGroupId().getValue(),
@@ -173,4 +173,4 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
         }
         return errors.toString();
     }
-}
+}
\ No newline at end of file