use of org.openkilda.messaging.command.flow.BaseInstallFlow in project open-kilda by telstra.
the class SpeakerBolt method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(Tuple tuple) {
String request = tuple.getString(0);
Values values = null;
try {
Message message = MAPPER.readValue(request, Message.class);
if (!Destination.WFM_TRANSACTION.equals(message.getDestination())) {
return;
}
logger.debug("Request tuple={}", tuple);
if (message instanceof CommandMessage) {
CommandData data = ((CommandMessage) message).getData();
if (data instanceof BaseInstallFlow) {
Long transactionId = ((BaseInstallFlow) data).getTransactionId();
String switchId = ((BaseInstallFlow) data).getSwitchId();
String flowId = ((BaseInstallFlow) data).getId();
logger.debug("Flow install message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
message.setDestination(Destination.TOPOLOGY_ENGINE);
values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
// FIXME(surabujin): looks like TE ignore this messages
outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
} else if (data instanceof RemoveFlow) {
Long transactionId = ((RemoveFlow) data).getTransactionId();
String switchId = ((RemoveFlow) data).getSwitchId();
String flowId = ((RemoveFlow) data).getId();
logger.debug("Flow remove message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
message.setDestination(Destination.TOPOLOGY_ENGINE);
values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
} else {
logger.debug("Skip undefined command message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} else if (message instanceof ErrorMessage) {
String flowId = ((ErrorMessage) message).getData().getErrorDescription();
FlowState status = FlowState.DOWN;
// TODO: Should add debug message if receiving ErrorMessage.
if (flowId != null) {
logger.error("Flow error message: {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), Utils.FLOW_ID, flowId, request);
values = new Values(flowId, status);
outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
} else {
logger.debug("Skip error message without flow-id: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} else {
// TODO: should this be a warn or error? Probably, after refactored / specific
// topics
logger.debug("Skip undefined message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} catch (IOException exception) {
logger.error("\n\nCould not deserialize message={}", request, exception);
} finally {
logger.debug("Speaker message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
outputCollector.ack(tuple);
}
}
use of org.openkilda.messaging.command.flow.BaseInstallFlow in project open-kilda by telstra.
the class TopologyEngineBolt method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(Tuple tuple) {
String request = tuple.getString(0);
Values values = null;
try {
Message message = MAPPER.readValue(request, Message.class);
if (!Destination.WFM.equals(message.getDestination())) {
return;
}
logger.debug("Request tuple={}", tuple);
if (message instanceof CommandMessage) {
CommandData data = ((CommandMessage) message).getData();
if (data instanceof BaseInstallFlow) {
BaseInstallFlow installData = (BaseInstallFlow) data;
Long transactionId = UUID.randomUUID().getLeastSignificantBits();
installData.setTransactionId(transactionId);
String switchId = installData.getSwitchId();
String flowId = installData.getId();
logger.debug("Flow install message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
// FIXME(surabujin): send here and in TE
message.setDestination(Destination.CONTROLLER);
values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
} else if (data instanceof RemoveFlow) {
RemoveFlow removeData = (RemoveFlow) data;
Long transactionId = UUID.randomUUID().getLeastSignificantBits();
removeData.setTransactionId(transactionId);
String switchId = removeData.getSwitchId();
String flowId = removeData.getId();
logger.debug("Flow remove message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
message.setDestination(Destination.CONTROLLER);
values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
} else {
logger.debug("Skip undefined command message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} else if (message instanceof InfoMessage) {
values = new Values(message);
logger.debug("Flow response message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
outputCollector.emit(StreamType.RESPONSE.toString(), tuple, values);
} else if (message instanceof ErrorMessage) {
String flowId = ((ErrorMessage) message).getData().getErrorDescription();
logger.error("Flow error message: {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), Utils.FLOW_ID, flowId, request);
values = new Values(message, flowId);
outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
} else {
logger.debug("Skip undefined message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} catch (IOException exception) {
logger.error("Could not deserialize message={}", request, exception);
} finally {
logger.debug("Topology-Engine message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
outputCollector.ack(tuple);
}
}
use of org.openkilda.messaging.command.flow.BaseInstallFlow in project open-kilda by telstra.
the class RecordHandler method doSyncRulesRequest.
/**
* Installs missed flows on the switch.
* @param message with list of flows.
*/
private void doSyncRulesRequest(final CommandMessage message) {
InstallMissedFlowsRequest request = (InstallMissedFlowsRequest) message.getData();
final String switchId = request.getSwitchId();
logger.debug("Processing rules to be updated for switch {}", switchId);
for (BaseInstallFlow command : request.getFlowCommands()) {
logger.debug("Processing command for switch {} {}", switchId, command);
try {
if (command instanceof InstallIngressFlow) {
installIngressFlow((InstallIngressFlow) command);
} else if (command instanceof InstallEgressFlow) {
installEgressFlow((InstallEgressFlow) command);
} else if (command instanceof InstallTransitFlow) {
installTransitFlow((InstallTransitFlow) command);
} else if (command instanceof InstallOneSwitchFlow) {
installOneSwitchFlow((InstallOneSwitchFlow) command);
}
} catch (SwitchOperationException e) {
logger.error("Error during flow installation", e);
}
}
}
use of org.openkilda.messaging.command.flow.BaseInstallFlow in project open-kilda by telstra.
the class CommandBuilderImpl method buildInstallCommandFromSegment.
private List<BaseInstallFlow> buildInstallCommandFromSegment(FlowPath flowPath, PathSegment segment, boolean switchRulesContainsFlowPathCookie, boolean switchRulesContainsMirrorCookie) {
if (segment.getSrcSwitchId().equals(segment.getDestSwitchId())) {
log.warn("One-switch flow segment {} is provided", flowPath.getCookie());
return new ArrayList<>();
}
Optional<Flow> foundFlow = flowRepository.findById(flowPath.getFlow().getFlowId());
if (!foundFlow.isPresent()) {
log.warn("Flow with id {} was not found", flowPath.getFlow().getFlowId());
return new ArrayList<>();
}
Flow flow = foundFlow.get();
EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
List<BaseInstallFlow> commands = new ArrayList<>();
if (switchRulesContainsMirrorCookie) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
commands.add(flowCommandFactory.buildInstallEgressMirrorFlow(flowPath, segment.getDestPort(), encapsulationResources, segment.isDestWithMultiTable(), mirrorConfig));
}
if (switchRulesContainsFlowPathCookie) {
commands.add(flowCommandFactory.buildInstallEgressFlow(flowPath, segment.getDestPort(), encapsulationResources, segment.isDestWithMultiTable()));
}
return commands;
} else {
int segmentIdx = flowPath.getSegments().indexOf(segment);
if (segmentIdx < 0 || segmentIdx + 1 == flowPath.getSegments().size()) {
log.warn("Paired segment for switch {} and cookie {} has not been found", segment.getDestSwitchId(), flowPath.getCookie());
return new ArrayList<>();
}
PathSegment foundPairedFlowSegment = flowPath.getSegments().get(segmentIdx + 1);
return Collections.singletonList(flowCommandFactory.buildInstallTransitFlow(flowPath, segment.getDestSwitchId(), segment.getDestPort(), foundPairedFlowSegment.getSrcPort(), encapsulationResources, segment.isDestWithMultiTable()));
}
}
use of org.openkilda.messaging.command.flow.BaseInstallFlow in project open-kilda by telstra.
the class FlowResource method installFlow.
/**
* Installing flow.
*
* @param json the json from request.
* @return json response.
* @throws JsonProcessingException if response can't be wrote to string.
*/
@Post("json")
@Put("json")
public String installFlow(String json) throws JsonProcessingException {
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
Message message;
try {
message = MAPPER.readValue(json, Message.class);
} catch (IOException exception) {
String messageString = "Received JSON is not valid for TPN";
logger.error("{}: {}", messageString, json, exception);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, exception.getMessage());
return MAPPER.writeValueAsString(responseMessage);
}
if (!(message instanceof CommandMessage)) {
String messageString = "Json payload message is not an instance of CommandMessage";
logger.error("{}: class={}, data={}", messageString, message.getClass().getCanonicalName(), json);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, message.getClass().getCanonicalName());
return MAPPER.writeValueAsString(responseMessage);
}
CommandMessage cmdMessage = (CommandMessage) message;
CommandData data = cmdMessage.getData();
if (!(data instanceof BaseInstallFlow)) {
String messageString = "Json payload data is not an instance of CommandData";
logger.error("{}: class={}, data={}", messageString, data.getClass().getCanonicalName(), json);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, data.getClass().getCanonicalName());
return MAPPER.writeValueAsString(responseMessage);
}
return MAPPER.writeValueAsString("ok");
}
Aggregations