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
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/AbstractFailed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/AbstractFailed.java
new file mode 100644
index 0000000..8c2734b
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/AbstractFailed.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.intent.IntentState.FAILED;
+
+/**
+ * A common parent class of a class representing failure
+ * as IntentUpdate subclass.
+ */
+abstract class AbstractFailed extends FinalIntentProcessPhase {
+
+ private final IntentData intentData;
+
+ /**
+ * Create an instance with the specified data.
+ *
+ * @param intentData intentData
+ */
+ AbstractFailed(IntentData intentData) {
+ this.intentData = checkNotNull(intentData);
+ this.intentData.setState(FAILED);
+ }
+
+ @Override
+ public IntentData data() {
+ return intentData;
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
new file mode 100644
index 0000000..b68230a
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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;
+
+import java.util.List;
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a phase where an intent is being compiled.
+ */
+final class Compiling implements IntentProcessPhase {
+
+ private static final Logger log = LoggerFactory.getLogger(Compiling.class);
+
+ // TODO: define an interface and use it, instead of IntentManager
+ private final IntentManager intentManager;
+ private final IntentData pending;
+ private final IntentData current;
+
+ Compiling(IntentManager intentManager, IntentData pending, IntentData current) {
+ this.intentManager = checkNotNull(intentManager);
+ this.pending = checkNotNull(pending);
+ this.current = current;
+ }
+
+ @Override
+ public Optional<IntentProcessPhase> execute() {
+ try {
+ List<Intent> installables = (current != null) ? current.installables() : null;
+ pending.setInstallables(intentManager.compileIntent(pending.intent(), installables));
+ return Optional.of(new InstallCoordinating(intentManager, pending, current));
+ } catch (IntentException e) {
+ log.debug("Unable to compile intent {} due to: {}", pending.intent(), e);
+ return Optional.of(new CompilingFailed(pending));
+ }
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompilingFailed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompilingFailed.java
new file mode 100644
index 0000000..e537308
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompilingFailed.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+
+/**
+ * Represents a phase where the compile has failed.
+ */
+public class CompilingFailed extends AbstractFailed {
+
+ /**
+ * Create an instance with the specified data.
+ *
+ * @param intentData intentData
+ */
+ public CompilingFailed(IntentData intentData) {
+ super(intentData);
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java
new file mode 100644
index 0000000..72451a5
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+
+import java.util.Optional;
+
+/**
+ * Represents a final phase of processing an intent.
+ */
+public abstract class FinalIntentProcessPhase implements IntentProcessPhase {
+
+ @Override
+ public final Optional<IntentProcessPhase> execute() {
+ return Optional.empty();
+ }
+
+ public abstract IntentData data();
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallCoordinating.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallCoordinating.java
new file mode 100644
index 0000000..5fd82ec
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallCoordinating.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a phase to create a {@link FlowRuleOperations} instance
+ * with using registered intent installers.
+ */
+final class InstallCoordinating implements IntentProcessPhase {
+
+ private static final Logger log = LoggerFactory.getLogger(InstallCoordinating.class);
+
+ private final IntentManager intentManager;
+ private final IntentData pending;
+ private final IntentData current;
+
+ // TODO: define an interface and use it, instead of IntentManager
+ InstallCoordinating(IntentManager intentManager, IntentData pending, IntentData current) {
+ this.intentManager = checkNotNull(intentManager);
+ this.pending = checkNotNull(pending);
+ this.current = current;
+ }
+
+ @Override
+ public Optional<IntentProcessPhase> execute() {
+ try {
+ //FIXME we orphan flow rules that are currently on the data plane
+ // ... should either reuse them or remove them
+ FlowRuleOperations flowRules = intentManager.coordinate(current, pending);
+ return Optional.of(new Installing(intentManager, pending, flowRules));
+ } catch (IntentException e) {
+ log.warn("Unable to generate a FlowRuleOperations from intent {} due to:", pending.intent().id(), e);
+ return Optional.of(new InstallingFailed(pending));
+ }
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java
new file mode 100644
index 0000000..e54b10a
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+import org.onosproject.net.intent.impl.IntentManager;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a phase where intent installation has been requested.
+ */
+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;
+
+ public InstallRequest(IntentManager intentManager, IntentData intentData, Optional<IntentData> current) {
+ this.intentManager = checkNotNull(intentManager);
+ this.pending = checkNotNull(intentData);
+ this.current = checkNotNull(current);
+ }
+
+ @Override
+ public Optional<IntentProcessPhase> execute() {
+ return Optional.of(new Compiling(intentManager, pending, current.orElse(null)));
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installed.java
new file mode 100644
index 0000000..cd4d14e
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installed.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.intent.IntentState.INSTALLING;
+
+/**
+ * Represent a phase where an intent has been installed.
+ */
+class Installed extends FinalIntentProcessPhase {
+
+ private final IntentData intentData;
+
+ Installed(IntentData intentData) {
+ this.intentData = checkNotNull(intentData);
+ this.intentData.setState(INSTALLING);
+ }
+
+ @Override
+ public IntentData data() {
+ return intentData;
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java
new file mode 100644
index 0000000..05c499f
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a phase of installing an intent with calling
+ * {@link org.onosproject.net.flow.FlowRuleService}.
+ */
+final class Installing implements IntentProcessPhase {
+
+ private static final Logger log = LoggerFactory.getLogger(Installing.class);
+
+ private final IntentManager intentManager;
+ private final IntentData pending;
+ private final FlowRuleOperations flowRules;
+
+ // TODO: define an interface and use it, instead of IntentManager
+ Installing(IntentManager intentManager, IntentData pending, FlowRuleOperations flowRules) {
+ this.intentManager = checkNotNull(intentManager);
+ this.pending = checkNotNull(pending);
+ this.flowRules = flowRules;
+ }
+
+ @Override
+ public Optional<IntentProcessPhase> execute() {
+ try {
+ intentManager.flowRuleService.apply(flowRules); // FIXME we need to provide a context
+ return Optional.of(new Installed(pending));
+ // What kinds of exceptions are thrown by FlowRuleService.apply()?
+ // Is IntentException a correct exception abstraction?
+ } catch (IntentException e) {
+ log.warn("Unable to install intent {} due to: {}", pending.intent().id(), e);
+ return Optional.of(new InstallingFailed(pending));
+ }
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallingFailed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallingFailed.java
new file mode 100644
index 0000000..b3bf3a3
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallingFailed.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+
+/**
+ * Represent a phase where the install has failed.
+ */
+class InstallingFailed extends AbstractFailed {
+
+ /**
+ * Create an instance with the specified data.
+ *
+ * @param intentData intentData
+ */
+ InstallingFailed(IntentData intentData) {
+ super(intentData);
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java
new file mode 100644
index 0000000..56bf122
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import java.util.Optional;
+
+/**
+ * Represents a phase of processing an intent.
+ */
+public interface IntentProcessPhase {
+
+ /**
+ * Execute the procedure represented by the instance
+ * and generates the next update instance.
+ *
+ * @return next update
+ */
+ Optional<IntentProcessPhase> execute();
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinating.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinating.java
new file mode 100644
index 0000000..24d6dd5
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinating.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a phase to create a {@link FlowRuleOperations} instance
+ * with using registered intent installers.
+ */
+final class WithdrawCoordinating implements IntentProcessPhase {
+
+ private static final Logger log = LoggerFactory.getLogger(WithdrawCoordinating.class);
+
+ // TODO: define an interface and use it, instead of IntentManager
+ private final IntentManager intentManager;
+ private final IntentData pending;
+ private final IntentData current;
+
+ WithdrawCoordinating(IntentManager intentManager, IntentData pending, IntentData current) {
+ this.intentManager = checkNotNull(intentManager);
+ this.pending = checkNotNull(pending);
+ this.current = checkNotNull(current);
+ }
+
+ @Override
+ public Optional<IntentProcessPhase> execute() {
+ try {
+ // Note: current.installables() are not null or empty due to createIntentUpdate check
+ FlowRuleOperations flowRules = intentManager.uninstallCoordinate(current, pending);
+ pending.setInstallables(current.installables());
+ return Optional.of(new Withdrawing(intentManager, pending, flowRules));
+ } catch (IntentException e) {
+ log.warn("Unable to generate generate a FlowRuleOperations from intent {} due to:", pending.intent(), e);
+ return Optional.of(new WithdrawingFailed(pending));
+ }
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
new file mode 100644
index 0000000..bbc7f34
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+import org.onosproject.net.intent.impl.IntentManager;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a phase of requesting a withdraw of an intent.
+ */
+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;
+
+ public WithdrawRequest(IntentManager intentManager, IntentData intentData, IntentData current) {
+ this.intentManager = checkNotNull(intentManager);
+ this.pending = checkNotNull(intentData);
+ this.current = checkNotNull(current);
+ }
+
+ @Override
+ 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
+ return Optional.of(new WithdrawCoordinating(intentManager, pending, current));
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java
new file mode 100644
index 0000000..676c3c7
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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;
+
+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 IntentProcessPhase {
+
+ // TODO: define an interface and use it, instead of IntentManager
+ private final IntentManager intentManager;
+ private final IntentData pending;
+ private final FlowRuleOperations flowRules;
+
+ Withdrawing(IntentManager intentManager, IntentData pending, FlowRuleOperations flowRules) {
+ this.intentManager = checkNotNull(intentManager);
+ this.pending = checkNotNull(pending);
+ this.flowRules = checkNotNull(flowRules);
+ }
+
+ @Override
+ public Optional<IntentProcessPhase> execute() {
+ intentManager.flowRuleService.apply(flowRules);
+ return Optional.of(new Withdrawn(pending));
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawingFailed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawingFailed.java
new file mode 100644
index 0000000..4e6874e
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawingFailed.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+
+/**
+ * Represents a phase where the withdraw has failed.
+ */
+final class WithdrawingFailed extends AbstractFailed {
+
+ /**
+ * Create an instance with the specified data.
+ *
+ * @param intentData intentData
+ */
+ WithdrawingFailed(IntentData intentData) {
+ super(intentData);
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
new file mode 100644
index 0000000..069a989
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+import org.onosproject.net.intent.IntentState;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.intent.IntentState.WITHDRAWING;
+
+/**
+ * Represents a phase where an intent has been withdrawn.
+ */
+public final class Withdrawn extends FinalIntentProcessPhase {
+
+ private final IntentData intentData;
+
+ public Withdrawn(IntentData intentData) {
+ this(intentData, WITHDRAWING);
+ }
+
+ public Withdrawn(IntentData intentData, IntentState newState) {
+ this.intentData = checkNotNull(intentData);
+ this.intentData.setState(newState);
+ }
+
+ @Override
+ public IntentData data() {
+ return intentData;
+ }
+}