use of org.openkilda.integration.source.store.dto.InventoryFlow 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.integration.source.store.dto.InventoryFlow in project open-kilda by telstra.
the class FlowService method getAllFlows.
/**
* get All Flows.
*
* @return SwitchRelationData
*/
public List<FlowInfo> getAllFlows(List<String> statuses, boolean controller) {
List<FlowInfo> flows = new ArrayList<FlowInfo>();
if (!CollectionUtil.isEmpty(statuses)) {
statuses = statuses.stream().map((status) -> status.toLowerCase()).collect(Collectors.toList());
}
if (CollectionUtil.isEmpty(statuses) || statuses.contains("active")) {
flows = flowsIntegrationService.getFlows();
if (flows == null) {
flows = new ArrayList<FlowInfo>();
}
}
if (!controller) {
if (storeService.getLinkStoreConfig().getUrls().size() > 0) {
try {
UserInfo userInfo = userService.getLoggedInUserInfo();
if (userInfo.getPermissions().contains(IConstants.Permission.FW_FLOW_INVENTORY)) {
List<InventoryFlow> inventoryFlows = new ArrayList<InventoryFlow>();
String status = "";
for (String statusObj : statuses) {
if (StringUtil.isNullOrEmpty(status)) {
status += statusObj;
} else {
status += "," + statusObj;
}
}
inventoryFlows = flowStoreService.getFlowsWithParams(status);
processInventoryFlow(flows, inventoryFlows);
}
} catch (Exception ex) {
LOGGER.error("Error occurred while retrieving flows from store", ex);
}
}
}
return flows;
}
use of org.openkilda.integration.source.store.dto.InventoryFlow 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