Search in sources :

Example 6 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class LinkOperationsBolt method dropLinkProps.

private LinkPropsResponse dropLinkProps(LinkPropsDrop request) {
    LinkProps linkPropsToDrop = LinkProps.builder().srcSwitchId(request.getPropsMask().getSource().getDatapath()).srcPort(request.getPropsMask().getSource().getPortNumber()).dstSwitchId(request.getPropsMask().getDest().getDatapath()).dstPort(request.getPropsMask().getDest().getPortNumber()).build();
    LinkProps reverseLinkPropsToDrop = swapLinkProps(linkPropsToDrop);
    try {
        LinkProps result = deleteLinkProps(linkPropsToDrop, reverseLinkPropsToDrop);
        return new LinkPropsResponse(request, LinkPropsMapper.INSTANCE.map(result), null);
    } catch (Exception e) {
        log.error("Unhandled exception in drop linkprops operation.", e);
        return new LinkPropsResponse(request, null, e.getMessage());
    }
}
Also used : LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) LinkProps(org.openkilda.model.LinkProps) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) LinkPropsException(org.openkilda.wfm.error.LinkPropsException) IllegalIslStateException(org.openkilda.wfm.error.IllegalIslStateException)

Example 7 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class LinkOperationsBolt method putLinkProps.

private LinkPropsResponse putLinkProps(LinkPropsPut request) {
    try {
        LinkProps toSetForward = LinkPropsMapper.INSTANCE.map(request.getLinkProps());
        LinkProps toSetBackward = swapLinkProps(toSetForward);
        LinkProps result = createOrUpdateProps(toSetForward);
        createOrUpdateProps(toSetBackward);
        return new LinkPropsResponse(request, LinkPropsMapper.INSTANCE.map(result), null);
    } catch (LinkPropsException e) {
        throw new MessageException(ErrorType.DATA_INVALID, "Can't create/update link props", e.getMessage());
    } catch (Exception e) {
        log.error("Unhandled exception in create or update linkprops operation.", e);
        return new LinkPropsResponse(request, null, e.getMessage());
    }
}
Also used : LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) LinkPropsException(org.openkilda.wfm.error.LinkPropsException) MessageException(org.openkilda.messaging.error.MessageException) LinkProps(org.openkilda.model.LinkProps) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) LinkPropsException(org.openkilda.wfm.error.LinkPropsException) IllegalIslStateException(org.openkilda.wfm.error.IllegalIslStateException)

Example 8 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class IslFsm method initializeFromLinkProps.

private void initializeFromLinkProps(Endpoint source, Endpoint dest, IslBuilder isl) {
    Optional<LinkProps> linkProps = loadLinkProps(source, dest);
    if (linkProps.isPresent()) {
        LinkProps entry = linkProps.get();
        Integer cost = entry.getCost();
        if (cost != null) {
            isl.cost(cost);
        }
        Long maxBandwidth = entry.getMaxBandwidth();
        if (maxBandwidth != null) {
            isl.maxBandwidth(maxBandwidth);
        }
    }
}
Also used : LinkProps(org.openkilda.model.LinkProps)

Example 9 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class SwitchIntegrationService method getIslLinkProps.

/**
 * Gets the isl link cost.
 *
 * @return the isl link cost
 */
public List<LinkProps> getIslLinkProps(final LinkProps keys) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(applicationProperties.getNbBaseUrl() + IConstants.NorthBoundUrl.GET_LINK_PROPS);
    builder = setLinkProps(keys, builder);
    String fullUri = builder.build().toUriString();
    HttpResponse response = restClientManager.invoke(fullUri, HttpMethod.GET, "", "", applicationService.getAuthHeader());
    try {
        if (RestClientManager.isValidResponse(response)) {
            List<LinkProps> linkPropsResponses = restClientManager.getResponseList(response, LinkProps.class);
            if (!CollectionUtil.isEmpty(linkPropsResponses)) {
                return linkPropsResponses;
            }
        }
    } catch (InvalidResponseException e) {
        LOGGER.warn("Error occurred while getting isl link props ", e);
        return null;
    }
    return null;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) HttpResponse(org.apache.http.HttpResponse) LinkProps(org.openkilda.model.LinkProps) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Example 10 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class SwitchService method getLinkProps.

/**
 * Gets the link props.
 *
 * @param srcSwitch the src switch
 *
 * @param srcPort  the src port
 *
 * @param dstSwitch the dst switch
 *
 * @param dstPort the dst port
 *
 * @return the link props
 */
public LinkProps getLinkProps(final String srcSwitch, final String srcPort, final String dstSwitch, final String dstPort) {
    if (StringUtil.isAnyNullOrEmpty(srcSwitch, srcPort, dstPort, dstSwitch)) {
        throw new InvalidResponseException(HttpError.PRECONDITION_FAILED.getCode(), HttpError.PRECONDITION_FAILED.getMessage());
    }
    LinkProps keys = new LinkProps();
    keys.setDstPort(dstPort);
    keys.setDstSwitch(dstSwitch);
    keys.setSrcPort(srcPort);
    keys.setSrcSwitch(srcSwitch);
    List<LinkProps> linkPropsList = switchIntegrationService.getIslLinkProps(keys);
    LinkProps linkProps = null;
    if (linkPropsList != null && linkPropsList.size() > 1) {
        throw new InvalidResponseException(HttpError.PRECONDITION_FAILED.getCode(), HttpError.PRECONDITION_FAILED.getMessage());
    } else {
        if (linkPropsList != null && linkPropsList.size() == 1) {
            linkProps = linkPropsList.get(0);
            if (!linkProps.getDstPort().equals(keys.getDstPort()) || !linkProps.getDstSwitch().equals(keys.getDstSwitch()) || !linkProps.getSrcPort().equals(keys.getSrcPort()) || !linkProps.getSrcSwitch().equals(keys.getSrcSwitch())) {
                throw new InvalidResponseException(HttpError.NO_CONTENT.getCode(), HttpError.NO_CONTENT.getMessage());
            }
        }
    }
    return linkProps;
}
Also used : LinkProps(org.openkilda.model.LinkProps) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Aggregations

LinkProps (org.openkilda.model.LinkProps)14 LinkPropsException (org.openkilda.wfm.error.LinkPropsException)3 InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)2 MessageException (org.openkilda.messaging.error.MessageException)2 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)2 Isl (org.openkilda.model.Isl)2 IllegalIslStateException (org.openkilda.wfm.error.IllegalIslStateException)2 IslNotFoundException (org.openkilda.wfm.error.IslNotFoundException)2 HttpResponse (org.apache.http.HttpResponse)1 Test (org.junit.Test)1 SwitchId (org.openkilda.model.SwitchId)1 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1