Skip to content

Commit 7a74af8

Browse files
committed
Separate diversity request param into separate payload subclasses
1 parent 6603044 commit 7a74af8

File tree

7 files changed

+143
-15
lines changed

7 files changed

+143
-15
lines changed

services/src/functional-tests/src/test/groovy/org/openkilda/functionaltests/helpers/FlowHelper.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FlowHelper {
4747
List<FlowPayload> existingFlows = []) {
4848
Wrappers.retry(3, 0) {
4949
def newFlow = new FlowPayload(generateFlowName(), getFlowEndpoint(srcSwitch, useTraffgenPorts),
50-
getFlowEndpoint(dstSwitch, useTraffgenPorts), 500, false, false, "autotest flow", null,null, null)
50+
getFlowEndpoint(dstSwitch, useTraffgenPorts), 500, false, false, "autotest flow", null, null)
5151
if (flowConflicts(newFlow, existingFlows)) {
5252
throw new Exception("Generated flow conflicts with existing flows. Flow: $newFlow")
5353
}
@@ -67,7 +67,7 @@ class FlowHelper {
6767
allowedPorts = allowedPorts - srcEndpoint.portNumber //do not pick the same port as in src
6868
def dstEndpoint = getFlowEndpoint(sw, allowedPorts)
6969
return new FlowPayload(generateFlowName(), srcEndpoint, dstEndpoint, 500,
70-
false, false, "autotest flow", null, null, null)
70+
false, false, "autotest flow", null, null)
7171
}
7272

7373
/**
@@ -82,7 +82,7 @@ class FlowHelper {
8282
dstEndpoint.vlanId--
8383
}
8484
return new FlowPayload(generateFlowName(), srcEndpoint, dstEndpoint, 500,
85-
false, false, "autotest flow", null, null, null)
85+
false, false, "autotest flow", null, null)
8686
}
8787

8888
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Copyright 2019 Telstra Open Source
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package org.openkilda.messaging.payload.flow;
17+
18+
import org.openkilda.messaging.Utils;
19+
20+
import com.fasterxml.jackson.annotation.JsonCreator;
21+
import com.fasterxml.jackson.annotation.JsonInclude;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import lombok.Data;
24+
import lombok.EqualsAndHashCode;
25+
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
@JsonInclude(JsonInclude.Include.NON_NULL)
29+
public class FlowCreatePayload extends FlowPayload {
30+
31+
@JsonProperty("diverse-flowid")
32+
private String diverseFlowId;
33+
34+
/**
35+
* Instance constructor.
36+
*
37+
* @param id flow id
38+
* @param source flow source
39+
* @param destination flow destination
40+
* @param maximumBandwidth flow maximum bandwidth
41+
* @param ignoreBandwidth should ignore bandwidth in path computation
42+
* @param periodicPings enable periodic flow pings
43+
* @param description flow description
44+
* @param lastUpdated flow last updated timestamp
45+
* @param diverseFlowId make new flow diverse with FlowId
46+
* @param status flow status
47+
*/
48+
@JsonCreator
49+
public FlowCreatePayload(@JsonProperty(Utils.FLOW_ID) String id,
50+
@JsonProperty("source") FlowEndpointPayload source,
51+
@JsonProperty("destination") FlowEndpointPayload destination,
52+
@JsonProperty("maximum-bandwidth") long maximumBandwidth,
53+
@JsonProperty("ignore_bandwidth") Boolean ignoreBandwidth,
54+
@JsonProperty("periodic-pings") Boolean periodicPings,
55+
@JsonProperty("description") String description,
56+
@JsonProperty("last-updated") String lastUpdated,
57+
@JsonProperty("diverse-flowid") String diverseFlowId,
58+
@JsonProperty("status") String status) {
59+
super(id, source, destination, maximumBandwidth, ignoreBandwidth, periodicPings, description,
60+
lastUpdated, status);
61+
this.diverseFlowId = diverseFlowId;
62+
}
63+
}

