use of org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest in project open-kilda by telstra.
the class FlowMirrorPointCreateHubBolt method onRequest.
@Override
protected void onRequest(Tuple input) throws PipelineException {
currentKey = pullKey(input);
FlowMirrorPointCreateRequest payload = pullValue(input, FIELD_ID_PAYLOAD, FlowMirrorPointCreateRequest.class);
service.handleCreateMirrorPointRequest(currentKey, pullContext(input), payload);
}
use of org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest in project open-kilda by telstra.
the class FlowServiceImpl method createFlowMirrorPoint.
@Override
public CompletableFuture<FlowMirrorPointResponseV2> createFlowMirrorPoint(String flowId, FlowMirrorPointPayload payload) {
logger.info("Processing flow mirror point creation: {}, for flow {}", payload, flowId);
final String correlationId = RequestCorrelationId.getId();
FlowMirrorPointCreateRequest request;
try {
if (!payload.getMirrorPointId().matches("^[\\w-]{1,100}$")) {
throw new IllegalArgumentException("Mirror path ID can only consist of alphanumeric characters, " + "underscore, and hyphen. The length of this parameter must not exceed 100 characters.");
}
request = flowMapper.toFlowMirrorPointCreateRequest(flowId, payload);
} catch (IllegalArgumentException ex) {
throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID, ex.getMessage(), "Can not parse arguments of the mirror point create request");
}
CommandMessage command = new CommandMessage(request, System.currentTimeMillis(), correlationId);
return messagingChannel.sendAndGet(flowHsTopic, command).thenApply(FlowMirrorPointResponse.class::cast).thenApply(flowMapper::toFlowMirrorPointResponseV2);
}
use of org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest in project open-kilda by telstra.
the class RouterBolt method handleInput.
@Override
protected void handleInput(Tuple input) {
if (active) {
String key = input.getStringByField(FIELD_ID_KEY);
if (StringUtils.isBlank(key)) {
// TODO: the key must be unique, but the correlationId comes in from outside and we can't guarantee that.
// IMPORTANT: Storm may initiate reprocessing of the same tuple (e.g. in the case of timeout) and
// cause creating multiple FSMs for the same tuple. This must be avoided.
// As for now tuples are routed by the key field, and services can check FSM uniqueness.
key = getCommandContext().getCorrelationId();
}
CommandMessage message = (CommandMessage) input.getValueByField(FIELD_ID_PAYLOAD);
MessageData data = message.getData();
if (data instanceof FlowRequest) {
FlowRequest request = (FlowRequest) data;
log.debug("Received request {} with key {}", request, key);
Values values = new Values(key, request.getFlowId(), request);
switch(request.getType()) {
case CREATE:
emitWithContext(ROUTER_TO_FLOW_CREATE_HUB.name(), input, values);
break;
case UPDATE:
emitWithContext(ROUTER_TO_FLOW_UPDATE_HUB.name(), input, values);
break;
default:
throw new UnsupportedOperationException(format("Flow operation %s is not supported", request.getType()));
}
} else if (data instanceof FlowRerouteRequest) {
FlowRerouteRequest rerouteRequest = (FlowRerouteRequest) data;
log.debug("Received a reroute request {}/{} with key {}. MessageId {}", rerouteRequest.getFlowId(), rerouteRequest.getAffectedIsl(), key, input.getMessageId());
Values values = new Values(key, rerouteRequest.getFlowId(), data);
emitWithContext(ROUTER_TO_FLOW_REROUTE_HUB.name(), input, values);
} else if (data instanceof FlowDeleteRequest) {
FlowDeleteRequest deleteRequest = (FlowDeleteRequest) data;
log.debug("Received a delete request {} with key {}. MessageId {}", deleteRequest.getFlowId(), key, input.getMessageId());
Values values = new Values(key, deleteRequest.getFlowId(), data);
emitWithContext(ROUTER_TO_FLOW_DELETE_HUB.name(), input, values);
} else if (data instanceof FlowPathSwapRequest) {
FlowPathSwapRequest pathSwapRequest = (FlowPathSwapRequest) data;
log.debug("Received a path swap request {} with key {}. MessageId {}", pathSwapRequest.getFlowId(), key, input.getMessageId());
Values values = new Values(key, pathSwapRequest.getFlowId(), data);
emitWithContext(ROUTER_TO_FLOW_PATH_SWAP_HUB.name(), input, values);
} else if (data instanceof SwapFlowEndpointRequest) {
log.debug("Received a swap flow endpoints request with key {}. MessageId {}", key, input.getMessageId());
emitWithContext(ROUTER_TO_FLOW_SWAP_ENDPOINTS_HUB.name(), input, new Values(key, data));
} else if (data instanceof CreateFlowLoopRequest) {
log.debug("Received a create flow loop request with key {}. MessageId {}", key, input.getMessageId());
CreateFlowLoopRequest request = (CreateFlowLoopRequest) data;
emitWithContext(ROUTER_TO_FLOW_UPDATE_HUB.name(), input, new Values(key, request.getFlowId(), data));
} else if (data instanceof DeleteFlowLoopRequest) {
log.debug("Received a delete flow loop request with key {}. MessageId {}", key, input.getMessageId());
DeleteFlowLoopRequest request = (DeleteFlowLoopRequest) data;
emitWithContext(ROUTER_TO_FLOW_UPDATE_HUB.name(), input, new Values(key, request.getFlowId(), data));
} else if (data instanceof FlowMirrorPointCreateRequest) {
log.debug("Received a flow mirror point create request with key {}. MessageId {}", key, input.getMessageId());
FlowMirrorPointCreateRequest request = (FlowMirrorPointCreateRequest) data;
emitWithContext(ROUTER_TO_FLOW_CREATE_MIRROR_POINT_HUB.name(), input, new Values(key, request.getFlowId(), data));
} else if (data instanceof FlowMirrorPointDeleteRequest) {
log.debug("Received a flow mirror point delete request with key {}. MessageId {}", key, input.getMessageId());
FlowMirrorPointDeleteRequest request = (FlowMirrorPointDeleteRequest) data;
emitWithContext(ROUTER_TO_FLOW_DELETE_MIRROR_POINT_HUB.name(), input, new Values(key, request.getFlowId(), data));
} else if (data instanceof FlowValidationRequest) {
log.debug("Received a flow validation request with key {}. MessageId {}", key, input.getMessageId());
FlowValidationRequest request = (FlowValidationRequest) data;
emitWithContext(ROUTER_TO_FLOW_VALIDATION_HUB.name(), input, new Values(key, request.getFlowId(), data));
} else if (data instanceof YFlowRequest) {
YFlowRequest request = (YFlowRequest) data;
log.debug("Received request {} with key {}", request, key);
Values values = new Values(key, request.getYFlowId(), request);
switch(request.getType()) {
case CREATE:
emitWithContext(ROUTER_TO_YFLOW_CREATE_HUB.name(), input, values);
break;
case UPDATE:
emitWithContext(ROUTER_TO_YFLOW_UPDATE_HUB.name(), input, values);
break;
default:
throw new UnsupportedOperationException(format("Y-flow operation %s is not supported", request.getType()));
}
} else if (data instanceof YFlowPartialUpdateRequest) {
YFlowPartialUpdateRequest request = (YFlowPartialUpdateRequest) data;
log.debug("Received a y-flow partial update request {} with key {}", request, key);
emitWithContext(ROUTER_TO_YFLOW_UPDATE_HUB.name(), input, new Values(key, request.getYFlowId(), data));
} else if (data instanceof YFlowRerouteRequest) {
YFlowRerouteRequest request = (YFlowRerouteRequest) data;
log.debug("Received a y-flow reroute request {} with key {}", data, key);
emitWithContext(ROUTER_TO_YFLOW_REROUTE_HUB.name(), input, new Values(key, request.getYFlowId(), data));
} else if (data instanceof YFlowDeleteRequest) {
YFlowDeleteRequest request = (YFlowDeleteRequest) data;
log.debug("Received a y-flow delete request {} with key {}", request, key);
emitWithContext(ROUTER_TO_YFLOW_DELETE_HUB.name(), input, new Values(key, request.getYFlowId(), data));
} else if (data instanceof YFlowsDumpRequest) {
log.debug("Received a y-flow dump request {} with key {}", data, key);
emitWithContext(ROUTER_TO_YFLOW_READ.name(), input, new Values(key, data));
} else if (data instanceof YFlowReadRequest) {
log.debug("Received a y-flow read request {} with key {}", data, key);
emitWithContext(ROUTER_TO_YFLOW_READ.name(), input, new Values(key, data));
} else if (data instanceof YFlowPathsReadRequest) {
log.debug("Received a y-flow read path request {} with key {}", data, key);
emitWithContext(ROUTER_TO_YFLOW_READ.name(), input, new Values(key, data));
} else if (data instanceof SubFlowsReadRequest) {
log.debug("Received a y-flow sub-flows request {} with key {}", data, key);
emitWithContext(ROUTER_TO_YFLOW_READ.name(), input, new Values(key, data));
} else if (data instanceof YFlowValidationRequest) {
YFlowValidationRequest request = (YFlowValidationRequest) data;
log.debug("Received a y-flow validation request {} with key {}", request, key);
emitWithContext(ROUTER_TO_YFLOW_VALIDATION_HUB.name(), input, new Values(key, request.getYFlowId(), data));
} else if (data instanceof YFlowSyncRequest) {
YFlowSyncRequest request = (YFlowSyncRequest) data;
log.debug("Received a y-flow synchronization request {} with key {}", request, key);
YFlowRerouteRequest rerouteRequest = new YFlowRerouteRequest(request.getYFlowId(), emptySet(), true, "initiated via synchronization request", false);
emitWithContext(ROUTER_TO_YFLOW_REROUTE_HUB.name(), input, new Values(key, rerouteRequest.getYFlowId(), rerouteRequest));
} else {
unhandledInput(input);
}
}
}
use of org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest in project open-kilda by telstra.
the class RequestedFlowMirrorPointMapperTest method testFlowMirrorPointCreateRequestToRequestedFlowMirrorPoint.
@Test
public void testFlowMirrorPointCreateRequestToRequestedFlowMirrorPoint() {
FlowMirrorPointCreateRequest request = FlowMirrorPointCreateRequest.builder().flowId(FLOW_ID).mirrorPointId(MIRROR_POINT_ID).mirrorPointDirection(MIRROR_POINT_DIRECTION).mirrorPointSwitchId(MIRROR_POINT_SWITCH_ID).sinkEndpoint(FlowEndpoint.builder().switchId(RECEIVER_POINT_SWITCH_ID).portNumber(RECEIVER_POINT_PORT).outerVlanId(RECEIVER_POINT_OUTER_VLAN).innerVlanId(RECEIVER_POINT_INNER_VLAN).build()).build();
RequestedFlowMirrorPoint flowMirrorPoint = RequestedFlowMirrorPointMapper.INSTANCE.map(request);
assertEquals(request.getFlowId(), flowMirrorPoint.getFlowId());
assertEquals(request.getMirrorPointId(), flowMirrorPoint.getMirrorPointId());
assertEquals(MIRROR_POINT_DIRECTION, flowMirrorPoint.getMirrorPointDirection());
assertEquals(request.getMirrorPointSwitchId(), flowMirrorPoint.getMirrorPointSwitchId());
assertEquals(request.getSinkEndpoint(), flowMirrorPoint.getSinkEndpoint());
}
use of org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest in project open-kilda by telstra.
the class FlowMapperTest method testFlowMirrorPointCreatePayloadToFlowMirrorPointCreateRequest.
@Test
public void testFlowMirrorPointCreatePayloadToFlowMirrorPointCreateRequest() {
FlowMirrorPointPayload payload = FlowMirrorPointPayload.builder().mirrorPointId(MIRROR_POINT_ID_A).mirrorPointDirection(MIRROR_POINT_DIRECTION_A).mirrorPointSwitchId(SRC_SWITCH_ID).sinkEndpoint(new FlowEndpointV2(DST_SWITCH_ID, DST_PORT, DST_VLAN, DST_INNER_VLAN)).build();
FlowMirrorPointCreateRequest request = flowMapper.toFlowMirrorPointCreateRequest(FLOW_ID, payload);
assertEquals(FLOW_ID, request.getFlowId());
assertEquals(payload.getMirrorPointId(), request.getMirrorPointId());
assertEquals(payload.getMirrorPointDirection(), request.getMirrorPointDirection().toString().toLowerCase());
assertEquals(payload.getMirrorPointSwitchId(), request.getMirrorPointSwitchId());
assertEquals(payload.getSinkEndpoint().getSwitchId(), request.getSinkEndpoint().getSwitchId());
assertEquals(payload.getSinkEndpoint().getPortNumber(), request.getSinkEndpoint().getPortNumber());
assertEquals(payload.getSinkEndpoint().getVlanId(), request.getSinkEndpoint().getOuterVlanId());
assertEquals(payload.getSinkEndpoint().getInnerVlanId(), request.getSinkEndpoint().getInnerVlanId());
}
Aggregations