Committed by
Gerrit Code Review
ConsistentLinkResourceStore to replace HazelcastLinkResourceStore. Also
includes: - typo fix (intendId -> intentId) - refactored ResourceAllocations command so it doesn't use error handling as part of control flow - add ability to compare LinkResourceAllocations Reference: ONOS-1076 Conflicts: cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java Change-Id: I6a68012d8d7d359ce7c5dcd31e80a3b9f63d5670
Showing
14 changed files
with
84 additions
and
38 deletions
... | @@ -21,14 +21,13 @@ import org.onosproject.cli.AbstractShellCommand; | ... | @@ -21,14 +21,13 @@ import org.onosproject.cli.AbstractShellCommand; |
21 | import org.onosproject.net.ConnectPoint; | 21 | import org.onosproject.net.ConnectPoint; |
22 | import org.onosproject.net.Link; | 22 | import org.onosproject.net.Link; |
23 | import org.onosproject.net.link.LinkService; | 23 | import org.onosproject.net.link.LinkService; |
24 | -import org.onosproject.net.resource.LinkResourceAllocations; | ||
25 | import org.onosproject.net.resource.LinkResourceService; | 24 | import org.onosproject.net.resource.LinkResourceService; |
26 | 25 | ||
27 | /** | 26 | /** |
28 | - * Lists allocations by link. | 27 | + * Lists allocations by link. Lists all allocations if link is unspecified. |
29 | */ | 28 | */ |
30 | @Command(scope = "onos", name = "resource-allocations", | 29 | @Command(scope = "onos", name = "resource-allocations", |
31 | - description = "Lists allocations by link") | 30 | + description = "Lists allocations by link. Lists all allocations if link is unspecified.") |
32 | public class ResourceAllocationsCommand extends AbstractShellCommand { | 31 | public class ResourceAllocationsCommand extends AbstractShellCommand { |
33 | 32 | ||
34 | private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s%s"; | 33 | private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s%s"; |
... | @@ -46,27 +45,20 @@ public class ResourceAllocationsCommand extends AbstractShellCommand { | ... | @@ -46,27 +45,20 @@ public class ResourceAllocationsCommand extends AbstractShellCommand { |
46 | LinkResourceService resourceService = get(LinkResourceService.class); | 45 | LinkResourceService resourceService = get(LinkResourceService.class); |
47 | LinkService linkService = get(LinkService.class); | 46 | LinkService linkService = get(LinkService.class); |
48 | 47 | ||
49 | - Iterable<LinkResourceAllocations> itr = null; | 48 | + if (srcString == null || dstString == null) { |
50 | - try { | 49 | + print("----- Displaying all resource allocations -----"); |
51 | - ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString); | 50 | + resourceService.getAllocations().forEach(alloc -> print("%s", alloc)); |
52 | - | 51 | + return; |
53 | - ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString); | 52 | + } |
54 | - | ||
55 | - Link link = linkService.getLink(src, dst); | ||
56 | - | ||
57 | - itr = resourceService.getAllocations(link); | ||
58 | - | ||
59 | - for (LinkResourceAllocations allocation : itr) { | ||
60 | - print("%s", allocation.getResourceAllocation(link)); | ||
61 | - } | ||
62 | 53 | ||
63 | - } catch (Exception e) { | 54 | + ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString); |
64 | - print("----- Displaying all resource allocations -----", e.getMessage()); | 55 | + ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString); |
65 | - itr = resourceService.getAllocations(); | ||
66 | - for (LinkResourceAllocations allocation : itr) { | ||
67 | - print("%s", allocation); | ||
68 | - } | ||
69 | 56 | ||
57 | + Link link = linkService.getLink(src, dst); | ||
58 | + if (link != null) { | ||
59 | + resourceService.getAllocations(link).forEach(alloc -> print("%s", alloc)); | ||
60 | + } else { | ||
61 | + print("No path found for endpoints: %s, %s", src, dst); | ||
70 | } | 62 | } |
71 | } | 63 | } |
72 | } | 64 | } | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.resource; | 16 | package org.onosproject.net.resource; |
17 | 17 | ||
18 | +import java.util.Objects; | ||
19 | + | ||
18 | import com.google.common.base.MoreObjects; | 20 | import com.google.common.base.MoreObjects; |
19 | 21 | ||
20 | /** | 22 | /** |
... | @@ -48,6 +50,23 @@ public class BandwidthResourceRequest implements ResourceRequest { | ... | @@ -48,6 +50,23 @@ public class BandwidthResourceRequest implements ResourceRequest { |
48 | } | 50 | } |
49 | 51 | ||
50 | @Override | 52 | @Override |
53 | + public int hashCode() { | ||
54 | + return Objects.hash(bandwidth); | ||
55 | + } | ||
56 | + | ||
57 | + @Override | ||
58 | + public boolean equals(Object obj) { | ||
59 | + if (this == obj) { | ||
60 | + return true; | ||
61 | + } | ||
62 | + if (obj == null || getClass() != obj.getClass()) { | ||
63 | + return false; | ||
64 | + } | ||
65 | + final BandwidthResourceAllocation other = (BandwidthResourceAllocation) obj; | ||
66 | + return Objects.equals(this.bandwidth, other.bandwidth()); | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
51 | public String toString() { | 70 | public String toString() { |
52 | return MoreObjects.toStringHelper(this) | 71 | return MoreObjects.toStringHelper(this) |
53 | .add("bandwidth", bandwidth) | 72 | .add("bandwidth", bandwidth) | ... | ... |
... | @@ -27,6 +27,7 @@ import org.onosproject.net.intent.IntentId; | ... | @@ -27,6 +27,7 @@ import org.onosproject.net.intent.IntentId; |
27 | import java.util.Collection; | 27 | import java.util.Collection; |
28 | import java.util.Collections; | 28 | import java.util.Collections; |
29 | import java.util.Map; | 29 | import java.util.Map; |
30 | +import java.util.Objects; | ||
30 | import java.util.Map.Entry; | 31 | import java.util.Map.Entry; |
31 | import java.util.Set; | 32 | import java.util.Set; |
32 | 33 | ||
... | @@ -56,8 +57,8 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations { | ... | @@ -56,8 +57,8 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations { |
56 | } | 57 | } |
57 | 58 | ||
58 | @Override | 59 | @Override |
59 | - public IntentId intendId() { | 60 | + public IntentId intentId() { |
60 | - return request.intendId(); | 61 | + return request.intentId(); |
61 | } | 62 | } |
62 | 63 | ||
63 | @Override | 64 | @Override |
... | @@ -85,6 +86,24 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations { | ... | @@ -85,6 +86,24 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations { |
85 | } | 86 | } |
86 | 87 | ||
87 | @Override | 88 | @Override |
89 | + public int hashCode() { | ||
90 | + return Objects.hash(request, allocations); | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public boolean equals(Object obj) { | ||
95 | + if (this == obj) { | ||
96 | + return true; | ||
97 | + } | ||
98 | + if (obj == null || getClass() != obj.getClass()) { | ||
99 | + return false; | ||
100 | + } | ||
101 | + final DefaultLinkResourceAllocations other = (DefaultLinkResourceAllocations) obj; | ||
102 | + return Objects.equals(this.request, other.request) | ||
103 | + && Objects.equals(this.allocations, other.allocations); | ||
104 | + } | ||
105 | + | ||
106 | + @Override | ||
88 | public String toString() { | 107 | public String toString() { |
89 | return MoreObjects.toStringHelper(this) | 108 | return MoreObjects.toStringHelper(this) |
90 | .add("allocations", allocations) | 109 | .add("allocations", allocations) | ... | ... |
... | @@ -18,12 +18,14 @@ package org.onosproject.net.resource; | ... | @@ -18,12 +18,14 @@ package org.onosproject.net.resource; |
18 | import java.util.Collection; | 18 | import java.util.Collection; |
19 | import java.util.HashSet; | 19 | import java.util.HashSet; |
20 | import java.util.Set; | 20 | import java.util.Set; |
21 | +import java.util.Objects; | ||
21 | 22 | ||
22 | import org.onosproject.net.Link; | 23 | import org.onosproject.net.Link; |
23 | import org.onosproject.net.intent.Constraint; | 24 | import org.onosproject.net.intent.Constraint; |
24 | import org.onosproject.net.intent.IntentId; | 25 | import org.onosproject.net.intent.IntentId; |
25 | 26 | ||
26 | import com.google.common.collect.ImmutableSet; | 27 | import com.google.common.collect.ImmutableSet; |
28 | + | ||
27 | import org.onosproject.net.intent.constraint.BandwidthConstraint; | 29 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
28 | import org.onosproject.net.intent.constraint.LambdaConstraint; | 30 | import org.onosproject.net.intent.constraint.LambdaConstraint; |
29 | 31 | ||
... | @@ -59,7 +61,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -59,7 +61,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
59 | } | 61 | } |
60 | 62 | ||
61 | @Override | 63 | @Override |
62 | - public IntentId intendId() { | 64 | + public IntentId intentId() { |
63 | return intentId; | 65 | return intentId; |
64 | } | 66 | } |
65 | 67 | ||
... | @@ -150,7 +152,6 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -150,7 +152,6 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
150 | return this; | 152 | return this; |
151 | } | 153 | } |
152 | 154 | ||
153 | - | ||
154 | /** | 155 | /** |
155 | * Returns link resource request. | 156 | * Returns link resource request. |
156 | * | 157 | * |
... | @@ -162,4 +163,21 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -162,4 +163,21 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
162 | } | 163 | } |
163 | } | 164 | } |
164 | 165 | ||
166 | + @Override | ||
167 | + public int hashCode() { | ||
168 | + return Objects.hash(intentId, links); | ||
169 | + } | ||
170 | + | ||
171 | + @Override | ||
172 | + public boolean equals(Object obj) { | ||
173 | + if (this == obj) { | ||
174 | + return true; | ||
175 | + } | ||
176 | + if (obj == null || getClass() != obj.getClass()) { | ||
177 | + return false; | ||
178 | + } | ||
179 | + final DefaultLinkResourceRequest other = (DefaultLinkResourceRequest) obj; | ||
180 | + return Objects.equals(this.intentId, other.intentId) | ||
181 | + && Objects.equals(this.links, other.links); | ||
182 | + } | ||
165 | } | 183 | } | ... | ... |
... | @@ -32,7 +32,7 @@ public interface LinkResourceRequest extends ResourceRequest { | ... | @@ -32,7 +32,7 @@ public interface LinkResourceRequest extends ResourceRequest { |
32 | * | 32 | * |
33 | * @return the {@link IntentId} associated with the request | 33 | * @return the {@link IntentId} associated with the request |
34 | */ | 34 | */ |
35 | - IntentId intendId(); | 35 | + IntentId intentId(); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Returns the set of target links. | 38 | * Returns the set of target links. | ... | ... |
... | @@ -34,7 +34,6 @@ import com.google.common.collect.Maps; | ... | @@ -34,7 +34,6 @@ import com.google.common.collect.Maps; |
34 | * Default TransactionContext implementation. | 34 | * Default TransactionContext implementation. |
35 | */ | 35 | */ |
36 | public class DefaultTransactionContext implements TransactionContext { | 36 | public class DefaultTransactionContext implements TransactionContext { |
37 | - | ||
38 | private static final String TX_NOT_OPEN_ERROR = "Transaction Context is not open"; | 37 | private static final String TX_NOT_OPEN_ERROR = "Transaction Context is not open"; |
39 | 38 | ||
40 | @SuppressWarnings("rawtypes") | 39 | @SuppressWarnings("rawtypes") | ... | ... |
... | @@ -356,7 +356,6 @@ public class PartitionedDatabase implements Database { | ... | @@ -356,7 +356,6 @@ public class PartitionedDatabase implements Database { |
356 | } | 356 | } |
357 | Map<Database, Transaction> subTransactions = Maps.newHashMap(); | 357 | Map<Database, Transaction> subTransactions = Maps.newHashMap(); |
358 | perPartitionUpdates.forEach((k, v) -> subTransactions.put(k, new DefaultTransaction(transaction.id(), v))); | 358 | perPartitionUpdates.forEach((k, v) -> subTransactions.put(k, new DefaultTransaction(transaction.id(), v))); |
359 | - | ||
360 | return subTransactions; | 359 | return subTransactions; |
361 | } | 360 | } |
362 | } | 361 | } | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.store.consistent.impl; | 16 | package org.onosproject.store.consistent.impl; |
17 | 17 | ||
18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
19 | + | ||
19 | import java.util.Collection; | 20 | import java.util.Collection; |
20 | import java.util.concurrent.CompletableFuture; | 21 | import java.util.concurrent.CompletableFuture; |
21 | import java.util.stream.Collectors; | 22 | import java.util.stream.Collectors; | ... | ... |
core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java
0 → 100644
This diff is collapsed. Click to expand it.
... | @@ -339,7 +339,7 @@ public class HazelcastLinkResourceStore | ... | @@ -339,7 +339,7 @@ public class HazelcastLinkResourceStore |
339 | 339 | ||
340 | STxMap<IntentId, LinkResourceAllocations> intentAllocs = getIntentAllocs(tx); | 340 | STxMap<IntentId, LinkResourceAllocations> intentAllocs = getIntentAllocs(tx); |
341 | // should this be conditional write? | 341 | // should this be conditional write? |
342 | - intentAllocs.put(allocations.intendId(), allocations); | 342 | + intentAllocs.put(allocations.intentId(), allocations); |
343 | 343 | ||
344 | for (Link link : allocations.links()) { | 344 | for (Link link : allocations.links()) { |
345 | allocateLinkResource(tx, link, allocations); | 345 | allocateLinkResource(tx, link, allocations); |
... | @@ -349,7 +349,7 @@ public class HazelcastLinkResourceStore | ... | @@ -349,7 +349,7 @@ public class HazelcastLinkResourceStore |
349 | return; | 349 | return; |
350 | } catch (TransactionException e) { | 350 | } catch (TransactionException e) { |
351 | log.debug("Failed to commit allocations for {}. [retry={}]", | 351 | log.debug("Failed to commit allocations for {}. [retry={}]", |
352 | - allocations.intendId(), i); | 352 | + allocations.intentId(), i); |
353 | log.trace(" details {} ", allocations, e); | 353 | log.trace(" details {} ", allocations, e); |
354 | continue; | 354 | continue; |
355 | } catch (Exception e) { | 355 | } catch (Exception e) { |
... | @@ -438,7 +438,7 @@ public class HazelcastLinkResourceStore | ... | @@ -438,7 +438,7 @@ public class HazelcastLinkResourceStore |
438 | public LinkResourceEvent releaseResources(LinkResourceAllocations allocations) { | 438 | public LinkResourceEvent releaseResources(LinkResourceAllocations allocations) { |
439 | checkNotNull(allocations); | 439 | checkNotNull(allocations); |
440 | 440 | ||
441 | - final IntentId intendId = allocations.intendId(); | 441 | + final IntentId intendId = allocations.intentId(); |
442 | final Collection<Link> links = allocations.links(); | 442 | final Collection<Link> links = allocations.links(); |
443 | 443 | ||
444 | boolean success = false; | 444 | boolean success = false; | ... | ... |
... | @@ -224,7 +224,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -224,7 +224,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
224 | @Override | 224 | @Override |
225 | public synchronized void allocateResources(LinkResourceAllocations allocations) { | 225 | public synchronized void allocateResources(LinkResourceAllocations allocations) { |
226 | checkNotNull(allocations); | 226 | checkNotNull(allocations); |
227 | - linkResourceAllocationsMap.put(allocations.intendId(), allocations); | 227 | + linkResourceAllocationsMap.put(allocations.intentId(), allocations); |
228 | for (Link link : allocations.links()) { | 228 | for (Link link : allocations.links()) { |
229 | subtractFreeResources(link, allocations); | 229 | subtractFreeResources(link, allocations); |
230 | Set<LinkResourceAllocations> linkAllocs = allocatedResources.get(link); | 230 | Set<LinkResourceAllocations> linkAllocs = allocatedResources.get(link); |
... | @@ -239,7 +239,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -239,7 +239,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
239 | @Override | 239 | @Override |
240 | public synchronized LinkResourceEvent releaseResources(LinkResourceAllocations allocations) { | 240 | public synchronized LinkResourceEvent releaseResources(LinkResourceAllocations allocations) { |
241 | checkNotNull(allocations); | 241 | checkNotNull(allocations); |
242 | - linkResourceAllocationsMap.remove(allocations.intendId()); | 242 | + linkResourceAllocationsMap.remove(allocations.intentId()); |
243 | for (Link link : allocations.links()) { | 243 | for (Link link : allocations.links()) { |
244 | addFreeResources(link, allocations); | 244 | addFreeResources(link, allocations); |
245 | Set<LinkResourceAllocations> linkAllocs = allocatedResources.get(link); | 245 | Set<LinkResourceAllocations> linkAllocs = allocatedResources.get(link); | ... | ... |
core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
... | @@ -191,7 +191,7 @@ public class SimpleLinkResourceStoreTest { | ... | @@ -191,7 +191,7 @@ public class SimpleLinkResourceStoreTest { |
191 | } | 191 | } |
192 | 192 | ||
193 | @Override | 193 | @Override |
194 | - public IntentId intendId() { | 194 | + public IntentId intentId() { |
195 | return null; | 195 | return null; |
196 | } | 196 | } |
197 | 197 | ||
... | @@ -227,7 +227,7 @@ public class SimpleLinkResourceStoreTest { | ... | @@ -227,7 +227,7 @@ public class SimpleLinkResourceStoreTest { |
227 | } | 227 | } |
228 | 228 | ||
229 | @Override | 229 | @Override |
230 | - public IntentId intendId() { | 230 | + public IntentId intentId() { |
231 | return null; | 231 | return null; |
232 | } | 232 | } |
233 | 233 | ... | ... |
-
Please register or login to post a comment