ONOS-2297: Decouple ResourceRequest and ResourceAllocation
Note: This change may break backward compatibility for those defining a sub-class of ResourceAllocation Change-Id: I01807b4ebb0f9af8fa822828953965b5119975d7
Showing
7 changed files
with
74 additions
and
23 deletions
... | @@ -21,5 +21,11 @@ import com.google.common.annotations.Beta; | ... | @@ -21,5 +21,11 @@ import com.google.common.annotations.Beta; |
21 | * Abstraction of allocated resource. | 21 | * Abstraction of allocated resource. |
22 | */ | 22 | */ |
23 | @Beta | 23 | @Beta |
24 | -public interface ResourceAllocation extends ResourceRequest { | 24 | +public interface ResourceAllocation { |
25 | + /** | ||
26 | + * Returns the resource type. | ||
27 | + * | ||
28 | + * @return the resource type | ||
29 | + */ | ||
30 | + ResourceType type(); | ||
25 | } | 31 | } | ... | ... |
... | @@ -19,31 +19,59 @@ import com.google.common.base.MoreObjects; | ... | @@ -19,31 +19,59 @@ import com.google.common.base.MoreObjects; |
19 | import org.onosproject.net.resource.ResourceAllocation; | 19 | import org.onosproject.net.resource.ResourceAllocation; |
20 | import org.onosproject.net.resource.ResourceType; | 20 | import org.onosproject.net.resource.ResourceType; |
21 | 21 | ||
22 | +import java.util.Objects; | ||
23 | + | ||
22 | /** | 24 | /** |
23 | * Representation of allocated bandwidth resource. | 25 | * Representation of allocated bandwidth resource. |
24 | */ | 26 | */ |
25 | -public class BandwidthResourceAllocation extends BandwidthResourceRequest | 27 | +public class BandwidthResourceAllocation implements ResourceAllocation { |
26 | - implements ResourceAllocation { | 28 | + private final BandwidthResource bandwidth; |
27 | - | ||
28 | - @Override | ||
29 | - public ResourceType type() { | ||
30 | - return ResourceType.BANDWIDTH; | ||
31 | - } | ||
32 | 29 | ||
33 | /** | 30 | /** |
34 | - * Creates a new {@link BandwidthResourceAllocation} with {@link BandwidthResource} | 31 | + * Creates a new {@link BandwidthResourceRequest} with {@link BandwidthResource} |
35 | * object. | 32 | * object. |
36 | * | 33 | * |
37 | - * @param bandwidth allocated bandwidth | 34 | + * @param bandwidth {@link BandwidthResource} object to be requested |
38 | */ | 35 | */ |
39 | public BandwidthResourceAllocation(BandwidthResource bandwidth) { | 36 | public BandwidthResourceAllocation(BandwidthResource bandwidth) { |
40 | - super(bandwidth); | 37 | + this.bandwidth = bandwidth; |
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * Returns the bandwidth resource. | ||
42 | + * | ||
43 | + * @return the bandwidth resource | ||
44 | + */ | ||
45 | + public BandwidthResource bandwidth() { | ||
46 | + return bandwidth; | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public ResourceType type() { | ||
51 | + return ResourceType.BANDWIDTH; | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public int hashCode() { | ||
56 | + return Objects.hash(bandwidth); | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public boolean equals(Object obj) { | ||
61 | + if (this == obj) { | ||
62 | + return true; | ||
63 | + } | ||
64 | + if (obj == null || getClass() != obj.getClass()) { | ||
65 | + return false; | ||
66 | + } | ||
67 | + final BandwidthResourceAllocation other = (BandwidthResourceAllocation) obj; | ||
68 | + return Objects.equals(this.bandwidth, other.bandwidth()); | ||
41 | } | 69 | } |
42 | 70 | ||
43 | @Override | 71 | @Override |
44 | public String toString() { | 72 | public String toString() { |
45 | return MoreObjects.toStringHelper(this) | 73 | return MoreObjects.toStringHelper(this) |
46 | - .add("bandwidth", bandwidth()) | 74 | + .add("bandwidth", bandwidth) |
47 | .toString(); | 75 | .toString(); |
48 | } | 76 | } |
49 | } | 77 | } | ... | ... |
... | @@ -59,17 +59,14 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations { | ... | @@ -59,17 +59,14 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations { |
59 | this.allocations = builder.build(); | 59 | this.allocations = builder.build(); |
60 | } | 60 | } |
61 | 61 | ||
62 | - @Override | ||
63 | public IntentId intentId() { | 62 | public IntentId intentId() { |
64 | return request.intentId(); | 63 | return request.intentId(); |
65 | } | 64 | } |
66 | 65 | ||
67 | - @Override | ||
68 | public Collection<Link> links() { | 66 | public Collection<Link> links() { |
69 | return request.links(); | 67 | return request.links(); |
70 | } | 68 | } |
71 | 69 | ||
72 | - @Override | ||
73 | public Set<ResourceRequest> resources() { | 70 | public Set<ResourceRequest> resources() { |
74 | return request.resources(); | 71 | return request.resources(); |
75 | } | 72 | } | ... | ... |
... | @@ -24,8 +24,7 @@ import java.util.Objects; | ... | @@ -24,8 +24,7 @@ import java.util.Objects; |
24 | /** | 24 | /** |
25 | * Representation of allocated lambda resource. | 25 | * Representation of allocated lambda resource. |
26 | */ | 26 | */ |
27 | -public class LambdaResourceAllocation extends LambdaResourceRequest | 27 | +public class LambdaResourceAllocation implements ResourceAllocation { |
28 | - implements ResourceAllocation { | ||
29 | private final LambdaResource lambda; | 28 | private final LambdaResource lambda; |
30 | 29 | ||
31 | @Override | 30 | @Override | ... | ... |
... | @@ -15,15 +15,40 @@ | ... | @@ -15,15 +15,40 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.resource.link; | 16 | package org.onosproject.net.resource.link; |
17 | 17 | ||
18 | +import java.util.Collection; | ||
18 | import java.util.Set; | 19 | import java.util.Set; |
19 | 20 | ||
20 | import org.onosproject.net.Link; | 21 | import org.onosproject.net.Link; |
22 | +import org.onosproject.net.intent.IntentId; | ||
21 | import org.onosproject.net.resource.ResourceAllocation; | 23 | import org.onosproject.net.resource.ResourceAllocation; |
24 | +import org.onosproject.net.resource.ResourceRequest; | ||
22 | 25 | ||
23 | /** | 26 | /** |
24 | * Representation of allocated link resources. | 27 | * Representation of allocated link resources. |
25 | */ | 28 | */ |
26 | -public interface LinkResourceAllocations extends LinkResourceRequest { | 29 | +public interface LinkResourceAllocations extends ResourceAllocation { |
30 | + | ||
31 | + /** | ||
32 | + * Returns the {@link IntentId} associated with the request. | ||
33 | + * | ||
34 | + * @return the {@link IntentId} associated with the request | ||
35 | + */ | ||
36 | + IntentId intentId(); | ||
37 | + | ||
38 | + /** | ||
39 | + * Returns the set of target links. | ||
40 | + * | ||
41 | + * @return the set of target links | ||
42 | + */ | ||
43 | + Collection<Link> links(); | ||
44 | + | ||
45 | + /** | ||
46 | + * Returns the set of resource requests. | ||
47 | + * | ||
48 | + * @return the set of resource requests | ||
49 | + */ | ||
50 | + Set<ResourceRequest> resources(); | ||
51 | + | ||
27 | /** | 52 | /** |
28 | * Returns allocated resource for the given link. | 53 | * Returns allocated resource for the given link. |
29 | * | 54 | * | ... | ... |
... | @@ -25,8 +25,7 @@ import java.util.Objects; | ... | @@ -25,8 +25,7 @@ import java.util.Objects; |
25 | /** | 25 | /** |
26 | * Representation of allocated MPLS label resource. | 26 | * Representation of allocated MPLS label resource. |
27 | */ | 27 | */ |
28 | -public class MplsLabelResourceAllocation extends MplsLabelResourceRequest | 28 | +public class MplsLabelResourceAllocation implements ResourceAllocation { |
29 | - implements ResourceAllocation { | ||
30 | private final MplsLabel mplsLabel; | 29 | private final MplsLabel mplsLabel; |
31 | 30 | ||
32 | @Override | 31 | @Override | ... | ... |
... | @@ -190,17 +190,14 @@ public class IntentTestsMocks { | ... | @@ -190,17 +190,14 @@ public class IntentTestsMocks { |
190 | new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); | 190 | new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); |
191 | } | 191 | } |
192 | 192 | ||
193 | - @Override | ||
194 | public IntentId intentId() { | 193 | public IntentId intentId() { |
195 | return null; | 194 | return null; |
196 | } | 195 | } |
197 | 196 | ||
198 | - @Override | ||
199 | public Collection<Link> links() { | 197 | public Collection<Link> links() { |
200 | return null; | 198 | return null; |
201 | } | 199 | } |
202 | 200 | ||
203 | - @Override | ||
204 | public Set<ResourceRequest> resources() { | 201 | public Set<ResourceRequest> resources() { |
205 | return null; | 202 | return null; |
206 | } | 203 | } | ... | ... |
-
Please register or login to post a comment