Committed by
Sho Shimizu
Resource Store Defect Fix: Allowing allocation/release of more than 1 continous …
…resource from same consumer with same value Change-Id: Ic143b263d5e5922c7bf4b78309bf3b2a38194a0b
Showing
1 changed file
with
17 additions
and
8 deletions
... | @@ -33,6 +33,7 @@ import java.util.List; | ... | @@ -33,6 +33,7 @@ import java.util.List; |
33 | import java.util.Optional; | 33 | import java.util.Optional; |
34 | import java.util.Set; | 34 | import java.util.Set; |
35 | import java.util.stream.Collectors; | 35 | import java.util.stream.Collectors; |
36 | +import java.util.stream.Stream; | ||
36 | 37 | ||
37 | import static com.google.common.base.Preconditions.checkArgument; | 38 | import static com.google.common.base.Preconditions.checkArgument; |
38 | import static org.onosproject.store.resource.impl.ConsistentResourceStore.SERIALIZER; | 39 | import static org.onosproject.store.resource.impl.ConsistentResourceStore.SERIALIZER; |
... | @@ -162,11 +163,6 @@ class TransactionalContinuousResourceStore { | ... | @@ -162,11 +163,6 @@ class TransactionalContinuousResourceStore { |
162 | return true; | 163 | return true; |
163 | } | 164 | } |
164 | 165 | ||
165 | - if (oldValue.allocations().contains(value)) { | ||
166 | - // don't write to map because all values are already stored | ||
167 | - return true; | ||
168 | - } | ||
169 | - | ||
170 | ContinuousResourceAllocation newValue = new ContinuousResourceAllocation(original, | 166 | ContinuousResourceAllocation newValue = new ContinuousResourceAllocation(original, |
171 | ImmutableList.<ResourceAllocation>builder() | 167 | ImmutableList.<ResourceAllocation>builder() |
172 | .addAll(oldValue.allocations()) | 168 | .addAll(oldValue.allocations()) |
... | @@ -177,13 +173,26 @@ class TransactionalContinuousResourceStore { | ... | @@ -177,13 +173,26 @@ class TransactionalContinuousResourceStore { |
177 | 173 | ||
178 | boolean release(ContinuousResource resource, ResourceConsumer consumer) { | 174 | boolean release(ContinuousResource resource, ResourceConsumer consumer) { |
179 | ContinuousResourceAllocation oldAllocation = consumers.get(resource.id()); | 175 | ContinuousResourceAllocation oldAllocation = consumers.get(resource.id()); |
180 | - ImmutableList<ResourceAllocation> newAllocations = oldAllocation.allocations().stream() | 176 | + |
177 | + List<ResourceAllocation> nonMatchResources = oldAllocation.allocations().stream() | ||
181 | .filter(x -> !(x.consumer().equals(consumer) && | 178 | .filter(x -> !(x.consumer().equals(consumer) && |
182 | ((ContinuousResource) x.resource()).value() == resource.value())) | 179 | ((ContinuousResource) x.resource()).value() == resource.value())) |
183 | - .collect(GuavaCollectors.toImmutableList()); | 180 | + .collect(Collectors.toList()); |
181 | + | ||
182 | + List<ResourceAllocation> matchResources = oldAllocation.allocations().stream() | ||
183 | + .filter(x -> (x.consumer().equals(consumer) && | ||
184 | + ((ContinuousResource) x.resource()).value() == resource.value())) | ||
185 | + .collect(Collectors.toList()); | ||
186 | + | ||
187 | + if (matchResources.size() > 1) { | ||
188 | + matchResources.remove(0); | ||
189 | + } | ||
190 | + | ||
191 | + ImmutableList<ResourceAllocation> finalAllocations = Stream.concat(nonMatchResources.stream(), | ||
192 | + matchResources.stream()).collect(GuavaCollectors.toImmutableList()); | ||
184 | 193 | ||
185 | if (!consumers.replace(resource.id(), oldAllocation, | 194 | if (!consumers.replace(resource.id(), oldAllocation, |
186 | - new ContinuousResourceAllocation(oldAllocation.original(), newAllocations))) { | 195 | + new ContinuousResourceAllocation(oldAllocation.original(), finalAllocations))) { |
187 | return false; | 196 | return false; |
188 | } | 197 | } |
189 | 198 | ... | ... |
-
Please register or login to post a comment