pacer-titan 0.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c3810e21df640978e98a39ccf84e9fc28be977c
4
+ data.tar.gz: 3399b781ddc7edb710deb1a8174c726719aa39b8
5
+ SHA512:
6
+ metadata.gz: bb27e8b12b5b48b73ab5431b86e519ecda849dd56dc9147e5e5e26d74660836029af688240c3d6de62b517d5c5939f2037e4750487740adc650ae5a163f575c0
7
+ data.tar.gz: 8803d3e557170aea64e42dadf9092f3911cc0e8e3bb345ca349f153bdea0dde6c6209694809160b92f76f57f0b5d32c0c24410893f42a8206381e7ebb4adb8fc
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ target/*
6
+ lib/*.jar
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pacer-graph.gemspec
4
+ gemspec
@@ -0,0 +1,51 @@
1
+ # Titan Graph Database Adapter for Pacer
2
+
3
+ [Pacer](https://github.com/pangloss/pacer) is a
4
+ [JRuby](http://jruby.org) graph traversal framework built on the
5
+ [Tinkerpop](http://www.tinkerpop.com) stack.
6
+
7
+ This is an alpha-version pacer adapter with basic support for a [Titan](http://thinkaurelius.github.io/titan) graph in Pacer.
8
+ Based on Derrick's pacer-dex and pacer-neo4j gems.
9
+
10
+ ## Installation
11
+
12
+ You will need to install Maven first.
13
+ Clone this repository.
14
+ Run 'rake install' in its directory to build Titan's jars.
15
+ Include the gem in your project's gemfile, directing its path to your cloned copy.
16
+
17
+ ## Backends
18
+
19
+ This gem includes Titan 0.4.2 and its dependencies.
20
+
21
+ It seems embedded backends (embedded Cassandra, embedded ElasticSearch) do not launch without extra work specifying their class paths when launching your app. The stock gem can run a Cassandra graph via the Thrift connector but will balk at not being able to load log4j.
22
+
23
+ The excellent [jBundler](https://github.com/mkristian/jbundler) does a great job of this for you, simply add any of the following to your Jarfile as needed:
24
+
25
+ jar 'org.slf4j:slf4j-log4j12', '~> 1.7.5' # Logging output
26
+ jar 'com.thinkaurelius.titan:titan-es', '~> 0.4.2' # ElasticSearch
27
+ jar 'com.thinkaurelius.titan:titan-cassandra', '~> 0.4.2' # Embedded Cassandra
28
+ jar 'com.thinkaurelius.titan:titan-berkeleyje', '~> 0.4.2' # BerkeleyDB
29
+
30
+ You may find your JRuby JVM crashes under heavy load if you include too many jars; increase your -XX:MaxPermSize
31
+
32
+ ## Usage
33
+
34
+ Opening a Titan graph in Pacer:
35
+
36
+ require 'pacer'
37
+ require 'pacer-titan'
38
+
39
+ g = Pacer.titan 'path/to/titan_config.properties'
40
+
41
+ The graph settings are specified in an Apache Configuration .properties file.
42
+
43
+ ## Titan-specific routes
44
+
45
+ You can use Titan's query() method in pacer routes.
46
+ g.query{ has('text', Java::ComThinkaureliusTitanCore::Text::CONTAINS, 'lorem') }.out(:author)
47
+
48
+ You can also use Titan's indexQuery() method to send queries in Lucene syntax to external indices like Elastic:
49
+ g.index_query(:text, '(lorem ipsum*)', index_name: 'search').out(:author)
50
+
51
+ The index_query route can take an array of indices as the first parameter, you can also pass an options hash as the third parameter to specify the index name if it is something other than 'search' as used in most of the Titan configuration examples.
@@ -0,0 +1,36 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ file 'pom.xml' => 'lib/pacer-titan/version.rb' do
5
+ pom = File.read 'pom.xml'
6
+ when_writing('Update pom.xml version number') do
7
+ open 'pom.xml', 'w' do |f|
8
+ pom.each_line do |line|
9
+ line.sub!(%r{<gem.version>.*</gem.version>}, "<gem.version>#{ Pacer::Titan::VERSION }</gem.version>")
10
+ line.sub!(%r{<blueprints.version>.*</blueprints.version>}, "<blueprints.version>#{ Pacer::Titan::BLUEPRINTS_VERSION }</blueprints.version>")
11
+ line.sub!(%r{<pipes.version>.*</pipes.version>}, "<pipes.version>#{ Pacer::Titan::PIPES_VERSION }</pipes.version>")
12
+ line.sub!(%r{<titan.version>.*</titan.version>}, "<titan.version>#{ Pacer::Titan::TITAN_VERSION }</titan.version>")
13
+ f << line
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ file Pacer::Titan::JAR_PATH => 'pom.xml' do
20
+ when_writing("Execute 'mvn package' task") do
21
+ system('mvn clean package')
22
+ end
23
+ end
24
+
25
+ task :note do
26
+ puts "NOTE: touch lib/pacer-titan/version.rb (or rake touch) to force everything to rebuild"
27
+ end
28
+
29
+ task :build => [:note, Pacer::Titan::JAR_PATH]
30
+ task :install => [:note, Pacer::Titan::JAR_PATH]
31
+
32
+ desc 'Touch version.rb so that the jar rebuilds'
33
+ task :touch do
34
+ system 'touch', 'lib/pacer-titan/version.rb'
35
+ end
36
+
@@ -0,0 +1,14 @@
1
+ storage.backend=cassandrathrift
2
+ storage.hostname=127.0.0.1
3
+
4
+ cache.db-cache = true
5
+ cache.db-cache-clean-wait = 20
6
+ cache.db-cache-time = 180000
7
+ cache.db-cache-size = 0.25
8
+
9
+ storage.index.search.backend=elasticsearch
10
+ storage.index.search.directory=../../lib/titan_server/db/cassandra/es
11
+ storage.index.search.client-only=false
12
+ storage.index.search.local-mode=true
13
+
14
+ storage.fast-property=true
@@ -0,0 +1,2 @@
1
+ storage.backend=inmemory
2
+ storage.fast-property=true
@@ -0,0 +1,38 @@
1
+ require 'pacer' unless defined? Pacer
2
+
3
+ lib_path = File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
4
+ $:.unshift lib_path unless $:.any? { |path| path == lib_path }
5
+
6
+ require 'pacer-titan/version'
7
+ require Pacer::Titan::JAR
8
+ require 'pacer-titan/graph'
9
+ require 'pacer-titan/titan_query'
10
+ require 'pacer-titan/external_index_query'
11
+
12
+ module Pacer
13
+ class << self
14
+ def titan(path="config/inmemory.properties")
15
+ open = proc do
16
+ graph = Pacer.open_graphs[path]
17
+ unless graph
18
+ args = [java.lang.String.java_class]
19
+ graph = com.thinkaurelius.titan.core.TitanFactory.java_send(:open, args, path)
20
+ Pacer.open_graphs[path] = graph
21
+ end
22
+ graph
23
+ end
24
+
25
+ shutdown = proc do |graph|
26
+ graph.blueprints_graph.shutdown
27
+ Pacer.open_graphs.delete path
28
+ end
29
+
30
+ Titan::Graph.new(Pacer::YamlEncoder, open, shutdown)
31
+ end
32
+
33
+ def executing_route(route)
34
+ Rails.logger.debug "Pacer Titan executing route: #{route.description}" if defined? Rails
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,67 @@
1
+ module Pacer
2
+ module Titan
3
+ class Graph
4
+ # Use Titan's indexQuery to access external indexes using a custom lucene string
5
+ # eg. for grouped words search starting with lorem: g.index_query(:text, '(lorem*)')
6
+ # can also pass an array of properties to hit multiple elasticsearch indices at once
7
+ def index_query(properties, query, options = {})
8
+ options[:element_type] ||= :vertex
9
+ options[:index_name] ||= 'search' # name of the external index as configured in the .properties file
10
+
11
+ chain_route options.merge(
12
+ query: query,
13
+ properties: properties,
14
+ filter: :external_index_query,
15
+ back: self
16
+ )
17
+ end
18
+ end
19
+ end
20
+
21
+ module Filter
22
+ module ExternalIndexQuery
23
+ attr_accessor :query, :properties, :top, :index_name
24
+
25
+ def top_hits(n)
26
+ self.top = n
27
+ self
28
+ end
29
+
30
+ def count
31
+ query_result.count
32
+ end
33
+
34
+ protected
35
+
36
+ def query_result
37
+ query_string = build_titan_lucene_query(query, properties)
38
+ path = graph.blueprints_graph.index_query(index_name, query_string)
39
+ path.limit(top) if top
40
+ path = path.vertices.collect{ |v| v.get_element }
41
+ end
42
+
43
+ # expects query in the form of 'v.text:(lorem*)'
44
+ def build_titan_lucene_query(term, property)
45
+ if property.is_a? Array
46
+ queries = []
47
+ property.each do |prop|
48
+ prop = "\"#{prop}\"" if prop.to_s.include?("_") # need to surround in double quotes if indexed property has an underscore
49
+ queries.concat [ "v.#{prop}:#{term}" ]
50
+ end
51
+ queries.join " OR "
52
+ else
53
+ property = "\"#{property}\"" if property.to_s.include?("_")
54
+ "v.#{property}:#{term}"
55
+ end
56
+ end
57
+
58
+ def source_iterator
59
+ query_result.to_route(element_type: :vertex, graph: graph)
60
+ end
61
+
62
+ def inspect_string
63
+ "#{ inspect_class_name }"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ module Pacer
2
+ module Titan
3
+ # hack to make indexing work:
4
+ class FeatureProxy
5
+ def initialize original_features
6
+ @features = original_features
7
+ end
8
+
9
+ def supportsIndices
10
+ true
11
+ end
12
+
13
+ def method_missing(name, *args, &block)
14
+ @features.public_send(name, *args, &block)
15
+ end
16
+ end
17
+
18
+ class Graph < PacerGraph
19
+ def features
20
+ FeatureProxy.new(blueprints_graph.features)
21
+ end
22
+
23
+ def indices
24
+ key_indices
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ class RSpec::GraphRunner
2
+ module Titan
3
+ def all(usage_style = :read_write, indices = true, &block)
4
+ super
5
+ titan(usage_style, indices, &block)
6
+ end
7
+
8
+ def titan(usage_style = :read_write, indices = true, &block)
9
+ for_graph('titan', usage_style, indices, false, titan_graph, titan_graph_2, nil, block)
10
+ end
11
+
12
+ protected
13
+
14
+ def titan_graph
15
+ return @titan_graph if @titan_graph
16
+ @titan_graph = Pacer.titan('../pacer-titan/config/inmemory.properties')
17
+ end
18
+
19
+ def titan_graph_2
20
+ return @titan_graph_2 if @titan_graph_2
21
+ @dex_graph2 = Pacer.titan('../pacer-titan/config/inmemory.properties')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,47 @@
1
+ module Pacer
2
+ module Titan
3
+ class Graph
4
+ # Use Titan's QueryBuilder to access indexes (replaces g.v(key: value) style index querying
5
+ # eg: g.query{ has('login', 'ilya').has('description', Text::CONTAINS, 'abc') }.out(:messages)
6
+ # be sure to java_import com.thinkaurelius.titan.core.attribute.Text for the above example
7
+ def query(options = { element_type: :vertex }, &query)
8
+ chain_route options.merge(
9
+ query: query,
10
+ filter: :titan_query,
11
+ back: self
12
+ )
13
+ end
14
+ end
15
+ end
16
+
17
+ module Filter
18
+ module TitanQuery
19
+ attr_accessor :query, :top
20
+
21
+ def top_hits(n)
22
+ self.top = n
23
+ self
24
+ end
25
+
26
+ def count
27
+ query_result.count
28
+ end
29
+
30
+ protected
31
+
32
+ def query_result
33
+ path = graph.blueprints_graph.query.instance_exec(&query)
34
+ path.limit(top) if top
35
+ path = path.vertices
36
+ end
37
+
38
+ def source_iterator
39
+ query_result.to_route(element_type: :vertex, graph: graph)
40
+ end
41
+
42
+ def inspect_string
43
+ "#{ inspect_class_name }"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,11 @@
1
+ module Pacer
2
+ module Titan
3
+ VERSION = "0.0.1"
4
+ JAR = "pacer-titan-#{ VERSION }-standalone.jar"
5
+ JAR_PATH = "lib/#{ JAR }"
6
+ BLUEPRINTS_VERSION = "2.4.0"
7
+ PIPES_VERSION = "2.4.0"
8
+ TITAN_VERSION = "0.4.2"
9
+ PACER_REQ = ">= 1.4.0"
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pacer-titan/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pacer-titan"
7
+ s.version = Pacer::Titan::VERSION
8
+ s.platform = 'java'
9
+ s.authors = ["Ilya Kardailsky"]
10
+ s.email = ["ilya.kardailsky@gmail.com"]
11
+ s.homepage = "http://www.github.com"
12
+ s.summary = %q{Titan jars and related code for Pacer}
13
+ s.description = s.summary
14
+
15
+ s.add_dependency 'pacer', Pacer::Titan::PACER_REQ
16
+
17
+ s.files = `git ls-files`.split("\n") + [Pacer::Titan::JAR_PATH]
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
data/pom.xml ADDED
@@ -0,0 +1,130 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5
+ <modelVersion>4.0.0</modelVersion>
6
+ <groupId>com.tinkerpop.pacer</groupId>
7
+ <artifactId>pacer-titan</artifactId>
8
+ <!-- NOTE: the following properties are automatically updated based on the values in lib/pacer-titan/version.rb -->
9
+ <properties>
10
+ <gem.version>0.0.1</gem.version>
11
+ <blueprints.version>2.4.0</blueprints.version>
12
+ <pipes.version>2.4.0</pipes.version>
13
+ <titan.version>0.4.2</titan.version>
14
+ </properties>
15
+ <!-- NOTE: the following properties are automatically updated based on the values in lib/pacer-titan/version.rb -->
16
+ <version>${gem.version}</version>
17
+ <packaging>pom</packaging>
18
+ <url>https://github.com/pangloss/pacer</url>
19
+ <name>Pacer Titan dependencies and related code.</name>
20
+ <description>
21
+ </description>
22
+ <inceptionYear>2014</inceptionYear>
23
+ <developers>
24
+ <developer>
25
+ <name>Ilya Kardailsky</name>
26
+ <email>ilya.kardailsky@gmail.com</email>
27
+ <url>http://github.com</url>
28
+ </developer>
29
+ </developers>
30
+ <dependencies>
31
+ <!-- PROPERTY GRAPH MODEL SUPPORT -->
32
+ <dependency>
33
+ <groupId>com.tinkerpop.blueprints</groupId>
34
+ <artifactId>blueprints-core</artifactId>
35
+ <version>${blueprints.version}</version>
36
+ </dependency>
37
+ <!-- GRAPH TRAVERSAL SUPPORT -->
38
+ <dependency>
39
+ <groupId>com.tinkerpop</groupId>
40
+ <artifactId>pipes</artifactId>
41
+ <version>${pipes.version}</version>
42
+ </dependency>
43
+ <!-- TITAN SUPPORT -->
44
+ <dependency>
45
+ <groupId>com.thinkaurelius.titan</groupId>
46
+ <artifactId>titan-core</artifactId>
47
+ <version>${titan.version}</version>
48
+ </dependency>
49
+ </dependencies>
50
+
51
+ <repositories>
52
+ <repository>
53
+ <id>tinkerpop-repository</id>
54
+ <name>TinkerPop Maven2 Repository</name>
55
+ <url>http://tinkerpop.com/maven2</url>
56
+ <snapshots>
57
+ <enabled>true</enabled>
58
+ <updatePolicy>always</updatePolicy>
59
+ </snapshots>
60
+ </repository>
61
+ </repositories>
62
+
63
+ <distributionManagement>
64
+ <repository>
65
+ <id>tinkerpop-repository</id>
66
+ <name>TinkerPop Maven2 Repository</name>
67
+ <url>ftp://ftp.tinkerpop.com:21/public/maven2/</url>
68
+ </repository>
69
+ </distributionManagement>
70
+
71
+ <build>
72
+ <directory>${basedir}/target</directory>
73
+ <finalName>${project.artifactId}-${project.version}</finalName>
74
+ <resources>
75
+ <resource>
76
+ <directory>${basedir}/src/main/resources
77
+ </directory>
78
+ </resource>
79
+ </resources>
80
+ <testResources>
81
+ <testResource>
82
+ <directory>${basedir}/src/test/resources
83
+ </directory>
84
+ </testResource>
85
+ </testResources>
86
+ <plugins>
87
+ <plugin>
88
+ <artifactId>maven-compiler-plugin</artifactId>
89
+ <configuration>
90
+ <source>1.6</source>
91
+ <target>1.6</target>
92
+ </configuration>
93
+ </plugin>
94
+ <plugin>
95
+ <artifactId>maven-assembly-plugin</artifactId>
96
+ <version>2.2-beta-4</version>
97
+ <executions>
98
+ <execution>
99
+ <phase>package</phase>
100
+ <goals>
101
+ <goal>attached</goal>
102
+ </goals>
103
+ </execution>
104
+ </executions>
105
+ <configuration>
106
+ <descriptors>
107
+ <descriptor>pom/standalone.xml</descriptor>
108
+ </descriptors>
109
+ <finalName>${project.artifactId}-${project.version}</finalName>
110
+ <outputDirectory>lib</outputDirectory>
111
+ <workDirectory>target/assembly/work</workDirectory>
112
+ <tarLongFileMode>warn</tarLongFileMode>
113
+ </configuration>
114
+ </plugin>
115
+ <plugin>
116
+ <groupId>org.apache.maven.plugins</groupId>
117
+ <artifactId>maven-javadoc-plugin</artifactId>
118
+ <version>2.6.1</version>
119
+ </plugin>
120
+ </plugins>
121
+ <extensions>
122
+ <extension>
123
+ <groupId>org.apache.maven.wagon</groupId>
124
+ <artifactId>wagon-ftp</artifactId>
125
+ <version>1.0-alpha-6</version>
126
+ </extension>
127
+ </extensions>
128
+ </build>
129
+
130
+ </project>
@@ -0,0 +1,22 @@
1
+ <assembly>
2
+ <id>standalone</id>
3
+ <formats>
4
+ <format>jar</format>
5
+ </formats>
6
+ <includeBaseDirectory>false</includeBaseDirectory>
7
+
8
+ <fileSets>
9
+ <fileSet>
10
+ <directory>target/classes</directory>
11
+ <outputDirectory>/</outputDirectory>
12
+ </fileSet>
13
+ </fileSets>
14
+
15
+ <dependencySets>
16
+ <dependencySet>
17
+ <outputDirectory>/</outputDirectory>
18
+ <unpack>true</unpack>
19
+ <scope>runtime</scope>
20
+ </dependencySet>
21
+ </dependencySets>
22
+ </assembly>
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pacer-titan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: java
6
+ authors:
7
+ - Ilya Kardailsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pacer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.0
27
+ description: Titan jars and related code for Pacer
28
+ email:
29
+ - ilya.kardailsky@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - README.md
37
+ - Rakefile
38
+ - config/cassandra-es.properties
39
+ - config/inmemory.properties
40
+ - lib/pacer-titan.rb
41
+ - lib/pacer-titan/external_index_query.rb
42
+ - lib/pacer-titan/graph.rb
43
+ - lib/pacer-titan/rspec.rb
44
+ - lib/pacer-titan/titan_query.rb
45
+ - lib/pacer-titan/version.rb
46
+ - pacer-titan.gemspec
47
+ - pom.xml
48
+ - pom/standalone.xml
49
+ - lib/pacer-titan-0.0.1-standalone.jar
50
+ homepage: http://www.github.com
51
+ licenses: []
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.0.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Titan jars and related code for Pacer
73
+ test_files: []