Search in sources :

Example 1 with FlowV2

use of org.openkilda.integration.model.FlowV2 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)

Example 2 with FlowV2

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

the class FlowService method deleteFlow.

/**
 * Delete flow.
 *
 * @param flowId
 *            the flow id
 * @param userInfo
 *            the user info
 * @return the flow
 */
public FlowV2 deleteFlow(String flowId, UserInfo userInfo) {
    if (userService.validateOtp(userInfo.getUserId(), userInfo.getCode())) {
        FlowV2 flow = flowsIntegrationService.deleteFlow(flowId);
        activityLogger.log(ActivityType.DELETE_FLOW, flow.getId());
        return flow;
    } else {
        return null;
    }
}
Also used : FlowV2(org.openkilda.integration.model.FlowV2)

Aggregations

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