use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class YFlowReadBolt method handleInput.
protected void handleInput(Tuple input) throws Exception {
String requestId = getCommandContext().getCorrelationId();
CommandData request = pullValue(input, FIELD_ID_PAYLOAD, CommandData.class);
try {
if (request instanceof YFlowsDumpRequest) {
List<YFlowResponse> result = processYFlowDumpRequest();
emitMessages(input, requestId, result);
} else if (request instanceof YFlowReadRequest) {
YFlowResponse result = processYFlowReadRequest((YFlowReadRequest) request);
emitMessage(input, requestId, result);
} else if (request instanceof YFlowPathsReadRequest) {
YFlowPathsResponse result = processYFlowPathsReadRequest((YFlowPathsReadRequest) request);
emitMessage(input, requestId, result);
} else if (request instanceof SubFlowsReadRequest) {
SubFlowsResponse result = processSubFlowsReadRequest((SubFlowsReadRequest) request);
emitMessage(input, requestId, result);
} else {
unhandledInput(input);
}
} catch (MessageException e) {
ErrorData errorData = new ErrorData(e.getErrorType(), e.getMessage(), e.getErrorDescription());
Message message = new ErrorMessage(errorData, System.currentTimeMillis(), requestId);
emit(input, new Values(requestId, message));
}
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class YFlowUpdateHubBolt method onRequest.
@Override
protected void onRequest(Tuple input) throws PipelineException {
currentKey = pullKey(input);
CommandData payload = pullValue(input, FIELD_ID_PAYLOAD, CommandData.class);
try {
if (payload instanceof YFlowRequest) {
yflowUpdateService.handleRequest(currentKey, pullContext(input), (YFlowRequest) payload);
} else if (payload instanceof YFlowPartialUpdateRequest) {
yflowUpdateService.handlePartialUpdateRequest(currentKey, pullContext(input), (YFlowPartialUpdateRequest) payload);
} else {
unhandledInput(input);
}
} catch (DuplicateKeyException e) {
log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
} catch (FlowProcessingException e) {
ErrorData errorData = new ErrorData(e.getErrorType(), "Y-flow update error", e.getMessage());
CommandContext commandContext = getCommandContext();
ErrorMessage errorMessage = new ErrorMessage(errorData, commandContext.getCreateTime(), commandContext.getCorrelationId());
sendNorthboundResponse(errorMessage);
}
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class FlowValidationHubServiceTest method testTimeout.
@Test
public void testTimeout() throws DuplicateKeyException, UnknownKeyException {
FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {
@Override
public void sendSpeakerRequest(String flowId, CommandData commandData) {
assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
if (commandData instanceof DumpRulesForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
} else if (commandData instanceof DumpMetersForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
} else {
assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
}
}
@Override
public void sendNorthboundResponse(List<? extends InfoData> message) {
fail();
}
@Override
public void sendNorthboundResponse(Message message) {
assertEquals(ErrorType.OPERATION_TIMED_OUT, ((ErrorMessage) message).getData().getErrorType());
}
@Override
public void cancelTimeoutCallback(String key) {
assertEquals(TEST_KEY, key);
}
@Override
public void sendInactive() {
}
};
flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
buildTransitVlanFlow("");
flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
flowValidationHubService.handleTimeout(TEST_KEY);
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class FlowValidationHubServiceTest method testFlowNotFoundError.
@Test
public void testFlowNotFoundError() throws DuplicateKeyException, UnknownKeyException {
FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {
@Override
public void sendSpeakerRequest(String flowId, CommandData commandData) {
assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
if (commandData instanceof DumpRulesForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
} else if (commandData instanceof DumpMetersForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
} else {
assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
}
}
@Override
public void sendNorthboundResponse(List<? extends InfoData> message) {
fail();
}
@Override
public void sendNorthboundResponse(Message message) {
assertEquals(ErrorType.NOT_FOUND, ((ErrorMessage) message).getData().getErrorType());
}
@Override
public void cancelTimeoutCallback(String key) {
assertEquals(TEST_KEY, key);
}
@Override
public void sendInactive() {
}
};
flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
buildTransitVlanFlow("");
flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest("test"));
flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
transactionManager.doInTransaction(() -> flowRepository.remove(flowRepository.findById(TEST_FLOW_ID_A).get()));
for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
}
for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
}
for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
}
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class FlowStateCacheBolt method handleInput.
@Override
protected void handleInput(Tuple input) throws PipelineException {
if (active) {
if (ComponentId.TICK_BOLT.name().equals(input.getSourceComponent())) {
flowStateCacheService.getFlows().forEach(flowId -> emit(input, new Values(flowId, getCommandContext())));
return;
}
if (FLOW_UPDATE_STREAM_ID.name().equals(input.getSourceStreamId())) {
CommandData payload = pullValue(input, COMMAND_DATA_FIELD, CommandData.class);
if (payload instanceof UpdateFlowCommand) {
UpdateFlowCommand updateFlowCommand = (UpdateFlowCommand) payload;
flowStateCacheService.updateFlow(updateFlowCommand);
emit(FLOW_UPDATE_STREAM_ID.name(), input, new Values(updateFlowCommand.getFlowId(), updateFlowCommand, getCommandContext()));
} else {
unhandledInput(input);
}
return;
}
if (FLOW_REMOVE_STREAM_ID.name().equals(input.getSourceStreamId())) {
String flowId = pullValue(input, FLOW_ID_FIELD, String.class);
flowStateCacheService.removeFlow(flowId);
emit(FLOW_REMOVE_STREAM_ID.name(), input, new Values(flowId, getCommandContext()));
} else {
unhandledInput(input);
}
}
}
Aggregations