Ray Milkey
Committed by Brian O'Connor

Refactoring of IntentId based APIs

- getIntent
- getIntentState
- getInstallableIntents

Change-Id: I6d2073dfa165e0e5adcef46fe5908b563b481a43
Showing 28 changed files with 183 additions and 199 deletions
......@@ -23,7 +23,6 @@ import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentListener;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
......@@ -108,12 +107,15 @@ public class BandwidthCalendarResource extends BaseResource {
public Response withdrawIntent(@PathParam("intentId") String intentId) {
log.info("Receiving Teardown request for {}", intentId);
IntentService service = get(IntentService.class);
// TODO: there needs to be an app id and key here
/*
Intent intent = service.getIntent(IntentId.valueOf(Long.parseLong(intentId)));
if (intent != null) {
service.withdraw(intent);
String reply = "ok\n";
return Response.ok(reply).build();
}
*/
return Response.status(Response.Status.NOT_FOUND).build();
}
......@@ -163,7 +165,7 @@ public class BandwidthCalendarResource extends BaseResource {
@Override
public void event(IntentEvent event) {
if (event.subject().equals(intent)) {
state = service.getIntentState(intent.id());
state = service.getIntentState(intent.key());
if (state == INSTALLED || state == FAILED || state == WITHDRAWN) {
latch.countDown();
}
......
......@@ -100,7 +100,7 @@ public class OpticalPathProvisioner {
inStatusTportMap.clear();
outStatusTportMap.clear();
for (Intent intent : intentService.getIntents()) {
if (intentService.getIntentState(intent.id()) == INSTALLED) {
if (intentService.getIntentState(intent.key()) == INSTALLED) {
if (intent instanceof OpticalConnectivityIntent) {
inStatusTportMap.put(((OpticalConnectivityIntent) intent).getSrc(),
(OpticalConnectivityIntent) intent);
......@@ -177,7 +177,7 @@ public class OpticalPathProvisioner {
// TODO change the coordination approach between packet intents and optical intents
// Low speed LLDP may cause multiple calls which are not expected
if (!IntentState.FAILED.equals(intentService.getIntentState(intent.id()))) {
if (!IntentState.FAILED.equals(intentService.getIntentState(intent.key()))) {
return;
}
......
......@@ -579,7 +579,7 @@ public class IntentSynchronizer implements FibListener {
}
IntentState state =
intentService.getIntentState(fetchedIntent.id());
intentService.getIntentState(fetchedIntent.key());
if (state == null ||
state == IntentState.WITHDRAWING ||
state == IntentState.WITHDRAWN) {
......@@ -601,7 +601,7 @@ public class IntentSynchronizer implements FibListener {
}
IntentState state =
intentService.getIntentState(fetchedIntent.id());
intentService.getIntentState(fetchedIntent.key());
if (state == null ||
state == IntentState.WITHDRAWING ||
state == IntentState.WITHDRAWN) {
......
......@@ -535,19 +535,19 @@ public class IntentSyncTest extends AbstractIntentTest {
reset(intentService);
Set<Intent> intents = new HashSet<Intent>();
intents.add(intent1);
expect(intentService.getIntentState(intent1.id()))
expect(intentService.getIntentState(intent1.key()))
.andReturn(IntentState.INSTALLED).anyTimes();
intents.add(intent2);
expect(intentService.getIntentState(intent2.id()))
expect(intentService.getIntentState(intent2.key()))
.andReturn(IntentState.INSTALLED).anyTimes();
intents.add(intent4);
expect(intentService.getIntentState(intent4.id()))
expect(intentService.getIntentState(intent4.key()))
.andReturn(IntentState.INSTALLED).anyTimes();
intents.add(intent5);
expect(intentService.getIntentState(intent5.id()))
expect(intentService.getIntentState(intent5.key()))
.andReturn(IntentState.INSTALLED).anyTimes();
intents.add(intent7);
expect(intentService.getIntentState(intent7.id()))
expect(intentService.getIntentState(intent7.key()))
.andReturn(IntentState.WITHDRAWING).anyTimes();
expect(intentService.getIntents()).andReturn(intents).anyTimes();
......
......@@ -39,7 +39,7 @@ public class IntentIdCompleter implements Completer {
Iterator<Intent> it = service.getIntents().iterator();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
strings.add(it.next().id().toString());
strings.add(it.next().key().toString());
}
// Now let the completer do the work for figuring out what to offer.
......
......@@ -19,8 +19,8 @@ import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import java.math.BigInteger;
......@@ -43,8 +43,8 @@ public class IntentRemoveCommand extends AbstractShellCommand {
id = id.replaceFirst("0x", "");
}
IntentId intentId = IntentId.valueOf(new BigInteger(id, 16).longValue());
Intent intent = service.getIntent(intentId);
Key key = Key.of(new BigInteger(id, 16).longValue(), appId());
Intent intent = service.getIntent(key);
if (intent != null) {
service.withdraw(intent);
}
......
......@@ -76,7 +76,7 @@ public class IntentsListCommand extends AbstractShellCommand {
print("%s", json(service, service.getIntents()));
} else {
for (Intent intent : service.getIntents()) {
IntentState state = service.getIntentState(intent.id());
IntentState state = service.getIntentState(intent.key());
if (state != null) {
print("id=%s, state=%s, type=%s, appId=%s",
intent.id(), state, intent.getClass().getSimpleName(),
......@@ -130,7 +130,7 @@ public class IntentsListCommand extends AbstractShellCommand {
// Collect the summary for each intent type intents
for (Intent intent : intents) {
IntentState intentState = service.getIntentState(intent.id());
IntentState intentState = service.getIntentState(intent.key());
if (intentState == null) {
continue;
}
......@@ -365,7 +365,7 @@ public class IntentsListCommand extends AbstractShellCommand {
print(" egress=%s", li.egressPoints());
}
List<Intent> installable = service.getInstallableIntents(intent.id());
List<Intent> installable = service.getInstallableIntents(intent.key());
if (showInstallable && installable != null && !installable.isEmpty()) {
print(" installable=%s", installable);
}
......@@ -387,7 +387,7 @@ public class IntentsListCommand extends AbstractShellCommand {
.put("type", intent.getClass().getSimpleName())
.put("appId", intent.appId().name());
IntentState state = service.getIntentState(intent.id());
IntentState state = service.getIntentState(intent.key());
if (state != null) {
result.put("state", state.toString());
}
......@@ -438,7 +438,7 @@ public class IntentsListCommand extends AbstractShellCommand {
result.set("links", LinksListCommand.json(li.links()));
}
List<Intent> installable = service.getInstallableIntents(intent.id());
List<Intent> installable = service.getInstallableIntents(intent.key());
if (installable != null && !installable.isEmpty()) {
result.set("installable", json(service, installable));
}
......
......@@ -64,7 +64,7 @@ public class WipeOutCommand extends ClustersListCommand {
print("Wiping intents");
IntentService intentService = get(IntentService.class);
for (Intent intent : intentService.getIntents()) {
if (intentService.getIntentState(intent.id()) == IntentState.INSTALLED) {
if (intentService.getIntentState(intent.key()) == IntentState.INSTALLED) {
intentService.withdraw(intent);
}
}
......
......@@ -43,6 +43,14 @@ public interface IntentService {
void withdraw(Intent intent);
/**
* Fetches an intent based on its key.
*
* @param key key of the intent
* @return intent object if the key is found, null otherwise
*/
public Intent getIntent(Key key);
/**
* Returns an iterable of intents currently in the system.
*
* @return set of intents
......@@ -57,30 +65,22 @@ public interface IntentService {
long getIntentCount();
/**
* Retrieves the intent specified by its identifier.
*
* @param id intent identifier
* @return the intent or null if one with the given identifier is not found
*/
Intent getIntent(IntentId id);
/**
* Retrieves the state of an intent by its identifier.
*
* @param id intent identifier
* @param intentKey intent identifier
* @return the intent state or null if one with the given identifier is not
* found
*/
IntentState getIntentState(IntentId id);
IntentState getIntentState(Key intentKey);
/**
* Returns the list of the installable events associated with the specified
* top-level intent.
*
* @param intentId top-level intent identifier
* @param intentKey top-level intent identifier
* @return compiled installable intents
*/
List<Intent> getInstallableIntents(IntentId intentId);
List<Intent> getInstallableIntents(Key intentKey);
/**
* Adds the specified listener for intent events.
......
......@@ -40,37 +40,24 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
Iterable<Intent> getIntents();
/**
* Returns the intent with the specified identifier.
*
* @param intentId intent identification
* @return intent or null if not found
*/
@Deprecated
default Intent getIntent(IntentId intentId) {
throw new UnsupportedOperationException("deprecated");
}
/**
* Returns the state of the specified intent.
*
* @param intentId intent identification
* @param intentKey intent identification
* @return current intent state
*/
@Deprecated
default IntentState getIntentState(IntentId intentId) {
throw new UnsupportedOperationException("deprecated");
default IntentState getIntentState(Key intentKey) {
return null;
}
/**
* Returns the list of the installable events associated with the specified
* original intent.
*
* @param intentId original intent identifier
* @param intentKey original intent identifier
* @return compiled installable intents
*/
@Deprecated
default List<Intent> getInstallableIntents(IntentId intentId) {
throw new UnsupportedOperationException("deprecated");
default List<Intent> getInstallableIntents(Key intentKey) {
throw new UnsupportedOperationException("getInstallableIntents()");
}
/**
......@@ -92,7 +79,8 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
* @param key key
* @return intent or null if not found
*/
default Intent getIntent(Key key) { //FIXME remove when impl.
default Intent getIntent(Key key) {
// FIXME remove this default implementation when all stores have implemented it
return null;
}
......
......@@ -196,18 +196,18 @@ public class FakeIntentManager implements TestableIntentService {
}
@Override
public Intent getIntent(IntentId id) {
return intents.get(id);
public Intent getIntent(Key intentKey) {
return intents.get(intentKey);
}
@Override
public IntentState getIntentState(IntentId id) {
return intentStates.get(id);
public IntentState getIntentState(Key intentKey) {
return intentStates.get(intentKey);
}
@Override
public List<Intent> getInstallableIntents(IntentId intentId) {
return installables.get(intentId);
public List<Intent> getInstallableIntents(Key intentKey) {
return installables.get(intentKey);
}
@Override
......
......@@ -43,17 +43,17 @@ public class IntentServiceAdapter implements IntentService {
}
@Override
public Intent getIntent(IntentId id) {
public Intent getIntent(Key intentKey) {
return null;
}
@Override
public IntentState getIntentState(IntentId id) {
public IntentState getIntentState(Key intentKey) {
return null;
}
@Override
public List<Intent> getInstallableIntents(IntentId intentId) {
public List<Intent> getInstallableIntents(Key intentKey) {
return null;
}
......
......@@ -91,7 +91,7 @@ public class IntentServiceTest {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.INSTALLED,
service.getIntentState(intent.id()));
service.getIntentState(intent.key()));
}
});
......@@ -112,7 +112,7 @@ public class IntentServiceTest {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.WITHDRAWN,
service.getIntentState(intent.id()));
service.getIntentState(intent.key()));
}
});
......@@ -140,7 +140,7 @@ public class IntentServiceTest {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.FAILED,
service.getIntentState(intent.id()));
service.getIntentState(intent.key()));
}
});
......@@ -163,7 +163,7 @@ public class IntentServiceTest {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.FAILED,
service.getIntentState(intent.id()));
service.getIntentState(intent.key()));
}
});
......@@ -255,7 +255,7 @@ public class IntentServiceTest {
@Override
public void run() {
assertEquals("incorrect intent state", IntentState.INSTALLED,
service.getIntentState(intent.id()));
service.getIntentState(intent.key()));
}
});
......
......@@ -40,13 +40,13 @@ import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentException;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentInstaller;
import org.onosproject.net.intent.IntentListener;
import org.onosproject.net.intent.IntentService;
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.slf4j.Logger;
import java.util.ArrayList;
......@@ -81,7 +81,7 @@ public class IntentManager
private static final Logger log = getLogger(IntentManager.class);
public static final String INTENT_NULL = "Intent cannot be null";
public static final String INTENT_ID_NULL = "Intent ID cannot be null";
public static final String INTENT_ID_NULL = "Intent key cannot be null";
private static final int NUM_THREADS = 12;
......@@ -163,6 +163,11 @@ public class IntentManager
}
@Override
public Intent getIntent(Key key) {
return store.getIntent(key);
}
@Override
public Iterable<Intent> getIntents() {
return store.getIntents();
}
......@@ -173,21 +178,15 @@ public class IntentManager
}
@Override
public Intent getIntent(IntentId id) {
checkNotNull(id, INTENT_ID_NULL);
return store.getIntent(id);
}
@Override
public IntentState getIntentState(IntentId id) {
checkNotNull(id, INTENT_ID_NULL);
return store.getIntentState(id);
public IntentState getIntentState(Key intentKey) {
checkNotNull(intentKey, INTENT_ID_NULL);
return store.getIntentState(intentKey);
}
@Override
public List<Intent> getInstallableIntents(IntentId intentId) {
checkNotNull(intentId, INTENT_ID_NULL);
return store.getInstallableIntents(intentId);
public List<Intent> getInstallableIntents(Key intentKey) {
checkNotNull(intentKey, INTENT_ID_NULL);
return store.getInstallableIntents(intentKey);
}
@Override
......@@ -446,11 +445,11 @@ public class IntentManager
}
}
private void buildAndSubmitBatches(Iterable<IntentId> intentIds,
private void buildAndSubmitBatches(Iterable<Key> intentKeys,
boolean compileAllFailed) {
// Attempt recompilation of the specified intents first.
for (IntentId id : intentIds) {
Intent intent = store.getIntent(id);
for (Key key : intentKeys) {
Intent intent = store.getIntent(key);
if (intent == null) {
continue;
}
......@@ -460,7 +459,7 @@ public class IntentManager
if (compileAllFailed) {
// If required, compile all currently failed intents.
for (Intent intent : getIntents()) {
IntentState state = getIntentState(intent.id());
IntentState state = getIntentState(intent.key());
if (RECOMPILE.contains(state)) {
if (state == WITHDRAW_REQ) {
withdraw(intent);
......@@ -482,9 +481,9 @@ public class IntentManager
// Topology change delegate
private class InternalTopoChangeDelegate implements TopologyChangeDelegate {
@Override
public void triggerCompile(Iterable<IntentId> intentIds,
public void triggerCompile(Iterable<Key> intentKeys,
boolean compileAllFailed) {
buildAndSubmitBatches(intentIds, compileAllFailed);
buildAndSubmitBatches(intentKeys, compileAllFailed);
}
}
......
......@@ -29,8 +29,8 @@ import org.onosproject.event.Event;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.resource.LinkResourceEvent;
import org.onosproject.net.resource.LinkResourceListener;
......@@ -65,8 +65,8 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
private final Logger log = getLogger(getClass());
private final SetMultimap<LinkKey, IntentId> intentsByLink =
synchronizedSetMultimap(HashMultimap.<LinkKey, IntentId>create());
private final SetMultimap<LinkKey, Key> intentsByLink =
synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyService topologyService;
......@@ -126,21 +126,21 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
}
@Override
public void addTrackedResources(IntentId intentId,
public void addTrackedResources(Key intentKey,
Collection<NetworkResource> resources) {
for (NetworkResource resource : resources) {
if (resource instanceof Link) {
intentsByLink.put(linkKey((Link) resource), intentId);
intentsByLink.put(linkKey((Link) resource), intentKey);
}
}
}
@Override
public void removeTrackedResources(IntentId intentId,
public void removeTrackedResources(Key intentKey,
Collection<NetworkResource> resources) {
for (NetworkResource resource : resources) {
if (resource instanceof Link) {
intentsByLink.remove(linkKey((Link) resource), intentId);
intentsByLink.remove(linkKey((Link) resource), intentKey);
}
}
}
......@@ -170,10 +170,10 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
}
if (event.reasons() == null || event.reasons().isEmpty()) {
delegate.triggerCompile(new HashSet<IntentId>(), true);
delegate.triggerCompile(new HashSet<Key>(), true);
} else {
Set<IntentId> toBeRecompiled = new HashSet<>();
Set<Key> toBeRecompiled = new HashSet<>();
boolean recompileOnly = true;
// Scan through the list of reasons and keep accruing all
......@@ -186,9 +186,9 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
linkEvent.subject().isDurable())) {
final LinkKey linkKey = linkKey(linkEvent.subject());
synchronized (intentsByLink) {
Set<IntentId> intentIds = intentsByLink.get(linkKey);
log.debug("recompile triggered by LinkDown {} {}", linkKey, intentIds);
toBeRecompiled.addAll(intentIds);
Set<Key> intentKeys = intentsByLink.get(linkKey);
log.debug("recompile triggered by LinkDown {} {}", linkKey, intentKeys);
toBeRecompiled.addAll(intentKeys);
}
}
recompileOnly = recompileOnly &&
......@@ -243,15 +243,15 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
}
intentService.getIntents().forEach(intent -> {
if (intent.appId().equals(appId)) {
IntentId id = intent.id();
Key key = intent.key();
Collection<NetworkResource> resources = Lists.newArrayList();
intentService.getInstallableIntents(id).stream()
intentService.getInstallableIntents(key).stream()
.map(installable -> installable.resources())
.forEach(resources::addAll);
if (track) {
addTrackedResources(id, resources);
addTrackedResources(key, resources);
} else {
removeTrackedResources(id, resources);
removeTrackedResources(key, resources);
}
}
});
......
......@@ -15,11 +15,11 @@
*/
package org.onosproject.net.intent.impl;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.IntentId;
import java.util.Collection;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.Key;
/**
* Auxiliary service for tracking intent path flows and for notifying the
* intent service of environment changes via topology change delegate.
......@@ -43,19 +43,20 @@ public interface ObjectiveTrackerService {
/**
* Adds a path flow to be tracked.
*
* @param intentId intent identity on whose behalf the path is being tracked
* @param intentKey intent identity on whose behalf the path is being tracked
* @param resources resources to track
*/
public void addTrackedResources(IntentId intentId,
// TODO consider using the IntentData here rather than just the key
public void addTrackedResources(Key intentKey,
Collection<NetworkResource> resources);
/**
* Removes a path flow to be tracked.
*
* @param intentId intent identity on whose behalf the path is being tracked
* @param intentKey intent identity on whose behalf the path is being tracked
* @param resources resources to stop tracking
*/
public void removeTrackedResources(IntentId intentId,
public void removeTrackedResources(Key intentKey,
Collection<NetworkResource> resources);
}
......
......@@ -15,7 +15,7 @@
*/
package org.onosproject.net.intent.impl;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.Key;
/**
* Auxiliary delegate for integration of intent manager and flow trackerService.
......@@ -32,6 +32,6 @@ public interface TopologyChangeDelegate {
* @param compileAllFailed true implies full compile of all failed intents
* is required; false for selective recompile only
*/
void triggerCompile(Iterable<IntentId> intentIds, boolean compileAllFailed);
void triggerCompile(Iterable<Key> intentIds, boolean compileAllFailed);
}
......
......@@ -45,6 +45,7 @@ import org.onosproject.net.intent.IntentListener;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.IntentTestsMocks;
import org.onosproject.net.intent.Key;
import org.onosproject.net.resource.LinkResourceAllocations;
import org.onosproject.store.trivial.impl.SimpleIntentStore;
......@@ -133,12 +134,12 @@ public class IntentManagerTest {
}
@Override
public void addTrackedResources(IntentId intentId, Collection<NetworkResource> resources) {
public void addTrackedResources(Key key, Collection<NetworkResource> resources) {
//TODO
}
@Override
public void removeTrackedResources(IntentId intentId, Collection<NetworkResource> resources) {
public void removeTrackedResources(Key key, Collection<NetworkResource> resources) {
//TODO
}
}
......@@ -294,7 +295,7 @@ public class IntentManagerTest {
// verify that all intents are parked and the batch operation is unblocked
Set<IntentState> parked = Sets.newHashSet(INSTALLED, WITHDRAWN, FAILED);
for (Intent i : service.getIntents()) {
IntentState state = service.getIntentState(i.id());
IntentState state = service.getIntentState(i.key());
assertTrue("Intent " + i.id() + " is in invalid state " + state,
parked.contains(state));
}
......
......@@ -32,7 +32,7 @@ import org.onosproject.event.Event;
import org.onosproject.net.Link;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.resource.LinkResourceEvent;
......@@ -49,6 +49,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.link;
/**
......@@ -99,13 +100,13 @@ public class ObjectiveTrackerTest {
static class TestTopologyChangeDelegate implements TopologyChangeDelegate {
CountDownLatch latch = new CountDownLatch(1);
List<IntentId> intentIdsFromEvent;
List<Key> intentIdsFromEvent;
boolean compileAllFailedFromEvent;
@Override
public void triggerCompile(Iterable<IntentId> intentIds,
public void triggerCompile(Iterable<Key> intentKeys,
boolean compileAllFailed) {
intentIdsFromEvent = Lists.newArrayList(intentIds);
intentIdsFromEvent = Lists.newArrayList(intentKeys);
compileAllFailedFromEvent = compileAllFailed;
latch.countDown();
}
......@@ -199,9 +200,9 @@ public class ObjectiveTrackerTest {
topology,
reasons);
final IntentId intentId = IntentId.valueOf(0x333L);
final Key key = Key.of(0x333L, APP_ID);
Collection<NetworkResource> resources = ImmutableSet.of(link);
tracker.addTrackedResources(intentId, resources);
tracker.addTrackedResources(key, resources);
listener.event(event);
assertThat(
......
......@@ -40,6 +40,7 @@ import org.onosproject.net.intent.IntentId;
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.store.AbstractStore;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.serializers.KryoSerializer;
......@@ -202,6 +203,10 @@ public class DistributedIntentStore
}
@Override
public Intent getIntent(Key intentKey) {
return null;
}
public Intent getIntent(IntentId intentId) {
Context timer = startTimer(getIntentTimer);
try {
......@@ -212,7 +217,10 @@ public class DistributedIntentStore
}
@Override
public IntentState getIntentState(IntentId id) {
public IntentState getIntentState(Key key) {
// TODO: either implement this or remove the class
return IntentState.FAILED;
/*
Context timer = startTimer(getIntentStateTimer);
try {
final IntentState localState = transientStates.get(id);
......@@ -223,6 +231,7 @@ public class DistributedIntentStore
} finally {
stopTimer(timer);
}
*/
}
private void verify(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {
......@@ -236,13 +245,17 @@ public class DistributedIntentStore
}
@Override
public List<Intent> getInstallableIntents(IntentId intentId) {
public List<Intent> getInstallableIntents(Key intentKey) {
// TODO: implement this or delete class
return null;
/*
Context timer = startTimer(getInstallableIntentsTimer);
try {
return installable.get(intentId);
} finally {
stopTimer(timer);
}
*/
}
protected String strIntentId(IntentId key) {
......
......@@ -137,18 +137,29 @@ public class GossipIntentStore
}
@Override
public Intent getIntent(Key intentKey) {
// TODO: Implement this
return null;
}
public Intent getIntent(IntentId intentId) {
return intents.get(intentId);
}
@Override
public IntentState getIntentState(IntentId intentId) {
return intentStates.get(intentId);
public IntentState getIntentState(Key intentKey) {
// TODO: implement this
return IntentState.FAILED;
}
@Override
public List<Intent> getInstallableIntents(IntentId intentId) {
public List<Intent> getInstallableIntents(Key intentKey) {
// TODO: implement this or delete class
return null;
/*
return installables.get(intentId);
*/
}
@Override
......@@ -225,11 +236,6 @@ public class GossipIntentStore
}
@Override
public Intent getIntent(Key key) {
return null; // TODO
}
@Override
public IntentData getIntentData(Key key) {
return null; // TODO
}
......
......@@ -46,6 +46,7 @@ import org.onosproject.net.intent.IntentId;
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.store.hz.AbstractHazelcastStore;
import org.onosproject.store.hz.SMap;
import org.onosproject.store.serializers.KryoNamespaces;
......@@ -209,6 +210,11 @@ public class HazelcastIntentStore
}
@Override
public Intent getIntent(Key intentKey) {
return null;
}
public Intent getIntent(IntentId intentId) {
Context timer = startTimer(getIntentTimer);
try {
......@@ -227,7 +233,10 @@ public class HazelcastIntentStore
}
@Override
public IntentState getIntentState(IntentId id) {
public IntentState getIntentState(Key key) {
// TODO: either implement this or remove this class
return IntentState.FAILED;
/*
Context timer = startTimer(getIntentStateTimer);
try {
final IntentState localState = transientStates.get(id);
......@@ -238,6 +247,7 @@ public class HazelcastIntentStore
} finally {
stopTimer(timer);
}
*/
}
private void verify(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {
......@@ -251,13 +261,18 @@ public class HazelcastIntentStore
}
@Override
public List<Intent> getInstallableIntents(IntentId intentId) {
public List<Intent> getInstallableIntents(Key intentKey) {
// TODO: implement this or delete class
return null;
/*
Context timer = startTimer(getInstallableIntentsTimer);
try {
return installable.get(intentId);
} finally {
stopTimer(timer);
}
*/
}
@Override
......
......@@ -25,7 +25,6 @@ import org.onosproject.net.intent.BatchWrite.Operation;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.IntentStore;
import org.onosproject.net.intent.IntentStoreDelegate;
......@@ -35,7 +34,6 @@ import org.slf4j.Logger;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -77,38 +75,23 @@ public class SimpleIntentStore
}
@Override
public Intent getIntent(IntentId intentId) {
for (IntentData data : current.values()) {
if (Objects.equals(data.intent().id(), intentId)) {
return data.intent();
}
}
return null;
public IntentState getIntentState(Key intentKey) {
IntentData data = current.get(intentKey);
return (data != null) ? data.state() : null;
}
@Override
public IntentState getIntentState(IntentId intentId) {
for (IntentData data : current.values()) {
if (Objects.equals(data.intent().id(), intentId)) {
return data.state();
}
}
public List<Intent> getInstallableIntents(Key intentKey) {
// TODO: implement this or delete class
return null;
}
@Override
public List<Intent> getInstallableIntents(IntentId intentId) {
/*
for (IntentData data : current.values()) {
if (Objects.equals(data.intent().id(), intentId)) {
return data.installables();
}
}
return null;
}
@Override
public IntentData getIntentData(Key key) {
return current.get(key);
*/
}
/*
......
......@@ -25,7 +25,6 @@ import org.onosproject.net.intent.BatchWrite.Operation;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.IntentStore;
import org.onosproject.net.intent.IntentStoreDelegate;
......@@ -35,7 +34,6 @@ import org.slf4j.Logger;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -76,38 +74,15 @@ public class SimpleIntentStore
}
@Override
public Intent getIntent(IntentId intentId) {
for (IntentData data : current.values()) {
if (Objects.equals(data.intent().id(), intentId)) {
return data.intent();
}
}
return null;
}
@Override
public IntentState getIntentState(IntentId intentId) {
for (IntentData data : current.values()) {
if (Objects.equals(data.intent().id(), intentId)) {
return data.state();
}
}
return null;
}
@Override
public List<Intent> getInstallableIntents(IntentId intentId) {
for (IntentData data : current.values()) {
if (Objects.equals(data.intent().id(), intentId)) {
return data.installables();
}
}
return null;
public IntentState getIntentState(Key intentKey) {
IntentData data = current.get(intentKey);
return (data != null) ? data.state() : null;
}
@Override
public IntentData getIntentData(Key key) {
return current.get(key);
public List<Intent> getInstallableIntents(Key intentKey) {
IntentData data = current.get(intentKey);
return (data != null) ? data.installables() : null;
}
/*
......
......@@ -24,8 +24,8 @@ import javax.ws.rs.core.Response;
import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.PointToPointIntent;
import com.fasterxml.jackson.databind.node.ObjectNode;
......@@ -54,15 +54,15 @@ public class IntentsWebResource extends AbstractWebResource {
/**
* Gets a single intent by Id.
*
* @param id Id to look up
* @param key Id to look up
* @return intent data
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
public Response getIntentById(@PathParam("id") long id) {
public Response getIntentById(@PathParam("id") String key) {
final Intent intent = nullIsNotFound(get(IntentService.class)
.getIntent(IntentId.valueOf(id)),
.getIntent(Key.of(key, null)),
INTENT_NOT_FOUND);
final ObjectNode root;
if (intent instanceof HostToHostIntent) {
......
......@@ -35,8 +35,8 @@ import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.IdGenerator;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
......@@ -339,7 +339,7 @@ public class IntentsResourceTest extends ResourceTest {
intents.add(intent);
expect(mockIntentService.getIntent(IntentId.valueOf(0)))
expect(mockIntentService.getIntent(Key.of(0, APP_ID)))
.andReturn(intent)
.anyTimes();
replay(mockIntentService);
......@@ -356,7 +356,7 @@ public class IntentsResourceTest extends ResourceTest {
@Test
public void testBadGet() {
expect(mockIntentService.getIntent(IntentId.valueOf(0)))
expect(mockIntentService.getIntent(Key.of(0, APP_ID)))
.andReturn(null)
.anyTimes();
replay(mockIntentService);
......
......@@ -110,7 +110,7 @@ public class TopologyViewIntentFilter {
// Search through all intents and see if they are relevant to our search.
for (Intent intent : sourceIntents) {
if (intentService.getIntentState(intent.id()) == INSTALLED) {
if (intentService.getIntentState(intent.key()) == INSTALLED) {
boolean isRelevant = false;
if (intent instanceof HostToHostIntent) {
isRelevant = isIntentRelevantToHosts((HostToHostIntent) intent, hosts) &&
......@@ -157,7 +157,7 @@ public class TopologyViewIntentFilter {
// Indicates whether the specified intent involves all of the given devices.
private boolean isIntentRelevantToDevices(Intent intent, Iterable<Device> devices) {
List<Intent> installables = intentService.getInstallableIntents(intent.id());
List<Intent> installables = intentService.getInstallableIntents(intent.key());
for (Device device : devices) {
if (!isIntentRelevantToDevice(installables, device)) {
return false;
......@@ -228,7 +228,7 @@ public class TopologyViewIntentFilter {
Link ccDst = getFirstLink(opticalIntent.getDst(), true);
for (Intent intent : intents) {
List<Intent> installables = intentService.getInstallableIntents(intent.id());
List<Intent> installables = intentService.getInstallableIntents(intent.key());
for (Intent installable : installables) {
if (installable instanceof PathIntent) {
List<Link> links = ((PathIntent) installable).path().links();
......
......@@ -672,7 +672,7 @@ public abstract class TopologyViewMessages {
for (TrafficClass trafficClass : trafficClasses) {
for (Intent intent : trafficClass.intents) {
boolean isOptical = intent instanceof OpticalConnectivityIntent;
List<Intent> installables = intentService.getInstallableIntents(intent.id());
List<Intent> installables = intentService.getInstallableIntents(intent.key());
if (installables != null) {
for (Intent installable : installables) {
String type = isOptical ? trafficClass.type + " optical" : trafficClass.type;
......