Search in sources :

Example 1 with FlowState

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

the class FlowService method processInventoryFlow.

/**
 * Process inventory flow.
 *
 * @param flows
 *            the flows
 * @param inventoryFlows
 *            the inventory flows
 */
private void processInventoryFlow(final List<FlowInfo> flows, final List<InventoryFlow> inventoryFlows) {
    List<FlowInfo> discrepancyFlow = new ArrayList<FlowInfo>();
    final Map<String, String> csNames = switchIntegrationService.getSwitchNames();
    for (InventoryFlow inventoryFlow : inventoryFlows) {
        int index = -1;
        for (FlowInfo flow : flows) {
            if (flow.getFlowid().equals(inventoryFlow.getId())) {
                index = flows.indexOf(flow);
                break;
            }
        }
        if (index >= 0) {
            FlowDiscrepancy discrepancy = new FlowDiscrepancy();
            discrepancy.setControllerDiscrepancy(false);
            if (flows.get(index).getMaximumBandwidth() != inventoryFlow.getMaximumBandwidth()) {
                discrepancy.setInventoryDiscrepancy(true);
                discrepancy.setBandwidth(true);
                FlowBandwidth flowBandwidth = new FlowBandwidth();
                flowBandwidth.setControllerBandwidth(flows.get(index).getMaximumBandwidth());
                flowBandwidth.setInventoryBandwidth(inventoryFlow.getMaximumBandwidth());
                discrepancy.setBandwidthValue(flowBandwidth);
            }
            if (("UP".equalsIgnoreCase(flows.get(index).getStatus()) && !"ACTIVE".equalsIgnoreCase(inventoryFlow.getState())) || ("DOWN".equalsIgnoreCase(flows.get(index).getStatus()) && "ACTIVE".equalsIgnoreCase(inventoryFlow.getState()))) {
                discrepancy.setInventoryDiscrepancy(true);
                discrepancy.setStatus(true);
                FlowState flowState = new FlowState();
                flowState.setControllerState(flows.get(index).getStatus());
                flowState.setInventoryState(inventoryFlow.getState());
                discrepancy.setStatusValue(flowState);
            }
            flows.get(index).setDiscrepancy(discrepancy);
            flows.get(index).setState(inventoryFlow.getState());
            flows.get(index).setInventoryFlow(true);
        } else {
            FlowInfo flowObj = new FlowInfo();
            flowConverter.toFlowInfo(flowObj, inventoryFlow, csNames);
            flowObj.setInventoryFlow(true);
            discrepancyFlow.add(flowObj);
        }
    }
    for (FlowInfo flow : flows) {
        boolean flag = false;
        for (InventoryFlow inventoryFlow : inventoryFlows) {
            if (flow.getFlowid().equals(inventoryFlow.getId())) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            FlowDiscrepancy discrepancy = new FlowDiscrepancy();
            discrepancy.setInventoryDiscrepancy(true);
            discrepancy.setControllerDiscrepancy(false);
            discrepancy.setStatus(true);
            discrepancy.setBandwidth(true);
            FlowBandwidth flowBandwidth = new FlowBandwidth();
            flowBandwidth.setControllerBandwidth(flow.getMaximumBandwidth());
            flowBandwidth.setInventoryBandwidth(0);
            discrepancy.setBandwidthValue(flowBandwidth);
            FlowState flowState = new FlowState();
            flowState.setControllerState(flow.getStatus());
            flowState.setInventoryState(null);
            discrepancy.setStatusValue(flowState);
            flow.setDiscrepancy(discrepancy);
        }
        flow.setControllerFlow(true);
    }
    flows.addAll(discrepancyFlow);
}
Also used : FlowInfo(org.openkilda.model.FlowInfo) FlowDiscrepancy(org.openkilda.model.FlowDiscrepancy) FlowState(org.openkilda.model.FlowState) InventoryFlow(org.openkilda.integration.source.store.dto.InventoryFlow) ArrayList(java.util.ArrayList) FlowBandwidth(org.openkilda.model.FlowBandwidth)

Example 2 with FlowState

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

the class FlowConverter method toFlowInfo.

/**
 * To flow info.
 *
 * @param flowInfo the flow info
 * @param inventoryFlow the inventory flow
 * @param csNames the cs names
 * @return the flow info
 */
