Search in sources :

Example 1 with LinkPropsDto

use of org.openkilda.northbound.dto.v1.links.LinkPropsDto in project open-kilda by telstra.

the class JsonSerializationTest method linksPropsDtoTest.

@Test
public void linksPropsDtoTest() throws IOException {
    LinkPropsDto dto = new LinkPropsDto(SWITCH_ID, 0, SWITCH_ID, 1, Collections.singletonMap("key", "val"));
    assertEquals(dto, pass(dto, LinkPropsDto.class));
}
Also used : LinkPropsDto(org.openkilda.northbound.dto.v1.links.LinkPropsDto) Test(org.junit.Test)

Example 2 with LinkPropsDto

use of org.openkilda.northbound.dto.v1.links.LinkPropsDto 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 LinkPropsDto

use of org.openkilda.northbound.dto.v1.links.LinkPropsDto in project open-kilda by telstra.

the class LinkServiceTest method dropLinkProps.

@Test
public void dropLinkProps() {
    final String correlationId = getClass().getCanonicalName();
    LinkPropsDto input = new LinkPropsDto("ff:fe:00:00:00:00:00:01", 8, "ff:fe:00:00:00:00:00:05", null, null);
    LinkPropsDrop request = new LinkPropsDrop(new LinkPropsMask(new NetworkEndpointMask(new SwitchId(input.getSrcSwitch()), input.getSrcPort()), new NetworkEndpointMask(new SwitchId(input.getDstSwitch()), input.getDstPort())));
    org.openkilda.messaging.model.LinkPropsDto linkProps = new org.openkilda.messaging.model.LinkPropsDto(new NetworkEndpoint(new SwitchId(input.getSrcSwitch()), input.getSrcPort()), new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:02"), 9), new HashMap<>());
    LinkPropsResponse payload = new LinkPropsResponse(request, linkProps, null);
    String requestIdBatch = idFactory.produceChained(String.valueOf(requestIdIndex++), correlationId);
    messageExchanger.mockChunkedResponse(requestIdBatch, Collections.singletonList(payload));
    RequestCorrelationId.create(correlationId);
    BatchResults result = linkService.delLinkProps(Collections.singletonList(input)).join();
    assertThat(result.getFailures(), is(0));
    assertThat(result.getSuccesses(), is(1));
    assertTrue(result.getMessages().isEmpty());
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) LinkPropsDto(org.openkilda.northbound.dto.v1.links.LinkPropsDto) SwitchId(org.openkilda.model.SwitchId) LinkPropsMask(org.openkilda.messaging.model.LinkPropsMask) BatchResults(org.openkilda.northbound.dto.BatchResults) LinkPropsDrop(org.openkilda.messaging.nbtopology.request.LinkPropsDrop) NetworkEndpointMask(org.openkilda.messaging.model.NetworkEndpointMask) LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) Test(org.junit.Test)

Example 4 with LinkPropsDto

use of org.openkilda.northbound.dto.v1.links.LinkPropsDto 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 5 with LinkPropsDto

use of org.openkilda.northbound.dto.v1.links.LinkPropsDto in project open-kilda by telstra.

the class NorthboundServiceImpl method getLinkProps.

@Override
public List<LinkPropsDto> getLinkProps(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) {
    UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString("/api/v1/link/props");
    if (srcSwitch != null) {
        uriBuilder.queryParam("src_switch", srcSwitch);
    }
    if (srcPort != null) {
        uriBuilder.queryParam("src_port", srcPort);
    }
    if (dstSwitch != null) {
        uriBuilder.queryParam("dst_switch", dstSwitch);
    }
    if (dstPort != null) {
        uriBuilder.queryParam("dst_port", dstPort);
    }
    LinkPropsDto[] linkProps = restTemplate.exchange(uriBuilder.build().toString(), HttpMethod.GET, new HttpEntity(buildHeadersWithCorrelationId()), LinkPropsDto[].class).getBody();
    return Arrays.asList(linkProps);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) LinkPropsDto(org.openkilda.northbound.dto.v1.links.LinkPropsDto)

Aggregations

LinkPropsDto (org.openkilda.northbound.dto.v1.links.LinkPropsDto)9 Test (org.junit.Test)4 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)4 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)4 SwitchId (org.openkilda.model.SwitchId)3 ArrayList (java.util.ArrayList)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 LinkPropsDrop (org.openkilda.messaging.nbtopology.request.LinkPropsDrop)2 LinkPropsPut (org.openkilda.messaging.nbtopology.request.LinkPropsPut)2 BatchResults (org.openkilda.northbound.dto.BatchResults)2 Then (cucumber.api.java.en.Then)1 When (cucumber.api.java.en.When)1 HashMap (java.util.HashMap)1 InfoData (org.openkilda.messaging.info.InfoData)1 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)1 LinkPropsMask (org.openkilda.messaging.model.LinkPropsMask)1 NetworkEndpointMask (org.openkilda.messaging.model.NetworkEndpointMask)1 LinkPropsRequest (org.openkilda.messaging.nbtopology.request.LinkPropsRequest)1 LinkPropsData (org.openkilda.messaging.nbtopology.response.LinkPropsData)1