services/src/messaging/src/main/java/org/openkilda/messaging/payload/flow/FlowPayload.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ public class FlowPayload implements Serializable {
6464
@JsonProperty("last-updated")
6565
private String lastUpdated;
6666

67-
// request only
68-
@JsonProperty("diverse-flowid")
69-
private String diverseFlowId;
70-
7167
@JsonProperty("status")
7268
private String status;
7369

@@ -79,8 +75,10 @@ public class FlowPayload implements Serializable {
7975
* @param destination flow destination
8076
* @param maximumBandwidth flow maximum bandwidth
8177
* @param ignoreBandwidth should ignore bandwidth in path computation
78+
* @param periodicPings enable periodic flow pings
8279
* @param description flow description
8380
* @param lastUpdated flow last updated timestamp
81+
* @param status flow status
8482
*/
8583
@Builder
8684
@JsonCreator
@@ -92,7 +90,6 @@ public FlowPayload(@JsonProperty(Utils.FLOW_ID) String id,
9290
@JsonProperty("periodic-pings") Boolean periodicPings,
9391
@JsonProperty("description") String description,
9492
@JsonProperty("last-updated") String lastUpdated,
95-
@JsonProperty("diverse-flowid") String diverseFlowId,
9693
@JsonProperty("status") String status) {
9794
setId(id);
9895
setSource(source);
@@ -108,7 +105,6 @@ public FlowPayload(@JsonProperty(Utils.FLOW_ID) String id,
108105

109106
this.description = description;
110107
this.lastUpdated = lastUpdated;
111-
this.diverseFlowId = diverseFlowId;
112108
this.status = status;
113109
}
114110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Copyright 2019 Telstra Open Source
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package org.openkilda.messaging.payload.flow;
17+
18+
import org.openkilda.messaging.Utils;
19+
20+
import com.fasterxml.jackson.annotation.JsonCreator;
21+
import com.fasterxml.jackson.annotation.JsonInclude;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import lombok.Data;
24+
import lombok.EqualsAndHashCode;
25+
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
@JsonInclude(JsonInclude.Include.NON_NULL)
29+
public class FlowUpdatePayload extends FlowPayload {
30+
31+
@JsonProperty("diverse-flowid")
32+
private String diverseFlowId;
33+
34+
/**
35+
* Instance constructor.
36+
*
37+
* @param id flow id
38+
* @param source flow source
39+
* @param destination flow destination
40+
* @param maximumBandwidth flow maximum bandwidth
41+
* @param ignoreBandwidth should ignore bandwidth in path computation
42+
* @param periodicPings enable periodic flow pings
43+
* @param description flow description
44+
* @param lastUpdated flow last updated timestamp
45+
* @param diverseFlowId make new flow diverse with FlowId
46+
* @param status flow status
47+
*/
48+
@JsonCreator
49+
public FlowUpdatePayload(@JsonProperty(Utils.FLOW_ID) String id,
50+
@JsonProperty("source") FlowEndpointPayload source,
51+
@JsonProperty("destination") FlowEndpointPayload destination,
52+
@JsonProperty("maximum-bandwidth") long maximumBandwidth,
53+
@JsonProperty("ignore_bandwidth") Boolean ignoreBandwidth,
54+
@JsonProperty("periodic-pings") Boolean periodicPings,
55+
@JsonProperty("description") String description,
56+
@JsonProperty("last-updated") String lastUpdated,
57+
@JsonProperty("diverse-flowid") String diverseFlowId,
58+
@JsonProperty("status") String status) {
59+
super(id, source, destination, maximumBandwidth, ignoreBandwidth, periodicPings, description,
60+
lastUpdated, status);
61+
this.diverseFlowId = diverseFlowId;
62+
}
63+
}

services/src/northbound/src/main/java/org/openkilda/northbound/controller/FlowController.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import org.openkilda.messaging.error.MessageError;
1919
import org.openkilda.messaging.info.flow.FlowInfoData;
2020
import org.openkilda.messaging.info.meter.FlowMeterEntries;
21+
import org.openkilda.messaging.payload.flow.FlowCreatePayload;
2122
import org.openkilda.messaging.payload.flow.FlowIdStatusPayload;
2223
import org.openkilda.messaging.payload.flow.FlowPathPayload;
2324
import org.openkilda.messaging.payload.flow.FlowPayload;
2425
import org.openkilda.messaging.payload.flow.FlowReroutePayload;
26+
import org.openkilda.messaging.payload.flow.FlowUpdatePayload;
2527
import org.openkilda.northbound.dto.BatchResults;
2628
import org.openkilda.northbound.dto.flows.FlowValidationDto;
2729
import org.openkilda.northbound.dto.flows.PingInput;
@@ -92,7 +94,7 @@ public class FlowController {
9294
@ApiOperation(value = "Creates new flow", response = FlowPayload.class)
9395
@PutMapping
9496
@ResponseStatus(HttpStatus.OK)
95-
public CompletableFuture<FlowPayload> createFlow(@RequestBody FlowPayload flow) {
97+
public CompletableFuture<FlowPayload> createFlow(@RequestBody FlowCreatePayload flow) {
9698
return flowService.createFlow(flow);
9799
}
98100

@@ -133,7 +135,7 @@ public CompletableFuture<FlowPayload> deleteFlow(@PathVariable(name = "flow-id")
133135
@PutMapping(value = "/{flow-id:.+}")
134136
@ResponseStatus(HttpStatus.OK)
135137
public CompletableFuture<FlowPayload> updateFlow(@PathVariable(name = "flow-id") String flowId,
136-
@RequestBody FlowPayload flow) {
138+
@RequestBody FlowUpdatePayload flow) {
137139
return flowService.updateFlow(flow);
138140
}
139141

services/src/northbound/src/main/java/org/openkilda/northbound/service/FlowService.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
import org.openkilda.messaging.info.flow.FlowInfoData;
1919
import org.openkilda.messaging.info.meter.FlowMeterEntries;
20+
import org.openkilda.messaging.payload.flow.FlowCreatePayload;
2021
import org.openkilda.messaging.payload.flow.FlowIdStatusPayload;
2122
import org.openkilda.messaging.payload.flow.FlowPathPayload;
2223
import org.openkilda.messaging.payload.flow.FlowPayload;
2324
import org.openkilda.messaging.payload.flow.FlowReroutePayload;
25+
import org.openkilda.messaging.payload.flow.FlowUpdatePayload;
2426
import org.openkilda.northbound.dto.BatchResults;
2527
import org.openkilda.northbound.dto.flows.FlowValidationDto;
2628
import org.openkilda.northbound.dto.flows.PingInput;
@@ -39,7 +41,7 @@ public interface FlowService {
3941
* @param flow flow
4042
* @return created flow
4143
*/
42-
CompletableFuture<FlowPayload> createFlow(final FlowPayload flow);
44+
CompletableFuture<FlowPayload> createFlow(final FlowCreatePayload flow);
4345

4446
/**
4547
* Deletes flow.
@@ -55,7 +57,7 @@ public interface FlowService {
5557
* @param flow flow
5658
* @return updated flow
5759
*/
58-
CompletableFuture<FlowPayload> updateFlow(final FlowPayload flow);
60+
CompletableFuture<FlowPayload> updateFlow(final FlowUpdatePayload flow);
5961

6062
/**
6163
* Gets flow by id.

services/src/northbound/src/main/java/org/openkilda/northbound/service/impl/FlowServiceImpl.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@
4545
import org.openkilda.messaging.info.rule.SwitchFlowEntries;
4646
import org.openkilda.messaging.model.BidirectionalFlowDto;
4747
import org.openkilda.messaging.model.FlowDto;
48+
import org.openkilda.messaging.payload.flow.FlowCreatePayload;
4849
import org.openkilda.messaging.payload.flow.FlowIdStatusPayload;
4950
import org.openkilda.messaging.payload.flow.FlowPathPayload;
5051
import org.openkilda.messaging.payload.flow.FlowPayload;
5152
import org.openkilda.messaging.payload.flow.FlowReroutePayload;
5253
import org.openkilda.messaging.payload.flow.FlowState;
54+
import org.openkilda.messaging.payload.flow.FlowUpdatePayload;
5355
import org.openkilda.model.Flow;
5456
import org.openkilda.model.FlowPath;
5557
import org.openkilda.model.SwitchId;
@@ -184,7 +186,7 @@ public int getConnectionPoolSize() {
184186
* {@inheritDoc}
185187
*/
186188
@Override
187-
public CompletableFuture<FlowPayload> createFlow(final FlowPayload input) {
189+
public CompletableFuture<FlowPayload> createFlow(final FlowCreatePayload input) {
188190
final String correlationId = RequestCorrelationId.getId();
189191
logger.info("Create flow: {}", input);
190192

@@ -214,7 +216,7 @@ public CompletableFuture<FlowPayload> getFlow(final String id) {
214216
* {@inheritDoc}
215217
*/
216218
@Override
217-
public CompletableFuture<FlowPayload> updateFlow(final FlowPayload input) {
219+
public CompletableFuture<FlowPayload> updateFlow(final FlowUpdatePayload input) {
218220
final String correlationId = RequestCorrelationId.getId();
219221
logger.info("Update flow request for flow {}", input.getId());
220222

0 commit comments

Comments
 (0)