Sho SHIMIZU

Narrow exceptions to be caught

Change-Id: I72d3153d8451e82bf2889d3fb983fdc9b5a37e6c
...@@ -68,7 +68,6 @@ import com.google.common.collect.ImmutableSet; ...@@ -68,7 +68,6 @@ import com.google.common.collect.ImmutableSet;
68 import com.google.common.collect.Sets; 68 import com.google.common.collect.Sets;
69 69
70 import static com.google.common.base.Preconditions.checkNotNull; 70 import static com.google.common.base.Preconditions.checkNotNull;
71 -import static com.google.common.base.Preconditions.checkState;
72 import static org.slf4j.LoggerFactory.getLogger; 71 import static org.slf4j.LoggerFactory.getLogger;
73 import static org.onosproject.net.AnnotationKeys.BANDWIDTH; 72 import static org.onosproject.net.AnnotationKeys.BANDWIDTH;
74 73
...@@ -295,6 +294,9 @@ public class ConsistentLinkResourceStore extends ...@@ -295,6 +294,9 @@ public class ConsistentLinkResourceStore extends
295 intentAllocs.put(allocations.intentId(), allocations); 294 intentAllocs.put(allocations.intentId(), allocations);
296 allocations.links().forEach(link -> allocateLinkResource(tx, link, allocations)); 295 allocations.links().forEach(link -> allocateLinkResource(tx, link, allocations));
297 tx.commit(); 296 tx.commit();
297 + } catch (TransactionException | ResourceAllocationException e) {
298 + log.error("Exception thrown, rolling back", e);
299 + tx.abort();
298 } catch (Exception e) { 300 } catch (Exception e) {
299 log.error("Exception thrown, rolling back", e); 301 log.error("Exception thrown, rolling back", e);
300 tx.abort(); 302 tx.abort();
...@@ -312,9 +314,7 @@ public class ConsistentLinkResourceStore extends ...@@ -312,9 +314,7 @@ public class ConsistentLinkResourceStore extends
312 if (req instanceof BandwidthResourceAllocation) { 314 if (req instanceof BandwidthResourceAllocation) {
313 // check if allocation should be accepted 315 // check if allocation should be accepted
314 if (avail.isEmpty()) { 316 if (avail.isEmpty()) {
315 - checkState(!avail.isEmpty(), 317 + throw new ResourceAllocationException(String.format("There's no Bandwidth resource on %s?", link));
316 - "There's no Bandwidth resource on %s?",
317 - link);
318 } 318 }
319 BandwidthResourceAllocation bw = (BandwidthResourceAllocation) avail.iterator().next(); 319 BandwidthResourceAllocation bw = (BandwidthResourceAllocation) avail.iterator().next();
320 double bwLeft = bw.bandwidth().toDouble(); 320 double bwLeft = bw.bandwidth().toDouble();
......