use of org.openkilda.messaging.nbtopology.request.LinkPropsPut in project open-kilda by telstra.
the class LinkOperationsBoltTest method shouldCreateLinkProps.
@Test
public void shouldCreateLinkProps() {
SwitchRepository switchRepository = persistenceManager.getRepositoryFactory().createSwitchRepository();
switchRepository.add(Switch.builder().switchId(SWITCH_ID_1).build());
switchRepository.add(Switch.builder().switchId(SWITCH_ID_2).build());
LinkOperationsBolt bolt = new LinkOperationsBolt(persistenceManager);
bolt.prepare(null, topologyContext, null);
LinkPropsPut linkPropsPutRequest = new LinkPropsPut(new LinkPropsDto(new NetworkEndpoint(SWITCH_ID_1, 1), new NetworkEndpoint(SWITCH_ID_2, 1), Collections.emptyMap()));
LinkPropsResponse response = (LinkPropsResponse) bolt.processRequest(null, linkPropsPutRequest).get(0);
assertNotNull(response.getLinkProps());
}
use of org.openkilda.messaging.nbtopology.request.LinkPropsPut in project open-kilda by telstra.
the class LinkServiceImpl method setLinkProps.
@Override
public CompletableFuture<BatchResults> setLinkProps(List<LinkPropsDto> linkPropsList) {
logger.debug("Link props \"SET\" request received (consists of {} records)", linkPropsList.size());
List<String> errors = new ArrayList<>();
List<CompletableFuture<?>> pendingRequest = new ArrayList<>(linkPropsList.size());
for (LinkPropsDto requestItem : linkPropsList) {
org.openkilda.messaging.model.LinkPropsDto linkProps;
try {
linkProps = linkPropsMapper.toLinkProps(requestItem);
} catch (IllegalArgumentException e) {
errors.add(e.getMessage());
continue;
}
LinkPropsPut commandRequest = new LinkPropsPut(linkProps);
String requestId = idFactory.produceChained(RequestCorrelationId.getId());
CommandMessage message = new CommandMessage(commandRequest, System.currentTimeMillis(), requestId);
pendingRequest.add(messagingChannel.sendAndGet(nbworkerTopic, message));
}
return collectResponses(pendingRequest, LinkPropsResponse.class).thenApply(responses -> getLinkPropsResult(responses, errors));
}
use of org.openkilda.messaging.nbtopology.request.LinkPropsPut in project open-kilda by telstra.
the class LinkServiceTest method putLinkProps.
@Test
public void putLinkProps() {
final String correlationId = getClass().getCanonicalName();
HashMap<String, String> requestProps = new HashMap<>();
requestProps.put("test", "value");
org.openkilda.messaging.model.LinkPropsDto linkProps = new org.openkilda.messaging.model.LinkPropsDto(new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:01"), 8), new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:02"), 9), requestProps);
LinkPropsRequest request = new LinkPropsPut(linkProps);
LinkPropsResponse payload = new LinkPropsResponse(request, linkProps, null);
String subCorrelationId = idFactory.produceChained(String.valueOf(requestIdIndex++), correlationId);
messageExchanger.mockResponse(subCorrelationId, payload);
LinkPropsDto inputItem = new LinkPropsDto(linkProps.getSource().getDatapath().toString(), linkProps.getSource().getPortNumber(), linkProps.getDest().getDatapath().toString(), linkProps.getDest().getPortNumber(), requestProps);
RequestCorrelationId.create(correlationId);
BatchResults result = linkService.setLinkProps(Collections.singletonList(inputItem)).join();
assertThat(result.getFailures(), is(0));
assertThat(result.getSuccesses(), is(1));
assertTrue(result.getMessages().isEmpty());
}
use of org.openkilda.messaging.nbtopology.request.LinkPropsPut in project open-kilda by telstra.
the class LinkServiceTest method updateMaxBandwidth.
@Test
public void updateMaxBandwidth() {
final String correlationId = "update-max-bw-corrId";
Long maxBandwidth = 1000L;
SwitchId srcSwitch = new SwitchId("ff:fe:00:00:00:00:00:01");
Integer srcPort = 8;
SwitchId dstSwitch = new SwitchId("ff:fe:00:00:00:00:00:02");
Integer dstPort = 9;
LinkMaxBandwidthRequest inputRequest = new LinkMaxBandwidthRequest();
inputRequest.setMaxBandwidth(maxBandwidth);
HashMap<String, String> requestProps = new HashMap<>();
requestProps.put(LinkProps.MAX_BANDWIDTH_PROP_NAME, String.valueOf(maxBandwidth));
org.openkilda.messaging.model.LinkPropsDto linkProps = new org.openkilda.messaging.model.LinkPropsDto(new NetworkEndpoint(srcSwitch, srcPort), new NetworkEndpoint(dstSwitch, dstPort), requestProps);
LinkPropsRequest request = new LinkPropsPut(linkProps);
LinkPropsResponse payload = new LinkPropsResponse(request, linkProps, null);
messageExchanger.mockResponse(correlationId, payload);
RequestCorrelationId.create(correlationId);
LinkMaxBandwidthDto result = linkService.updateLinkBandwidth(srcSwitch, srcPort, dstSwitch, dstPort, inputRequest).join();
assertEquals(srcSwitch.toString(), result.getSrcSwitch());
assertEquals(dstSwitch.toString(), result.getDstSwitch());
assertEquals(srcPort, result.getSrcPort());
assertEquals(dstPort, result.getDstPort());
assertEquals(maxBandwidth, result.getMaxBandwidth());
}
use of org.openkilda.messaging.nbtopology.request.LinkPropsPut in project open-kilda by telstra.
the class LinkServiceImpl method updateLinkBandwidth.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<LinkMaxBandwidthDto> updateLinkBandwidth(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort, LinkMaxBandwidthRequest input) {
if (input.getMaxBandwidth() == null || input.getMaxBandwidth() < 0) {
throw new MessageException(ErrorType.PARAMETERS_INVALID, "Invalid value of max_bandwidth", "Maximum bandwidth must not be null");
}
if (srcPort < 0) {
throw new MessageException(ErrorType.PARAMETERS_INVALID, "Invalid value of source port", "Port number can't be negative");
}
if (dstPort < 0) {
throw new MessageException(ErrorType.PARAMETERS_INVALID, "Invalid value of destination port", "Port number can't be negative");
}
org.openkilda.messaging.model.LinkPropsDto linkProps = org.openkilda.messaging.model.LinkPropsDto.builder().source(new NetworkEndpoint(srcSwitch, srcPort)).dest(new NetworkEndpoint(dstSwitch, dstPort)).props(ImmutableMap.of(LinkProps.MAX_BANDWIDTH_PROP_NAME, input.getMaxBandwidth().toString())).build();
LinkPropsPut request = new LinkPropsPut(linkProps);
String correlationId = RequestCorrelationId.getId();
CommandMessage message = new CommandMessage(request, System.currentTimeMillis(), correlationId);
return messagingChannel.sendAndGet(nbworkerTopic, message).thenApply(response -> linkPropsMapper.toLinkMaxBandwidth(((LinkPropsResponse) response).getLinkProps()));
}
Aggregations