Search in sources :

Example 1 with UpdateSwitchPropertiesRequest

use of org.openkilda.messaging.nbtopology.request.UpdateSwitchPropertiesRequest in project open-kilda by telstra.

the class SwitchServiceImpl method updateSwitchProperties.

@Override
public CompletableFuture<SwitchPropertiesDto> updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto) {
    String correlationId = RequestCorrelationId.getId();
    logger.info("Update switch properties for the switch: {}, New properties: {}", switchId, switchPropertiesDto);
    if (switchPropertiesDto.getServer42Port() != null && switchPropertiesDto.getServer42Port() <= 0) {
        throw new MessageException(ErrorType.REQUEST_INVALID, format("Property 'server42_port' for switch %s has invalid value '%d'. Port must be positive", switchId, switchPropertiesDto.getServer42Port()), "Invalid server 42 Port");
    }
    if (switchPropertiesDto.getServer42Vlan() != null && (switchPropertiesDto.getServer42Vlan() < 0 || switchPropertiesDto.getServer42Vlan() > 4095)) {
        throw new MessageException(ErrorType.REQUEST_INVALID, format("Property 'server42_vlan' for switch %s has invalid value '%d'. Vlan must be in range [0, 4095]", switchId, switchPropertiesDto.getServer42Vlan()), "Invalid server 42 Vlan");
    }
    if (switchPropertiesDto.getServer42MacAddress() != null && !MacAddress.isValid(switchPropertiesDto.getServer42MacAddress())) {
        throw new MessageException(ErrorType.REQUEST_INVALID, format("Property 'server42_mac_address' for switch %s has invalid value '%s'.", switchId, switchPropertiesDto.getServer42MacAddress()), "Invalid server 42 Mac Address");
    }
    UpdateSwitchPropertiesRequest data = null;
    try {
        data = new UpdateSwitchPropertiesRequest(switchId, switchMapper.map(switchPropertiesDto));
        CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId);
        return messagingChannel.sendAndGet(nbworkerTopic, request).thenApply(SwitchPropertiesResponse.class::cast).thenApply(response -> switchMapper.map(response.getSwitchProperties()));
    } catch (IllegalArgumentException e) {
        throw new MessageException(ErrorType.REQUEST_INVALID, "Unable to parse request payload", e.getMessage());
    }
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) UpdateSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.UpdateSwitchPropertiesRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

CommandMessage (org.openkilda.messaging.command.CommandMessage)1 MessageException (org.openkilda.messaging.error.MessageException)1 UpdateSwitchPropertiesRequest (org.openkilda.messaging.nbtopology.request.UpdateSwitchPropertiesRequest)1