public FlowInfo toFlowInfo(final FlowInfo flowInfo, final InventoryFlow inventoryFlow, final Map<String, String> csNames) {
    FlowDiscrepancy discrepancy = new FlowDiscrepancy();
    discrepancy.setControllerDiscrepancy(true);
    discrepancy.setStatus(true);
    discrepancy.setBandwidth(true);
    FlowBandwidth flowBandwidth = new FlowBandwidth();
    flowBandwidth.setControllerBandwidth(0);
    flowBandwidth.setInventoryBandwidth(inventoryFlow.getMaximumBandwidth());
    discrepancy.setBandwidthValue(flowBandwidth);
    FlowState flowState = new FlowState();
    flowState.setControllerState(null);
    flowState.setInventoryState(inventoryFlow.getState());
    discrepancy.setStatusValue(flowState);
    flowInfo.setFlowid(inventoryFlow.getId());
    flowInfo.setDiscrepancy(discrepancy);
    if (!StringUtil.isNullOrEmpty(inventoryFlow.getSource().getId())) {
        flowInfo.setSourceSwitch(inventoryFlow.getSource().getId());
        flowInfo.setSourceSwitchName(switchIntegrationService.customSwitchName(csNames, inventoryFlow.getSource().getId()));
    }
    if (inventoryFlow.getSource().getPortId() != null) {
        flowInfo.setSrcPort(inventoryFlow.getSource().getPortId());
    }
    try {
        flowInfo.setSrcVlan(Integer.parseInt(inventoryFlow.getSource().getVlanId()));
    } catch (NumberFormatException numberFormatException) {
        inventoryFlow.getSource().setVlanId(null);
    }
    if (!StringUtil.isNullOrEmpty(inventoryFlow.getDestination().getId())) {
        flowInfo.setTargetSwitch(inventoryFlow.getDestination().getId());
        flowInfo.setTargetSwitchName(switchIntegrationService.customSwitchName(csNames, inventoryFlow.getDestination().getId()));
    }
    if (inventoryFlow.getDestination().getPortId() != null) {
        flowInfo.setDstPort(inventoryFlow.getDestination().getPortId());
    }
    try {
        flowInfo.setDstVlan(Integer.parseInt(inventoryFlow.getDestination().getVlanId()));
    } catch (NumberFormatException numberFormatException) {
        inventoryFlow.getDestination().setVlanId(null);
    }
    flowInfo.setDescription(inventoryFlow.getDescription());
    flowInfo.setMaximumBandwidth(inventoryFlow.getMaximumBandwidth());
    flowInfo.setState(inventoryFlow.getState());
    flowInfo.setInventoryFlow(true);
    return flowInfo;
}
Also used : FlowDiscrepancy(org.openkilda.model.FlowDiscrepancy) FlowState(org.openkilda.model.FlowState) FlowBandwidth(org.openkilda.model.FlowBandwidth)

Example 3 with FlowState

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

the class FlowService method getFlowById.

/**
 * Flow by flow id.
 *
 * @param flowId
 *            the flow id
 * @return the flow by id
 * @throws AccessDeniedException the access denied exception
 */
