Sho SHIMIZU

ONOS-2297: Decouple ResourceRequest and ResourceAllocation

Note: This change may break backward compatibility for those defining a
sub-class of ResourceAllocation

Change-Id: I01807b4ebb0f9af8fa822828953965b5119975d7
......@@ -21,5 +21,11 @@ import com.google.common.annotations.Beta;
* Abstraction of allocated resource.
*/
@Beta
public interface ResourceAllocation extends ResourceRequest {
public interface ResourceAllocation {
/**
* Returns the resource type.
*
* @return the resource type
*/
ResourceType type();
}
......
......@@ -19,31 +19,59 @@ import com.google.common.base.MoreObjects;
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 {
@Override
public ResourceType type() {
return ResourceType.BANDWIDTH;
}
public class BandwidthResourceAllocation implements ResourceAllocation {
private final BandwidthResource bandwidth;
/**
* Creates a new {@link BandwidthResourceAllocation} with {@link BandwidthResource}
* Creates a new {@link BandwidthResourceRequest} with {@link BandwidthResource}
* object.
*
* @param bandwidth allocated bandwidth
* @param bandwidth {@link BandwidthResource} object to be requested
*/
public BandwidthResourceAllocation(BandwidthResource bandwidth) {
super(bandwidth);
this.bandwidth = bandwidth;
}
/**
* Returns the bandwidth resource.
*
* @return the bandwidth resource
*/
public BandwidthResource bandwidth() {
return bandwidth;
}
@Override
public ResourceType type() {
return ResourceType.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();
}
}
......
......@@ -59,17 +59,14 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations {
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();
}
......
......@@ -24,8 +24,7 @@ import java.util.Objects;
/**
* Representation of allocated lambda resource.
*/
public class LambdaResourceAllocation extends LambdaResourceRequest
implements ResourceAllocation {
public class LambdaResourceAllocation implements ResourceAllocation {
private final LambdaResource lambda;
@Override
......
......@@ -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.
*
......
......@@ -25,8 +25,7 @@ import java.util.Objects;
/**
* Representation of allocated MPLS label resource.
*/
public class MplsLabelResourceAllocation extends MplsLabelResourceRequest
implements ResourceAllocation {
public class MplsLabelResourceAllocation implements ResourceAllocation {
private final MplsLabel mplsLabel;
@Override
......
......@@ -190,17 +190,14 @@ public class IntentTestsMocks {
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;
}
......