mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 09:51:38 +02:00
Fix for ONOS-5417:Issue with Creating Flows using POST flows REST API
Change-Id: Ie608f2ef0447fc8c2a73f46df0e5b195c333fcbf (cherry picked from commit 3565ca6f5b2b46ee2fe9b93aa7d0ea4df592830b)
This commit is contained in:
parent
cf527d1c7a
commit
dba61119d1
@ -116,13 +116,14 @@ public class FlowsWebResource extends AbstractWebResource {
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response createFlows(@QueryParam("appId") String appId, InputStream stream) {
|
public Response createFlows(@QueryParam("appId") String appId, InputStream stream) {
|
||||||
try {
|
try {
|
||||||
|
final ApplicationService appService = get(ApplicationService.class);
|
||||||
|
final ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
|
||||||
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
|
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
|
||||||
ArrayNode flowsArray = nullIsIllegal((ArrayNode) jsonTree.get(FLOWS),
|
ArrayNode flowsArray = nullIsIllegal((ArrayNode) jsonTree.get(FLOWS),
|
||||||
FLOW_ARRAY_REQUIRED);
|
FLOW_ARRAY_REQUIRED);
|
||||||
|
|
||||||
if (appId != null) {
|
flowsArray.forEach(flowJson -> ((ObjectNode) flowJson).put("appId", idInstant.name()));
|
||||||
flowsArray.forEach(flowJson -> ((ObjectNode) flowJson).put("appId", appId));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<FlowRule> rules = codec(FlowRule.class).decode(flowsArray, this);
|
List<FlowRule> rules = codec(FlowRule.class).decode(flowsArray, this);
|
||||||
|
|
||||||
@ -253,6 +254,8 @@ public class FlowsWebResource extends AbstractWebResource {
|
|||||||
@QueryParam("appId") String appId,
|
@QueryParam("appId") String appId,
|
||||||
InputStream stream) {
|
InputStream stream) {
|
||||||
try {
|
try {
|
||||||
|
final ApplicationService appService = get(ApplicationService.class);
|
||||||
|
final ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
|
||||||
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
|
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
|
||||||
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
|
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
|
||||||
if (specifiedDeviceId != null &&
|
if (specifiedDeviceId != null &&
|
||||||
@ -262,9 +265,7 @@ public class FlowsWebResource extends AbstractWebResource {
|
|||||||
}
|
}
|
||||||
jsonTree.put("deviceId", deviceId);
|
jsonTree.put("deviceId", deviceId);
|
||||||
|
|
||||||
if (appId != null) {
|
jsonTree.put("appId", idInstant.name());
|
||||||
jsonTree.put("appId", appId);
|
|
||||||
}
|
|
||||||
|
|
||||||
FlowRule rule = codec(FlowRule.class).decode(jsonTree, this);
|
FlowRule rule = codec(FlowRule.class).decode(jsonTree, this);
|
||||||
service.applyFlowRules(rule);
|
service.applyFlowRules(rule);
|
||||||
|
@ -33,7 +33,6 @@ import org.onlab.rest.BaseResource;
|
|||||||
import org.onosproject.app.ApplicationService;
|
import org.onosproject.app.ApplicationService;
|
||||||
import org.onosproject.codec.CodecService;
|
import org.onosproject.codec.CodecService;
|
||||||
import org.onosproject.codec.impl.CodecManager;
|
import org.onosproject.codec.impl.CodecManager;
|
||||||
import org.onosproject.codec.impl.FlowRuleCodec;
|
|
||||||
import org.onosproject.core.CoreService;
|
import org.onosproject.core.CoreService;
|
||||||
import org.onosproject.core.DefaultGroupId;
|
import org.onosproject.core.DefaultGroupId;
|
||||||
import org.onosproject.core.GroupId;
|
import org.onosproject.core.GroupId;
|
||||||
@ -46,7 +45,6 @@ import org.onosproject.net.flow.DefaultTrafficSelector;
|
|||||||
import org.onosproject.net.flow.DefaultTrafficTreatment;
|
import org.onosproject.net.flow.DefaultTrafficTreatment;
|
||||||
import org.onosproject.net.flow.FlowEntry;
|
import org.onosproject.net.flow.FlowEntry;
|
||||||
import org.onosproject.net.flow.FlowId;
|
import org.onosproject.net.flow.FlowId;
|
||||||
import org.onosproject.net.flow.FlowRule.FlowRemoveReason;
|
|
||||||
import org.onosproject.net.flow.FlowRule;
|
import org.onosproject.net.flow.FlowRule;
|
||||||
import org.onosproject.net.flow.FlowRuleExtPayLoad;
|
import org.onosproject.net.flow.FlowRuleExtPayLoad;
|
||||||
import org.onosproject.net.flow.FlowRuleService;
|
import org.onosproject.net.flow.FlowRuleService;
|
||||||
@ -404,7 +402,7 @@ public class FlowsResourceTest extends ResourceTest {
|
|||||||
.andReturn(NetTestTools.APP_ID).anyTimes();
|
.andReturn(NetTestTools.APP_ID).anyTimes();
|
||||||
expect(mockCoreService.getAppId(anyString()))
|
expect(mockCoreService.getAppId(anyString()))
|
||||||
.andReturn(NetTestTools.APP_ID).anyTimes();
|
.andReturn(NetTestTools.APP_ID).anyTimes();
|
||||||
expect(mockCoreService.registerApplication(FlowRuleCodec.REST_APP_ID))
|
expect(mockCoreService.registerApplication(anyString()))
|
||||||
.andReturn(APP_ID).anyTimes();
|
.andReturn(APP_ID).anyTimes();
|
||||||
replay(mockCoreService);
|
replay(mockCoreService);
|
||||||
|
|
||||||
@ -880,8 +878,6 @@ public class FlowsResourceTest extends ResourceTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testPostWithoutAppId() {
|
public void testPostWithoutAppId() {
|
||||||
mockFlowService.applyFlowRules(anyObject());
|
|
||||||
expectLastCall();
|
|
||||||
replay(mockFlowService);
|
replay(mockFlowService);
|
||||||
|
|
||||||
WebTarget wt = target();
|
WebTarget wt = target();
|
||||||
@ -891,9 +887,7 @@ public class FlowsResourceTest extends ResourceTest {
|
|||||||
Response response = wt.path("flows/of:0000000000000001")
|
Response response = wt.path("flows/of:0000000000000001")
|
||||||
.request(MediaType.APPLICATION_JSON_TYPE)
|
.request(MediaType.APPLICATION_JSON_TYPE)
|
||||||
.post(Entity.json(jsonStream));
|
.post(Entity.json(jsonStream));
|
||||||
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));
|
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NOT_FOUND));
|
||||||
String location = response.getLocation().getPath();
|
|
||||||
assertThat(location, Matchers.startsWith("/flows/of:0000000000000001/"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -905,6 +899,9 @@ public class FlowsResourceTest extends ResourceTest {
|
|||||||
expectLastCall();
|
expectLastCall();
|
||||||
replay(mockFlowService);
|
replay(mockFlowService);
|
||||||
|
|
||||||
|
expect(mockApplicationService.getId(anyObject())).andReturn(APP_ID).anyTimes();
|
||||||
|
replay(mockApplicationService);
|
||||||
|
|
||||||
WebTarget wt = target();
|
WebTarget wt = target();
|
||||||
InputStream jsonStream = FlowsResourceTest.class
|
InputStream jsonStream = FlowsResourceTest.class
|
||||||
.getResourceAsStream("post-flow.json");
|
.getResourceAsStream("post-flow.json");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user