public FlowInfo getFlowById(String flowId, boolean controller) throws AccessDeniedException {
    FlowInfo flowInfo = new FlowInfo();
    FlowV2 flow = null;
    try {
        flow = flowsIntegrationService.getFlowById(flowId);
    } catch (InvalidResponseException ex) {
        LOGGER.error("Error occurred while retrieving flows from controller", ex);
        if (controller) {
            throw new InvalidResponseException(ex.getCode(), ex.getResponse());
        }
    }
    Map<String, String> csNames = switchIntegrationService.getSwitchNames();
    if (flow != null) {
        flowInfo = flowConverter.toFlowV2Info(flow, csNames);
    }
    UserInfo userInfo = userService.getLoggedInUserInfo();
    try {
        if (!controller && userInfo.getPermissions().contains(IConstants.Permission.FW_FLOW_INVENTORY)) {
            if (storeService.getLinkStoreConfig().getUrls().size() > 0) {
                InventoryFlow inventoryFlow = flowStoreService.getFlowById(flowId);
                if (flow == null && inventoryFlow.getId() == null) {
                    throw new RequestValidationException("Can not get flow: Flow " + flowId + " not found");
                } else if (flow != null && inventoryFlow.getId() != null) {
                    flowInfo.setState(inventoryFlow.getState());
                    FlowDiscrepancy discrepancy = new FlowDiscrepancy();
                    discrepancy.setControllerDiscrepancy(false);
                    if (flowInfo.getMaximumBandwidth() != (inventoryFlow.getMaximumBandwidth() == null ? 0 : inventoryFlow.getMaximumBandwidth())) {
                        discrepancy.setBandwidth(true);
                        FlowBandwidth flowBandwidth = new FlowBandwidth();
                        flowBandwidth.setControllerBandwidth(flow.getMaximumBandwidth());
                        flowBandwidth.setInventoryBandwidth(inventoryFlow.getMaximumBandwidth());
                        discrepancy.setBandwidthValue(flowBandwidth);
                    }
                    if (("UP".equalsIgnoreCase(flowInfo.getStatus()) && !"ACTIVE".equalsIgnoreCase(inventoryFlow.getState())) || ("DOWN".equalsIgnoreCase(flowInfo.getStatus()) && "ACTIVE".equalsIgnoreCase(inventoryFlow.getState()))) {
                        discrepancy.setStatus(true);
                        FlowState flowState = new FlowState();
                        flowState.setControllerState(flow.getStatus());
                        flowState.setInventoryState(inventoryFlow.getState());
                        discrepancy.setStatusValue(flowState);
                    }
                    flowInfo.setInventoryFlow(true);
                    flowInfo.setDiscrepancy(discrepancy);
                } else if (inventoryFlow.getId() == null && flow != null) {
                    FlowDiscrepancy discrepancy = new FlowDiscrepancy();
                    discrepancy.setInventoryDiscrepancy(true);
                    discrepancy.setControllerDiscrepancy(false);
                    discrepancy.setStatus(true);
                    discrepancy.setBandwidth(true);
                    FlowBandwidth flowBandwidth = new FlowBandwidth();
                    flowBandwidth.setControllerBandwidth(flow.getMaximumBandwidth());
                    flowBandwidth.setInventoryBandwidth(0);
                    discrepancy.setBandwidthValue(flowBandwidth);
                    FlowState flowState = new FlowState();
                    flowState.setControllerState(flow.getStatus());
                    flowState.setInventoryState(null);
                    discrepancy.setStatusValue(flowState);
                    flowInfo.setDiscrepancy(discrepancy);
                } else {
                    flowConverter.toFlowInfo(flowInfo, inventoryFlow, csNames);
                }
            }
        }
        if (flow == null) {
            throw new RequestValidationException("Can not get flow: Flow " + flowId + " not found");
        }
    } catch (Exception ex) {
        LOGGER.error("Error occurred while retrieving flows from store", ex);
        throw new RequestValidationException(ex.getMessage());
    }
    return flowInfo;
}
Also used : FlowInfo(org.openkilda.model.FlowInfo) FlowDiscrepancy(org.openkilda.model.FlowDiscrepancy) FlowState(org.openkilda.model.FlowState) FlowV2(org.openkilda.integration.model.FlowV2) InventoryFlow(org.openkilda.integration.source.store.dto.InventoryFlow) UserInfo(org.usermanagement.model.UserInfo) FlowBandwidth(org.openkilda.model.FlowBandwidth) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException) RequestValidationException(org.usermanagement.exception.RequestValidationException) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException) IntegrationException(org.openkilda.integration.exception.IntegrationException) RequestValidationException(org.usermanagement.exception.RequestValidationException) AccessDeniedException(java.nio.file.AccessDeniedException)

Aggregations

FlowBandwidth (org.openkilda.model.FlowBandwidth)3 FlowDiscrepancy (org.openkilda.model.FlowDiscrepancy)3 FlowState (org.openkilda.model.FlowState)3 InventoryFlow (org.openkilda.integration.source.store.dto.InventoryFlow)2 FlowInfo (org.openkilda.model.FlowInfo)2 AccessDeniedException (java.nio.file.AccessDeniedException)1 ArrayList (java.util.ArrayList)1 IntegrationException (org.openkilda.integration.exception.IntegrationException)1 InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)1 FlowV2 (org.openkilda.integration.model.FlowV2)1 RequestValidationException (org.usermanagement.exception.RequestValidationException)1 UserInfo (org.usermanagement.model.UserInfo)1