kijirest-client 0.0.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +203 -22
- data/README.md +21 -23
- data/client_tester.rb +35 -0
- data/lib/kijirest/client.rb +44 -55
- data/lib/kijirest/server.rb +11 -15
- data/lib/kijirest/version.rb +1 -1
- data/pkg/kijirest-client-0.0.1.gem +0 -0
- data/pkg/kijirest-client-0.0.1.pre.gem +0 -0
- data/server_tester.rb +22 -0
- metadata +7 -3
- data/.gitignore +0 -17
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NTRkNjA2ZTEwMjJlYzhhMWU5NDZhNGZmZGI5OWRjNWNmYmMzMzI5Ng==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
NTg5MjJmNTc0ZmE2MzZhMDIzOTg4YjJmODI4NWY3MGYyNTQyMzg0ZQ==
|
|
7
7
|
!binary "U0hBNTEy":
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
YjhjMGQyZjA5Mjk3ZjMyMWVhMWE3MGI4OGJhOGI2NjZhZjhmZTBkYWYyNjll
|
|
10
|
+
YjM5Yjk2MmYzNDAxYTI1ZWQ5NTA4NzRlYWNmOThkZDdlOTZkNmVjZWYzMzA2
|
|
11
|
+
NTFiMDkzOWU1ODI1YjAzMjkxMmM3ZTZlZGQ1NTE5NWJiMTc5NzA=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
YmRmYjBmZTFhMmI0NzdjYzI3ZTUyMGFlZmRmN2Y3YmE4OTM3Njk2ZmFiMGM4
|
|
14
|
+
NWMyNzQzOTBlNzhiMDEwMjEwYzk2OWQyYjQ2OTIxYjg2NzI1MjFlZGJmNzE2
|
|
15
|
+
OGNkNzMwNGFlZWY3MjkyYWIyYjVkN2ZmN2YwZjE5MDE0MGNlYmM=
|
data/Gemfile.lock
ADDED
data/LICENSE.txt
CHANGED
|
@@ -1,22 +1,203 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
data/README.md
CHANGED
|
@@ -36,34 +36,32 @@ Or install it yourself as:
|
|
|
36
36
|
# List instances
|
|
37
37
|
instances = c.instances
|
|
38
38
|
|
|
39
|
-
# List tables for a known instance ("
|
|
40
|
-
tables = c.tables("
|
|
41
|
-
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
cell["value"] = 300
|
|
55
|
-
break
|
|
56
|
-
end
|
|
39
|
+
# List tables for a known instance ("default")
|
|
40
|
+
tables = c.tables("default") # Assuming the layout created from http://www.kiji.org/getstarted/#Quick_Start_Guide
|
|
41
|
+
|
|
42
|
+
# Create a new user
|
|
43
|
+
eid = ["my_user"]
|
|
44
|
+
row_hash={
|
|
45
|
+
KijiRest::Client::ENTITY_ID => eid,
|
|
46
|
+
"cells" => {
|
|
47
|
+
"info" => {
|
|
48
|
+
"email" => [ {
|
|
49
|
+
"value" => "name@company.com",
|
|
50
|
+
"writer_schema" => "string"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
# Set the entity_id key to the new entity_id we wish to create
|
|
60
|
-
row_hash[KijiRest::Client::ENTITY_ID] = new_eid
|
|
55
|
+
}
|
|
61
56
|
|
|
62
57
|
# Write the new row. The final argument is what dictates whether or not to strip
|
|
63
58
|
# timestamps from an existing row_hash or not. This is handy if you are using the results
|
|
64
59
|
# from the GET of another row to write a new row.
|
|
65
|
-
puts c.write_row("
|
|
60
|
+
puts c.write_row("default","users",row_hash,true)
|
|
66
61
|
|
|
62
|
+
# Verify that what we wrote is what we expected
|
|
63
|
+
my_written_row = c.row("default","users",["my_user"])
|
|
64
|
+
puts my_written_row["cells"]["info"]["email"][0]["value"] == "name@company.com"
|
|
67
65
|
## KijiRest::Server
|
|
68
66
|
|
|
69
67
|
require 'kijirest/server'
|
|
@@ -86,4 +84,4 @@ Or install it yourself as:
|
|
|
86
84
|
puts c.instances
|
|
87
85
|
|
|
88
86
|
# Let's stop the server and wait for the server to shutdown before returning.
|
|
89
|
-
s.stop(true)
|
|
87
|
+
s.stop(true)
|
data/client_tester.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require "./lib/kijirest/client.rb"
|
|
2
|
+
#require 'kijirest/client'
|
|
3
|
+
|
|
4
|
+
# Construct a new client pointing at localhost:8080
|
|
5
|
+
c=KijiRest::Client.new("http://localhost:8080")
|
|
6
|
+
|
|
7
|
+
# List instances
|
|
8
|
+
instances = c.instances
|
|
9
|
+
|
|
10
|
+
# List tables for a known instance ("default")
|
|
11
|
+
tables = c.tables("default") # Assuming the layout created from http://www.kiji.org/getstarted/#Quick_Start_Guide
|
|
12
|
+
|
|
13
|
+
# Create a new user
|
|
14
|
+
eid = ["my_user"]
|
|
15
|
+
row_hash={
|
|
16
|
+
KijiRest::Client::ENTITY_ID => eid,
|
|
17
|
+
"cells" => {
|
|
18
|
+
"info" => {
|
|
19
|
+
"email" => [ {
|
|
20
|
+
"value" => "name@company.com",
|
|
21
|
+
"writer_schema" => "string"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Write the new row. The final argument is what dictates whether or not to strip
|
|
29
|
+
# timestamps from an existing row_hash or not. This is handy if you are using the results
|
|
30
|
+
# from the GET of another row to write a new row.
|
|
31
|
+
puts c.write_row("default","users",row_hash,true)
|
|
32
|
+
|
|
33
|
+
# Verify that what we wrote is what we expected
|
|
34
|
+
my_written_row = c.row("default","users",["my_user"])
|
|
35
|
+
puts my_written_row["cells"]["info"]["email"][0]["value"] == "name@company.com"
|
data/lib/kijirest/client.rb
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
require "kijirest/version"
|
|
19
19
|
require 'net/http'
|
|
20
|
+
require 'uri'
|
|
20
21
|
require 'json'
|
|
21
22
|
require 'cgi'
|
|
22
23
|
|
|
@@ -62,25 +63,19 @@ module KijiRest
|
|
|
62
63
|
get_json(instance_endpoint(instance_name))
|
|
63
64
|
end
|
|
64
65
|
|
|
65
|
-
# Returns a single row from the given table.
|
|
66
|
-
# param: instance_name is the name of the instance
|
|
67
|
-
# param: table_name is the name of the table
|
|
68
|
-
# param: rowkey is the rowkey to fetch
|
|
69
|
-
# param: filters is a hash containing any filters to apply which will get translated as
|
|
70
|
-
# query parameters in the REST call.
|
|
71
|
-
def row(instance_name, table_name, rowkey, filters= {})
|
|
72
|
-
get_json("#{rows_endpoint(instance_name, table_name)}/#{rowkey}", filters)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
66
|
# Returns a single row (identified by the specified entity_id) from the given table.
|
|
76
67
|
# param: instance_name is the name of the instance
|
|
77
68
|
# param: table_name is the name of the table
|
|
78
|
-
# param: entity_id is
|
|
69
|
+
# param: entity_id is an array of components comprising the entity_id to fetch.
|
|
79
70
|
# param: filters is a hash containing any filters to apply which will get translated as
|
|
80
71
|
# query parameters in the REST call.
|
|
81
|
-
def
|
|
82
|
-
eid_filter =
|
|
83
|
-
|
|
72
|
+
def row(instance_name, table_name, entity_id, filters= {})
|
|
73
|
+
eid_filter = if(entity_id.is_a? Array)
|
|
74
|
+
entity_id.to_json
|
|
75
|
+
else
|
|
76
|
+
entity_id
|
|
77
|
+
end
|
|
78
|
+
get_json(rows_endpoint(instance_name, table_name), filters.merge({:eid => eid_filter}))
|
|
84
79
|
end
|
|
85
80
|
|
|
86
81
|
# Returns a list of the tables in the given instance.
|
|
@@ -144,53 +139,47 @@ module KijiRest
|
|
|
144
139
|
end
|
|
145
140
|
end
|
|
146
141
|
|
|
147
|
-
def self.format_entity_id(*components)
|
|
148
|
-
# Take non-strings and quote them
|
|
149
|
-
json_entity_id = components.map {|comp|
|
|
150
|
-
if comp.is_a?(Numeric)
|
|
151
|
-
comp.to_s
|
|
152
|
-
else
|
|
153
|
-
"'#{comp}'"
|
|
154
|
-
end
|
|
155
|
-
}.join(",")
|
|
156
|
-
"[#{json_entity_id}]"
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# Returns the rowkey for a given list of components. Note: string components do NOT need
|
|
160
|
-
# to be escaped strings or specially quoted. When the endpoint is invoked, they will be
|
|
161
|
-
# enclosed in single quotes to satisfy the server-side requirements.
|
|
162
|
-
# param: components are the individual components that comprise the rowkey
|
|
163
|
-
def rowkey(instance_name, table_name, *components)
|
|
164
|
-
return_obj = get_json(entityid_endpoint(instance_name, table_name),
|
|
165
|
-
"eid" => Client::format_entity_id(*components))
|
|
166
|
-
if return_obj
|
|
167
|
-
return_obj["rowKey"]
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
142
|
# Creates or updates a new row by POSTing the row_hash to the server. Will create/update
|
|
172
143
|
# the row specified by the entityId key in the row_hash.
|
|
173
144
|
# param: instance_name is the instance
|
|
174
145
|
# param: table_name is the table
|
|
175
146
|
# param: row_hash is a hash containing the data to POST. Must be of the format:
|
|
176
|
-
# {
|
|
177
|
-
#
|
|
178
|
-
#
|
|
179
|
-
#
|
|
180
|
-
#
|
|
181
|
-
#
|
|
182
|
-
#
|
|
147
|
+
# {
|
|
148
|
+
# "entityId" : [//JSON component Array],
|
|
149
|
+
# "cells" : {
|
|
150
|
+
# "family" : {
|
|
151
|
+
# "qualifier" : [
|
|
152
|
+
# {
|
|
153
|
+
# "timestamp" : <timestamp>,
|
|
154
|
+
# "value": <JSON representation of object to post>,
|
|
155
|
+
# "writer_schema": <JSON representation of the writer
|
|
156
|
+
# schema (Avro) OR the Kiji ID of the
|
|
157
|
+
# schema>
|
|
158
|
+
# },
|
|
159
|
+
# ...
|
|
160
|
+
# ]
|
|
161
|
+
# }
|
|
162
|
+
# }
|
|
163
|
+
# }
|
|
183
164
|
# param: strip_timestamp will remove any timestamp fields from the cells allowing the server
|
|
184
165
|
# to set the timestamp automatically (default false).
|
|
185
|
-
|
|
166
|
+
# param: timeout_seconds specifies the number of seconds before a Timeout::Error is thrown
|
|
167
|
+
# (default nil, which falls back to Net:HTTP default of 60 seconds)
|
|
168
|
+
def write_row(instance_name, table_name, row_hash, strip_timestamp= false, timeout_seconds = nil)
|
|
186
169
|
if strip_timestamp
|
|
187
|
-
local_row_hash =
|
|
170
|
+
local_row_hash = row_hash.clone
|
|
188
171
|
if local_row_hash.include?("cells")
|
|
189
|
-
local_row_hash["cells"].each {|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
172
|
+
local_row_hash["cells"].each { |family,qualifierMap|
|
|
173
|
+
if qualifierMap
|
|
174
|
+
qualifierMap.each_value { |cells|
|
|
175
|
+
cells.each {|cell|
|
|
176
|
+
# TODO: Remove condition when there's a better way to represent cell level error
|
|
177
|
+
# conditions on GETs.
|
|
178
|
+
cell.delete("timestamp") unless cell["timestamp"] == -1
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
end
|
|
182
|
+
}
|
|
194
183
|
end
|
|
195
184
|
row_json = local_row_hash.to_json
|
|
196
185
|
else
|
|
@@ -198,6 +187,9 @@ module KijiRest
|
|
|
198
187
|
end
|
|
199
188
|
uri= URI(@base_uri)
|
|
200
189
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
190
|
+
if timeout_seconds
|
|
191
|
+
http.read_timeout = timeout_seconds
|
|
192
|
+
end
|
|
201
193
|
response = http.post(rows_endpoint(instance_name, table_name), row_json,
|
|
202
194
|
"Content-Type" => "application/json")
|
|
203
195
|
case response
|
|
@@ -231,9 +223,6 @@ module KijiRest
|
|
|
231
223
|
"#{table_endpoint(instance_name, table_name)}/rows"
|
|
232
224
|
end
|
|
233
225
|
|
|
234
|
-
def entityid_endpoint(instance_name, table_name)
|
|
235
|
-
"#{table_endpoint(instance_name, table_name)}/entityId"
|
|
236
|
-
end
|
|
237
226
|
# END endpoint definitions
|
|
238
227
|
|
|
239
228
|
# Generic method that will raise a KijiRestClientError that contains a JSON object
|
data/lib/kijirest/server.rb
CHANGED
|
@@ -62,15 +62,15 @@ module KijiRest
|
|
|
62
62
|
f.puts(dropwizard_config.to_yaml)
|
|
63
63
|
f.close
|
|
64
64
|
#Now start the service
|
|
65
|
-
launch_command = qualify_file("/bin/kiji-rest")
|
|
65
|
+
launch_command = qualify_file("/bin/kiji-rest start")
|
|
66
66
|
%x{#{launch_command}}
|
|
67
67
|
if wait_for_load
|
|
68
68
|
(1..20).each {|i|
|
|
69
|
-
break if
|
|
69
|
+
break if running?
|
|
70
70
|
sleep 2
|
|
71
71
|
}
|
|
72
|
-
unless
|
|
73
|
-
raise "
|
|
72
|
+
unless running?
|
|
73
|
+
raise "KijiREST failed to start!"
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
end
|
|
@@ -81,22 +81,18 @@ module KijiRest
|
|
|
81
81
|
# before returning.
|
|
82
82
|
def stop(wait_for_shutdown = false)
|
|
83
83
|
pid_file = qualify_file("kiji-rest.pid")
|
|
84
|
+
launch_command = qualify_file("/bin/kiji-rest stop")
|
|
84
85
|
if File.exist?(pid_file)
|
|
85
|
-
|
|
86
|
-
pid = pid_file_obj.gets
|
|
87
|
-
pid_file_obj.close
|
|
88
|
-
#Kill the pid cleanly first
|
|
89
|
-
%x{kill #{pid}}
|
|
86
|
+
%x{#{launch_command}}
|
|
90
87
|
if wait_for_shutdown
|
|
91
88
|
(1..20).each {|i|
|
|
92
|
-
break unless
|
|
89
|
+
break unless running?
|
|
93
90
|
sleep 2
|
|
94
91
|
}
|
|
95
|
-
if
|
|
96
|
-
|
|
92
|
+
if running?
|
|
93
|
+
raise "KijiREST failed to stop."
|
|
97
94
|
end
|
|
98
95
|
end
|
|
99
|
-
File.delete(pid_file)
|
|
100
96
|
else
|
|
101
97
|
raise "KijiREST not running!"
|
|
102
98
|
end
|
|
@@ -128,7 +124,7 @@ module KijiRest
|
|
|
128
124
|
# Checks if the application is running by hitting a known URI
|
|
129
125
|
def app_running?
|
|
130
126
|
begin
|
|
131
|
-
f = open("http://localhost:#{@http_port}/v1
|
|
127
|
+
f = open("http://localhost:#{@http_port}/v1")
|
|
132
128
|
f.close
|
|
133
129
|
true
|
|
134
130
|
rescue
|
|
@@ -148,7 +144,7 @@ module KijiRest
|
|
|
148
144
|
# Checks if the server is running by checking the process file (kiji-rest.pid)
|
|
149
145
|
# or the global/root run /var/run/kiji-rest.pid
|
|
150
146
|
def running?
|
|
151
|
-
app_running?
|
|
147
|
+
app_running? && pid_exists?
|
|
152
148
|
end
|
|
153
149
|
|
|
154
150
|
# Returns a fully qualified filename prefixed by the location of kiji_rest_server
|
data/lib/kijirest/version.rb
CHANGED
|
Binary file
|
|
Binary file
|
data/server_tester.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "./lib/kijirest/server.rb"
|
|
2
|
+
#require 'kijirest/server'
|
|
3
|
+
|
|
4
|
+
# Construct a new server object passing in the location where the kiji-rest application
|
|
5
|
+
# resides. Note: The owner of the kiji-rest folder must be the same user who is running
|
|
6
|
+
# this code else an exception will be raised.
|
|
7
|
+
s = KijiRest::Server.new("../../kiji-rest/target/kiji-rest-1.0.1-SNAPSHOT-release/kiji-rest-1.0.1-SNAPSHOT/")
|
|
8
|
+
|
|
9
|
+
# Launch the KijiREST server setting the cluster to .env and the array of visible instances
|
|
10
|
+
# to ["default"]. The final argument indicates to wait for the server to finish launching
|
|
11
|
+
# before returning.
|
|
12
|
+
s.start(".env",["default"], true)
|
|
13
|
+
|
|
14
|
+
# Get a reference to a new client pointing at
|
|
15
|
+
# http://localhost:<port set in conf/configuration.yml>
|
|
16
|
+
c = s.new_client
|
|
17
|
+
|
|
18
|
+
# Get a list of instances.
|
|
19
|
+
puts c.instances
|
|
20
|
+
|
|
21
|
+
# Let's stop the server and wait for the server to shutdown before returning.
|
|
22
|
+
s.stop(true)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kijirest-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- wibidata
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-
|
|
11
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -45,15 +45,19 @@ executables: []
|
|
|
45
45
|
extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
|
47
47
|
files:
|
|
48
|
-
- .gitignore
|
|
49
48
|
- Gemfile
|
|
49
|
+
- Gemfile.lock
|
|
50
50
|
- LICENSE.txt
|
|
51
51
|
- README.md
|
|
52
52
|
- Rakefile
|
|
53
|
+
- client_tester.rb
|
|
53
54
|
- kijirest-client.gemspec
|
|
54
55
|
- lib/kijirest/client.rb
|
|
55
56
|
- lib/kijirest/server.rb
|
|
56
57
|
- lib/kijirest/version.rb
|
|
58
|
+
- pkg/kijirest-client-0.0.1.gem
|
|
59
|
+
- pkg/kijirest-client-0.0.1.pre.gem
|
|
60
|
+
- server_tester.rb
|
|
57
61
|
homepage: http://www.kiji.org
|
|
58
62
|
licenses:
|
|
59
63
|
- Apache
|