use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class FlowMirrorPointsFrame method getMirrorGroup.
@Override
public MirrorGroup getMirrorGroup() {
if (mirrorGroup == null) {
List<? extends MirrorGroupFrame> mirrorGroupFrames = traverse(v -> v.out(HAS_MIRROR_GROUP_EDGE).hasLabel(MirrorGroupFrame.FRAME_LABEL)).toListExplicit(MirrorGroupFrame.class);
if (!mirrorGroupFrames.isEmpty()) {
mirrorGroup = new MirrorGroup((mirrorGroupFrames.get(0)));
if (!Objects.equals(getMirrorGroupId(), mirrorGroup.getGroupId())) {
throw new IllegalStateException(format("The flow mirror points %s has inconsistent mirror group %s / %s", getId(), getMirrorGroupId(), mirrorGroup.getGroupId()));
}
} else {
String switchId = getProperty(MIRROR_SWITCH_ID_PROPERTY);
String pathId = getProperty(FLOW_PATH_ID_PROPERTY);
log.warn("Fallback to find the mirror group by a reference instead of an edge. " + "The switch {}, the vertex {}", switchId, this);
mirrorGroup = MirrorGroupFrame.load(getGraph(), switchId, pathId).map(MirrorGroup::new).orElse(null);
}
}
return mirrorGroup;
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class FlowMirrorPointsFrame method getMirrorSwitch.
@Override
public Switch getMirrorSwitch() {
if (mirrorSwitch == null) {
List<? extends SwitchFrame> switchFrames = traverse(v -> v.out(SOURCE_EDGE).hasLabel(SwitchFrame.FRAME_LABEL)).toListExplicit(SwitchFrame.class);
if (!switchFrames.isEmpty()) {
mirrorSwitch = new Switch((switchFrames.get(0)));
if (!Objects.equals(getMirrorSwitchId(), mirrorSwitch.getSwitchId())) {
throw new IllegalStateException(format("The flow mirror points %s has inconsistent mirror switch %s / %s", getId(), getMirrorSwitchId(), mirrorSwitch.getSwitchId()));
}
} else {
String switchId = getProperty(MIRROR_SWITCH_ID_PROPERTY);
log.warn("Fallback to find the mirror switch by a reference instead of an edge. " + "The switch {}, the vertex {}", switchId, this);
mirrorSwitch = SwitchFrame.load(getGraph(), switchId).map(Switch::new).orElse(null);
}
}
return mirrorSwitch;
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class FermaFlowMeterRepository method findFirstUnassignedMeter.
@Override
public Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId) {
String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
Long lowestMeterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(lowestMeterId);
Long highestMeterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(highestMeterId);
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, P.gte(lowestMeterIdAsLong)).has(FlowMeterFrame.METER_ID_PROPERTY, P.lt(highestMeterIdAsLong)).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr).values(FlowMeterFrame.METER_ID_PROPERTY).order().math("_ + 1").as("a").where(__.not(__.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr).values(FlowMeterFrame.METER_ID_PROPERTY).where(P.eq("a")))).select("a").limit(1)).getRawTraversal()) {
if (traversal.hasNext()) {
return traversal.tryNext().map(l -> ((Double) l).longValue()).map(MeterIdConverter.INSTANCE::toEntityAttribute);
}
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, lowestMeterIdAsLong).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr)).getRawTraversal()) {
if (!traversal.hasNext()) {
return Optional.of(lowestMeterId);
}
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
return Optional.empty();
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class FermaFlowMeterRepository method exists.
@Override
public boolean exists(SwitchId switchId, MeterId meterId) {
String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
Long meterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(meterId);
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, meterIdAsLong).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr)).getRawTraversal()) {
return traversal.hasNext();
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class SwitchConnectedDeviceFrame method getSwitchObj.
@Override
public Switch getSwitchObj() {
if (switchObj == null) {
List<? extends SwitchFrame> switchFrames = traverse(v -> v.in(HAS_BY_EDGE).hasLabel(SwitchFrame.FRAME_LABEL)).toListExplicit(SwitchFrame.class);
switchObj = !switchFrames.isEmpty() ? new Switch(switchFrames.get(0)) : null;
SwitchId switchId = switchObj != null ? switchObj.getSwitchId() : null;
if (!Objects.equals(getSwitchId(), switchId)) {
throw new IllegalStateException(format("The connected device %s has inconsistent switch %s / %s", getId(), getSwitchId(), switchId));
}
}
return switchObj;
}
Aggregations