Committed by
Gerrit Code Review
Fixes to solve Jira Issues ONOS-4173 and ONOS-4174
- Using Pair<DeviceId, MeterId> instead of MeterId in storedMeterMap to avoid duplicate key IllegalStateException - Replaced ADD operation with MODIFY in pushMeterMetrics method to avoid METER_EXISTS errors Change-Id: I80d3ccededa452445b11bb09b949fb2a208293a4
Showing
1 changed file
with
6 additions
and
5 deletions
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.incubator.net.meter.impl; | 16 | package org.onosproject.incubator.net.meter.impl; |
17 | 17 | ||
18 | +import org.apache.commons.lang3.tuple.Pair; | ||
18 | import com.google.common.collect.Maps; | 19 | import com.google.common.collect.Maps; |
19 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
20 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
... | @@ -210,19 +211,19 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M | ... | @@ -210,19 +211,19 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M |
210 | public void pushMeterMetrics(DeviceId deviceId, Collection<Meter> meterEntries) { | 211 | public void pushMeterMetrics(DeviceId deviceId, Collection<Meter> meterEntries) { |
211 | //FIXME: FOLLOWING CODE CANNOT BE TESTED UNTIL SOMETHING THAT | 212 | //FIXME: FOLLOWING CODE CANNOT BE TESTED UNTIL SOMETHING THAT |
212 | //FIXME: IMPLEMENTS METERS EXISTS | 213 | //FIXME: IMPLEMENTS METERS EXISTS |
213 | - Map<MeterId, Meter> storedMeterMap = store.getAllMeters().stream() | 214 | + Map<Pair<DeviceId, MeterId>, Meter> storedMeterMap = store.getAllMeters().stream() |
214 | - .collect(Collectors.toMap(Meter::id, m -> m)); | 215 | + .collect(Collectors.toMap(m -> Pair.of(m.deviceId(), m.id()), m -> m)); |
215 | 216 | ||
216 | meterEntries.stream() | 217 | meterEntries.stream() |
217 | - .filter(m -> storedMeterMap.remove(m.id()) != null) | 218 | + .filter(m -> storedMeterMap.remove(Pair.of(m.deviceId(), m.id())) != null) |
218 | .forEach(m -> store.updateMeterState(m)); | 219 | .forEach(m -> store.updateMeterState(m)); |
219 | 220 | ||
220 | storedMeterMap.values().stream().forEach(m -> { | 221 | storedMeterMap.values().stream().forEach(m -> { |
221 | if (m.state() == MeterState.PENDING_ADD) { | 222 | if (m.state() == MeterState.PENDING_ADD) { |
222 | provider().performMeterOperation(m.deviceId(), | 223 | provider().performMeterOperation(m.deviceId(), |
223 | new MeterOperation(m, | 224 | new MeterOperation(m, |
224 | - MeterOperation.Type.ADD)); | 225 | + MeterOperation.Type.MODIFY)); |
225 | - } else if ((m.state() == MeterState.PENDING_REMOVE)) { | 226 | + } else if (m.state() == MeterState.PENDING_REMOVE) { |
226 | store.deleteMeterNow(m); | 227 | store.deleteMeterNow(m); |
227 | } | 228 | } |
228 | }); | 229 | }); | ... | ... |
-
Please register or login to post a comment