Sho SHIMIZU
Committed by Gerrit Code Review

Simplify method names by removing redundancy

Change-Id: I36df7e23792f7004dfae823a8700f6c887ea1efd
......@@ -32,8 +32,8 @@ public interface ResourceAdminService {
* @return true if registration is successfully done, false otherwise. Registration
* succeeds when each resource is not registered or unallocated.
*/
default boolean registerResources(Resource... resources) {
return registerResources(ImmutableList.copyOf(resources));
default boolean register(Resource... resources) {
return register(ImmutableList.copyOf(resources));
}
/**
......@@ -43,7 +43,7 @@ public interface ResourceAdminService {
* @return true if registration is successfully done, false otherwise. Registration
* succeeds when each resource is not registered or unallocated.
*/
boolean registerResources(List<Resource> resources);
boolean register(List<Resource> resources);
/**
* Unregisters the specified resources.
......@@ -52,8 +52,8 @@ public interface ResourceAdminService {
* @return true if unregistration is successfully done, false otherwise. Unregistration
* succeeds when each resource is not registered or unallocated.
*/
default boolean unregisterResources(ResourceId... ids) {
return unregisterResources(ImmutableList.copyOf(ids));
default boolean unregister(ResourceId... ids) {
return unregister(ImmutableList.copyOf(ids));
}
/**
......@@ -64,5 +64,5 @@ public interface ResourceAdminService {
* succeeds when each resource is not registered or unallocated.
*/
// TODO: might need to change the first argument type to ResourceId
boolean unregisterResources(List<ResourceId> ids);
boolean unregister(List<ResourceId> ids);
}
......
......@@ -127,25 +127,25 @@ final class ResourceDeviceListener implements DeviceListener {
}
private void registerDeviceResource(Device device) {
executor.submit(() -> adminService.registerResources(Resources.discrete(device.id()).resource()));
executor.submit(() -> adminService.register(Resources.discrete(device.id()).resource()));
}
private void unregisterDeviceResource(Device device) {
executor.submit(() -> {
DiscreteResource devResource = Resources.discrete(device.id()).resource();
List<Resource> allResources = getDescendantResources(devResource);
adminService.unregisterResources(Lists.transform(allResources, Resource::id));
adminService.unregister(Lists.transform(allResources, Resource::id));
});
}
private void registerPortResource(Device device, Port port) {
Resource portPath = Resources.discrete(device.id(), port.number()).resource();
executor.submit(() -> {
adminService.registerResources(portPath);
adminService.register(portPath);
queryBandwidth(device.id(), port.number())
.map(bw -> portPath.child(Bandwidth.class, bw.bps()))
.map(adminService::registerResources)
.map(adminService::register)
.ifPresent(success -> {
if (!success) {
log.error("Failed to register Bandwidth for {}", portPath.id());
......@@ -155,7 +155,7 @@ final class ResourceDeviceListener implements DeviceListener {
// for VLAN IDs
Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
if (!vlans.isEmpty()) {
adminService.registerResources(vlans.stream()
adminService.register(vlans.stream()
.map(portPath::child)
.collect(Collectors.toList()));
}
......@@ -163,7 +163,7 @@ final class ResourceDeviceListener implements DeviceListener {
// for MPLS labels
Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number());
if (!mplsLabels.isEmpty()) {
adminService.registerResources(mplsLabels.stream()
adminService.register(mplsLabels.stream()
.map(portPath::child)
.collect(Collectors.toList()));
}
......@@ -171,7 +171,7 @@ final class ResourceDeviceListener implements DeviceListener {
// for Lambdas
Set<OchSignal> lambdas = queryLambdas(device.id(), port.number());
if (!lambdas.isEmpty()) {
adminService.registerResources(lambdas.stream()
adminService.register(lambdas.stream()
.map(portPath::child)
.collect(Collectors.toList()));
}
......@@ -179,7 +179,7 @@ final class ResourceDeviceListener implements DeviceListener {
// for Tributary slots
Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number());
if (!tSlots.isEmpty()) {
adminService.registerResources(tSlots.stream()
adminService.register(tSlots.stream()
.map(portPath::child)
.collect(Collectors.toList()));
}
......@@ -190,7 +190,7 @@ final class ResourceDeviceListener implements DeviceListener {
executor.submit(() -> {
DiscreteResource portResource = Resources.discrete(device.id(), port.number()).resource();
List<Resource> allResources = getDescendantResources(portResource);
adminService.unregisterResources(Lists.transform(allResources, Resource::id));
adminService.unregister(Lists.transform(allResources, Resource::id));
});
}
......
......@@ -171,14 +171,14 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
}
@Override
public boolean registerResources(List<Resource> resources) {
public boolean register(List<Resource> resources) {
checkNotNull(resources);
return store.register(resources);
}
@Override
public boolean unregisterResources(List<ResourceId> ids) {
public boolean unregister(List<ResourceId> ids) {
checkNotNull(ids);
return store.unregister(ids);
......
......@@ -93,7 +93,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
switch (event.type()) {
case CONFIG_ADDED:
if (!adminService.registerResources(Resources.continuous(cp.deviceId(),
if (!adminService.register(Resources.continuous(cp.deviceId(),
cp.port(), Bandwidth.class)
.resource(bwCapacity.capacity().bps()))) {
log.info("Failed to register Bandwidth for {}, attempting update", cp);
......@@ -115,7 +115,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
case CONFIG_REMOVED:
// FIXME Following should be an update to the value based on port speed
if (!adminService.unregisterResources(Resources.continuous(cp.deviceId(),
if (!adminService.unregister(Resources.continuous(cp.deviceId(),
cp.port(),
Bandwidth.class).id())) {
log.warn("Failed to unregister Bandwidth for {}", cp);
......@@ -147,11 +147,11 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
// but both unregisterResources(..) and registerResources(..)
// returns true (success)
if (!adminService.unregisterResources(
if (!adminService.unregister(
Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).id())) {
log.warn("unregisterResources for {} failed", cp);
}
return adminService.registerResources(Resources.continuous(cp.deviceId(),
return adminService.register(Resources.continuous(cp.deviceId(),
cp.port(),
Bandwidth.class).resource(bwCapacity.capacity().bps()));
}
......