use of org.openkilda.messaging.model.LinkPropsDto 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.model.LinkPropsDto in project open-kilda by telstra.
the class LinkPropsResponseTest method serializeLoop.
@Test
public void serializeLoop() throws Exception {
LinkPropsRequest[] requestsBatch = new LinkPropsRequest[] { makePutRequest(), makeDropRequest() };
for (LinkPropsRequest request : requestsBatch) {
LinkPropsDto result = LinkPropsTest.makeSubject();
LinkPropsResponse origin = new LinkPropsResponse(request, result, null);
InfoMessage wrapper = new InfoMessage(origin, System.currentTimeMillis(), getClass().getCanonicalName());
serializer.serialize(wrapper);
InfoMessage reconstructedWrapper = (InfoMessage) serializer.deserialize();
LinkPropsResponse reconstructed = (LinkPropsResponse) reconstructedWrapper.getData();
Assert.assertEquals(origin, reconstructed);
}
}
use of org.openkilda.messaging.model.LinkPropsDto in project open-kilda by telstra.
the class LinkPropsMapper method toLinkProps.
/**
* Converts {@link org.openkilda.northbound.dto.v1.links.LinkPropsDto} into {@link LinkPropsDto}.
*/
default LinkPropsDto toLinkProps(org.openkilda.northbound.dto.v1.links.LinkPropsDto input) {
NetworkEndpoint source = new NetworkEndpoint(new SwitchId(input.getSrcSwitch()), input.getSrcPort());
NetworkEndpoint dest = new NetworkEndpoint(new SwitchId(input.getDstSwitch()), input.getDstPort());
return new LinkPropsDto(source, dest, input.getProps());
}
use of org.openkilda.messaging.model.LinkPropsDto in project open-kilda by telstra.
the class LinkPropsPutTest method makeRequest.
/**
* Produce {@link LinkPropsPut} request with predefined data.
*/
public static LinkPropsPut makeRequest() {
HashMap<String, String> keyValuePairs = new HashMap<>();
keyValuePairs.put("cost", "10000");
LinkPropsDto linkProps = new 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"), 8), keyValuePairs);
return new LinkPropsPut(linkProps);
}
use of org.openkilda.messaging.model.LinkPropsDto in project open-kilda by telstra.
the class LinkPropsMapper method map.
/**
* Convert {@link LinkProps} to {@link LinkPropsDto}.
*/
public LinkPropsDto map(LinkProps linkProps) {
if (linkProps == null) {
return null;
}
Map<String, String> props = new HashMap<>();
if (linkProps.getCost() != null) {
props.put(LinkProps.COST_PROP_NAME, Integer.toString(linkProps.getCost()));
}
if (linkProps.getMaxBandwidth() != null) {
props.put(LinkProps.MAX_BANDWIDTH_PROP_NAME, Long.toString(linkProps.getMaxBandwidth()));
}
Long created = Optional.ofNullable(linkProps.getTimeCreate()).map(Instant::toEpochMilli).orElse(null);
Long modified = Optional.ofNullable(linkProps.getTimeModify()).map(Instant::toEpochMilli).orElse(null);
NetworkEndpoint source = new NetworkEndpoint(linkProps.getSrcSwitchId(), linkProps.getSrcPort());
NetworkEndpoint destination = new NetworkEndpoint(linkProps.getDstSwitchId(), linkProps.getDstPort());
return new LinkPropsDto(source, destination, props, created, modified);
}
Aggregations