Update MRI projects for Aluminium
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / AllMeterConfigStatsService.java
index f79d24460e1a6e35f5b44921b84abe335969d0d3..c3ef683e870b6ba8aa213b487a285a01dce8ee7a 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -7,16 +7,19 @@
  */
 package org.opendaylight.openflowplugin.impl.statistics.services;
 
+import com.google.common.collect.Lists;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
 import org.opendaylight.openflowjava.protocol.api.util.BinContent;
 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.services.util.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
@@ -72,7 +75,7 @@ final class AllMeterConfigStatsService
 
     @Override
     protected OfHeader buildRequest(final Xid xid,
-                                    final GetAllMeterConfigStatisticsInput input) throws ServiceException {
+                                    final GetAllMeterConfigStatisticsInput input) {
         MultipartRequestInputBuilder mprInput = RequestInputUtils
                 .createMultipartHeader(MultipartType.OFPMPMETERCONFIG, xid.getValue(), getVersion());
         return mprInput.setMultipartRequestBody(METER_CONFIG_CASE).build();
@@ -98,7 +101,15 @@ final class AllMeterConfigStatsService
             final Optional<List<MeterConfigStats>> meterConfigStatsList =
                     convertorExecutor.convert(replyBody.getMeterConfig(), data);
 
-            meterConfigStatsList.ifPresent(meterConfigStats -> message.getMeterConfigStats().addAll(meterConfigStats));
+            meterConfigStatsList.ifPresent(meterConfigStats -> {
+                if (message.getMeterConfigStats() == null) {
+                    message.setMeterConfigStats(Lists.newArrayList(meterConfigStats));
+                } else {
+                    Set<MeterConfigStats> stats = new HashSet<>(message.getMeterConfigStats().values());
+                    stats.addAll(meterConfigStats);
+                    message.setMeterConfigStats(stats.stream().collect(Collectors.toList()));
+                }
+            });
         }
 
         return message.build();