Search in sources :

Example 1 with PathSegmentFrame

use of org.openkilda.persistence.ferma.frames.PathSegmentFrame in project open-kilda by telstra.

the class FermaPathSegmentRepository method updateFailedStatus.

@Override
@TransactionRequired
public void updateFailedStatus(FlowPath path, PathSegment segment, boolean failed) {
    PathSegment segmentToUpdate;
    if (segment.getData() instanceof PathSegmentFrame) {
        segmentToUpdate = segment;
    } else {
        segmentToUpdate = path.getSegments().stream().filter(pathSegment -> pathSegment.getSrcSwitchId().equals(segment.getSrcSwitchId()) && pathSegment.getSrcPort() == segment.getSrcPort() && pathSegment.getDestSwitchId().equals(segment.getDestSwitchId()) && pathSegment.getDestPort() == segment.getDestPort()).findAny().orElse(null);
    }
    if (segmentToUpdate == null) {
        throw new PersistenceException(format("PathSegment not found to be updated: %s_%d - %s_%d. Path id: %s.", segment.getSrcSwitchId(), segment.getSrcPort(), segment.getDestSwitchId(), segment.getDestPort(), path.getPathId()));
    }
    segmentToUpdate.setFailed(failed);
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) TransactionRequired(org.openkilda.persistence.tx.TransactionRequired) PathSegmentData(org.openkilda.model.PathSegment.PathSegmentData) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) List(java.util.List) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) IslRepository(org.openkilda.persistence.repositories.IslRepository) Optional(java.util.Optional) Comparator(java.util.Comparator) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PathSegment(org.openkilda.model.PathSegment) TransactionRequired(org.openkilda.persistence.tx.TransactionRequired)

Example 2 with PathSegmentFrame

use of org.openkilda.persistence.ferma.frames.PathSegmentFrame in project open-kilda by telstra.

the class FermaIslRepository method findByPathIds.

@Override
public Collection<Isl> findByPathIds(List<PathId> pathIds) {
    List<String> pathIdAsStr = pathIds.stream().map(PathIdConverter.INSTANCE::toGraphProperty).collect(Collectors.toList());
    List<? extends PathSegmentFrame> segmentFrames = framedGraph().traverse(g -> g.V().hasLabel(PathSegmentFrame.FRAME_LABEL).has(PathSegmentFrame.PATH_ID_PROPERTY, P.within(pathIdAsStr))).toListExplicit(PathSegmentFrame.class);
    if (segmentFrames.isEmpty()) {
        return emptyList();
    }
    List<Isl> result = new ArrayList<>();
    segmentFrames.forEach(segmentFrame -> {
        framedGraph().traverse(g -> g.E().hasLabel(IslFrame.FRAME_LABEL).has(IslFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(segmentFrame.getSrcSwitchId())).has(IslFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(segmentFrame.getDestSwitchId())).has(IslFrame.SRC_PORT_PROPERTY, segmentFrame.getSrcPort()).has(IslFrame.DST_PORT_PROPERTY, segmentFrame.getDestPort())).frameExplicit(IslFrame.class).forEachRemaining(frame -> result.add(addIslConfigToIsl(new Isl(frame))));
    });
    return result;
}
Also used : Collectors.groupingBy(java.util.stream.Collectors.groupingBy) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) FlowEncapsulationTypeConverter(org.openkilda.persistence.ferma.frames.converters.FlowEncapsulationTypeConverter) HashMap(java.util.HashMap) IslConfig(org.openkilda.model.IslConfig) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) IslStatusConverter(org.openkilda.persistence.ferma.frames.converters.IslStatusConverter) Collectors.mapping(java.util.stream.Collectors.mapping) IslRepository(org.openkilda.persistence.repositories.IslRepository) Map(java.util.Map) SwitchFrame(org.openkilda.persistence.ferma.frames.SwitchFrame) Collectors.toSet(java.util.stream.Collectors.toSet) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) Edge(org.apache.tinkerpop.gremlin.structure.Edge) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) IslFrame(org.openkilda.persistence.ferma.frames.IslFrame) SwitchStatusConverter(org.openkilda.persistence.ferma.frames.converters.SwitchStatusConverter) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Set(java.util.Set) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) IslStatus(org.openkilda.model.IslStatus) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) KildaBaseEdgeFrame(org.openkilda.persistence.ferma.frames.KildaBaseEdgeFrame) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchPropertiesFrame(org.openkilda.persistence.ferma.frames.SwitchPropertiesFrame) Instant(java.time.Instant) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) IslData(org.openkilda.model.Isl.IslData) SwitchId(org.openkilda.model.SwitchId) FramedGraph(com.syncleus.ferma.FramedGraph) Optional(java.util.Optional) Isl(org.openkilda.model.Isl) SwitchStatus(org.openkilda.model.SwitchStatus) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) Isl(org.openkilda.model.Isl) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) IslFrame(org.openkilda.persistence.ferma.frames.IslFrame) ArrayList(java.util.ArrayList)

Aggregations

String.format (java.lang.String.format)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 PathId (org.openkilda.model.PathId)2 PersistenceException (org.openkilda.persistence.exceptions.PersistenceException)2 FermaPersistentImplementation (org.openkilda.persistence.ferma.FermaPersistentImplementation)2 PathSegmentFrame (org.openkilda.persistence.ferma.frames.PathSegmentFrame)2 FramedGraph (com.syncleus.ferma.FramedGraph)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.unmodifiableCollection (java.util.Collections.unmodifiableCollection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1