Search in sources :

Example 1 with LinkPropsPut

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());
}
Also used : LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut) LinkPropsDto(org.openkilda.messaging.model.LinkPropsDto) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) Test(org.junit.Test)

Example 2 with LinkPropsPut

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));
}
Also used : ArrayList(java.util.ArrayList) LinkPropsDto(org.openkilda.northbound.dto.v1.links.LinkPropsDto) CommandMessage(org.openkilda.messaging.command.CommandMessage) CompletableFuture(java.util.concurrent.CompletableFuture) LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut)

Example 3 with LinkPropsPut

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());
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) HashMap(java.util.HashMap) LinkPropsDto(org.openkilda.northbound.dto.v1.links.LinkPropsDto) SwitchId(org.openkilda.model.SwitchId) BatchResults(org.openkilda.northbound.dto.BatchResults) LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) LinkPropsRequest(org.openkilda.messaging.nbtopology.request.LinkPropsRequest) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut) Test(org.junit.Test)

Example 4 with LinkPropsPut

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());
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) HashMap(java.util.HashMap) LinkPropsDto(org.openkilda.northbound.dto.v1.links.LinkPropsDto) SwitchId(org.openkilda.model.SwitchId) LinkMaxBandwidthRequest(org.openkilda.northbound.dto.v1.links.LinkMaxBandwidthRequest) LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) LinkPropsRequest(org.openkilda.messaging.nbtopology.request.LinkPropsRequest) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut) LinkMaxBandwidthDto(org.openkilda.northbound.dto.v1.links.LinkMaxBandwidthDto) Test(org.junit.Test)

Example 5 with LinkPropsPut

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()));
}
Also used : LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) MessageException(org.openkilda.messaging.error.MessageException) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

LinkPropsPut (org.openkilda.messaging.nbtopology.request.LinkPropsPut)5 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)5 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)4 Test (org.junit.Test)3 LinkPropsDto (org.openkilda.northbound.dto.v1.links.LinkPropsDto)3 HashMap (java.util.HashMap)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 LinkPropsRequest (org.openkilda.messaging.nbtopology.request.LinkPropsRequest)2 SwitchId (org.openkilda.model.SwitchId)2 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 MessageException (org.openkilda.messaging.error.MessageException)1 LinkPropsDto (org.openkilda.messaging.model.LinkPropsDto)1 BatchResults (org.openkilda.northbound.dto.BatchResults)1 LinkMaxBandwidthDto (org.openkilda.northbound.dto.v1.links.LinkMaxBandwidthDto)1 LinkMaxBandwidthRequest (org.openkilda.northbound.dto.v1.links.LinkMaxBandwidthRequest)1 SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)1