Committed by
Brian O'Connor
REST API modifications to take application ID/Kep pair to fetch intents.
Change-Id: Icee85c6d801c92d94c6905f1d4316f63fea4e560 Reference: ONOS-1007
Showing
2 changed files
with
28 additions
and
10 deletions
... | @@ -22,6 +22,8 @@ import javax.ws.rs.Produces; | ... | @@ -22,6 +22,8 @@ import javax.ws.rs.Produces; |
22 | import javax.ws.rs.core.MediaType; | 22 | import javax.ws.rs.core.MediaType; |
23 | import javax.ws.rs.core.Response; | 23 | import javax.ws.rs.core.Response; |
24 | 24 | ||
25 | +import org.onosproject.core.ApplicationId; | ||
26 | +import org.onosproject.core.CoreService; | ||
25 | import org.onosproject.net.intent.HostToHostIntent; | 27 | import org.onosproject.net.intent.HostToHostIntent; |
26 | import org.onosproject.net.intent.Intent; | 28 | import org.onosproject.net.intent.Intent; |
27 | import org.onosproject.net.intent.IntentService; | 29 | import org.onosproject.net.intent.IntentService; |
... | @@ -54,16 +56,24 @@ public class IntentsWebResource extends AbstractWebResource { | ... | @@ -54,16 +56,24 @@ public class IntentsWebResource extends AbstractWebResource { |
54 | /** | 56 | /** |
55 | * Gets a single intent by Id. | 57 | * Gets a single intent by Id. |
56 | * | 58 | * |
57 | - * @param key Id to look up | 59 | + * @param appId the Application ID |
60 | + * @param key the Intent key value to look up | ||
58 | * @return intent data | 61 | * @return intent data |
59 | */ | 62 | */ |
60 | @GET | 63 | @GET |
61 | @Produces(MediaType.APPLICATION_JSON) | 64 | @Produces(MediaType.APPLICATION_JSON) |
62 | - @Path("{id}") | 65 | + @Path("{appId}/{key}") |
63 | - public Response getIntentById(@PathParam("id") String key) { | 66 | + public Response getIntentById(@PathParam("appId") Short appId, |
64 | - final Intent intent = nullIsNotFound(get(IntentService.class) | 67 | + @PathParam("key") String key) { |
65 | - .getIntent(Key.of(key, null)), | 68 | + final ApplicationId app = get(CoreService.class).getAppId(appId); |
66 | - INTENT_NOT_FOUND); | 69 | + |
70 | + Intent intent = get(IntentService.class).getIntent(Key.of(key, app)); | ||
71 | + if (intent == null) { | ||
72 | + intent = get(IntentService.class) | ||
73 | + .getIntent(Key.of(Long.valueOf(key), app)); | ||
74 | + } | ||
75 | + nullIsNotFound(intent, INTENT_NOT_FOUND); | ||
76 | + | ||
67 | final ObjectNode root; | 77 | final ObjectNode root; |
68 | if (intent instanceof HostToHostIntent) { | 78 | if (intent instanceof HostToHostIntent) { |
69 | root = codec(HostToHostIntent.class).encode((HostToHostIntent) intent, this); | 79 | root = codec(HostToHostIntent.class).encode((HostToHostIntent) intent, this); | ... | ... |
... | @@ -32,6 +32,7 @@ import org.onlab.rest.BaseResource; | ... | @@ -32,6 +32,7 @@ import org.onlab.rest.BaseResource; |
32 | import org.onosproject.codec.CodecService; | 32 | import org.onosproject.codec.CodecService; |
33 | import org.onosproject.codec.impl.CodecManager; | 33 | import org.onosproject.codec.impl.CodecManager; |
34 | import org.onosproject.core.ApplicationId; | 34 | import org.onosproject.core.ApplicationId; |
35 | +import org.onosproject.core.CoreService; | ||
35 | import org.onosproject.core.DefaultApplicationId; | 36 | import org.onosproject.core.DefaultApplicationId; |
36 | import org.onosproject.core.IdGenerator; | 37 | import org.onosproject.core.IdGenerator; |
37 | import org.onosproject.net.NetworkResource; | 38 | import org.onosproject.net.NetworkResource; |
... | @@ -63,6 +64,7 @@ import static org.junit.Assert.fail; | ... | @@ -63,6 +64,7 @@ import static org.junit.Assert.fail; |
63 | @Ignore | 64 | @Ignore |
64 | public class IntentsResourceTest extends ResourceTest { | 65 | public class IntentsResourceTest extends ResourceTest { |
65 | final IntentService mockIntentService = createMock(IntentService.class); | 66 | final IntentService mockIntentService = createMock(IntentService.class); |
67 | + final CoreService mockCoreService = createMock(CoreService.class); | ||
66 | final HashSet<Intent> intents = new HashSet<>(); | 68 | final HashSet<Intent> intents = new HashSet<>(); |
67 | private static final ApplicationId APP_ID = new DefaultApplicationId(1, "test"); | 69 | private static final ApplicationId APP_ID = new DefaultApplicationId(1, "test"); |
68 | private IdGenerator mockGenerator; | 70 | private IdGenerator mockGenerator; |
... | @@ -105,6 +107,7 @@ public class IntentsResourceTest extends ResourceTest { | ... | @@ -105,6 +107,7 @@ public class IntentsResourceTest extends ResourceTest { |
105 | this.id = id; | 107 | this.id = id; |
106 | } | 108 | } |
107 | 109 | ||
110 | + @Override | ||
108 | public String toString() { | 111 | public String toString() { |
109 | return "Resource " + Integer.toString(id); | 112 | return "Resource " + Integer.toString(id); |
110 | } | 113 | } |
... | @@ -260,14 +263,14 @@ public class IntentsResourceTest extends ResourceTest { | ... | @@ -260,14 +263,14 @@ public class IntentsResourceTest extends ResourceTest { |
260 | @Before | 263 | @Before |
261 | public void setUpTest() { | 264 | public void setUpTest() { |
262 | expect(mockIntentService.getIntents()).andReturn(intents).anyTimes(); | 265 | expect(mockIntentService.getIntents()).andReturn(intents).anyTimes(); |
263 | - | ||
264 | // Register the services needed for the test | 266 | // Register the services needed for the test |
265 | final CodecManager codecService = new CodecManager(); | 267 | final CodecManager codecService = new CodecManager(); |
266 | codecService.activate(); | 268 | codecService.activate(); |
267 | ServiceDirectory testDirectory = | 269 | ServiceDirectory testDirectory = |
268 | new TestServiceDirectory() | 270 | new TestServiceDirectory() |
269 | .add(IntentService.class, mockIntentService) | 271 | .add(IntentService.class, mockIntentService) |
270 | - .add(CodecService.class, codecService); | 272 | + .add(CodecService.class, codecService) |
273 | + .add(CoreService.class, mockCoreService); | ||
271 | 274 | ||
272 | BaseResource.setServiceDirectory(testDirectory); | 275 | BaseResource.setServiceDirectory(testDirectory); |
273 | 276 | ||
... | @@ -344,10 +347,15 @@ public class IntentsResourceTest extends ResourceTest { | ... | @@ -344,10 +347,15 @@ public class IntentsResourceTest extends ResourceTest { |
344 | expect(mockIntentService.getIntent(Key.of(0, APP_ID))) | 347 | expect(mockIntentService.getIntent(Key.of(0, APP_ID))) |
345 | .andReturn(intent) | 348 | .andReturn(intent) |
346 | .anyTimes(); | 349 | .anyTimes(); |
350 | + expect(mockIntentService.getIntent(Key.of("0", APP_ID))) | ||
351 | + .andReturn(intent) | ||
352 | + .anyTimes(); | ||
347 | replay(mockIntentService); | 353 | replay(mockIntentService); |
348 | - | 354 | + expect(mockCoreService.getAppId(APP_ID.id())) |
355 | + .andReturn(APP_ID).anyTimes(); | ||
356 | + replay(mockCoreService); | ||
349 | final WebResource rs = resource(); | 357 | final WebResource rs = resource(); |
350 | - final String response = rs.path("intents/0").get(String.class); | 358 | + final String response = rs.path("intents/1/0").get(String.class); |
351 | final JsonObject result = JsonObject.readFrom(response); | 359 | final JsonObject result = JsonObject.readFrom(response); |
352 | assertThat(result, matchesIntent(intent)); | 360 | assertThat(result, matchesIntent(intent)); |
353 | } | 361 | } | ... | ... |
-
Please register or login to post a comment