Added createEmptyRpcBatchResultFuture method 92/41492/1
authorAndrej Leitner <anleitne@cisco.com>
Thu, 7 Jul 2016 14:59:48 +0000 (16:59 +0200)
committerAndrej Leitner <anleitne@cisco.com>
Thu, 7 Jul 2016 15:04:54 +0000 (17:04 +0200)
 - duplicated creation replaced by util method

Change-Id: I1dcf8a15c294f0810112c4c9b1bf25dccb0f105c
Signed-off-by: Andrej Leitner <anleitne@cisco.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalFlatBatchServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/FlatBatchUtil.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlatBatchServiceImplTest.java

index 69647dd4f79864afdabe6ab4699f9e5ddb267323..05a88b15333626c1d6d09881ef460f43884a70f9 100644 (file)
@@ -24,7 +24,6 @@ import org.opendaylight.openflowplugin.impl.util.FlatBatchUtil;
 import org.opendaylight.openflowplugin.impl.util.PathUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput;
@@ -50,7 +49,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.Sa
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutput;
 import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -90,10 +88,7 @@ public class SalFlatBatchServiceImpl implements SalFlatBatchService {
         BatchStepJob batchJob;
         final List<ListenableFuture<RpcResult<ProcessFlatBatchOutput>>> firedJobs = new ArrayList<>();
         ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainSummaryResult =
-            RpcResultBuilder.<ProcessFlatBatchOutput>success()
-                            .withRpcErrors(new ArrayList<>())
-                            .withResult(new ProcessFlatBatchOutputBuilder().setBatchFailure(new ArrayList<>()).build())
-                            .buildFuture();
+                FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
 
         for (int i = 0; i < batchJobsChain.size(); i++)  {
             batchJob = batchJobsChain.get(i);
@@ -119,10 +114,7 @@ public class SalFlatBatchServiceImpl implements SalFlatBatchService {
             chainJobs.add(new BatchStepJob(planStep, chainInput -> {
                 if (exitOnFirstError && !chainInput.isSuccessful()) {
                     LOG.debug("error on flat batch chain occurred -> skipping step {}", planStep.getStepType());
-                    return RpcResultBuilder.<ProcessFlatBatchOutput>status(false)
-                                           .withRpcErrors(new ArrayList<>())
-                                           .withResult(new ProcessFlatBatchOutputBuilder().setBatchFailure(new ArrayList<>()).build())
-                                           .buildFuture();
+                    return FlatBatchUtil.createEmptyRpcBatchResultFuture(false);
                 }
 
                 LOG.trace("batch progressing on step type {}", planStep.getStepType());
@@ -177,10 +169,7 @@ public class SalFlatBatchServiceImpl implements SalFlatBatchService {
                         break;
                     default:
                         LOG.warn("Unsupported plan-step type occurred: {} -> OMITTING", planStep.getStepType());
-                        chainOutput = RpcResultBuilder.<ProcessFlatBatchOutput>status(true)
-                                                      .withRpcErrors(new ArrayList<>())
-                                                      .withResult(new ProcessFlatBatchOutputBuilder().setBatchFailure(new ArrayList<>()).build())
-                                                      .buildFuture();
+                        chainOutput = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
                 }
                 return chainOutput;
             }));
index 8bd950cff20db5d2953346b11f69986ad0ab8ea0..9850864e0d64412243b6afb5c30bed1336fdd0a7 100644 (file)
@@ -213,5 +213,16 @@ public final class FlatBatchUtil {
         return Futures.transform(Futures.successfulAsList(firedJobs), mergeRpcResults());
     }
 
+    /**
+     *
+     * @param status RPC result status
+     * @return ListenableFuture of RPC result with empty list of errors and batch failures
+     */
+    public static ListenableFuture<RpcResult<ProcessFlatBatchOutput>> createEmptyRpcBatchResultFuture(final boolean status) {
+        return RpcResultBuilder.<ProcessFlatBatchOutput>status(status)
+                               .withRpcErrors(new ArrayList<>())
+                               .withResult(new ProcessFlatBatchOutputBuilder().setBatchFailure(new ArrayList<>()).build())
+                               .buildFuture();
+    }
 
 }
index 0a5084f90b3dd7e0b160083ea5143f4fca904610..889ee00e5c844c8db4c000eee0f43beb9474767e 100644 (file)
@@ -30,6 +30,7 @@ import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep;
 import org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob;
 import org.opendaylight.openflowplugin.impl.services.batch.BatchStepType;
+import org.opendaylight.openflowplugin.impl.util.FlatBatchUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput;
@@ -447,8 +448,7 @@ public class SalFlatBatchServiceImplTest {
         Mockito.when(batchStepJob1.getPlanStep()).thenReturn(batchPlanStep1);
         Mockito.when(batchStepJob2.getPlanStep()).thenReturn(batchPlanStep2);
 
-        final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> succeededChainOutput =
-                RpcResultBuilder.<ProcessFlatBatchOutput>success().withResult(new ProcessFlatBatchOutputBuilder().setBatchFailure(new ArrayList<>()).build()).buildFuture();
+        final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> succeededChainOutput = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
         final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> failedChainOutput =
                 RpcResultBuilder.<ProcessFlatBatchOutput>failed()
                         .withError(RpcError.ErrorType.APPLICATION, "ut-chainError")