ONOS-2297: Decouple ResourceRequest and ResourceAllocation
Note: This change may break backward compatibility for those defining a
sub-class of ResourceAllocation
Change-Id: I01807b4ebb0f9af8fa822828953965b5119975d7
diff --git a/core/api/src/main/java/org/onosproject/net/resource/ResourceAllocation.java b/core/api/src/main/java/org/onosproject/net/resource/ResourceAllocation.java
index 4dd7381..01b69b2 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/ResourceAllocation.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/ResourceAllocation.java
@@ -21,5 +21,11 @@
* Abstraction of allocated resource.
*/
@Beta
-public interface ResourceAllocation extends ResourceRequest {
+public interface ResourceAllocation {
+ /**
+ * Returns the resource type.
+ *
+ * @return the resource type
+ */
+ ResourceType type();
}
diff --git a/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java b/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java
index de2f52f..74f6e10 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java
@@ -19,31 +19,59 @@
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceType;
+import java.util.Objects;
+
/**
* Representation of allocated bandwidth resource.
*/
-public class BandwidthResourceAllocation extends BandwidthResourceRequest
- implements ResourceAllocation {
+public class BandwidthResourceAllocation implements ResourceAllocation {
+ private final BandwidthResource bandwidth;
+
+ /**
+ * Creates a new {@link BandwidthResourceRequest} with {@link BandwidthResource}
+ * object.
+ *
+ * @param bandwidth {@link BandwidthResource} object to be requested
+ */
+ public BandwidthResourceAllocation(BandwidthResource bandwidth) {
+ this.bandwidth = bandwidth;
+ }
+
+ /**
+ * Returns the bandwidth resource.
+ *
+ * @return the bandwidth resource
+ */
+ public BandwidthResource bandwidth() {
+ return bandwidth;
+ }
@Override
public ResourceType type() {
return ResourceType.BANDWIDTH;
}
- /**
- * Creates a new {@link BandwidthResourceAllocation} with {@link BandwidthResource}
- * object.
- *
- * @param bandwidth allocated bandwidth
- */
- public BandwidthResourceAllocation(BandwidthResource bandwidth) {
- super(bandwidth);
+ @Override
+ public int hashCode() {
+ return Objects.hash(bandwidth);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final BandwidthResourceAllocation other = (BandwidthResourceAllocation) obj;
+ return Objects.equals(this.bandwidth, other.bandwidth());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("bandwidth", bandwidth())
+ .add("bandwidth", bandwidth)
.toString();
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java b/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java
index 0227d3f..379bf71 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java
@@ -59,17 +59,14 @@
this.allocations = builder.build();
}
- @Override
public IntentId intentId() {
return request.intentId();
}
- @Override
public Collection<Link> links() {
return request.links();
}
- @Override
public Set<ResourceRequest> resources() {
return request.resources();
}
diff --git a/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java b/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java
index 210bba6..545f025 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java
@@ -24,8 +24,7 @@
/**
* Representation of allocated lambda resource.
*/
-public class LambdaResourceAllocation extends LambdaResourceRequest
- implements ResourceAllocation {
+public class LambdaResourceAllocation implements ResourceAllocation {
private final LambdaResource lambda;
@Override
diff --git a/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java b/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java
index 172e902..7828867 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java
@@ -15,15 +15,40 @@
*/
package org.onosproject.net.resource.link;
+import java.util.Collection;
import java.util.Set;
import org.onosproject.net.Link;
+import org.onosproject.net.intent.IntentId;
import org.onosproject.net.resource.ResourceAllocation;
+import org.onosproject.net.resource.ResourceRequest;
/**
* Representation of allocated link resources.
*/
-public interface LinkResourceAllocations extends LinkResourceRequest {
+public interface LinkResourceAllocations extends ResourceAllocation {
+
+ /**
+ * Returns the {@link IntentId} associated with the request.
+ *
+ * @return the {@link IntentId} associated with the request
+ */
+ IntentId intentId();
+
+ /**
+ * Returns the set of target links.
+ *
+ * @return the set of target links
+ */
+ Collection<Link> links();
+
+ /**
+ * Returns the set of resource requests.
+ *
+ * @return the set of resource requests
+ */
+ Set<ResourceRequest> resources();
+
/**
* Returns allocated resource for the given link.
*
diff --git a/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java b/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java
index 1b3b8fc..1091153 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java
@@ -25,8 +25,7 @@
/**
* Representation of allocated MPLS label resource.
*/
-public class MplsLabelResourceAllocation extends MplsLabelResourceRequest
- implements ResourceAllocation {
+public class MplsLabelResourceAllocation implements ResourceAllocation {
private final MplsLabel mplsLabel;
@Override
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
index e47d1aa..6aeeb56 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
@@ -190,17 +190,14 @@
new MplsLabelResourceAllocation(MplsLabel.valueOf(10)));
}
- @Override
public IntentId intentId() {
return null;
}
- @Override
public Collection<Link> links() {
return null;
}
- @Override
public Set<ResourceRequest> resources() {
return null;
}