Search in sources :

Example 6 with ErrorData

use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.

the class FlowTopologyTest method errorFlowUpdateMessageStatusBoltTopologyEngineBoltTest.

@Test
public void errorFlowUpdateMessageStatusBoltTopologyEngineBoltTest() throws Exception {
    String flowId = UUID.randomUUID().toString();
    ConsumerRecord<String, String> record;
    createFlow(flowId);
    record = cacheConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    updateFlow(flowId);
    record = cacheConsumer.pollMessage();
    assertNotNull(record);
    InfoMessage message = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(message);
    ImmutablePair<Flow, Flow> flow = getFlowPayload(message);
    assertNotNull(flow);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage infoMessageUp = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(infoMessageUp);
    FlowStatusResponse infoDataUp = (FlowStatusResponse) infoMessageUp.getData();
    assertNotNull(infoDataUp);
    FlowIdStatusPayload flowNbPayloadUp = infoDataUp.getPayload();
    assertNotNull(flowNbPayloadUp);
    assertEquals(flowId, flowNbPayloadUp.getId());
    assertEquals(FlowState.ALLOCATED, flowNbPayloadUp.getStatus());
    errorFlowTopologyEngineCommand(flowId, ErrorType.UPDATE_FAILURE);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    ErrorMessage errorMessage = objectMapper.readValue(record.value(), ErrorMessage.class);
    assertNotNull(errorMessage);
    ErrorData errorData = errorMessage.getData();
    assertEquals(ErrorType.UPDATE_FAILURE, errorData.getErrorType());
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(infoMessage);
    FlowStatusResponse response = (FlowStatusResponse) infoMessage.getData();
    assertNotNull(response);
    FlowIdStatusPayload flowNbPayload = response.getPayload();
    assertNotNull(flowNbPayload);
    assertEquals(flowId, flowNbPayload.getId());
    assertEquals(FlowState.DOWN, flowNbPayload.getStatus());
}
Also used : FlowStatusResponse(org.openkilda.messaging.info.flow.FlowStatusResponse) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) InfoMessage(org.openkilda.messaging.info.InfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Flow(org.openkilda.messaging.model.Flow) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 7 with ErrorData

use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.

the class BasicService method validateInfoMessage.

/**
 * Validates info message.
 *
 * @param correlationId  request correlation id
 * @param commandMessage request command message
 * @param message        response info message
 * @return parsed response InfoData
 */
default InfoData validateInfoMessage(final CommandMessage commandMessage, final Message message, final String correlationId) {
    InfoData data;
    if (message != null) {
        if (message instanceof ErrorMessage) {
            ErrorData error = ((ErrorMessage) message).getData();
            logger.error("Response message is error: {}={}, command={}, error={}", CORRELATION_ID, correlationId, commandMessage, error);
            throw new MessageException(error.getErrorType(), message.getTimestamp());
        } else if (message instanceof InfoMessage) {
            InfoMessage info = (InfoMessage) message;
            data = info.getData();
            if (data == null) {
                logger.error("Response message data is empty: {}={}, command={}, info={}", CORRELATION_ID, correlationId, commandMessage, info);
                throw new MessageException(INTERNAL_ERROR, message.getTimestamp());
            }
        } else {
            logger.error("Response message type is unexpected: {}:{}, command={}, message={}", CORRELATION_ID, correlationId, commandMessage, message);
            throw new MessageException(INTERNAL_ERROR, message.getTimestamp());
        }
    } else {
        logger.error("Response message is empty: {}={}, command={}", CORRELATION_ID, correlationId, commandMessage);
        throw new MessageException(INTERNAL_ERROR, System.currentTimeMillis());
    }
    return data;
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 8 with ErrorData

use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.

the class AbstractSerializerTest method errorMessageTest.

@Test
public void errorMessageTest() throws IOException, ClassNotFoundException {
    ErrorData data = new ErrorData(ErrorType.AUTH_FAILED, FLOW_NAME, "Bad credentials");
    System.out.println(data);
    ErrorMessage info = new ErrorMessage(data, System.currentTimeMillis(), CORRELATION_ID, DESTINATION);
    info.setData(data);
    serialize(info);
    Message message = (Message) deserialize();
    assertTrue(message instanceof ErrorMessage);
    ErrorMessage resultInfo = (ErrorMessage) message;
    assertTrue(resultInfo.getData() != null);
    ErrorData resultData = resultInfo.getData();
    System.out.println(resultData);
    assertEquals(data, resultData);
    assertEquals(data.hashCode(), resultData.hashCode());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData) Test(org.junit.Test)

Example 9 with ErrorData

use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.

the class BasicService method validateInfoMessage.

/**
 * Validates info message.
 *
 * @param correlationId     request correlation id
 * @param requestMessage    request command message
 * @param responseMessage   response info message
 * @return parsed response InfoData
 */
default InfoData validateInfoMessage(final Message requestMessage, final Message responseMessage, final String correlationId) {
    InfoData data;
    if (responseMessage != null) {
        if (responseMessage instanceof ErrorMessage) {
            ErrorData error = ((ErrorMessage) responseMessage).getData();
            logger.error("Response message is error: {}={}, command={}, error={}", CORRELATION_ID, correlationId, requestMessage, error);
            throw new MessageException((ErrorMessage) responseMessage);
        } else if (responseMessage instanceof InfoMessage) {
            InfoMessage info = (InfoMessage) responseMessage;
            data = info.getData();
            if (data == null) {
                String errorMessage = "Response message data is empty";
                logger.error("{}: {}={}, command={}, info={}", errorMessage, CORRELATION_ID, correlationId, requestMessage, info);
                throw new MessageException(responseMessage.getCorrelationId(), responseMessage.getTimestamp(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
            }
        } else {
            String errorMessage = "Response message type is unexpected";
            logger.error("{}: {}:{}, command={}, message={}", errorMessage, CORRELATION_ID, correlationId, requestMessage, responseMessage);
            throw new MessageException(responseMessage.getCorrelationId(), responseMessage.getTimestamp(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
        }
    } else {
        String errorMessage = "Response message is empty";
        logger.error("{}: {}={}, command={}", errorMessage, CORRELATION_ID, correlationId, requestMessage);
        throw new MessageException(DEFAULT_CORRELATION_ID, System.currentTimeMillis(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
    }
    return data;
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 10 with ErrorData

use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.

the class RecordHandler method doInstallSwitchRules.

private void doInstallSwitchRules(final CommandMessage message, String replyToTopic, Destination replyDestination) {
    SwitchRulesInstallRequest request = (SwitchRulesInstallRequest) message.getData();
    logger.debug("Installing rules on '{}' switch: action={}", request.getSwitchId(), request.getInstallRulesAction());
    DatapathId dpid = DatapathId.of(request.getSwitchId());
    ISwitchManager switchManager = context.getSwitchManager();
    InstallRulesAction installAction = request.getInstallRulesAction();
    List<Long> installedRules = new ArrayList<>();
    try {
        if (installAction == InstallRulesAction.INSTALL_DROP) {
            switchManager.installDropFlow(dpid);
            installedRules.add(ISwitchManager.DROP_RULE_COOKIE);
        } else if (installAction == InstallRulesAction.INSTALL_BROADCAST) {
            switchManager.installVerificationRule(dpid, true);
            installedRules.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
        } else if (installAction == InstallRulesAction.INSTALL_UNICAST) {
            // TODO: this isn't always added (ie if OF1.2). Is there a better response?
            switchManager.installVerificationRule(dpid, false);
            installedRules.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
        } else {
            switchManager.installDefaultRules(dpid);
            installedRules.addAll(asList(ISwitchManager.DROP_RULE_COOKIE, ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE, ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE));
        }
        SwitchRulesResponse response = new SwitchRulesResponse(installedRules);
        InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
        context.getKafkaProducer().postMessage(replyToTopic, infoMessage);
    } catch (SwitchOperationException e) {
        ErrorData errorData = new ErrorData(ErrorType.CREATION_FAILURE, e.getMessage(), request.getSwitchId());
        ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
        context.getKafkaProducer().postMessage(replyToTopic, error);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) InstallRulesAction(org.openkilda.messaging.command.switches.InstallRulesAction) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) DatapathId(org.projectfloodlight.openflow.types.DatapathId) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Aggregations

ErrorData (org.openkilda.messaging.error.ErrorData)18 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)18 Test (org.junit.Test)11 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)10 InfoMessage (org.openkilda.messaging.info.InfoMessage)8 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)2 SwitchOperationException (org.openkilda.floodlight.switchmanager.SwitchOperationException)2 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)2 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)2 MessageException (org.openkilda.messaging.error.MessageException)2 InfoData (org.openkilda.messaging.info.InfoData)2 FlowStatusResponse (org.openkilda.messaging.info.flow.FlowStatusResponse)2 SwitchRulesResponse (org.openkilda.messaging.info.switches.SwitchRulesResponse)2 Flow (org.openkilda.messaging.model.Flow)2 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)2 DatapathId (org.projectfloodlight.openflow.types.DatapathId)2 Message (org.openkilda.messaging.Message)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 DeleteRulesAction (org.openkilda.messaging.command.switches.DeleteRulesAction)1 InstallRulesAction (org.openkilda.messaging.command.switches.InstallRulesAction)1