Sho SHIMIZU
Committed by Gerrit Code Review

Move IntentUpdate subclasses to the dedicated package

Resolve ONOS-1051
- Create package "phase" under intent.impl
- Rename IntentUpdate and CompletedIntentUpdate
  - IntentUpdate -> IntentProcessPhase
  - CompletedIntentUpdate -> FinalIntentProcessPhase
- Loosen method/field visibility as short term hack

Change-Id: Idc0fd9a74aadd227d62006d00fee473c63b1fc05
Showing 16 changed files with 79 additions and 62 deletions
......@@ -47,6 +47,12 @@ import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.IntentStore;
import org.onosproject.net.intent.IntentStoreDelegate;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.impl.phase.CompilingFailed;
import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase;
import org.onosproject.net.intent.impl.phase.InstallRequest;
import org.onosproject.net.intent.impl.phase.IntentProcessPhase;
import org.onosproject.net.intent.impl.phase.WithdrawRequest;
import org.onosproject.net.intent.impl.phase.Withdrawn;
import org.slf4j.Logger;
import java.util.ArrayList;
......@@ -112,8 +118,9 @@ public class IntentManager
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
// TODO: make this protected due to short term hack for ONOS-1051
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowRuleService flowRuleService;
public FlowRuleService flowRuleService;
private ExecutorService batchExecutor;
......@@ -268,7 +275,8 @@ public class IntentManager
* @param previousInstallables previous intent installables
* @return result of compilation
*/
List<Intent> compileIntent(Intent intent, List<Intent> previousInstallables) {
// TODO: make this non-public due to short term hack for ONOS-1051
public List<Intent> compileIntent(Intent intent, List<Intent> previousInstallables) {
if (intent.isInstallable()) {
return ImmutableList.of(intent);
}
......@@ -284,7 +292,8 @@ public class IntentManager
//TODO javadoc
//FIXME
FlowRuleOperations coordinate(IntentData current, IntentData pending) {
// TODO: make this non-public due to short term hack for ONOS-1051
public FlowRuleOperations coordinate(IntentData current, IntentData pending) {
List<Intent> oldInstallables = (current != null) ? current.installables() : null;
List<Intent> newInstallables = pending.installables();
......@@ -347,7 +356,8 @@ public class IntentManager
* @param current intent data stored in the store
* @return flow rule operations
*/
FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) {
// TODO: make this non-public due to short term hack for ONOS-1051
public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) {
List<Intent> installables = current.installables();
List<List<FlowRuleBatchOperation>> plans = new ArrayList<>();
for (Intent installable : installables) {
......@@ -520,7 +530,7 @@ public class IntentManager
}
}
private IntentUpdate createIntentUpdate(IntentData intentData) {
private IntentProcessPhase createIntentUpdate(IntentData intentData) {
IntentData current = store.getIntentData(intentData.key());
switch (intentData.state()) {
case INSTALL_REQ:
......@@ -537,7 +547,7 @@ public class IntentManager
}
}
private Future<CompletedIntentUpdate> submitIntentData(IntentData data) {
private Future<FinalIntentProcessPhase> submitIntentData(IntentData data) {
return workerExecutor.submit(new IntentWorker(data));
}
......@@ -590,15 +600,15 @@ public class IntentManager
}
}
private List<Future<CompletedIntentUpdate>> createIntentUpdates() {
private List<Future<FinalIntentProcessPhase>> createIntentUpdates() {
return data.stream()
.map(IntentManager.this::submitIntentData)
.collect(Collectors.toList());
}
private List<CompletedIntentUpdate> waitForFutures(List<Future<CompletedIntentUpdate>> futures) {
ImmutableList.Builder<CompletedIntentUpdate> updateBuilder = ImmutableList.builder();
for (Future<CompletedIntentUpdate> future : futures) {
private List<FinalIntentProcessPhase> waitForFutures(List<Future<FinalIntentProcessPhase>> futures) {
ImmutableList.Builder<FinalIntentProcessPhase> updateBuilder = ImmutableList.builder();
for (Future<FinalIntentProcessPhase> future : futures) {
try {
updateBuilder.add(future.get());
} catch (InterruptedException | ExecutionException e) {
......@@ -609,14 +619,14 @@ public class IntentManager
return updateBuilder.build();
}
private void submitUpdates(List<CompletedIntentUpdate> updates) {
private void submitUpdates(List<FinalIntentProcessPhase> updates) {
store.batchWrite(updates.stream()
.map(CompletedIntentUpdate::data)
.map(FinalIntentProcessPhase::data)
.collect(Collectors.toList()));
}
}
private final class IntentWorker implements Callable<CompletedIntentUpdate> {
private final class IntentWorker implements Callable<FinalIntentProcessPhase> {
private final IntentData data;
......@@ -625,16 +635,16 @@ public class IntentManager
}
@Override
public CompletedIntentUpdate call() throws Exception {
IntentUpdate update = createIntentUpdate(data);
Optional<IntentUpdate> currentPhase = Optional.of(update);
IntentUpdate previousPhase = update;
public FinalIntentProcessPhase call() throws Exception {
IntentProcessPhase update = createIntentUpdate(data);
Optional<IntentProcessPhase> currentPhase = Optional.of(update);
IntentProcessPhase previousPhase = update;
while (currentPhase.isPresent()) {
previousPhase = currentPhase.get();
currentPhase = previousPhase.execute();
}
return (CompletedIntentUpdate) previousPhase;
return (FinalIntentProcessPhase) previousPhase;
}
}
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
......@@ -24,7 +24,7 @@ import static org.onosproject.net.intent.IntentState.FAILED;
* A common parent class of a class representing failure
* as IntentUpdate subclass.
*/
abstract class AbstractFailed extends CompletedIntentUpdate {
abstract class AbstractFailed extends FinalIntentProcessPhase {
private final IntentData intentData;
......
......@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentException;
import org.onosproject.net.intent.impl.IntentManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -29,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Represents a phase where an intent is being compiled.
*/
class Compiling implements IntentUpdate {
final class Compiling implements IntentProcessPhase {
private static final Logger log = LoggerFactory.getLogger(Compiling.class);
......@@ -45,7 +46,7 @@ class Compiling implements IntentUpdate {
}
@Override
public Optional<IntentUpdate> execute() {
public Optional<IntentProcessPhase> execute() {
try {
List<Intent> installables = (current != null) ? current.installables() : null;
pending.setInstallables(intentManager.compileIntent(pending.intent(), installables));
......
......@@ -13,21 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
/**
* Represents a phase where the compile has failed.
*/
class CompilingFailed extends AbstractFailed {
public class CompilingFailed extends AbstractFailed {
/**
* Create an instance with the specified data.
*
* @param intentData intentData
*/
CompilingFailed(IntentData intentData) {
public CompilingFailed(IntentData intentData) {
super(intentData);
}
}
......
......@@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
import java.util.Optional;
/**
* Represents a completed phase of processing an intent.
* Represents a final phase of processing an intent.
*/
abstract class CompletedIntentUpdate implements IntentUpdate {
public abstract class FinalIntentProcessPhase implements IntentProcessPhase {
@Override
public final Optional<IntentUpdate> execute() {
public final Optional<IntentProcessPhase> execute() {
return Optional.empty();
}
......
......@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentException;
import org.onosproject.net.intent.impl.IntentManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -29,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Represents a phase to create a {@link FlowRuleOperations} instance
* with using registered intent installers.
*/
class InstallCoordinating implements IntentUpdate {
final class InstallCoordinating implements IntentProcessPhase {
private static final Logger log = LoggerFactory.getLogger(InstallCoordinating.class);
......@@ -45,7 +46,7 @@ class InstallCoordinating implements IntentUpdate {
}
@Override
public Optional<IntentUpdate> execute() {
public Optional<IntentProcessPhase> execute() {
try {
//FIXME we orphan flow rules that are currently on the data plane
// ... should either reuse them or remove them
......
......@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.impl.IntentManager;
import java.util.Optional;
......@@ -24,21 +25,21 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Represents a phase where intent installation has been requested.
*/
class InstallRequest implements IntentUpdate {
public final class InstallRequest implements IntentProcessPhase {
// TODO: define an interface and use it, instead of IntentManager
private final IntentManager intentManager;
private final IntentData pending;
private final Optional<IntentData> current;
InstallRequest(IntentManager intentManager, IntentData intentData, Optional<IntentData> current) {
public InstallRequest(IntentManager intentManager, IntentData intentData, Optional<IntentData> current) {
this.intentManager = checkNotNull(intentManager);
this.pending = checkNotNull(intentData);
this.current = checkNotNull(current);
}
@Override
public Optional<IntentUpdate> execute() {
public Optional<IntentProcessPhase> execute() {
return Optional.of(new Compiling(intentManager, pending, current.orElse(null)));
}
}
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
......@@ -23,7 +23,7 @@ import static org.onosproject.net.intent.IntentState.INSTALLING;
/**
* Represent a phase where an intent has been installed.
*/
class Installed extends CompletedIntentUpdate {
class Installed extends FinalIntentProcessPhase {
private final IntentData intentData;
......
......@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentException;
import org.onosproject.net.intent.impl.IntentManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -29,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Represents a phase of installing an intent with calling
* {@link org.onosproject.net.flow.FlowRuleService}.
*/
class Installing implements IntentUpdate {
final class Installing implements IntentProcessPhase {
private static final Logger log = LoggerFactory.getLogger(Installing.class);
......@@ -45,7 +46,7 @@ class Installing implements IntentUpdate {
}
@Override
public Optional<IntentUpdate> execute() {
public Optional<IntentProcessPhase> execute() {
try {
intentManager.flowRuleService.apply(flowRules); // FIXME we need to provide a context
return Optional.of(new Installed(pending));
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
......
......@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import java.util.Optional;
/**
* Represents a phase of processing an intent.
*/
interface IntentUpdate {
public interface IntentProcessPhase {
/**
* Execute the procedure represented by the instance
......@@ -28,5 +28,5 @@ interface IntentUpdate {
*
* @return next update
*/
Optional<IntentUpdate> execute();
Optional<IntentProcessPhase> execute();
}
......
......@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentException;
import org.onosproject.net.intent.impl.IntentManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -29,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Represents a phase to create a {@link FlowRuleOperations} instance
* with using registered intent installers.
*/
class WithdrawCoordinating implements IntentUpdate {
final class WithdrawCoordinating implements IntentProcessPhase {
private static final Logger log = LoggerFactory.getLogger(WithdrawCoordinating.class);
......@@ -45,7 +46,7 @@ class WithdrawCoordinating implements IntentUpdate {
}
@Override
public Optional<IntentUpdate> execute() {
public Optional<IntentProcessPhase> execute() {
try {
// Note: current.installables() are not null or empty due to createIntentUpdate check
FlowRuleOperations flowRules = intentManager.uninstallCoordinate(current, pending);
......
......@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.impl.IntentManager;
import java.util.Optional;
......@@ -24,21 +25,21 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Represents a phase of requesting a withdraw of an intent.
*/
class WithdrawRequest implements IntentUpdate {
public final class WithdrawRequest implements IntentProcessPhase {
// TODO: define an interface and use it, instead of IntentManager
private final IntentManager intentManager;
private final IntentData pending;
private final IntentData current;
WithdrawRequest(IntentManager intentManager, IntentData intentData, IntentData current) {
public WithdrawRequest(IntentManager intentManager, IntentData intentData, IntentData current) {
this.intentManager = checkNotNull(intentManager);
this.pending = checkNotNull(intentData);
this.current = checkNotNull(current);
}
@Override
public Optional<IntentUpdate> execute() {
public Optional<IntentProcessPhase> execute() {
//TODO perhaps we want to validate that the pending and current are the
// same version i.e. they are the same
// Note: this call is not just the symmetric version of submit
......
......@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.impl.IntentManager;
import java.util.Optional;
......@@ -26,7 +27,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Represents a phase of withdrawing an intent with calling
* {@link org.onosproject.net.flow.FlowRuleService}.
*/
class Withdrawing implements IntentUpdate {
class Withdrawing implements IntentProcessPhase {
// TODO: define an interface and use it, instead of IntentManager
private final IntentManager intentManager;
......@@ -40,7 +41,7 @@ class Withdrawing implements IntentUpdate {
}
@Override
public Optional<IntentUpdate> execute() {
public Optional<IntentProcessPhase> execute() {
intentManager.flowRuleService.apply(flowRules);
return Optional.of(new Withdrawn(pending));
}
......
......@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
/**
* Represents a phase where the withdraw has failed.
*/
class WithdrawingFailed extends AbstractFailed {
final class WithdrawingFailed extends AbstractFailed {
/**
* Create an instance with the specified data.
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentState;
......@@ -24,15 +24,15 @@ import static org.onosproject.net.intent.IntentState.WITHDRAWING;
/**
* Represents a phase where an intent has been withdrawn.
*/
class Withdrawn extends CompletedIntentUpdate {
public final class Withdrawn extends FinalIntentProcessPhase {
private final IntentData intentData;
Withdrawn(IntentData intentData) {
public Withdrawn(IntentData intentData) {
this(intentData, WITHDRAWING);
}
Withdrawn(IntentData intentData, IntentState newState) {
public Withdrawn(IntentData intentData, IntentState newState) {
this.intentData = checkNotNull(intentData);
this.intentData.setState(newState);
}
......