Tabnine Logo
VertexProgram
Code IndexAdd Tabnine to your IDE (free)

How to use
VertexProgram
in
org.apache.tinkerpop.gremlin.process.computer

Best Java code snippets using org.apache.tinkerpop.gremlin.process.computer.VertexProgram (Showing top 20 results out of 315)

Refine searchRefine arrow

  • Optional
origin: thinkaurelius/titan

public FulgoraMemory(final VertexProgram<?> vertexProgram, final Set<MapReduce> mapReducers) {
  this.currentMap = new ConcurrentHashMap<>();
  this.previousMap = new ConcurrentHashMap<>();
  if (null != vertexProgram) {
    for (final String key : vertexProgram.getMemoryComputeKeys()) {
      MemoryHelper.validateKey(key);
      this.memoryKeys.add(key);
    }
  }
  for (final MapReduce mapReduce : mapReducers) {
    this.memoryKeys.add(mapReduce.getMemoryKey());
  }
}
origin: thinkaurelius/titan

@Override
public void workerIterationEnd(ScanMetrics metrics) {
  vertexProgram.workerIterationEnd(memory.asImmutable());
}
origin: thinkaurelius/titan

@Override
public void workerIterationStart(TitanGraph graph, Configuration config, ScanMetrics metrics) {
  vertexProgram.workerIterationStart(memory.asImmutable());
}
origin: thinkaurelius/titan

@Override
public RecordWriter<NullWritable, VertexWritable> getRecordWriter(TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {
  synchronized (this) {
    if (null == graph) {
      Configuration hadoopConf = taskAttemptContext.getConfiguration();
      ModifiableHadoopConfiguration mhc =
          ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, hadoopConf);
      graph = (StandardTitanGraph) TitanFactory.open(mhc.getTitanGraphConf());
    }
  }
  // Special case for a TP3 vertex program: persist only those properties whose keys are
  // returned by VertexProgram.getComputeKeys()
  if (null == persistableKeys) {
    try {
      persistableKeys = VertexProgram.createVertexProgram(graph,
          ConfUtil.makeApacheConfiguration(taskAttemptContext.getConfiguration())).getElementComputeKeys();
      log.debug("Set persistableKeys={}", Joiner.on(",").join(persistableKeys));
    } catch (Exception e) {
      log.debug("Unable to detect or instantiate vertex program", e);
      persistableKeys = ImmutableSet.of();
    }
  }
  StandardTitanTx tx = transactions.computeIfAbsent(taskAttemptContext.getTaskAttemptID(),
      id -> (StandardTitanTx)graph.newTransaction());
  return new TitanH1RecordWriter(taskAttemptContext, tx, persistableKeys);
}
origin: thinkaurelius/titan

  this.mapReduces.addAll(this.vertexProgram.getMapReducers());
