Showing
9 changed files
with
196 additions
and
6 deletions
... | @@ -14,6 +14,7 @@ import java.util.List; | ... | @@ -14,6 +14,7 @@ import java.util.List; |
14 | * @param <T> the enum of operators <br> | 14 | * @param <T> the enum of operators <br> |
15 | * This enum must be defined in each sub-classes. | 15 | * This enum must be defined in each sub-classes. |
16 | */ | 16 | */ |
17 | +@Deprecated | ||
17 | public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> { | 18 | public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> { |
18 | 19 | ||
19 | private final List<T> ops; | 20 | private final List<T> ops; | ... | ... |
... | @@ -11,6 +11,7 @@ import com.google.common.base.MoreObjects; | ... | @@ -11,6 +11,7 @@ import com.google.common.base.MoreObjects; |
11 | * This is the interface to classes which are maintained by BatchOperation as | 11 | * This is the interface to classes which are maintained by BatchOperation as |
12 | * its entries. | 12 | * its entries. |
13 | */ | 13 | */ |
14 | +@Deprecated | ||
14 | public class BatchOperationEntry<T extends Enum<?>, U extends BatchOperationTarget> { | 15 | public class BatchOperationEntry<T extends Enum<?>, U extends BatchOperationTarget> { |
15 | private final T operator; | 16 | private final T operator; |
16 | private final U target; | 17 | private final U target; | ... | ... |
... | @@ -4,6 +4,7 @@ package org.onlab.onos.net.intent; | ... | @@ -4,6 +4,7 @@ package org.onlab.onos.net.intent; |
4 | /** | 4 | /** |
5 | * An interface of the class which is assigned to BatchOperation. | 5 | * An interface of the class which is assigned to BatchOperation. |
6 | */ | 6 | */ |
7 | +@Deprecated | ||
7 | public interface BatchOperationTarget { | 8 | public interface BatchOperationTarget { |
8 | 9 | ||
9 | } | 10 | } | ... | ... |
... | @@ -3,6 +3,7 @@ package org.onlab.onos.net.intent; | ... | @@ -3,6 +3,7 @@ package org.onlab.onos.net.intent; |
3 | /** | 3 | /** |
4 | * A list of intent operations. | 4 | * A list of intent operations. |
5 | */ | 5 | */ |
6 | +@Deprecated | ||
6 | public class IntentBatchOperation extends | 7 | public class IntentBatchOperation extends |
7 | BatchOperation<BatchOperationEntry<IntentBatchOperation.Operator, ?>> { | 8 | BatchOperation<BatchOperationEntry<IntentBatchOperation.Operator, ?>> { |
8 | /** | 9 | /** | ... | ... |
1 | +/* | ||
2 | + * Licensed to the Apache Software Foundation (ASF) under one | ||
3 | + * or more contributor license agreements. See the NOTICE file | ||
4 | + * distributed with this work for additional information | ||
5 | + * regarding copyright ownership. The ASF licenses this file | ||
6 | + * to you under the Apache License, Version 2.0 (the | ||
7 | + * "License"); you may not use this file except in compliance | ||
8 | + * with the License. You may obtain a copy of the License at | ||
9 | + * | ||
10 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
11 | + * | ||
12 | + * Unless required by applicable law or agreed to in writing, | ||
13 | + * software distributed under the License is distributed on an | ||
14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
15 | + * KIND, either express or implied. See the License for the | ||
16 | + * specific language governing permissions and limitations | ||
17 | + * under the License. | ||
18 | + */ | ||
19 | +package org.onlab.onos.net.intent; | ||
20 | + | ||
21 | +/** | ||
22 | + * Abstraction of an intent-related operation, e.g. add, remove, replace. | ||
23 | + */ | ||
24 | +public class IntentOperation { | ||
25 | + | ||
26 | + private final Type type; | ||
27 | + private final IntentId intentId; | ||
28 | + private final Intent intent; | ||
29 | + | ||
30 | + /** | ||
31 | + * Operation type. | ||
32 | + */ | ||
33 | + enum Type { | ||
34 | + /** | ||
35 | + * Indicates that an intent should be added. | ||
36 | + */ | ||
37 | + SUBMIT, | ||
38 | + | ||
39 | + /** | ||
40 | + * Indicates that an intent should be removed. | ||
41 | + */ | ||
42 | + WITHDRAW, | ||
43 | + | ||
44 | + /** | ||
45 | + * Indicates that an intent should be replaced with another. | ||
46 | + */ | ||
47 | + REPLACE | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * Creates an intent operation. | ||
52 | + * | ||
53 | + * @param type operation type | ||
54 | + * @param intentId identifier of the intent subject to the operation | ||
55 | + * @param intent intent subject | ||
56 | + */ | ||
57 | + IntentOperation(Type type, IntentId intentId, Intent intent) { | ||
58 | + this.type = type; | ||
59 | + this.intentId = intentId; | ||
60 | + this.intent = intent; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Returns the type of the operation. | ||
65 | + * | ||
66 | + * @return operation type | ||
67 | + */ | ||
68 | + public Type type() { | ||
69 | + return type; | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * Returns the identifier of the intent to which this operation applies. | ||
74 | + * | ||
75 | + * @return intent identifier | ||
76 | + */ | ||
77 | + public IntentId intentId() { | ||
78 | + return intentId; | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Returns the intent to which this operation applied. For remove, | ||
83 | + * this can be null. | ||
84 | + * | ||
85 | + * @return intent that is the subject of the operation; null for remove | ||
86 | + */ | ||
87 | + public Intent intent() { | ||
88 | + return intent; | ||
89 | + } | ||
90 | + | ||
91 | +} |
1 | package org.onlab.onos.net.intent; | 1 | package org.onlab.onos.net.intent; |
2 | 2 | ||
3 | +import com.google.common.collect.ImmutableList; | ||
4 | + | ||
5 | +import java.util.List; | ||
6 | + | ||
7 | +import static org.onlab.onos.net.intent.IntentOperation.Type.REPLACE; | ||
8 | +import static org.onlab.onos.net.intent.IntentOperation.Type.SUBMIT; | ||
9 | +import static org.onlab.onos.net.intent.IntentOperation.Type.WITHDRAW; | ||
10 | + | ||
3 | /** | 11 | /** |
4 | - * Abstraction of a batch of intent submit/withdraw operations. | 12 | + * Batch of intent submit/withdraw/replace operations. |
13 | + */ | ||
14 | +public final class IntentOperations { | ||
15 | + | ||
16 | + private final List<IntentOperation> operations; | ||
17 | + | ||
18 | + /** | ||
19 | + * Creates a batch of intent operations using the supplied list. | ||
20 | + * | ||
21 | + * @param operations list of intent operations | ||
5 | */ | 22 | */ |
6 | -public interface IntentOperations { | 23 | + private IntentOperations(List<IntentOperation> operations) { |
24 | + this.operations = operations; | ||
25 | + } | ||
7 | 26 | ||
8 | - // TODO: elaborate once the revised BatchOperation scheme is in place | 27 | + /** |
28 | + * List of operations that need to be executed as a unit. | ||
29 | + * | ||
30 | + * @return list of intent operations | ||
31 | + */ | ||
32 | + public List<IntentOperation> operations() { | ||
33 | + return operations; | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * Returns a builder for intent operation batches. | ||
38 | + * | ||
39 | + * @return intent operations builder | ||
40 | + */ | ||
41 | + public static Builder builder() { | ||
42 | + return new Builder(); | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * Builder for batches of intent operations. | ||
47 | + */ | ||
48 | + public static final class Builder { | ||
49 | + | ||
50 | + ImmutableList.Builder<IntentOperation> builder = ImmutableList.builder(); | ||
51 | + | ||
52 | + // Public construction is forbidden. | ||
53 | + private Builder() { | ||
54 | + } | ||
55 | + | ||
56 | + /** | ||
57 | + * Adds an intent submit operation. | ||
58 | + * | ||
59 | + * @param intent intent to be submitted | ||
60 | + * @return self | ||
61 | + */ | ||
62 | + public Builder addSubmitOperation(Intent intent) { | ||
63 | + builder.add(new IntentOperation(SUBMIT, intent.id(), intent)); | ||
64 | + return this; | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Adds an intent submit operation. | ||
69 | + * | ||
70 | + * @param oldIntentId intent to be replaced | ||
71 | + * @param newIntent replacement intent | ||
72 | + * @return self | ||
73 | + */ | ||
74 | + public Builder addReplaceOperation(IntentId oldIntentId, Intent newIntent) { | ||
75 | + builder.add(new IntentOperation(REPLACE, oldIntentId, newIntent)); | ||
76 | + return this; | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Adds an intent submit operation. | ||
81 | + * | ||
82 | + * @param intentId identifier of the intent to be withdrawn | ||
83 | + * @return self | ||
84 | + */ | ||
85 | + public Builder addWithdrawOperation(IntentId intentId) { | ||
86 | + builder.add(new IntentOperation(WITHDRAW, intentId, null)); | ||
87 | + return this; | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * Builds a batch of intent operations. | ||
92 | + * | ||
93 | + * @return immutable batch of intent operations | ||
94 | + */ | ||
95 | + public IntentOperations build() { | ||
96 | + return new IntentOperations(builder.build()); | ||
97 | + } | ||
9 | 98 | ||
99 | + } | ||
10 | } | 100 | } | ... | ... |
... | @@ -2,6 +2,7 @@ package org.onlab.onos.net.intent; | ... | @@ -2,6 +2,7 @@ package org.onlab.onos.net.intent; |
2 | 2 | ||
3 | 3 | ||
4 | import java.util.List; | 4 | import java.util.List; |
5 | +import java.util.concurrent.Future; | ||
5 | 6 | ||
6 | /** | 7 | /** |
7 | * Service for application submitting or withdrawing their intents. | 8 | * Service for application submitting or withdrawing their intents. |
... | @@ -27,6 +28,8 @@ public interface IntentService { | ... | @@ -27,6 +28,8 @@ public interface IntentService { |
27 | */ | 28 | */ |
28 | void withdraw(Intent intent); | 29 | void withdraw(Intent intent); |
29 | 30 | ||
31 | + // void replace(IntentId oldIntentId, Intent newIntent); | ||
32 | + | ||
30 | /** | 33 | /** |
31 | * Submits a batch of submit & withdraw operations. Such a batch is | 34 | * Submits a batch of submit & withdraw operations. Such a batch is |
32 | * assumed to be processed together. | 35 | * assumed to be processed together. |
... | @@ -36,7 +39,7 @@ public interface IntentService { | ... | @@ -36,7 +39,7 @@ public interface IntentService { |
36 | * | 39 | * |
37 | * @param operations batch of intent operations | 40 | * @param operations batch of intent operations |
38 | */ | 41 | */ |
39 | - void execute(IntentOperations operations); | 42 | + Future<IntentOperations> execute(IntentOperations operations); |
40 | 43 | ||
41 | /** | 44 | /** |
42 | * Returns an iterable of intents currently in the system. | 45 | * Returns an iterable of intents currently in the system. | ... | ... |
... | @@ -9,6 +9,7 @@ import java.util.Map; | ... | @@ -9,6 +9,7 @@ import java.util.Map; |
9 | import java.util.Set; | 9 | import java.util.Set; |
10 | import java.util.concurrent.ExecutorService; | 10 | import java.util.concurrent.ExecutorService; |
11 | import java.util.concurrent.Executors; | 11 | import java.util.concurrent.Executors; |
12 | +import java.util.concurrent.Future; | ||
12 | 13 | ||
13 | /** | 14 | /** |
14 | * Fake implementation of the intent service to assist in developing tests of | 15 | * Fake implementation of the intent service to assist in developing tests of |
... | @@ -171,8 +172,9 @@ public class FakeIntentManager implements TestableIntentService { | ... | @@ -171,8 +172,9 @@ public class FakeIntentManager implements TestableIntentService { |
171 | } | 172 | } |
172 | 173 | ||
173 | @Override | 174 | @Override |
174 | - public void execute(IntentOperations operations) { | 175 | + public Future<IntentOperations> execute(IntentOperations operations) { |
175 | // TODO: implement later | 176 | // TODO: implement later |
177 | + return null; | ||
176 | } | 178 | } |
177 | 179 | ||
178 | @Override | 180 | @Override | ... | ... |
... | @@ -126,7 +126,7 @@ public class IntentManager | ... | @@ -126,7 +126,7 @@ public class IntentManager |
126 | 126 | ||
127 | // FIXME: implement this method | 127 | // FIXME: implement this method |
128 | @Override | 128 | @Override |
129 | - public void execute(IntentOperations operations) { | 129 | + public Future<IntentOperations> execute(IntentOperations operations) { |
130 | throw new UnsupportedOperationException("execute() is not implemented yet"); | 130 | throw new UnsupportedOperationException("execute() is not implemented yet"); |
131 | } | 131 | } |
132 | 132 | ... | ... |
-
Please register or login to post a comment