protected void checkKeyValue(final String key, final Object value) { if (!this.memoryKeys.containsKey(key)) throw GraphComputer.Exceptions.providedKeyIsNotAMemoryComputeKey(key); MemoryHelper.validateValue(value); } }
@Override public <V> JanusGraphVertexProperty<V> property(VertexProperty.Cardinality cardinality, String key, V value) { if (!supports(key)) throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key); Preconditions.checkArgument(value != null); if (cardinality == VertexProperty.Cardinality.single) { vertexMemory.setProperty(vertexId, key, value); } else { final V previousValue = vertexMemory.getProperty(vertexId, key); final List<V> values; if (previousValue != null) { assert previousValue instanceof List; values = new ArrayList<>(((List) previousValue)); } else { values = new ArrayList<>(); } values.add(value); vertexMemory.setProperty(vertexId, key, values); } return constructProperty(key,value); }
@Override public Future<ComputerResult> submit() { if (executed) throw Exceptions.computerHasAlreadyBeenSubmittedAVertexProgram(); else executed = true; throw GraphComputer.Exceptions.computerHasNoVertexProgramNorMapReducers(); throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraphMode, this.persistMode); throw GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported(this.numThreads, this.features().getMaxWorkers());
@Override public Future<ComputerResult> submit() { if (executed) throw Exceptions.computerHasAlreadyBeenSubmittedAVertexProgram(); else executed = true; throw GraphComputer.Exceptions.computerHasNoVertexProgramNorMapReducers(); throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraphMode, this.persistMode);
throw Exceptions.computerHasAlreadyBeenSubmittedAVertexProgram(); else this.executed = true; throw GraphComputer.Exceptions.computerHasNoVertexProgramNorMapReducers(); this.persist = GraphComputerHelper.getPersistState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.persist)); if (!this.features().supportsResultGraphPersistCombination(this.resultGraph, this.persist)) throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraph, this.persist); throw GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported(this.workers, this.features().getMaxWorkers());
throw Exceptions.computerHasAlreadyBeenSubmittedAVertexProgram(); else this.executed = true; throw GraphComputer.Exceptions.computerHasNoVertexProgramNorMapReducers(); this.persist = GraphComputerHelper.getPersistState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.persist)); if (!this.features().supportsResultGraphPersistCombination(this.resultGraph, this.persist)) throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraph, this.persist); throw GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported(this.workers, this.features().getMaxWorkers());
fail("Edges should not be accessible in MapReduce.map()"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.incidentAndAdjacentElementsCanNotBeAccessedInMapReduce().getMessage(), e.getMessage()); fail("Edges should not be accessible in MapReduce.map()"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.incidentAndAdjacentElementsCanNotBeAccessedInMapReduce().getMessage(), e.getMessage()); fail("Edges should not be accessible in MapReduce.map()"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.incidentAndAdjacentElementsCanNotBeAccessedInMapReduce().getMessage(), e.getMessage()); fail("Vertex properties should be immutable in MapReduce.map()"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce().getMessage(), e.getMessage()); fail("Vertex properties should be immutable in MapReduce.map()"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce().getMessage(), e.getMessage());
protected void validateStatePriorToExecution() { // a graph computer can only be executed one time if (this.executed) throw Exceptions.computerHasAlreadyBeenSubmittedAVertexProgram(); else this.executed = true; // it is not possible execute a computer if it has no vertex program nor mapreducers if (null == this.vertexProgram && this.mapReducers.isEmpty()) throw GraphComputer.Exceptions.computerHasNoVertexProgramNorMapReducers(); // it is possible to run mapreducers without a vertex program if (null != this.vertexProgram) { GraphComputerHelper.validateProgramOnComputer(this, vertexProgram); this.mapReducers.addAll(this.vertexProgram.getMapReducers()); } // if the user didn't set desired persistence/resultgraph, then get from vertex program or else, no persistence this.persist = GraphComputerHelper.getPersistState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.persist)); this.resultGraph = GraphComputerHelper.getResultGraphState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.resultGraph)); // determine persistence and result graph options if (!this.features().supportsResultGraphPersistCombination(this.resultGraph, this.persist)) throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraph, this.persist); // if too many workers are requested, throw appropriate exception if (this.workers > this.features().getMaxWorkers()) throw GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported(this.workers, this.features().getMaxWorkers()); }
@Test @LoadGraphWith public void shouldSupportPersistResultGraphPairsStatedInFeatures() throws Exception { for (final GraphComputer.ResultGraph resultGraph : GraphComputer.ResultGraph.values()) { for (final GraphComputer.Persist persist : GraphComputer.Persist.values()) { final GraphComputer computer = graphProvider.getGraphComputer(graph); if (computer.features().supportsResultGraphPersistCombination(resultGraph, persist)) { computer.program(new VertexProgramK()).result(resultGraph).persist(persist).submit().get(); } else { try { computer.program(new VertexProgramK()).result(resultGraph).persist(persist).submit().get(); fail("The GraphComputer " + computer + " states that it does support the following resultGraph/persist pair: " + resultGraph + ":" + persist); } catch (final IllegalArgumentException e) { assertEquals(GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(resultGraph, persist).getMessage(), e.getMessage()); } } } } }
@Override public void execute(final Vertex vertex, final Messenger<Object> messenger, final Memory memory) { try { vertex.property(VertexProperty.Cardinality.single, "blah", "blah"); fail("Should throw an IllegalArgumentException"); } catch (final IllegalArgumentException e) { assertEquals(GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey("blah").getMessage(), e.getMessage()); } catch (final Exception e) { fail("Should throw an IllegalArgumentException: " + e); } memory.add("a", 1); if (memory.isInitialIteration()) { vertex.property(VertexProperty.Cardinality.single, "nameLengthCounter", vertex.<String>value("name").length()); memory.add("b", vertex.<String>value("name").length()); } else { vertex.property(VertexProperty.Cardinality.single, "nameLengthCounter", vertex.<String>value("name").length() + vertex.<Integer>value("nameLengthCounter")); } }
@Override public boolean terminate(final Memory memory) { try { memory.get("a"); fail("The memory key does not exist and should fail"); } catch (Exception e) { validateException(Memory.Exceptions.memoryDoesNotExist("a"), e); } try { memory.set("a", true); // fail("Setting a memory key that wasn't declared should fail"); } catch (Exception e) { validateException(GraphComputer.Exceptions.providedKeyIsNotAMemoryComputeKey("a"), e); } return true; }
public <V> Property<V> addProperty(final TinkerVertex vertex, final String key, final V value) { ElementHelper.validateProperty(key, value); if (isComputeKey(key)) { final TinkerVertexProperty<V> property = new TinkerVertexProperty<V>((TinkerVertex) vertex, key, value) { @Override public void remove() { removeProperty(vertex, key, this); } }; this.addValue(vertex, key, property); return property; } else { throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key); } }
@Override public void execute(final Vertex vertex, final Messenger messenger, final Memory memory) { try { memory.get("a"); fail("The memory key does not exist and should fail"); } catch (Exception e) { validateException(Memory.Exceptions.memoryDoesNotExist("a"), e); } try { memory.add("a", true); fail("Setting a memory key that wasn't declared should fail"); } catch (Exception e) { validateException(GraphComputer.Exceptions.providedKeyIsNotAMemoryComputeKey("a"), e); } }
public <V> Property<V> addProperty(final TinkerVertex vertex, final String key, final V value) { ElementHelper.validateProperty(key, value); if (isComputeKey(key)) { final TinkerVertexProperty<V> property = new TinkerVertexProperty<V>((TinkerVertex) vertex, key, value) { @Override public void remove() { removeProperty(vertex, key, this); } }; this.addValue(vertex, key, property); return property; } else { throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key); } }
public <V> Property<V> addProperty(DuctileVertex vertex, String key, V value) { ElementHelper.validateProperty(key, value); if (!isComputeKey(key)) { throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key); } DuctileVertexProperty<V> property = new DuctileVertexProperty<V>(vertex, key, value) { @Override public void remove() { removeProperty(vertex, key, this); } }; addValue(vertex, key, property); return property; }
@Override public void setup(final Memory memory) { try { memory.get("a"); fail("The memory key does not exist and should fail"); } catch (Exception e) { validateException(Memory.Exceptions.memoryDoesNotExist("a"), e); } try { memory.set("a", true); fail("Setting a memory key that wasn't declared should fail"); } catch (Exception e) { validateException(GraphComputer.Exceptions.providedKeyIsNotAMemoryComputeKey("a"), e); } }
@Override public final void accessEdges() { throw GraphComputer.Exceptions.incidentAndAdjacentElementsCanNotBeAccessedInMapReduce(); }
@Override public void accessSetProperty() { throw GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce(); }
@Override public Iterator<Edge> edges(Direction direction, String... edgeLabels) { throw GraphComputer.Exceptions.adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated(); }
@Override public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) { throw GraphComputer.Exceptions.adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated(); }