Search in sources :

Example 1 with GetSwitchResponse

use of org.openkilda.messaging.nbtopology.response.GetSwitchResponse in project open-kilda by telstra.

the class SwitchServiceImpl method getSwitch.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<SwitchDto> getSwitch(SwitchId switchId) {
    logger.debug("Get one switch request");
    CommandMessage request = new CommandMessage(new GetSwitchRequest(switchId), System.currentTimeMillis(), RequestCorrelationId.getId());
    return messagingChannel.sendAndGetChunked(nbworkerTopic, request).thenApply(messages -> messages.stream().map(GetSwitchResponse.class::cast).map(GetSwitchResponse::getPayload).map(switchMapper::toSwitchDto).collect(Collectors.toList()).get(0));
}
Also used : GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) GetSwitchRequest(org.openkilda.messaging.nbtopology.request.GetSwitchRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with GetSwitchResponse

use of org.openkilda.messaging.nbtopology.response.GetSwitchResponse in project open-kilda by telstra.

the class SwitchOperationsService method getSwitch.

/**
 * Get switch by switch id.
 *
 * @param switchId switch id.
 */
public GetSwitchResponse getSwitch(SwitchId switchId) throws SwitchNotFoundException {
    Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
    switchRepository.detach(sw);
    return new GetSwitchResponse(sw);
}
Also used : GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) Switch(org.openkilda.model.Switch) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 3 with GetSwitchResponse

use of org.openkilda.messaging.nbtopology.response.GetSwitchResponse in project open-kilda by telstra.

the class SwitchOperationsBolt method updateSwitchUnderMaintenanceFlag.

private List<GetSwitchResponse> updateSwitchUnderMaintenanceFlag(UpdateSwitchUnderMaintenanceRequest request, Tuple tuple) {
    SwitchId switchId = request.getSwitchId();
    boolean underMaintenance = request.isUnderMaintenance();
    boolean evacuate = request.isEvacuate();
    Switch sw;
    try {
        sw = switchOperationsService.updateSwitchUnderMaintenanceFlag(switchId, underMaintenance);
    } catch (SwitchNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Switch was not found.");
    }
    if (underMaintenance && evacuate) {
        Collection<FlowPath> paths = flowOperationsService.getFlowPathsForSwitch(switchId);
        Set<IslEndpoint> affectedIslEndpoint = new HashSet<>(switchOperationsService.getSwitchIslEndpoints(switchId));
        String reason = format("evacuated due to switch maintenance %s", switchId);
        for (FlowRerouteRequest reroute : flowOperationsService.makeRerouteRequests(paths, affectedIslEndpoint, reason)) {
            CommandContext forkedContext = getCommandContext().fork(reroute.getFlowId());
            getOutput().emit(StreamType.REROUTE.toString(), tuple, new Values(reroute, forkedContext.getCorrelationId()));
        }
    }
    return Collections.singletonList(new GetSwitchResponse(sw));
}
Also used : IslEndpoint(org.openkilda.model.IslEndpoint) GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) Switch(org.openkilda.model.Switch) MessageException(org.openkilda.messaging.error.MessageException) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet)

Example 4 with GetSwitchResponse

use of org.openkilda.messaging.nbtopology.response.GetSwitchResponse in project open-kilda by telstra.

the class SwitchServiceImpl method updateSwitchUnderMaintenance.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<SwitchDto> updateSwitchUnderMaintenance(SwitchId switchId, UnderMaintenanceDto underMaintenanceDto) {
    String correlationId = RequestCorrelationId.getId();
    logger.debug("Update under maintenance flag for switch request processing");
    UpdateSwitchUnderMaintenanceRequest data = new UpdateSwitchUnderMaintenanceRequest(switchId, underMaintenanceDto.isUnderMaintenance(), underMaintenanceDto.isEvacuate());
    CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId);
    return messagingChannel.sendAndGetChunked(nbworkerTopic, request).thenApply(messages -> messages.stream().map(GetSwitchResponse.class::cast).map(GetSwitchResponse::getPayload).map(switchMapper::toSwitchDto).collect(Collectors.toList()).get(0));
}
Also used : GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) UpdateSwitchUnderMaintenanceRequest(org.openkilda.messaging.nbtopology.request.UpdateSwitchUnderMaintenanceRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 5 with GetSwitchResponse

use of org.openkilda.messaging.nbtopology.response.GetSwitchResponse in project open-kilda by telstra.

the class SwitchServiceImpl method patchSwitch.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<SwitchDtoV2> patchSwitch(SwitchId switchId, SwitchPatchDto dto) {
    logger.info("Patch switch request for switch {}", switchId);
    CommandMessage request = new CommandMessage(new SwitchPatchRequest(switchId, switchMapper.map(dto)), System.currentTimeMillis(), RequestCorrelationId.getId());
    return messagingChannel.sendAndGet(nbworkerTopic, request).thenApply(GetSwitchResponse.class::cast).thenApply(GetSwitchResponse::getPayload).thenApply(switchMapper::map);
}
Also used : GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) SwitchPatchRequest(org.openkilda.messaging.nbtopology.request.SwitchPatchRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

GetSwitchResponse (org.openkilda.messaging.nbtopology.response.GetSwitchResponse)6 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 Switch (org.openkilda.model.Switch)2 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)2 HashSet (java.util.HashSet)1 Values (org.apache.storm.tuple.Values)1 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)1 MessageException (org.openkilda.messaging.error.MessageException)1 GetSwitchRequest (org.openkilda.messaging.nbtopology.request.GetSwitchRequest)1 GetSwitchesRequest (org.openkilda.messaging.nbtopology.request.GetSwitchesRequest)1 SwitchPatchRequest (org.openkilda.messaging.nbtopology.request.SwitchPatchRequest)1 UpdateSwitchUnderMaintenanceRequest (org.openkilda.messaging.nbtopology.request.UpdateSwitchUnderMaintenanceRequest)1 FlowPath (org.openkilda.model.FlowPath)1 IslEndpoint (org.openkilda.model.IslEndpoint)1 SwitchId (org.openkilda.model.SwitchId)1 CommandContext (org.openkilda.wfm.CommandContext)1