use of org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources.EndpointResources in project open-kilda by telstra.
the class HandleNotDeallocatedResourcesAction method perform.
protected void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlowResources newResources = stateMachine.getNewResources();
if (newResources == null) {
log.debug("No resources were allocated for y-flow {}", yFlowId);
return;
}
EndpointResources sharedEndpointResources = newResources.getSharedEndpointResources();
if (sharedEndpointResources != null) {
stateMachine.saveErrorToHistory("Failed to deallocate resources", format("Failed to deallocate resources %s of y-flow %s (shared endpoint): %s", sharedEndpointResources, stateMachine.getYFlowId(), context.getError()));
}
EndpointResources mainResources = newResources.getMainPathYPointResources();
if (mainResources != null) {
stateMachine.saveErrorToHistory("Failed to deallocate resources", format("Failed to deallocate resources %s of y-flow %s (main paths): %s", mainResources, stateMachine.getYFlowId(), context.getError()));
}
EndpointResources protectedResources = newResources.getProtectedPathYPointResources();
if (protectedResources != null) {
stateMachine.saveErrorToHistory("Failed to deallocate resources", format("Failed to deallocate resources %s of y-flow %s (protected paths): %s", mainResources, stateMachine.getYFlowId(), context.getError()));
}
}
use of org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources.EndpointResources in project open-kilda by telstra.
the class HandleNotDeallocatedResourcesAction method perform.
protected void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlowResources newResources = stateMachine.getNewResources();
if (newResources == null) {
log.debug("No resources were allocated for y-flow {}", yFlowId);
return;
}
EndpointResources sharedEndpointResources = newResources.getSharedEndpointResources();
if (sharedEndpointResources != null) {
stateMachine.saveErrorToHistory("Failed to deallocate resources", format("Failed to deallocate resources %s of y-flow %s (shared endpoint): %s", sharedEndpointResources, stateMachine.getYFlowId(), context.getError()));
}
EndpointResources mainResources = newResources.getMainPathYPointResources();
if (mainResources != null) {
stateMachine.saveErrorToHistory("Failed to deallocate resources", format("Failed to deallocate resources %s of y-flow %s (main paths): %s", mainResources, stateMachine.getYFlowId(), context.getError()));
}
EndpointResources protectedResources = newResources.getProtectedPathYPointResources();
if (protectedResources != null) {
stateMachine.saveErrorToHistory("Failed to deallocate resources", format("Failed to deallocate resources %s of y-flow %s (protected paths): %s", mainResources, stateMachine.getYFlowId(), context.getError()));
}
}
use of org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources.EndpointResources in project open-kilda by telstra.
the class DeallocateYFlowResourcesAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
notifyStats(stateMachine);
String yFlowId = stateMachine.getYFlowId();
Optional<YFlowResources> oldResources = Optional.ofNullable(stateMachine.getOldResources());
Optional<EndpointResources> sharedEndpointResources = oldResources.map(YFlowResources::getSharedEndpointResources);
Optional<MeterId> sharedEndpointMeterId = sharedEndpointResources.map(EndpointResources::getMeterId);
if (sharedEndpointMeterId.isPresent()) {
MeterId meterId = sharedEndpointMeterId.get();
SwitchId endpoint = sharedEndpointResources.get().getEndpoint();
resourcesManager.deallocateMeter(endpoint, meterId);
// reset to avoid false notifications in {@link HandleNotRemovedResourcesAction}.
oldResources.get().setSharedEndpointResources(null);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", endpoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (shared endpoint)", yFlowId);
}
Optional<EndpointResources> mainResources = oldResources.map(YFlowResources::getMainPathYPointResources);
Optional<MeterId> mainMeterId = mainResources.map(EndpointResources::getMeterId);
if (mainMeterId.isPresent()) {
MeterId meterId = mainMeterId.get();
SwitchId endpoint = mainResources.get().getEndpoint();
resourcesManager.deallocateMeter(endpoint, meterId);
// reset to avoid false notifications in {@link HandleNotRemovedResourcesAction}.
oldResources.get().setMainPathYPointResources(null);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", endpoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (main paths)", yFlowId);
}
Optional<EndpointResources> protectedResources = oldResources.map(YFlowResources::getProtectedPathYPointResources);
Optional<MeterId> protectedMeterId = protectedResources.map(EndpointResources::getMeterId);
if (protectedMeterId.isPresent()) {
MeterId meterId = protectedMeterId.get();
SwitchId endpoint = protectedResources.get().getEndpoint();
resourcesManager.deallocateMeter(endpoint, meterId);
// reset to avoid false notifications in {@link HandleNotRemovedResourcesAction}.
oldResources.get().setProtectedPathYPointResources(null);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", endpoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (protected paths)", yFlowId);
}
}
use of org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources.EndpointResources in project open-kilda by telstra.
the class AllocateYFlowResourcesAction method perform.
@Override
public void perform(S from, S to, E event, C context, T stateMachine) {
try {
String yFlowId = stateMachine.getYFlowId();
YFlowResources newResources;
// This could be a retry.
if (stateMachine.getNewResources() != null) {
newResources = stateMachine.getNewResources();
} else {
newResources = new YFlowResources();
stateMachine.setNewResources(newResources);
}
YFlow yFlow = getYFlow(yFlowId);
SwitchId sharedEndpoint = yFlow.getSharedEndpoint().getSwitchId();
if (newResources.getSharedEndpointResources() == null) {
EndpointResources sharedEndpointResources = allocateMeterAsEndpointResources(yFlowId, sharedEndpoint, yFlow.getMaximumBandwidth());
newResources.setSharedEndpointResources(sharedEndpointResources);
stateMachine.saveActionToHistory("A new meter was allocated for the y-flow shared endpoint", format("A new meter %s / %s was allocated", sharedEndpointResources.getMeterId(), sharedEndpointResources.getEndpoint()));
}
if (newResources.getMainPathYPointResources() == null) {
List<FlowPath> subFlowsReversePaths = new ArrayList<>();
yFlow.getSubFlows().forEach(subFlow -> {
Flow flow = subFlow.getFlow();
FlowPath path = flow.getReversePath();
if (path == null) {
throw new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Missing a reverse path for %s sub-flow", flow.getFlowId()));
} else {
subFlowsReversePaths.add(path);
}
});
EndpointResources yPointResources = allocateYPointResources(yFlowId, sharedEndpoint, yFlow.getMaximumBandwidth(), subFlowsReversePaths.toArray(new FlowPath[0]));
newResources.setMainPathYPointResources(yPointResources);
stateMachine.saveActionToHistory("A new meter was allocated for the y-flow y-point", format("A new meter %s / %s was allocated", yPointResources.getMeterId(), yPointResources.getEndpoint()));
}
if (yFlow.isAllocateProtectedPath() && newResources.getProtectedPathYPointResources() == null) {
List<FlowPath> subFlowsReversePaths = new ArrayList<>();
yFlow.getSubFlows().forEach(subFlow -> {
Flow flow = subFlow.getFlow();
FlowPath path = flow.getProtectedReversePath();
if (path == null) {
if (flow.getStatus() == FlowStatus.UP) {
throw new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Missing a protected path for %s sub-flow", flow.getFlowId()));
} else {
log.warn("Sub-flow {} has no expected protected path and status {}", flow.getFlowId(), flow.getStatus());
}
} else {
subFlowsReversePaths.add(path);
}
});
if (subFlowsReversePaths.size() > 1) {
EndpointResources yPointResources = allocateYPointResources(yFlowId, sharedEndpoint, yFlow.getMaximumBandwidth(), subFlowsReversePaths.toArray(new FlowPath[0]));
newResources.setProtectedPathYPointResources(yPointResources);
stateMachine.saveActionToHistory("A new meter was allocated for the y-flow protected path y-point", format("A new meter %s / %s was allocated", yPointResources.getMeterId(), yPointResources.getEndpoint()));
} else {
stateMachine.saveActionToHistory("Skip meter allocation for the y-flow protected path y-point", "Y-flow protected path y-point can't be found - sub-flow(s) lacks a protected path");
}
}
transactionManager.doInTransaction(() -> {
YFlow yFlowToUpdate = getYFlow(yFlowId);
yFlowToUpdate.setYPoint(newResources.getMainPathYPointResources().getEndpoint());
yFlowToUpdate.setMeterId(newResources.getMainPathYPointResources().getMeterId());
if (newResources.getProtectedPathYPointResources() != null) {
yFlowToUpdate.setProtectedPathYPoint(newResources.getProtectedPathYPointResources().getEndpoint());
yFlowToUpdate.setProtectedPathMeterId(newResources.getProtectedPathYPointResources().getMeterId());
} else {
yFlowToUpdate.setProtectedPathYPoint(null);
yFlowToUpdate.setProtectedPathMeterId(null);
}
yFlowToUpdate.setSharedEndpointMeterId(newResources.getSharedEndpointResources().getMeterId());
});
notifyStats(stateMachine, newResources);
} catch (ResourceAllocationException ex) {
String errorMessage = format("Failed to allocate y-flow resources. %s", ex.getMessage());
stateMachine.saveErrorToHistory(errorMessage, ex);
stateMachine.fireError(errorMessage);
}
}
use of org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources.EndpointResources in project open-kilda by telstra.
the class DeallocateYFlowResourcesAction method deallocateYFlowResources.
protected void deallocateYFlowResources(YFlowResources resources, T stateMachine) {
String yFlowId = stateMachine.getYFlowId();
if (resources == null) {
log.debug("No resources were allocated for y-flow {}", yFlowId);
return;
}
stateMachine.sendRemoveStatsNotification(resources);
Optional<EndpointResources> sharedEndpointResources = ofNullable(resources.getSharedEndpointResources());
Optional<MeterId> sharedEndpointMeterId = sharedEndpointResources.map(EndpointResources::getMeterId);
if (sharedEndpointMeterId.isPresent()) {
MeterId meterId = sharedEndpointMeterId.get();
SwitchId endpoint = sharedEndpointResources.get().getEndpoint();
resourcesManager.deallocateMeter(endpoint, meterId);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", endpoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (shared endpoint)", yFlowId);
}
Optional<EndpointResources> mainResources = ofNullable(resources.getMainPathYPointResources());
Optional<MeterId> mainMeterId = mainResources.map(EndpointResources::getMeterId);
if (mainMeterId.isPresent()) {
MeterId meterId = mainMeterId.get();
SwitchId yPoint = mainResources.get().getEndpoint();
resourcesManager.deallocateMeter(yPoint, meterId);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", yPoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (main paths)", yFlowId);
}
Optional<EndpointResources> protectedResources = ofNullable(resources.getProtectedPathYPointResources());
Optional<MeterId> protectedMeterId = protectedResources.map(EndpointResources::getMeterId);
if (protectedMeterId.isPresent()) {
MeterId meterId = protectedMeterId.get();
SwitchId yPoint = protectedResources.get().getEndpoint();
resourcesManager.deallocateMeter(yPoint, meterId);
stateMachine.saveActionToHistory("The meter was deallocated", format("The meter %s / %s was deallocated", yPoint, meterId));
} else {
log.debug("No meter was allocated for y-flow {} (main paths)", yFlowId);
}
}
Aggregations