Thomas Vachuska

Adding intent operations batch abstraction.

......@@ -14,6 +14,7 @@ import java.util.List;
* @param <T> the enum of operators <br>
* This enum must be defined in each sub-classes.
*/
@Deprecated
public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> {
private final List<T> ops;
......
......@@ -11,6 +11,7 @@ import com.google.common.base.MoreObjects;
* This is the interface to classes which are maintained by BatchOperation as
* its entries.
*/
@Deprecated
public class BatchOperationEntry<T extends Enum<?>, U extends BatchOperationTarget> {
private final T operator;
private final U target;
......
......@@ -4,6 +4,7 @@ package org.onlab.onos.net.intent;
/**
* An interface of the class which is assigned to BatchOperation.
*/
@Deprecated
public interface BatchOperationTarget {
}
......
......@@ -3,6 +3,7 @@ package org.onlab.onos.net.intent;
/**
* A list of intent operations.
*/
@Deprecated
public class IntentBatchOperation extends
BatchOperation<BatchOperationEntry<IntentBatchOperation.Operator, ?>> {
/**
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.net.intent;
/**
* Abstraction of an intent-related operation, e.g. add, remove, replace.
*/
public class IntentOperation {
private final Type type;
private final IntentId intentId;
private final Intent intent;
/**
* Operation type.
*/
enum Type {
/**
* Indicates that an intent should be added.
*/
SUBMIT,
/**
* Indicates that an intent should be removed.
*/
WITHDRAW,
/**
* Indicates that an intent should be replaced with another.
*/
REPLACE
}
/**
* Creates an intent operation.
*
* @param type operation type
* @param intentId identifier of the intent subject to the operation
* @param intent intent subject
*/
IntentOperation(Type type, IntentId intentId, Intent intent) {
this.type = type;
this.intentId = intentId;
this.intent = intent;
}
/**
* Returns the type of the operation.
*
* @return operation type
*/
public Type type() {
return type;
}
/**
* Returns the identifier of the intent to which this operation applies.
*
* @return intent identifier
*/
public IntentId intentId() {
return intentId;
}
/**
* Returns the intent to which this operation applied. For remove,
* this can be null.
*
* @return intent that is the subject of the operation; null for remove
*/
public Intent intent() {
return intent;
}
}
package org.onlab.onos.net.intent;
import com.google.common.collect.ImmutableList;
import java.util.List;
import static org.onlab.onos.net.intent.IntentOperation.Type.REPLACE;
import static org.onlab.onos.net.intent.IntentOperation.Type.SUBMIT;
import static org.onlab.onos.net.intent.IntentOperation.Type.WITHDRAW;
/**
* Abstraction of a batch of intent submit/withdraw operations.
* Batch of intent submit/withdraw/replace operations.
*/
public interface IntentOperations {
public final class IntentOperations {
private final List<IntentOperation> operations;
/**
* Creates a batch of intent operations using the supplied list.
*
* @param operations list of intent operations
*/
private IntentOperations(List<IntentOperation> operations) {
this.operations = operations;
}
/**
* List of operations that need to be executed as a unit.
*
* @return list of intent operations
*/
public List<IntentOperation> operations() {
return operations;
}
/**
* Returns a builder for intent operation batches.
*
* @return intent operations builder
*/
public static Builder builder() {
return new Builder();
}
/**
* Builder for batches of intent operations.
*/
public static final class Builder {
ImmutableList.Builder<IntentOperation> builder = ImmutableList.builder();
// Public construction is forbidden.
private Builder() {
}
/**
* Adds an intent submit operation.
*
* @param intent intent to be submitted
* @return self
*/
public Builder addSubmitOperation(Intent intent) {
builder.add(new IntentOperation(SUBMIT, intent.id(), intent));
return this;
}
/**
* Adds an intent submit operation.
*
* @param oldIntentId intent to be replaced
* @param newIntent replacement intent
* @return self
*/
public Builder addReplaceOperation(IntentId oldIntentId, Intent newIntent) {
builder.add(new IntentOperation(REPLACE, oldIntentId, newIntent));
return this;
}
/**
* Adds an intent submit operation.
*
* @param intentId identifier of the intent to be withdrawn
* @return self
*/
public Builder addWithdrawOperation(IntentId intentId) {
builder.add(new IntentOperation(WITHDRAW, intentId, null));
return this;
}
// TODO: elaborate once the revised BatchOperation scheme is in place
/**
* Builds a batch of intent operations.
*
* @return immutable batch of intent operations
*/
public IntentOperations build() {
return new IntentOperations(builder.build());
}
}
}
......
......@@ -2,6 +2,7 @@ package org.onlab.onos.net.intent;
import java.util.List;
import java.util.concurrent.Future;
/**
* Service for application submitting or withdrawing their intents.
......@@ -27,6 +28,8 @@ public interface IntentService {
*/
void withdraw(Intent intent);
// void replace(IntentId oldIntentId, Intent newIntent);
/**
* Submits a batch of submit &amp; withdraw operations. Such a batch is
* assumed to be processed together.
......@@ -36,7 +39,7 @@ public interface IntentService {
*
* @param operations batch of intent operations
*/
void execute(IntentOperations operations);
Future<IntentOperations> execute(IntentOperations operations);
/**
* Returns an iterable of intents currently in the system.
......
......@@ -9,6 +9,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* Fake implementation of the intent service to assist in developing tests of
......@@ -171,8 +172,9 @@ public class FakeIntentManager implements TestableIntentService {
}
@Override
public void execute(IntentOperations operations) {
public Future<IntentOperations> execute(IntentOperations operations) {
// TODO: implement later
return null;
}
@Override
......
......@@ -126,7 +126,7 @@ public class IntentManager
// FIXME: implement this method
@Override
public void execute(IntentOperations operations) {
public Future<IntentOperations> execute(IntentOperations operations) {
throw new UnsupportedOperationException("execute() is not implemented yet");
}
......