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);
}
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;
}
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;
}
Aggregations