You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by mw...@apache.org on 2019/12/20 16:49:58 UTC
[accumulo-proxy] branch master updated: Updated Ruby client code
and documentation (#15)
This is an automated email from the ASF dual-hosted git repository.
mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo-proxy.git
The following commit(s) were added to refs/heads/master by this push:
new 32e2c09 Updated Ruby client code and documentation (#15)
32e2c09 is described below
commit 32e2c09a3c00442c6ea9afd181d36934bc308e2c
Author: Mike Walch <mw...@apache.org>
AuthorDate: Fri Dec 20 11:49:52 2019 -0500
Updated Ruby client code and documentation (#15)
---
README.md | 17 +++++++-
src/main/ruby/{proxy_constants.rb => Gemfile} | 15 ++-----
.../accumulo.gemspec} | 20 ++++-----
src/main/ruby/{ => accumulo/lib}/accumulo_proxy.rb | 0
.../ruby/{ => accumulo/lib}/proxy_constants.rb | 0
src/main/ruby/{ => accumulo/lib}/proxy_types.rb | 0
src/main/ruby/client.rb | 47 ++++++++++++++++++++++
7 files changed, 78 insertions(+), 21 deletions(-)
diff --git a/README.md b/README.md
index 63bcb56..943ed5b 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ thrift -r --gen <language> <Thrift filename>
# Create an Accumulo client using Python
-Run the commands below to install the Python bindings and create an example client:
+Run the commands below to install the Python bindings and create an example Python client:
```bash
mkdir accumulo-client/
@@ -68,6 +68,21 @@ vim example.py
pipenv run python2 example.py
```
+# Create an Accumulo client using Ruby
+
+Run the command below to create an example Ruby client:
+
+```bash
+mkdir accumulo-client/
+cd accumulo-client/
+cp /path/to/accumulo-proxy/src/main/ruby/Gemfile .
+vim Gemfile # Set correct path
+cp /path/to/accumulo-proxy/src/main/ruby/client.rb .
+gem install bundler
+bundle install
+bundle exec client.rb
+```
+
[accumulo]: https://accumulo.apache.org
[Thrift]: https://thrift.apache.org
[Thrift tutorial]: https://thrift.apache.org/tutorial/
diff --git a/src/main/ruby/proxy_constants.rb b/src/main/ruby/Gemfile
similarity index 81%
copy from src/main/ruby/proxy_constants.rb
copy to src/main/ruby/Gemfile
index 189a7b4..fc5ad1f 100644
--- a/src/main/ruby/proxy_constants.rb
+++ b/src/main/ruby/Gemfile
@@ -12,14 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-#
-# Autogenerated by Thrift Compiler (0.12.0)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-
-require 'thrift'
-require 'proxy_types'
-
-module Accumulo
-end
+ruby '>2.5'
+source "https://rubygems.org"
+gem 'thrift', '0.11.0.0'
+gem 'accumulo', :path => "/path/to/accumulo-proxy/src/main/ruby/accumulo"
diff --git a/src/main/ruby/proxy_constants.rb b/src/main/ruby/accumulo/accumulo.gemspec
similarity index 59%
copy from src/main/ruby/proxy_constants.rb
copy to src/main/ruby/accumulo/accumulo.gemspec
index 189a7b4..c0f4ff9 100644
--- a/src/main/ruby/proxy_constants.rb
+++ b/src/main/ruby/accumulo/accumulo.gemspec
@@ -12,14 +12,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-#
-# Autogenerated by Thrift Compiler (0.12.0)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-
-require 'thrift'
-require 'proxy_types'
-module Accumulo
+Gem::Specification.new do |s|
+ s.name = 'accumulo'
+ s.version = '1.0.0'
+ s.date = '2019-12-18'
+ s.summary = "Accumulo Client library using Proxy"
+ s.description = "Code that lets you communicate with Accumulo using the Proxy"
+ s.authors = ["Apache Accumulo committers"]
+ s.email = 'user@accumulo.apache.org'
+ s.files = ["lib/accumulo_proxy.rb", "lib/proxy_types.rb", "lib/proxy_constants.rb"]
+ s.homepage = 'https://github.com/apache/accumulo-proxy'
+ s.license = 'Apache-2.0'
end
diff --git a/src/main/ruby/accumulo_proxy.rb b/src/main/ruby/accumulo/lib/accumulo_proxy.rb
similarity index 100%
rename from src/main/ruby/accumulo_proxy.rb
rename to src/main/ruby/accumulo/lib/accumulo_proxy.rb
diff --git a/src/main/ruby/proxy_constants.rb b/src/main/ruby/accumulo/lib/proxy_constants.rb
similarity index 100%
rename from src/main/ruby/proxy_constants.rb
rename to src/main/ruby/accumulo/lib/proxy_constants.rb
diff --git a/src/main/ruby/proxy_types.rb b/src/main/ruby/accumulo/lib/proxy_types.rb
similarity index 100%
rename from src/main/ruby/proxy_types.rb
rename to src/main/ruby/accumulo/lib/proxy_types.rb
diff --git a/src/main/ruby/client.rb b/src/main/ruby/client.rb
new file mode 100755
index 0000000..97d3998
--- /dev/null
+++ b/src/main/ruby/client.rb
@@ -0,0 +1,47 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'thrift'
+require 'accumulo_proxy'
+
+server = ARGV[0] || 'localhost'
+
+socket = Thrift::Socket.new(server, 42424, 9001)
+transport = Thrift::FramedTransport.new(socket)
+proto = Thrift::CompactProtocol.new(transport)
+proxy = Accumulo::AccumuloProxy::Client.new(proto)
+
+# open up the connect
+transport.open()
+
+# Test if the server is up
+login = proxy.login('root', {'password' => 'secret'})
+
+# print out a table list
+puts "List of tables: #{proxy.listTables(login).inspect}"
+
+testtable = "rubytest"
+proxy.createTable(login, testtable, true, Accumulo::TimeType::MILLIS) unless proxy.tableExists(login,testtable)
+
+update1 = Accumulo::ColumnUpdate.new({'colFamily' => "cf1", 'colQualifier' => "cq1", 'value'=> "a"})
+update2 = Accumulo::ColumnUpdate.new({'colFamily' => "cf2", 'colQualifier' => "cq2", 'value'=> "b"})
+proxy.updateAndFlush(login,testtable,{'row1' => [update1,update2]})
+
+cookie = proxy.createScanner(login,testtable,nil)
+result = proxy.nextK(cookie,10)
+result.results.each{ |keyvalue| puts "Key: #{keyvalue.key.inspect} Value: #{keyvalue.value}" }