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));
}
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);
}
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));
}
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));
}
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);
}
Aggregations