Brian O'Connor
Committed by Gerrit Code Review

Initial work on Intent API (ONOS-618)

Change-Id: I2b4aa0befabbf0b4dce8b2c991e38411709b2e80
......@@ -34,7 +34,10 @@ import static com.google.common.base.Preconditions.checkState;
public abstract class Intent {
private final IntentId id;
private final ApplicationId appId;
private final String key;
private final Collection<NetworkResource> resources;
private static IdGenerator idGenerator;
......@@ -45,6 +48,7 @@ public abstract class Intent {
protected Intent() {
this.id = null;
this.appId = null;
this.key = null;
this.resources = null;
}
......@@ -54,11 +58,26 @@ public abstract class Intent {
* @param appId application identifier
* @param resources required network resources (optional)
*/
@Deprecated
protected Intent(ApplicationId appId,
Collection<NetworkResource> resources) {
this(appId, null, resources);
}
/**
* Creates a new intent.
*
* @param appId application identifier
* @param key optional key
* @param resources required network resources (optional)
*/
protected Intent(ApplicationId appId,
String key,
Collection<NetworkResource> resources) {
checkState(idGenerator != null, "Id generator is not bound.");
this.id = IntentId.valueOf(idGenerator.getNewId());
this.appId = checkNotNull(appId, "Application ID cannot be null");
this.key = (key != null) ? key : id.toString(); //FIXME
this.resources = checkNotNull(resources);
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.net.intent;
/**
* Facade for receiving notifications from the intent batch service.
*/
@Deprecated
public interface IntentBatchDelegate {
/**
......
......@@ -21,6 +21,7 @@ import org.onosproject.event.AbstractEvent;
/**
* A class to represent an intent related event.
*/
@Deprecated
public class IntentBatchLeaderEvent extends AbstractEvent<IntentBatchLeaderEvent.Type, ApplicationId> {
public enum Type {
......
......@@ -20,5 +20,6 @@ import org.onosproject.event.EventListener;
/**
* Listener for {@link org.onosproject.net.intent.IntentEvent intent events}.
*/
@Deprecated
public interface IntentBatchListener extends EventListener<IntentBatchLeaderEvent> {
}
......
......@@ -22,6 +22,7 @@ import java.util.Set;
/**
* Service for tracking and delegating batches of intent operations.
*/
@Deprecated
public interface IntentBatchService {
/**
......
......@@ -29,6 +29,7 @@ public final class IntentOperation {
private final Type type;
private final IntentId intentId;
private final Intent intent;
//FIXME consider pulling the key out (we will hash based on key)
/**
* Operation type.
......@@ -47,11 +48,13 @@ public final class IntentOperation {
/**
* Indicates that an intent should be replaced with another.
*/
@Deprecated
REPLACE,
/**
* Indicates that an intent should be updated (i.e. recompiled/reinstalled).
*/
@Deprecated
UPDATE,
}
......
......@@ -31,6 +31,7 @@ import static org.onosproject.net.intent.IntentOperation.Type.WITHDRAW;
/**
* Batch of intent submit/withdraw/replace operations.
*/
@Deprecated
public final class IntentOperations {
private final List<IntentOperation> operations;
......
......@@ -48,6 +48,7 @@ public interface IntentService {
* @param oldIntentId identifier of the old intent being replaced
* @param newIntent new intent replacing the old one
*/
@Deprecated
void replace(IntentId oldIntentId, Intent newIntent);
/**
......@@ -59,6 +60,7 @@ public interface IntentService {
* </p>
* @param operations batch of intent operations
*/
@Deprecated
void execute(IntentOperations operations);
/**
......
......@@ -37,7 +37,7 @@ public enum IntentState {
* This is a transitional state after which the intent will enter either
* {@link #FAILED} state or {@link #INSTALLING} state.
*/
COMPILING,
COMPILING, //TODO do we really need this?
/**
* Signifies that the resulting installable intents are being installed
......
......@@ -73,4 +73,22 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
*/
List<Operation> batchWrite(BatchWrite batch);
/**
* Adds a new operation, which should be persisted and delegated.
*
* @param op operation
*/
default void add(IntentOperation op) {} //FIXME remove when impl.
/**
* Checks to see whether the calling instance is the master for processing
* this intent, or more specifically, the key contained in this intent.
*
* @param intent intent to check
* @return true if master; false, otherwise
*/
//TODO better name
default boolean isMaster(Intent intent) { //FIXME remove default when impl.
return true;
}
}
......
......@@ -21,4 +21,12 @@ import org.onosproject.store.StoreDelegate;
* Intent store delegate abstraction.
*/
public interface IntentStoreDelegate extends StoreDelegate<IntentEvent> {
/**
* Provides an intent operation that should be processed (compiled and
* installed) by this manager.
*
* @param op intent operation
*/
void process(IntentOperation op);
}
......
......@@ -380,6 +380,11 @@ public class IntentManager
public void notify(IntentEvent event) {
eventDispatcher.post(event);
}
@Override
public void process(IntentOperation op) {
//FIXME
}
}
private void buildAndSubmitBatches(Iterable<IntentId> intentIds,
......