use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project open-kilda by telstra.
the class FermaMirrorGroupRepository method exists.
@Override
public boolean exists(SwitchId switchId, GroupId groupId) {
String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
Long groupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(groupId);
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(MirrorGroupFrame.GROUP_ID_PROPERTY, groupIdAsLong).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr)).getRawTraversal()) {
return traversal.hasNext();
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal 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.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal 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.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project grakn by graknlabs.
the class ComparatorPredicate method applyPredicate.
@Override
public final <S, E> GraphTraversal<S, E> applyPredicate(GraphTraversal<S, E> traversal) {
var.ifPresent(theVar -> {
// Compare to another variable
String thisVar = UUID.randomUUID().toString();
Var otherVar = theVar.var();
String otherValue = UUID.randomUUID().toString();
Traversal[] traversals = Stream.of(VALUE_PROPERTIES).map(prop -> __.values(prop).as(otherValue).select(thisVar).values(prop).where(gremlinPredicate(otherValue))).toArray(Traversal[]::new);
traversal.as(thisVar).select(otherVar.name()).or(traversals).select(thisVar);
});
persistedValue().ifPresent(theValue -> {
// Compare to a given value
DataType<?> dataType = DataType.SUPPORTED_TYPES.get(value().get().getClass().getTypeName());
Schema.VertexProperty property = dataType.getVertexProperty();
traversal.has(property.name(), gremlinPredicate(theValue));
});
return traversal;
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project grakn by graknlabs.
the class JanusPreviousPropertyStepTest method whenFilteringAPropertyToBeEqualToAPreviousProperty_UseJanusGraphStep.
@Test
public void whenFilteringAPropertyToBeEqualToAPreviousProperty_UseJanusGraphStep() {
GraphTraversal traversal = optimisableTraversal(janus);
GraphTraversal expected = optimisedTraversal(janus);
traversal.asAdmin().applyStrategies();
assertEquals(expected, traversal);
}
Aggregations