Committed by
Gerrit Code Review
Allow to specify appId through FlowObjective REST API
Change-Id: Iadff74d379e1d5ec4f6e8ff2cda2ad96892d2cc1
Showing
10 changed files
with
74 additions
and
27 deletions
... | @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode; | ... | @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | import org.onosproject.codec.CodecContext; | 21 | import org.onosproject.codec.CodecContext; |
22 | import org.onosproject.codec.JsonCodec; | 22 | import org.onosproject.codec.JsonCodec; |
23 | -import org.onosproject.core.ApplicationId; | ||
24 | import org.onosproject.core.CoreService; | 23 | import org.onosproject.core.CoreService; |
25 | import org.onosproject.net.flow.TrafficTreatment; | 24 | import org.onosproject.net.flow.TrafficTreatment; |
26 | import org.onosproject.net.flow.criteria.Criterion; | 25 | import org.onosproject.net.flow.criteria.Criterion; |
... | @@ -37,7 +36,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -37,7 +36,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
37 | /** | 36 | /** |
38 | * Filtering Objective Codec. | 37 | * Filtering Objective Codec. |
39 | */ | 38 | */ |
40 | -public class FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { | 39 | +public final class FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { |
41 | private final Logger log = getLogger(getClass()); | 40 | private final Logger log = getLogger(getClass()); |
42 | 41 | ||
43 | // JSON field names | 42 | // JSON field names |
... | @@ -45,6 +44,7 @@ public class FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { | ... | @@ -45,6 +44,7 @@ public class FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { |
45 | private static final String TYPE = "type"; | 44 | private static final String TYPE = "type"; |
46 | private static final String KEY = "key"; | 45 | private static final String KEY = "key"; |
47 | private static final String META = "meta"; | 46 | private static final String META = "meta"; |
47 | + private static final String APP_ID = "appId"; | ||
48 | private static final String OPERATION = "operation"; | 48 | private static final String OPERATION = "operation"; |
49 | private static final String CONDITIONS = "conditions"; | 49 | private static final String CONDITIONS = "conditions"; |
50 | 50 | ||
... | @@ -118,9 +118,12 @@ public class FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { | ... | @@ -118,9 +118,12 @@ public class FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { |
118 | final DefaultFilteringObjective.Builder builder = | 118 | final DefaultFilteringObjective.Builder builder = |
119 | (DefaultFilteringObjective.Builder) och.decode(json, baseBuilder, context); | 119 | (DefaultFilteringObjective.Builder) och.decode(json, baseBuilder, context); |
120 | 120 | ||
121 | + | ||
122 | + | ||
121 | // application id | 123 | // application id |
122 | - ApplicationId appId = coreService.registerApplication(REST_APP_ID); | 124 | + JsonNode appIdJson = json.get(APP_ID); |
123 | - builder.fromApp(appId); | 125 | + String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID; |
126 | + builder.fromApp(coreService.registerApplication(appId)); | ||
124 | 127 | ||
125 | // decode type | 128 | // decode type |
126 | String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText(); | 129 | String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText(); | ... | ... |
... | @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | import org.onosproject.codec.CodecContext; | 20 | import org.onosproject.codec.CodecContext; |
21 | import org.onosproject.codec.JsonCodec; | 21 | import org.onosproject.codec.JsonCodec; |
22 | -import org.onosproject.core.ApplicationId; | ||
23 | import org.onosproject.core.CoreService; | 22 | import org.onosproject.core.CoreService; |
24 | import org.onosproject.net.flow.TrafficSelector; | 23 | import org.onosproject.net.flow.TrafficSelector; |
25 | import org.onosproject.net.flow.TrafficTreatment; | 24 | import org.onosproject.net.flow.TrafficTreatment; |
... | @@ -34,11 +33,12 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -34,11 +33,12 @@ import static org.slf4j.LoggerFactory.getLogger; |
34 | /** | 33 | /** |
35 | * Forwarding Objective Codec. | 34 | * Forwarding Objective Codec. |
36 | */ | 35 | */ |
37 | -public class ForwardingObjectiveCodec extends JsonCodec<ForwardingObjective> { | 36 | +public final class ForwardingObjectiveCodec extends JsonCodec<ForwardingObjective> { |
38 | private final Logger log = getLogger(getClass()); | 37 | private final Logger log = getLogger(getClass()); |
39 | 38 | ||
40 | // JSON field names | 39 | // JSON field names |
41 | private static final String ID = "id"; | 40 | private static final String ID = "id"; |
41 | + private static final String APP_ID = "appId"; | ||
42 | private static final String SELECTOR = "selector"; | 42 | private static final String SELECTOR = "selector"; |
43 | private static final String FLAG = "flag"; | 43 | private static final String FLAG = "flag"; |
44 | private static final String OPERATION = "operation"; | 44 | private static final String OPERATION = "operation"; |
... | @@ -116,8 +116,9 @@ public class ForwardingObjectiveCodec extends JsonCodec<ForwardingObjective> { | ... | @@ -116,8 +116,9 @@ public class ForwardingObjectiveCodec extends JsonCodec<ForwardingObjective> { |
116 | (DefaultForwardingObjective.Builder) och.decode(json, baseBuilder, context); | 116 | (DefaultForwardingObjective.Builder) och.decode(json, baseBuilder, context); |
117 | 117 | ||
118 | // application id | 118 | // application id |
119 | - ApplicationId appId = coreService.registerApplication(REST_APP_ID); | 119 | + JsonNode appIdJson = json.get(APP_ID); |
120 | - builder.fromApp(appId); | 120 | + String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID; |
121 | + builder.fromApp(coreService.registerApplication(appId)); | ||
121 | 122 | ||
122 | // decode flag | 123 | // decode flag |
123 | String flagStr = nullIsIllegal(json.get(FLAG), FLAG + MISSING_MEMBER_MESSAGE).asText(); | 124 | String flagStr = nullIsIllegal(json.get(FLAG), FLAG + MISSING_MEMBER_MESSAGE).asText(); | ... | ... |
... | @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode; | ... | @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | import org.onosproject.codec.CodecContext; | 21 | import org.onosproject.codec.CodecContext; |
22 | import org.onosproject.codec.JsonCodec; | 22 | import org.onosproject.codec.JsonCodec; |
23 | -import org.onosproject.core.ApplicationId; | ||
24 | import org.onosproject.core.CoreService; | 23 | import org.onosproject.core.CoreService; |
25 | import org.onosproject.net.flow.TrafficSelector; | 24 | import org.onosproject.net.flow.TrafficSelector; |
26 | import org.onosproject.net.flow.TrafficTreatment; | 25 | import org.onosproject.net.flow.TrafficTreatment; |
... | @@ -37,12 +36,13 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -37,12 +36,13 @@ import static org.slf4j.LoggerFactory.getLogger; |
37 | /** | 36 | /** |
38 | * Next Objective Codec. | 37 | * Next Objective Codec. |
39 | */ | 38 | */ |
40 | -public class NextObjectiveCodec extends JsonCodec<NextObjective> { | 39 | +public final class NextObjectiveCodec extends JsonCodec<NextObjective> { |
41 | 40 | ||
42 | private final Logger log = getLogger(getClass()); | 41 | private final Logger log = getLogger(getClass()); |
43 | 42 | ||
44 | // JSON field names | 43 | // JSON field names |
45 | private static final String ID = "id"; | 44 | private static final String ID = "id"; |
45 | + private static final String APP_ID = "appId"; | ||
46 | private static final String TYPE = "type"; | 46 | private static final String TYPE = "type"; |
47 | private static final String OPERATION = "operation"; | 47 | private static final String OPERATION = "operation"; |
48 | private static final String TREATMENTS = "treatments"; | 48 | private static final String TREATMENTS = "treatments"; |
... | @@ -121,8 +121,9 @@ public class NextObjectiveCodec extends JsonCodec<NextObjective> { | ... | @@ -121,8 +121,9 @@ public class NextObjectiveCodec extends JsonCodec<NextObjective> { |
121 | builder.withId(idJson.asInt()); | 121 | builder.withId(idJson.asInt()); |
122 | 122 | ||
123 | // decode application id | 123 | // decode application id |
124 | - ApplicationId appId = coreService.registerApplication(REST_APP_ID); | 124 | + JsonNode appIdJson = json.get(APP_ID); |
125 | - builder.fromApp(appId); | 125 | + String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID; |
126 | + builder.fromApp(coreService.registerApplication(appId)); | ||
126 | 127 | ||
127 | // decode type | 128 | // decode type |
128 | String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText(); | 129 | String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText(); | ... | ... |
... | @@ -21,7 +21,9 @@ import org.junit.Before; | ... | @@ -21,7 +21,9 @@ import org.junit.Before; |
21 | import org.junit.Test; | 21 | import org.junit.Test; |
22 | import org.onlab.packet.VlanId; | 22 | import org.onlab.packet.VlanId; |
23 | import org.onosproject.codec.JsonCodec; | 23 | import org.onosproject.codec.JsonCodec; |
24 | +import org.onosproject.core.ApplicationId; | ||
24 | import org.onosproject.core.CoreService; | 25 | import org.onosproject.core.CoreService; |
26 | +import org.onosproject.core.DefaultApplicationId; | ||
25 | import org.onosproject.net.flow.criteria.Criteria; | 27 | import org.onosproject.net.flow.criteria.Criteria; |
26 | import org.onosproject.net.flow.criteria.Criterion; | 28 | import org.onosproject.net.flow.criteria.Criterion; |
27 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; | 29 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
... | @@ -47,6 +49,7 @@ public class FilteringObjectiveCodecTest { | ... | @@ -47,6 +49,7 @@ public class FilteringObjectiveCodecTest { |
47 | MockCodecContext context; | 49 | MockCodecContext context; |
48 | JsonCodec<FilteringObjective> filteringObjectiveCodec; | 50 | JsonCodec<FilteringObjective> filteringObjectiveCodec; |
49 | final CoreService mockCoreService = createMock(CoreService.class); | 51 | final CoreService mockCoreService = createMock(CoreService.class); |
52 | + static final String SAMPLE_APP_ID = "org.onosproject.sample"; | ||
50 | 53 | ||
51 | /** | 54 | /** |
52 | * Sets up for each test. | 55 | * Sets up for each test. |
... | @@ -58,9 +61,6 @@ public class FilteringObjectiveCodecTest { | ... | @@ -58,9 +61,6 @@ public class FilteringObjectiveCodecTest { |
58 | filteringObjectiveCodec = context.codec(FilteringObjective.class); | 61 | filteringObjectiveCodec = context.codec(FilteringObjective.class); |
59 | assertThat(filteringObjectiveCodec, notNullValue()); | 62 | assertThat(filteringObjectiveCodec, notNullValue()); |
60 | 63 | ||
61 | - expect(mockCoreService.registerApplication(FilteringObjectiveCodec.REST_APP_ID)) | ||
62 | - .andReturn(APP_ID).anyTimes(); | ||
63 | - replay(mockCoreService); | ||
64 | context.registerService(CoreService.class, mockCoreService); | 64 | context.registerService(CoreService.class, mockCoreService); |
65 | } | 65 | } |
66 | 66 | ||
... | @@ -93,6 +93,12 @@ public class FilteringObjectiveCodecTest { | ... | @@ -93,6 +93,12 @@ public class FilteringObjectiveCodecTest { |
93 | */ | 93 | */ |
94 | @Test | 94 | @Test |
95 | public void testFilteringObjectiveDecode() throws IOException { | 95 | public void testFilteringObjectiveDecode() throws IOException { |
96 | + | ||
97 | + ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID); | ||
98 | + | ||
99 | + expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes(); | ||
100 | + replay(mockCoreService); | ||
101 | + | ||
96 | FilteringObjective filteringObjective = getFilteringObjective("FilteringObjective.json"); | 102 | FilteringObjective filteringObjective = getFilteringObjective("FilteringObjective.json"); |
97 | 103 | ||
98 | assertThat(filteringObjective.type(), is(FilteringObjective.Type.PERMIT)); | 104 | assertThat(filteringObjective.type(), is(FilteringObjective.Type.PERMIT)); | ... | ... |
... | @@ -21,7 +21,9 @@ import org.junit.Before; | ... | @@ -21,7 +21,9 @@ import org.junit.Before; |
21 | import org.junit.Test; | 21 | import org.junit.Test; |
22 | import org.onlab.packet.VlanId; | 22 | import org.onlab.packet.VlanId; |
23 | import org.onosproject.codec.JsonCodec; | 23 | import org.onosproject.codec.JsonCodec; |
24 | +import org.onosproject.core.ApplicationId; | ||
24 | import org.onosproject.core.CoreService; | 25 | import org.onosproject.core.CoreService; |
26 | +import org.onosproject.core.DefaultApplicationId; | ||
25 | import org.onosproject.net.flow.DefaultTrafficSelector; | 27 | import org.onosproject.net.flow.DefaultTrafficSelector; |
26 | import org.onosproject.net.flow.TrafficSelector; | 28 | import org.onosproject.net.flow.TrafficSelector; |
27 | import org.onosproject.net.flow.criteria.Criteria; | 29 | import org.onosproject.net.flow.criteria.Criteria; |
... | @@ -32,9 +34,7 @@ import org.onosproject.net.flowobjective.ForwardingObjective; | ... | @@ -32,9 +34,7 @@ import org.onosproject.net.flowobjective.ForwardingObjective; |
32 | import java.io.IOException; | 34 | import java.io.IOException; |
33 | import java.io.InputStream; | 35 | import java.io.InputStream; |
34 | 36 | ||
35 | -import static org.easymock.EasyMock.createMock; | 37 | +import static org.easymock.EasyMock.*; |
36 | -import static org.easymock.EasyMock.expect; | ||
37 | -import static org.easymock.EasyMock.replay; | ||
38 | import static org.hamcrest.MatcherAssert.assertThat; | 38 | import static org.hamcrest.MatcherAssert.assertThat; |
39 | import static org.hamcrest.Matchers.is; | 39 | import static org.hamcrest.Matchers.is; |
40 | import static org.hamcrest.Matchers.notNullValue; | 40 | import static org.hamcrest.Matchers.notNullValue; |
... | @@ -49,6 +49,7 @@ public class ForwardingObjectiveCodecTest { | ... | @@ -49,6 +49,7 @@ public class ForwardingObjectiveCodecTest { |
49 | MockCodecContext context; | 49 | MockCodecContext context; |
50 | JsonCodec<ForwardingObjective> forwardingObjectiveCodec; | 50 | JsonCodec<ForwardingObjective> forwardingObjectiveCodec; |
51 | final CoreService mockCoreService = createMock(CoreService.class); | 51 | final CoreService mockCoreService = createMock(CoreService.class); |
52 | + static final String SAMPLE_APP_ID = "org.onosproject.sample"; | ||
52 | 53 | ||
53 | /** | 54 | /** |
54 | * Sets up for each test. | 55 | * Sets up for each test. |
... | @@ -60,9 +61,6 @@ public class ForwardingObjectiveCodecTest { | ... | @@ -60,9 +61,6 @@ public class ForwardingObjectiveCodecTest { |
60 | forwardingObjectiveCodec = context.codec(ForwardingObjective.class); | 61 | forwardingObjectiveCodec = context.codec(ForwardingObjective.class); |
61 | assertThat(forwardingObjectiveCodec, notNullValue()); | 62 | assertThat(forwardingObjectiveCodec, notNullValue()); |
62 | 63 | ||
63 | - expect(mockCoreService.registerApplication(ForwardingObjectiveCodec.REST_APP_ID)) | ||
64 | - .andReturn(APP_ID).anyTimes(); | ||
65 | - replay(mockCoreService); | ||
66 | context.registerService(CoreService.class, mockCoreService); | 64 | context.registerService(CoreService.class, mockCoreService); |
67 | } | 65 | } |
68 | 66 | ||
... | @@ -97,6 +95,12 @@ public class ForwardingObjectiveCodecTest { | ... | @@ -97,6 +95,12 @@ public class ForwardingObjectiveCodecTest { |
97 | */ | 95 | */ |
98 | @Test | 96 | @Test |
99 | public void testForwardingObjectiveDecode() throws IOException { | 97 | public void testForwardingObjectiveDecode() throws IOException { |
98 | + | ||
99 | + ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID); | ||
100 | + | ||
101 | + expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes(); | ||
102 | + replay(mockCoreService); | ||
103 | + | ||
100 | ForwardingObjective forwardingObjective = getForwardingObjective("ForwardingObjective.json"); | 104 | ForwardingObjective forwardingObjective = getForwardingObjective("ForwardingObjective.json"); |
101 | 105 | ||
102 | assertThat(forwardingObjective.flag(), is(ForwardingObjective.Flag.SPECIFIC)); | 106 | assertThat(forwardingObjective.flag(), is(ForwardingObjective.Flag.SPECIFIC)); |
... | @@ -104,6 +108,7 @@ public class ForwardingObjectiveCodecTest { | ... | @@ -104,6 +108,7 @@ public class ForwardingObjectiveCodecTest { |
104 | assertThat(forwardingObjective.timeout(), is(1)); | 108 | assertThat(forwardingObjective.timeout(), is(1)); |
105 | assertThat(forwardingObjective.op(), is(ForwardingObjective.Operation.ADD)); | 109 | assertThat(forwardingObjective.op(), is(ForwardingObjective.Operation.ADD)); |
106 | assertThat(forwardingObjective.permanent(), is(false)); | 110 | assertThat(forwardingObjective.permanent(), is(false)); |
111 | + assertThat(forwardingObjective.appId().name(), is(SAMPLE_APP_ID)); | ||
107 | } | 112 | } |
108 | 113 | ||
109 | /** | 114 | /** | ... | ... |
... | @@ -20,7 +20,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode; | ... | @@ -20,7 +20,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | import org.junit.Before; | 20 | import org.junit.Before; |
21 | import org.junit.Test; | 21 | import org.junit.Test; |
22 | import org.onosproject.codec.JsonCodec; | 22 | import org.onosproject.codec.JsonCodec; |
23 | +import org.onosproject.core.ApplicationId; | ||
23 | import org.onosproject.core.CoreService; | 24 | import org.onosproject.core.CoreService; |
25 | +import org.onosproject.core.DefaultApplicationId; | ||
24 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 26 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
25 | import org.onosproject.net.flow.TrafficTreatment; | 27 | import org.onosproject.net.flow.TrafficTreatment; |
26 | import org.onosproject.net.flowobjective.DefaultNextObjective; | 28 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
... | @@ -46,6 +48,7 @@ public class NextObjectiveCodecTest { | ... | @@ -46,6 +48,7 @@ public class NextObjectiveCodecTest { |
46 | MockCodecContext context; | 48 | MockCodecContext context; |
47 | JsonCodec<NextObjective> nextObjectiveCodec; | 49 | JsonCodec<NextObjective> nextObjectiveCodec; |
48 | final CoreService mockCoreService = createMock(CoreService.class); | 50 | final CoreService mockCoreService = createMock(CoreService.class); |
51 | + static final String SAMPLE_APP_ID = "org.onosproject.sample"; | ||
49 | 52 | ||
50 | /** | 53 | /** |
51 | * Sets up for each test. | 54 | * Sets up for each test. |
... | @@ -57,9 +60,6 @@ public class NextObjectiveCodecTest { | ... | @@ -57,9 +60,6 @@ public class NextObjectiveCodecTest { |
57 | nextObjectiveCodec = context.codec(NextObjective.class); | 60 | nextObjectiveCodec = context.codec(NextObjective.class); |
58 | assertThat(nextObjectiveCodec, notNullValue()); | 61 | assertThat(nextObjectiveCodec, notNullValue()); |
59 | 62 | ||
60 | - expect(mockCoreService.registerApplication(NextObjectiveCodec.REST_APP_ID)) | ||
61 | - .andReturn(APP_ID).anyTimes(); | ||
62 | - replay(mockCoreService); | ||
63 | context.registerService(CoreService.class, mockCoreService); | 63 | context.registerService(CoreService.class, mockCoreService); |
64 | } | 64 | } |
65 | 65 | ||
... | @@ -89,6 +89,12 @@ public class NextObjectiveCodecTest { | ... | @@ -89,6 +89,12 @@ public class NextObjectiveCodecTest { |
89 | */ | 89 | */ |
90 | @Test | 90 | @Test |
91 | public void testNextObjectiveDecode() throws IOException { | 91 | public void testNextObjectiveDecode() throws IOException { |
92 | + | ||
93 | + ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID); | ||
94 | + | ||
95 | + expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes(); | ||
96 | + replay(mockCoreService); | ||
97 | + | ||
92 | NextObjective nextObjective = getNextObjective("NextObjective.json"); | 98 | NextObjective nextObjective = getNextObjective("NextObjective.json"); |
93 | 99 | ||
94 | assertThat(nextObjective.type(), is(NextObjective.Type.FAILOVER)); | 100 | assertThat(nextObjective.type(), is(NextObjective.Type.FAILOVER)); | ... | ... |
... | @@ -30,6 +30,7 @@ import javax.ws.rs.POST; | ... | @@ -30,6 +30,7 @@ import javax.ws.rs.POST; |
30 | import javax.ws.rs.Path; | 30 | import javax.ws.rs.Path; |
31 | import javax.ws.rs.PathParam; | 31 | import javax.ws.rs.PathParam; |
32 | import javax.ws.rs.Produces; | 32 | import javax.ws.rs.Produces; |
33 | +import javax.ws.rs.QueryParam; | ||
33 | import javax.ws.rs.core.Context; | 34 | import javax.ws.rs.core.Context; |
34 | import javax.ws.rs.core.MediaType; | 35 | import javax.ws.rs.core.MediaType; |
35 | import javax.ws.rs.core.Response; | 36 | import javax.ws.rs.core.Response; |
... | @@ -57,6 +58,7 @@ public class FlowObjectiveWebResource extends AbstractWebResource { | ... | @@ -57,6 +58,7 @@ public class FlowObjectiveWebResource extends AbstractWebResource { |
57 | /** | 58 | /** |
58 | * Creates and installs a new filtering objective for the specified device. | 59 | * Creates and installs a new filtering objective for the specified device. |
59 | * | 60 | * |
61 | + * @param appId application identifier | ||
60 | * @param deviceId device identifier | 62 | * @param deviceId device identifier |
61 | * @param stream filtering objective JSON | 63 | * @param stream filtering objective JSON |
62 | * @return status of the request - CREATED if the JSON is correct, | 64 | * @return status of the request - CREATED if the JSON is correct, |
... | @@ -67,12 +69,18 @@ public class FlowObjectiveWebResource extends AbstractWebResource { | ... | @@ -67,12 +69,18 @@ public class FlowObjectiveWebResource extends AbstractWebResource { |
67 | @Path("{deviceId}/filter") | 69 | @Path("{deviceId}/filter") |
68 | @Consumes(MediaType.APPLICATION_JSON) | 70 | @Consumes(MediaType.APPLICATION_JSON) |
69 | @Produces(MediaType.APPLICATION_JSON) | 71 | @Produces(MediaType.APPLICATION_JSON) |
70 | - public Response createFilteringObjective(@PathParam("deviceId") String deviceId, | 72 | + public Response createFilteringObjective(@QueryParam("appId") String appId, |
73 | + @PathParam("deviceId") String deviceId, | ||
71 | InputStream stream) { | 74 | InputStream stream) { |
72 | try { | 75 | try { |
73 | UriBuilder locationBuilder = null; | 76 | UriBuilder locationBuilder = null; |
74 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | 77 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
75 | if (validateDeviceId(deviceId, jsonTree)) { | 78 | if (validateDeviceId(deviceId, jsonTree)) { |
79 | + | ||
80 | + if (appId != null) { | ||
81 | + jsonTree.put("appId", appId); | ||
82 | + } | ||
83 | + | ||
76 | DeviceId did = DeviceId.deviceId(deviceId); | 84 | DeviceId did = DeviceId.deviceId(deviceId); |
77 | FilteringObjective filteringObjective = | 85 | FilteringObjective filteringObjective = |
78 | codec(FilteringObjective.class).decode(jsonTree, this); | 86 | codec(FilteringObjective.class).decode(jsonTree, this); |
... | @@ -94,6 +102,7 @@ public class FlowObjectiveWebResource extends AbstractWebResource { | ... | @@ -94,6 +102,7 @@ public class FlowObjectiveWebResource extends AbstractWebResource { |
94 | /** | 102 | /** |
95 | * Creates and installs a new forwarding objective for the specified device. | 103 | * Creates and installs a new forwarding objective for the specified device. |
96 | * | 104 | * |
105 | + * @param appId application identifier | ||
97 | * @param deviceId device identifier | 106 | * @param deviceId device identifier |
98 | * @param stream forwarding objective JSON | 107 | * @param stream forwarding objective JSON |
99 | * @return status of the request - CREATED if the JSON is correct, | 108 | * @return status of the request - CREATED if the JSON is correct, |
... | @@ -104,12 +113,18 @@ public class FlowObjectiveWebResource extends AbstractWebResource { | ... | @@ -104,12 +113,18 @@ public class FlowObjectiveWebResource extends AbstractWebResource { |
104 | @Path("{deviceId}/forward") | 113 | @Path("{deviceId}/forward") |
105 | @Consumes(MediaType.APPLICATION_JSON) | 114 | @Consumes(MediaType.APPLICATION_JSON) |
106 | @Produces(MediaType.APPLICATION_JSON) | 115 | @Produces(MediaType.APPLICATION_JSON) |
107 | - public Response createForwardingObjective(@PathParam("deviceId") String deviceId, | 116 | + public Response createForwardingObjective(@QueryParam("appId") String appId, |
117 | + @PathParam("deviceId") String deviceId, | ||
108 | InputStream stream) { | 118 | InputStream stream) { |
109 | try { | 119 | try { |
110 | UriBuilder locationBuilder = null; | 120 | UriBuilder locationBuilder = null; |
111 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | 121 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
112 | if (validateDeviceId(deviceId, jsonTree)) { | 122 | if (validateDeviceId(deviceId, jsonTree)) { |
123 | + | ||
124 | + if (appId != null) { | ||
125 | + jsonTree.put("appId", appId); | ||
126 | + } | ||
127 | + | ||
113 | DeviceId did = DeviceId.deviceId(deviceId); | 128 | DeviceId did = DeviceId.deviceId(deviceId); |
114 | ForwardingObjective forwardingObjective = | 129 | ForwardingObjective forwardingObjective = |
115 | codec(ForwardingObjective.class).decode(jsonTree, this); | 130 | codec(ForwardingObjective.class).decode(jsonTree, this); |
... | @@ -131,6 +146,7 @@ public class FlowObjectiveWebResource extends AbstractWebResource { | ... | @@ -131,6 +146,7 @@ public class FlowObjectiveWebResource extends AbstractWebResource { |
131 | /** | 146 | /** |
132 | * Creates and installs a new next objective for the specified device. | 147 | * Creates and installs a new next objective for the specified device. |
133 | * | 148 | * |
149 | + * @param appId application identifier | ||
134 | * @param deviceId device identifier | 150 | * @param deviceId device identifier |
135 | * @param stream next objective JSON | 151 | * @param stream next objective JSON |
136 | * @return status of the request - CREATED if the JSON is correct, | 152 | * @return status of the request - CREATED if the JSON is correct, |
... | @@ -141,12 +157,18 @@ public class FlowObjectiveWebResource extends AbstractWebResource { | ... | @@ -141,12 +157,18 @@ public class FlowObjectiveWebResource extends AbstractWebResource { |
141 | @Path("{deviceId}/next") | 157 | @Path("{deviceId}/next") |
142 | @Consumes(MediaType.APPLICATION_JSON) | 158 | @Consumes(MediaType.APPLICATION_JSON) |
143 | @Produces(MediaType.APPLICATION_JSON) | 159 | @Produces(MediaType.APPLICATION_JSON) |
144 | - public Response createNextObjective(@PathParam("deviceId") String deviceId, | 160 | + public Response createNextObjective(@QueryParam("appId") String appId, |
161 | + @PathParam("deviceId") String deviceId, | ||
145 | InputStream stream) { | 162 | InputStream stream) { |
146 | try { | 163 | try { |
147 | UriBuilder locationBuilder = null; | 164 | UriBuilder locationBuilder = null; |
148 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | 165 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
149 | if (validateDeviceId(deviceId, jsonTree)) { | 166 | if (validateDeviceId(deviceId, jsonTree)) { |
167 | + | ||
168 | + if (appId != null) { | ||
169 | + jsonTree.put("appId", appId); | ||
170 | + } | ||
171 | + | ||
150 | DeviceId did = DeviceId.deviceId(deviceId); | 172 | DeviceId did = DeviceId.deviceId(deviceId); |
151 | NextObjective nextObjective = | 173 | NextObjective nextObjective = |
152 | codec(NextObjective.class).decode(jsonTree, this); | 174 | codec(NextObjective.class).decode(jsonTree, this); | ... | ... |
-
Please register or login to post a comment