this.persistMode = GraphComputerHelper.getPersistState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.persistMode));
this.resultGraphMode = GraphComputerHelper.getResultGraphState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.resultGraphMode));
    vertexProgram.setup(memory);
    memory.completeSubRound();
      vertexMemory.nextIteration(vertexProgram.getMessageScopes(memory));
      memory.completeSubRound();
      try {
        if (this.vertexProgram.terminate(this.memory)) {
          break;
  if (persistMode == Persist.NOTHING && resultGraphMode == ResultGraph.NEW) {
    resultgraph = EmptyGraph.instance();
  } else if (persistMode != Persist.NOTHING && vertexProgram != null && !vertexProgram.getElementComputeKeys().isEmpty()) {
      for (String key : vertexProgram.getElementComputeKeys()) {
        if (!mgmt.containsPropertyKey(key))
          log.warn("Property key [{}] is not part of the schema and will be created. It is advised to initialize all keys.", key);
      AtomicInteger failures = new AtomicInteger(0);
      try (WorkerPool workers = new WorkerPool(numThreads)) {
        List<Map.Entry<Long, Map<String, Object>>> subset = new ArrayList<>(writeBatchSize / vertexProgram.getElementComputeKeys().size());
        int currentSize = 0;
        for (Map.Entry<Long, Map<String, Object>> entry : mutatedProperties.entrySet()) {
origin: apache/tinkerpop

private ComputerGraph(final State state, final Vertex starVertex, final Optional<VertexProgram<?>> vertexProgram) {
  this.state = state;
  this.computeKeys = vertexProgram.isPresent() ? vertexProgram.get().getVertexComputeKeys().stream().map(VertexComputeKey::getKey).collect(Collectors.toSet()) : Collections.emptySet();
  this.starVertex = new ComputerVertex(starVertex);
}
origin: apache/tinkerpop

        return Collections.emptyIterator();
      final VertexProgram<M> workerVertexProgram = VertexProgram.createVertexProgram(HadoopGraph.open(graphComputerConfiguration), vertexProgramConfiguration); // each partition(Spark)/worker(TP3) has a local copy of the vertex program (a worker's task)
      final String[] vertexComputeKeysArray = VertexProgramHelper.vertexComputeKeysAsArray(workerVertexProgram.getVertexComputeKeys()); // the compute keys as an array
      final SparkMessenger<M> messenger = new SparkMessenger<>();
      workerVertexProgram.workerIterationStart(memory.asImmutable()); // start the worker
      return IteratorUtils.map(partitionIterator, vertexViewIncoming -> {
        final StarGraph.StarVertex vertex = vertexViewIncoming._2()._1().get(); // get the vertex from the vertex writable
        workerVertexProgram.execute(ComputerGraph.vertexProgram(vertex, workerVertexProgram), messenger, memory); // execute the vertex program on this vertex for this iteration
        final List<Tuple2<Object, M>> outgoingMessages = messenger.getOutgoingMessages(); // get the outgoing messages being sent by this vertex
        if (!partitionIterator.hasNext())
          workerVertexProgram.workerIterationEnd(memory.asImmutable()); // if no more vertices in the partition, end the worker's iteration
        return (nextView.isEmpty() && outgoingMessages.isEmpty()) ?
        IteratorUtils.of(new Tuple2<>(tuple._1(), tuple._2().getView())),      // emit the view payload
        IteratorUtils.map(tuple._2().getOutgoingMessages().iterator(), message -> new Tuple2<>(message._1(), new MessagePayload<>(message._2()))));
final MessageCombiner<M> messageCombiner = VertexProgram.<VertexProgram<M>>createVertexProgram(HadoopGraph.open(vertexProgramConfiguration), vertexProgramConfiguration).getMessageCombiner().orElse(null);
final Function2<Payload, Payload, Payload> reducerFunction = (a, b) -> {      // reduce the view and outgoing messages into a single payload object representing the new view and incoming messages for a vertex
  if (a instanceof ViewIncomingPayload) {
origin: apache/tinkerpop

String inputLocation = Constants
    .getSearchGraphLocation(hadoopConfiguration.get(Constants.GREMLIN_HADOOP_INPUT_LOCATION),
        fileSystemStorage).orElse(null);
if (null != inputLocation) {
  try {
    this.vertexProgram.storeState(vertexProgramConfiguration);
    this.vertexProgram.setup(memory);
    JavaPairRDD<Object, ViewIncomingPayload<Object>> viewIncomingRDD = null;
    memory.broadcastMemory(sparkContext);
      viewIncomingRDD = SparkExecutor.executeVertexProgramIteration(loadedGraphRDD, viewIncomingRDD, memory, graphComputerConfiguration, vertexProgramConfiguration);
      memory.setInExecute(false);
      if (this.vertexProgram.terminate(memory))
        break;
      else {
      computedGraphRDD = SparkExecutor.prepareFinalGraphRDD(loadedGraphRDD, viewIncomingRDD, this.vertexProgram.getVertexComputeKeys());
      assert null != computedGraphRDD && computedGraphRDD != loadedGraphRDD;
    } else {
origin: thinkaurelius/titan

public static<M> MessageCombiner<M> getMessageCombiner(VertexProgram<M> program) {
  return program.getMessageCombiner().orElse(DEFAULT_COMBINER);
}
origin: apache/tinkerpop

  this.mapReducers.addAll(this.vertexProgram.getMapReducers());
final Future<ComputerResult> result = computerService.submit(() -> {
  final long time = System.currentTimeMillis();
  final TinkerGraphComputerView view = TinkerHelper.createGraphComputerView(this.graph, this.graphFilter, null != this.vertexProgram ? this.vertexProgram.getVertexComputeKeys() : Collections.emptySet());
  final TinkerWorkerPool workers = new TinkerWorkerPool(this.graph, this.memory, this.workers);
  try {
    if (null != this.vertexProgram) {
      this.vertexProgram.setup(this.memory);
      while (true) {
        if (Thread.interrupted()) throw new TraversalInterruptedException();
        workers.setVertexProgram(this.vertexProgram);
        workers.executeVertexProgram((vertices, vertexProgram, workerMemory) -> {
          vertexProgram.workerIterationStart(workerMemory.asImmutable());
          while (vertices.hasNext()) {
            final Vertex vertex = vertices.next();
            if (Thread.interrupted()) throw new TraversalInterruptedException();
            vertexProgram.execute(
                ComputerGraph.vertexProgram(vertex, vertexProgram),
                new TinkerMessenger<>(vertex, this.messageBoard, vertexProgram.getMessageCombiner()),
                workerMemory);
          vertexProgram.workerIterationEnd(workerMemory.asImmutable());
          workerMemory.complete();
        });
        this.messageBoard.completeIteration();
        this.memory.completeSubRound();
origin: apache/tinkerpop

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());
}
origin: JanusGraph/janusgraph

  this.mapReduces.addAll(this.vertexProgram.getMapReducers());
this.persistMode = GraphComputerHelper.getPersistState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.persistMode));
this.resultGraphMode = GraphComputerHelper.getResultGraphState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.resultGraphMode));
    vertexProgram.setup(memory);
        vertexMemory.nextIteration(vertexProgram.getMessageScopes(memory));
        memory.completeSubRound();
        try {
          if (this.vertexProgram.terminate(this.memory)) {
            break;
  if (persistMode == Persist.NOTHING && resultGraphMode == ResultGraph.NEW) {
    resultgraph = EmptyGraph.instance();
  } else if (persistMode != Persist.NOTHING && vertexProgram != null && !vertexProgram.getVertexComputeKeys().isEmpty()) {
      for (VertexComputeKey key : vertexProgram.getVertexComputeKeys()) {
        if (!management.containsPropertyKey(key.getKey()))
          log.warn("Property key [{}] is not part of the schema and will be created. It is advised to initialize all keys.", key.getKey());
      AtomicInteger failures = new AtomicInteger(0);
      try (WorkerPool workers = new WorkerPool(numThreads)) {
        List<Map.Entry<Long, Map<String, Object>>> subset = new ArrayList<>(writeBatchSize / vertexProgram.getVertexComputeKeys().size());
        int currentSize = 0;
        for (Map.Entry<Long, Map<String, Object>> entry : mutatedProperties.entrySet()) {
origin: apache/tinkerpop

  @Override
  public <P extends VertexProgram> P create(final Graph graph) {
    return (P) VertexProgram.createVertexProgram(graph, this.configuration);
  }
}
origin: apache/tinkerpop

public static void validateProgramOnComputer(final GraphComputer computer, final VertexProgram vertexProgram) {
  if (vertexProgram.getMemoryComputeKeys().contains(null))
    throw Memory.Exceptions.memoryKeyCanNotBeNull();
  if (vertexProgram.getMemoryComputeKeys().contains(""))
    throw Memory.Exceptions.memoryKeyCanNotBeEmpty();
  final GraphComputer.Features graphComputerFeatures = computer.features();
  final VertexProgram.Features vertexProgramFeatures = vertexProgram.getFeatures();
  for (final Method method : VertexProgram.Features.class.getMethods()) {
    if (method.getName().startsWith("requires")) {
      final boolean supports;
      final boolean requires;
      try {
        supports = (boolean) GraphComputer.Features.class.getMethod(method.getName().replace("requires", "supports")).invoke(graphComputerFeatures);
        requires = (boolean) method.invoke(vertexProgramFeatures);
      } catch (final Exception e) {
        throw new IllegalStateException("A reflection exception has occurred: " + e.getMessage(), e);
      }
      if (requires && !supports)
        throw new IllegalStateException("The vertex program can not be executed on the graph computer: " + method.getName());
    }
  }
}
origin: thinkaurelius/titan

@Override
public void process(TitanVertex vertex, ScanMetrics metrics) {
  PreloadedVertex v = (PreloadedVertex)vertex;
  long vertexId = v.longId();
  VertexMemoryHandler<M> vh = new VertexMemoryHandler(vertexMemory,v);
  v.setAccessCheck(PreloadedVertex.OPENSTAR_CHECK);
  if (idManager.isPartitionedVertex(vertexId)) {
    if (idManager.isCanonicalVertexId(vertexId)) {
      EntryList results = v.getFromCache(SYSTEM_PROPS_QUERY);
      if (results == null) results = EntryList.EMPTY_LIST;
      vertexMemory.setLoadedProperties(vertexId,results);
    }
    for (MessageScope scope : vertexMemory.getPreviousScopes()) {
      if (scope instanceof MessageScope.Local) {
        M combinedMsg = null;
        for (Iterator<M> msgIter = vh.receiveMessages(scope).iterator(); msgIter.hasNext(); ) {
          M msg = msgIter.next();
          if (combinedMsg==null) combinedMsg=msg;
          else combinedMsg = combiner.combine(combinedMsg,msg);
        }
        if (combinedMsg!=null) vertexMemory.aggregateMessage(vertexId,combinedMsg,scope);
      }
    }
  } else {
    v.setPropertyMixing(vh);
    vertexProgram.execute(v, vh, memory);
  }
}
origin: JanusGraph/janusgraph

public FulgoraVertexMemory(int numVertices, final IDManager idManager, final VertexProgram<M> vertexProgram) {
  Preconditions.checkArgument(numVertices>=0 && vertexProgram!=null && idManager!=null);
  vertexStates = new NonBlockingHashMapLong<>(numVertices);
  partitionVertices = new NonBlockingHashMapLong<>(64);
  this.idManager = idManager;
  this.combiner = FulgoraUtil.getMessageCombiner(vertexProgram);
  this.computeKeys = vertexProgram.getVertexComputeKeys();
  this.elementKeyMap = getIdMap(vertexProgram.getVertexComputeKeys().stream().map(VertexComputeKey::getKey).collect(Collectors.toCollection(HashSet::new)));
  this.previousScopes = ImmutableMap.of();
}
origin: org.apache.tinkerpop/gremlin-core

private ComputerGraph(final State state, final Vertex starVertex, final Optional<VertexProgram<?>> vertexProgram) {
  this.state = state;
  this.computeKeys = vertexProgram.isPresent() ? vertexProgram.get().getVertexComputeKeys().stream().map(VertexComputeKey::getKey).collect(Collectors.toSet()) : Collections.emptySet();
  this.starVertex = new ComputerVertex(starVertex);
}
origin: ai.grakn/grakn-kb

        return Collections.emptyIterator();}
      final VertexProgram<M> workerVertexProgram = VertexProgram.createVertexProgram(HadoopGraph.open(graphComputerConfiguration), vertexProgramConfiguration); // each partition(Spark)/worker(TP3) has a local copy of the vertex program (a worker's task)
      final String[] vertexComputeKeysArray = VertexProgramHelper.vertexComputeKeysAsArray(workerVertexProgram.getVertexComputeKeys()); // the compute keys as an array
      final SparkMessenger<M> messenger = new SparkMessenger<>();
      workerVertexProgram.workerIterationStart(memory.asImmutable()); // start the worker
      return IteratorUtils.map(partitionIterator, vertexViewIncoming -> {
        final StarGraph.StarVertex vertex = vertexViewIncoming._2()._1().get(); // get the vertex from the vertex writable
        workerVertexProgram.execute(ComputerGraph.vertexProgram(vertex, workerVertexProgram), messenger, memory); // execute the vertex program on this vertex for this iteration
        final List<Tuple2<Object, M>> outgoingMessages = messenger.getOutgoingMessages(); // get the outgoing messages being sent by this vertex
        if (!partitionIterator.hasNext()) {
          workerVertexProgram.workerIterationEnd(memory.asImmutable()); // if no more vertices in the partition, end the worker's iteration}
        }return (nextView.isEmpty() && outgoingMessages.isEmpty()) ?
        IteratorUtils.of(new Tuple2<>(tuple._1(), tuple._2().getView())),      // emit the view payload
        IteratorUtils.map(tuple._2().getOutgoingMessages().iterator(), message -> new Tuple2<>(message._1(), new MessagePayload<>(message._2()))));
final MessageCombiner<M> messageCombiner = VertexProgram.<VertexProgram<M>>createVertexProgram(HadoopGraph.open(vertexProgramConfiguration), vertexProgramConfiguration).getMessageCombiner().orElse(null);
final Function2<Payload, Payload, Payload> reducerFunction = (a, b) -> {      // reduce the view and outgoing messages into a single payload object representing the new view and incoming messages for a vertex
  if (a instanceof ViewIncomingPayload) {
origin: org.apache.tinkerpop/spark-gremlin

String inputLocation = Constants
    .getSearchGraphLocation(hadoopConfiguration.get(Constants.GREMLIN_HADOOP_INPUT_LOCATION),
        fileSystemStorage).orElse(null);
if (null != inputLocation) {
  try {
    this.vertexProgram.storeState(vertexProgramConfiguration);
    this.vertexProgram.setup(memory);
    JavaPairRDD<Object, ViewIncomingPayload<Object>> viewIncomingRDD = null;
    memory.broadcastMemory(sparkContext);
      viewIncomingRDD = SparkExecutor.executeVertexProgramIteration(loadedGraphRDD, viewIncomingRDD, memory, graphComputerConfiguration, vertexProgramConfiguration);
      memory.setInExecute(false);
      if (this.vertexProgram.terminate(memory))
        break;
      else {
      computedGraphRDD = SparkExecutor.prepareFinalGraphRDD(loadedGraphRDD, viewIncomingRDD, this.vertexProgram.getVertexComputeKeys());
      assert null != computedGraphRDD && computedGraphRDD != loadedGraphRDD;
    } else {
origin: JanusGraph/janusgraph

public static<M> MessageCombiner<M> getMessageCombiner(VertexProgram<M> program) {
  return program.getMessageCombiner().orElse(DEFAULT_COMBINER);
}
org.apache.tinkerpop.gremlin.process.computerVertexProgram

Javadoc

A VertexProgram represents one component of a distributed graph computation. Each vertex in the graph (logically) executes the VertexProgram instance in parallel. The collective behavior yields the computational result. In practice, a "worker" (i.e. task, thread, etc.) is responsible for executing the VertexProgram against each vertex that it has in its vertex set (a subset of the full graph vertex set). At minimum there is one "worker" for each vertex, though this is impractical in practice and GraphComputerimplementations that leverage such a design are not expected to perform well due to the excess object creation. Any local state/fields in a VertexProgram is static to the vertices within the same worker set. It is not safe to assume that the VertexProgram's "worker" state will remain stable between iterations. Hence, the existence of VertexProgram#workerIterationStart and VertexProgram#workerIterationEnd.

Most used methods

  • getMemoryComputeKeys
    The Memory keys that will be used during the computation. These are the only keys that can be read o
  • workerIterationEnd
    This method is called at the end of each iteration of each "computational chunk." The set of vertice
  • workerIterationStart
    This method is called at the start of each iteration of each "computational chunk." The set of verti
  • createVertexProgram
    A helper method to construct a VertexProgram given the content of the supplied configuration. The cl
  • execute
    This method denotes the main body of the computation and is executed on each vertex in the graph. Th
  • getMessageCombiner
    Combine the messages in route to a particular vertex. Useful to reduce the amount of data transmitte
  • getVertexComputeKeys
    The org.apache.tinkerpop.gremlin.structure.Element properties that will be mutated during the comput
  • setup
    The method is called at the beginning of the computation. The method is global to the GraphComputer
  • terminate
    The method is called at the end of each iteration to determine if the computation is complete. The m
  • getMapReducers
    The set of MapReduce jobs that are associated with the VertexProgram. This is not necessarily the ex
  • storeState
    When it is necessary to store the state of the VertexProgram, this method is called. This is typical
  • clone
    When multiple workers on a single machine need VertexProgram instances, it is possible to use clone.
  • storeState,
  • clone,
  • getElementComputeKeys,
  • getMessageScopes,
  • loadState,
  • getFeatures,
  • getPreferredPersist,
  • getPreferredResultGraph,
  • getTraverserRequirements

Popular in Java

  • Making http requests using okhttp
  • getSharedPreferences (Context)
  • findViewById (Activity)
  • runOnUiThread (Activity)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Notification (javax.management)
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now