use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class NetworkPortService method savePortProperties.
private PortProperties savePortProperties(Endpoint endpoint, boolean discoveryEnabled) {
Switch sw = switchRepository.findById(endpoint.getDatapath()).orElseThrow(() -> new PersistenceException(format("Switch %s not found.", endpoint.getDatapath())));
PortProperties portProperties = portPropertiesRepository.getBySwitchIdAndPort(endpoint.getDatapath(), endpoint.getPortNumber()).orElseGet(() -> {
PortProperties newProps = PortProperties.builder().switchObj(sw).port(endpoint.getPortNumber()).build();
portPropertiesRepository.add(newProps);
return newProps;
});
portProperties.setDiscoveryEnabled(discoveryEnabled);
return portProperties;
}
use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class OrientDbPersistenceImplementation method onContextClose.
@Override
public void onContextClose(PersistenceContext context) {
OrientDbContextExtension contextExtension = getContextExtension(context);
DelegatingFramedGraph<OrientGraph> currentGraph = contextExtension.removeGraph();
if (currentGraph != null) {
String threadName = Thread.currentThread().getName();
// Commit an implicit transaction to release graph resources.
try {
log.trace("Committing a transaction on the graph: {} in {}", currentGraph, threadName);
currentGraph.getBaseGraph().commit();
} catch (Exception e) {
log.error("Failed to commit a transaction in {}", threadName, e);
}
try {
log.trace("Closing the framed graph: {} in {}", currentGraph, threadName);
currentGraph.close();
} catch (IOException e) {
throw new PersistenceException(String.format("Failed to close graph in %s", threadName), e);
}
}
}
use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class FermaTransactionAdapter method open.
@Override
public void open() throws Exception {
try {
closeForeignTransactionIfExist();
} catch (PersistenceException e) {
throw e;
} catch (Exception e) {
throw wrapException(e);
}
DelegatingFramedGraph<?> graph = getContextExtension().getGraphCreateIfMissing();
WrappedTransaction transaction = graph.tx();
if (transaction.isOpen()) {
throw new PersistenceException("Attempt to reopen transaction: " + transaction);
}
log.debug("Opening a new transaction {} on graph {}", transaction, graph);
transaction.open();
}
use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class FermaMirrorGroupRepository method findFirstUnassignedGroupId.
@Override
public Optional<GroupId> findFirstUnassignedGroupId(SwitchId switchId, GroupId lowestGroupId, GroupId highestGroupId) {
String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
Long lowestGroupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(lowestGroupId);
Long highestGroupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(highestGroupId);
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).has(MirrorGroupFrame.GROUP_ID_PROPERTY, P.gte(lowestGroupIdAsLong)).has(MirrorGroupFrame.GROUP_ID_PROPERTY, P.lt(highestGroupIdAsLong)).values(MirrorGroupFrame.GROUP_ID_PROPERTY).order().math("_ + 1").as("a").where(__.not(__.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).values(MirrorGroupFrame.GROUP_ID_PROPERTY).where(P.eq("a")))).select("a").limit(1)).getRawTraversal()) {
if (traversal.hasNext()) {
return traversal.tryNext().map(l -> ((Double) l).longValue()).map(GroupIdConverter.INSTANCE::toEntityAttribute);
}
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).has(MirrorGroupFrame.GROUP_ID_PROPERTY, lowestGroupIdAsLong)).getRawTraversal()) {
if (!traversal.hasNext()) {
return Optional.of(lowestGroupId);
}
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
return Optional.empty();
}
use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class AvailableNetworkFactory method getAvailableNetwork.
/**
* Gets a {@link AvailableNetwork}.
*
* @param flow the flow, for which {@link AvailableNetwork} is constructing.
* @param reusePathsResources reuse resources already allocated by {@param reusePathsResources} paths.
* @return {@link AvailableNetwork} instance.
*/
public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException {
BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy());
AvailableNetwork network = new AvailableNetwork();
try {
// Reads all active links from the database and creates representation of the network.
getAvailableIsls(buildStrategy, flow).forEach(link -> addIslAsEdge(link, network));
if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) {
reusePathsResources.stream().filter(pathId -> flowPathRepository.findById(pathId).map(path -> !path.isIgnoreBandwidth()).orElse(false)).forEach(pathId -> {
// ISLs occupied by the flow (take the bandwidth already occupied by the flow into account).
islRepository.findActiveByPathAndBandwidthAndEncapsulationType(pathId, flow.getBandwidth(), flow.getEncapsulationType()).forEach(link -> addIslAsEdge(link, network));
});
}
} catch (PersistenceException e) {
throw new RecoverableException("An error from the database", e);
}
if (flow.getDiverseGroupId() != null) {
log.info("Filling AvailableNetwork diverse weights for group with id {}", flow.getDiverseGroupId());
Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowDiverseGroupId(flow.getDiverseGroupId());
if (!reusePathsResources.isEmpty()) {
flowPaths = flowPaths.stream().filter(s -> !reusePathsResources.contains(s)).collect(Collectors.toList());
}
Collection<PathId> affinityPathIds = flowPathRepository.findPathIdsByFlowAffinityGroupId(flow.getAffinityGroupId());
flowPaths.forEach(pathId -> flowPathRepository.findById(pathId).filter(flowPath -> !affinityPathIds.contains(flowPath.getPathId()) || flowPath.getFlowId().equals(flow.getFlowId())).ifPresent(flowPath -> {
network.processDiversitySegments(flowPath.getSegments(), flow);
network.processDiversitySegmentsWithPop(flowPath.getSegments());
}));
}
// The main flow should not take into account the rest of the flows in this affinity group.
if (flow.getAffinityGroupId() != null && !flow.getAffinityGroupId().equals(flow.getFlowId())) {
log.info("Filling AvailableNetwork affinity weights for group with id {}", flow.getAffinityGroupId());
flowPathRepository.findByFlowId(flow.getAffinityGroupId()).stream().filter(flowPath -> !flowPath.isProtected()).filter(FlowPath::isForward).map(FlowPath::getSegments).forEach(network::processAffinitySegments);
}
return network;
}
Aggregations