Committed by
Brian O'Connor
Extract a method to create a list of FlowRuleBatchOperation
- Define FlowRuleBatchOperationConvertionException, which is a new IntentException sub-class Change-Id: I798303fa986f573c885b8712ac1dfee1bcaadf95
Showing
2 changed files
with
55 additions
and
15 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.net.intent.impl; | ||
| 17 | + | ||
| 18 | +import com.google.common.collect.ImmutableList; | ||
| 19 | +import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
| 20 | +import org.onosproject.net.intent.IntentException; | ||
| 21 | + | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 25 | + | ||
| 26 | +// TODO: Reconsider error handling and intent exception design. Otherwise, write Javadoc. | ||
| 27 | +public class FlowRuleBatchOperationConvertionException extends IntentException { | ||
| 28 | + | ||
| 29 | + private final List<FlowRuleBatchOperation> converted; | ||
| 30 | + | ||
| 31 | + public FlowRuleBatchOperationConvertionException(List<FlowRuleBatchOperation> converted, Throwable cause) { | ||
| 32 | + super("exception occurred during IntentInstaller.install()", cause); | ||
| 33 | + this.converted = ImmutableList.copyOf((checkNotNull(converted))); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public List<FlowRuleBatchOperation> converted() { | ||
| 37 | + return converted; | ||
| 38 | + } | ||
| 39 | +} |
| ... | @@ -502,28 +502,29 @@ public class IntentManager | ... | @@ -502,28 +502,29 @@ public class IntentManager |
| 502 | 502 | ||
| 503 | @Override | 503 | @Override |
| 504 | public Optional<IntentUpdate> execute() { | 504 | public Optional<IntentUpdate> execute() { |
| 505 | - Exception exception = null; | 505 | + try { |
| 506 | + List<FlowRuleBatchOperation> converted = convert(installables); | ||
| 507 | + // TODO: call FlowRuleService API to push FlowRules and track resources, | ||
| 508 | + // which the submitted intent will use. | ||
| 509 | + return Optional.of(new Installed(intent, installables, converted)); | ||
| 510 | + } catch (FlowRuleBatchOperationConvertionException e) { | ||
| 511 | + log.warn("Unable to install intent {} due to:", intent.id(), e.getCause()); | ||
| 512 | + return Optional.of(new InstallingFailed(intent, installables, e.converted())); | ||
| 513 | + } | ||
| 514 | + } | ||
| 515 | + } | ||
| 506 | 516 | ||
| 507 | - List<FlowRuleBatchOperation> batches = Lists.newArrayList(); | 517 | + private List<FlowRuleBatchOperation> convert(List<Intent> installables) { |
| 518 | + List<FlowRuleBatchOperation> batches = new ArrayList<>(installables.size()); | ||
| 508 | for (Intent installable : installables) { | 519 | for (Intent installable : installables) { |
| 509 | - registerSubclassInstallerIfNeeded(installable); | ||
| 510 | - trackerService.addTrackedResources(intent.id(), installable.resources()); | ||
| 511 | try { | 520 | try { |
| 521 | + registerSubclassInstallerIfNeeded(installable); | ||
| 512 | batches.addAll(getInstaller(installable).install(installable)); | 522 | batches.addAll(getInstaller(installable).install(installable)); |
| 513 | } catch (Exception e) { // TODO this should be IntentException | 523 | } catch (Exception e) { // TODO this should be IntentException |
| 514 | - log.warn("Unable to install intent {} due to:", intent.id(), e); | 524 | + throw new FlowRuleBatchOperationConvertionException(batches, e); |
| 515 | - trackerService.removeTrackedResources(intent.id(), installable.resources()); | ||
| 516 | - //TODO we failed; intent should be recompiled | ||
| 517 | - exception = e; | ||
| 518 | - } | ||
| 519 | - } | ||
| 520 | - | ||
| 521 | - if (exception != null) { | ||
| 522 | - return Optional.of(new InstallingFailed(intent, installables, batches)); | ||
| 523 | } | 525 | } |
| 524 | - | ||
| 525 | - return Optional.of(new Installed(intent, installables, batches)); | ||
| 526 | } | 526 | } |
| 527 | + return batches; | ||
| 527 | } | 528 | } |
| 528 | 529 | ||
| 529 | private class Withdrawing implements IntentUpdate { | 530 | private class Withdrawing implements IntentUpdate { | ... | ... |
-
Please register or login to post a comment