embulk-input-mongodb 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc232a73722d1157d53b5d4de1374cadd11cd234
4
- data.tar.gz: 7792d6114a467b793fcacfaa9a64df7bfe1e5aa3
3
+ metadata.gz: 669b8b7010ff112526a166dd4eef85a50656e77f
4
+ data.tar.gz: adea0810c4f04ee5cec5ec8ba7414557a8f179a2
5
5
  SHA512:
6
- metadata.gz: 1af752c57c9fc04d2d65e9665d6c11c739be8c2805c07b6bd65fad7a244685bf78eaf8da6a5a84e59d48e1fd18db671690789ace2d9cd7c6d62d2e1afcb5c390
7
- data.tar.gz: 2cb4e589f0e8d524414b6a51135b4931ca91514f811b036c5d1452e2933045a4a86d7c3a615ce31eef85d8c23e66c1ba78d8ad952d9a5dd324e9c15682933038
6
+ metadata.gz: b8fad0bab206efc47861e6cb714c1def66cbfcb7440e042584daf454f84ef2673cdd2c8482bb3edfe3920d3bf82827c99c6cccb06d2890ea2a823be8122fffe8
7
+ data.tar.gz: 277157cc6382dbb98795f6e3e0ef3aaa14a31faec1f663069d9bc133f4b246a6cb73da39a2e5c5b7f80a36ae4ade7145cd01464b9c9feec896eb205dbec2ba7b
data/.travis.yml CHANGED
@@ -26,7 +26,8 @@ cache:
26
26
  before_install:
27
27
  - cat /etc/hosts # optionally check the content *before*
28
28
  - sudo hostname "$(hostname | cut -c1-63)"
29
- - sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts | sudo tee /etc/hosts
29
+ - sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts > /tmp/hosts
30
+ - sudo mv /tmp/hosts /etc/hosts
30
31
  - cat /etc/hosts # optionally check the content *after*
31
32
 
32
33
  install:
@@ -42,14 +43,14 @@ install:
42
43
 
43
44
  before_script:
44
45
  - echo "Wait mongodb wakeup"
45
- - sleep 10
46
+ - sleep 15
46
47
  - mkdir -p ./tmp
47
48
  - date
48
49
 
49
50
  script:
50
51
  - ./gradlew check
51
52
  - ./gradlew package
52
- - mongoimport --db $MONGO_DATABASE --collection $MONGO_COLLECTION --type json --drop src/test/resources/my_collection.jsonl
53
+ - mongoimport --host 127.0.0.1 --db $MONGO_DATABASE --collection $MONGO_COLLECTION --type json --drop src/test/resources/my_collection.jsonl
53
54
  - |
54
55
  for target in basic full id_field_name
55
56
  do
data/CHANGELOG.md ADDED
@@ -0,0 +1,97 @@
1
+ # Change Log
2
+
3
+ ## [v0.5.0](https://github.com/hakobera/embulk-input-mongodb/tree/v0.5.0) (2016-08-23)
4
+ [Full Changelog](https://github.com/hakobera/embulk-input-mongodb/compare/v0.4.0...v0.5.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Support separated URI params [\#24](https://github.com/hakobera/embulk-input-mongodb/pull/24) ([sakama](https://github.com/sakama))
9
+
10
+ **Merged pull requests:**
11
+
12
+ - Add --host option to mongoimport to prevent connection failure. [\#27](https://github.com/hakobera/embulk-input-mongodb/pull/27) ([hakobera](https://github.com/hakobera))
13
+ - Add document about batch\_size config [\#25](https://github.com/hakobera/embulk-input-mongodb/pull/25) ([hakobera](https://github.com/hakobera))
14
+
15
+ ## [v0.4.0](https://github.com/hakobera/embulk-input-mongodb/tree/v0.4.0) (2016-07-08)
16
+ [Full Changelog](https://github.com/hakobera/embulk-input-mongodb/compare/v0.3.2...v0.4.0)
17
+
18
+ **Implemented enhancements:**
19
+
20
+ - Support incremental load [\#16](https://github.com/hakobera/embulk-input-mongodb/pull/16) ([sakama](https://github.com/sakama))
21
+
22
+ **Merged pull requests:**
23
+
24
+ - Bumpup version to 0.4.0 [\#23](https://github.com/hakobera/embulk-input-mongodb/pull/23) ([hakobera](https://github.com/hakobera))
25
+
26
+ ## [v0.3.2](https://github.com/hakobera/embulk-input-mongodb/tree/v0.3.2) (2016-06-23)
27
+ [Full Changelog](https://github.com/hakobera/embulk-input-mongodb/compare/v0.3.1...v0.3.2)
28
+
29
+ **Implemented enhancements:**
30
+
31
+ - Support Symbol type [\#19](https://github.com/hakobera/embulk-input-mongodb/issues/19)
32
+
33
+ **Merged pull requests:**
34
+
35
+ - Bumpup version to 0.3.2 [\#22](https://github.com/hakobera/embulk-input-mongodb/pull/22) ([hakobera](https://github.com/hakobera))
36
+ - Release v0.3.1 [\#17](https://github.com/hakobera/embulk-input-mongodb/pull/17) ([hakobera](https://github.com/hakobera))
37
+ - Support Symbol type [\#21](https://github.com/hakobera/embulk-input-mongodb/pull/21) ([hakobera](https://github.com/hakobera))
38
+
39
+ ## [v0.3.1](https://github.com/hakobera/embulk-input-mongodb/tree/v0.3.1) (2016-06-21)
40
+ [Full Changelog](https://github.com/hakobera/embulk-input-mongodb/compare/v0.3.0...v0.3.1)
41
+
42
+ **Implemented enhancements:**
43
+
44
+ - Support id\_field\_name config [\#15](https://github.com/hakobera/embulk-input-mongodb/pull/15) ([hakobera](https://github.com/hakobera))
45
+
46
+ **Closed issues:**
47
+
48
+ - readName can only be called when State is NAME, not when State is VALUE. [\#18](https://github.com/hakobera/embulk-input-mongodb/issues/18)
49
+
50
+ ## [v0.3.0](https://github.com/hakobera/embulk-input-mongodb/tree/v0.3.0) (2016-06-13)
51
+ [Full Changelog](https://github.com/hakobera/embulk-input-mongodb/compare/v0.2.0...v0.3.0)
52
+
53
+ **Merged pull requests:**
54
+
55
+ - Add checkstyle plugin and format code [\#14](https://github.com/hakobera/embulk-input-mongodb/pull/14) ([sakama](https://github.com/sakama))
56
+ - Bumpup version to 0.3.0 [\#13](https://github.com/hakobera/embulk-input-mongodb/pull/13) ([hakobera](https://github.com/hakobera))
57
+ - Add unit test for existing code, \#9 and \#10 [\#11](https://github.com/hakobera/embulk-input-mongodb/pull/11) ([sakama](https://github.com/sakama))
58
+ - Change schema convert logic [\#10](https://github.com/hakobera/embulk-input-mongodb/pull/10) ([sakama](https://github.com/sakama))
59
+
60
+ ## [v0.2.0](https://github.com/hakobera/embulk-input-mongodb/tree/v0.2.0) (2016-05-30)
61
+ [Full Changelog](https://github.com/hakobera/embulk-input-mongodb/compare/v0.1.2...v0.2.0)
62
+
63
+ **Implemented enhancements:**
64
+
65
+ - Support JSON type [\#6](https://github.com/hakobera/embulk-input-mongodb/issues/6)
66
+
67
+ **Merged pull requests:**
68
+
69
+ - Prepare release for v0.2.0 [\#12](https://github.com/hakobera/embulk-input-mongodb/pull/12) ([hakobera](https://github.com/hakobera))
70
+ - Add minimum limit to batch\_size and changed not to allow null [\#9](https://github.com/hakobera/embulk-input-mongodb/pull/9) ([sakama](https://github.com/sakama))
71
+ - Refactor some codes [\#8](https://github.com/hakobera/embulk-input-mongodb/pull/8) ([sakama](https://github.com/sakama))
72
+ - Fix example config on readme [\#5](https://github.com/hakobera/embulk-input-mongodb/pull/5) ([hakobera](https://github.com/hakobera))
73
+ - Support JSON type [\#7](https://github.com/hakobera/embulk-input-mongodb/pull/7) ([hakobera](https://github.com/hakobera))
74
+
75
+ ## [v0.1.2](https://github.com/hakobera/embulk-input-mongodb/tree/v0.1.2) (2015-09-10)
76
+ [Full Changelog](https://github.com/hakobera/embulk-input-mongodb/compare/v0.1.1...v0.1.2)
77
+
78
+ **Merged pull requests:**
79
+
80
+ - Change build option for JDK7 [\#4](https://github.com/hakobera/embulk-input-mongodb/pull/4) ([hakobera](https://github.com/hakobera))
81
+ - Set homepage info [\#3](https://github.com/hakobera/embulk-input-mongodb/pull/3) ([hakobera](https://github.com/hakobera))
82
+
83
+ ## [v0.1.1](https://github.com/hakobera/embulk-input-mongodb/tree/v0.1.1) (2015-09-06)
84
+ [Full Changelog](https://github.com/hakobera/embulk-input-mongodb/compare/v0.1.0...v0.1.1)
85
+
86
+ ## [v0.1.0](https://github.com/hakobera/embulk-input-mongodb/tree/v0.1.0) (2015-09-06)
87
+ **Implemented enhancements:**
88
+
89
+ - Fix projection logic and better logging [\#2](https://github.com/hakobera/embulk-input-mongodb/pull/2) ([hakobera](https://github.com/hakobera))
90
+
91
+ **Merged pull requests:**
92
+
93
+ - Run test on travis [\#1](https://github.com/hakobera/embulk-input-mongodb/pull/1) ([hakobera](https://github.com/hakobera))
94
+
95
+
96
+
97
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -14,7 +14,16 @@ This plugin only works with embulk >= 0.8.8.
14
14
 
15
15
  ## Configuration
16
16
 
17
- - **uri**: [MongoDB connection string URI](http://docs.mongodb.org/manual/reference/connection-string/) (e.g. 'mongodb://localhost:27017/mydb') (string, required)
17
+ - Connection parameters
18
+ One of them is required.
19
+
20
+ - use MongoDB connection string URI
21
+ - **uri**: [MongoDB connection string URI](http://docs.mongodb.org/manual/reference/connection-string/) (e.g. 'mongodb://localhost:27017/mydb') (string, required)
22
+ - use separated URI parameters
23
+ - **hosts**: list of hosts. `hosts` are pairs of host(string, required) and port(integer, optional, default: 27017)
24
+ - **user**: (string, optional)
25
+ - **password**: (string, optional)
26
+ - **database**: (string, required)
18
27
  - **collection**: source collection name (string, required)
19
28
  - **fields**: **(deprecated)** ~~hash records that has the following two fields (array, required)~~
20
29
  ~~- name: Name of the column~~
@@ -24,12 +33,13 @@ This plugin only works with embulk >= 0.8.8.
24
33
  ~~- double~~
25
34
  ~~- string~~
26
35
  ~~- timestamp~~
27
- - **id_field_name** (string, optional, default: "_id") Name of Object ID field name. Set if you want to change the default name `_id`
28
- - **query**: a JSON document used for [querying](https://docs.mongodb.com/manual/tutorial/query-documents/) on the source collection. Documents are loaded from the colleciton if they match with this condition. (string, optional)
36
+ - **id_field_name** Name of Object ID field name. Set if you want to change the default name `_id` (string, optional, default: "_id")
37
+ - **query**: A JSON document used for [querying](https://docs.mongodb.com/manual/tutorial/query-documents/) on the source collection. Documents are loaded from the colleciton if they match with this condition. (string, optional)
29
38
  - **projection**: A JSON document used for [projection](https://docs.mongodb.com/manual/reference/operator/projection/positional/) on query results. Fields in a document are used only if they match with this condition. (string, optional)
30
- - **sort**: ordering of results (string, optional)
31
- - **incremental_field** list of field name (list, optional, can't use with sort option)
32
- - **last_record** (hash, optional) last loaded record for incremental load
39
+ - **sort**: Ordering of results (string, optional)
40
+ - **batch_size**: Limits the number of objects returned in one [batch](http://api.mongodb.com/java/current/com/mongodb/DBCursor.html#batchSize-int-) (integer, optional, default: 10000)
41
+ - **incremental_field** List of field name (list, optional, can't use with sort option)
42
+ - **last_record** Last loaded record for incremental load (hash, optional)
33
43
  - **stop_on_invalid_record** Stop bulk load transaction if a document includes invalid record (such as unsupported object type) (boolean, optional, default: false)
34
44
  - **json_column_name**: column name used in outputs (string, optional, default: "json")
35
45
 
@@ -37,6 +47,8 @@ This plugin only works with embulk >= 0.8.8.
37
47
 
38
48
  ### Exporting all objects
39
49
 
50
+ #### Specify with MongoDB connection string URI.
51
+
40
52
  ```yaml
41
53
  in:
42
54
  type: mongodb
@@ -44,6 +56,20 @@ in:
44
56
  collection: "my_collection"
45
57
  ```
46
58
 
59
+ #### Specify with separated URI parameters.
60
+
61
+ ```yaml
62
+ in:
63
+ type: mongodb
64
+ hosts:
65
+ - {host: localhost, port: 27017}
66
+ - {host: example.com, port: 27017}
67
+ user: myuser
68
+ password: mypassword
69
+ database: my_database
70
+ collection: "my_collection"
71
+ ```
72
+
47
73
  ### Filtering documents by query and projection
48
74
 
49
75
  ```yaml
@@ -187,4 +213,4 @@ $ launchctl load ~/Library/LaunchAgents/environment.plist
187
213
  $ launchctl getenv MONGO_URI //try to get value.
188
214
 
189
215
  Then start your applications.
190
- ```
216
+ ```
data/build.gradle CHANGED
@@ -17,7 +17,7 @@ configurations {
17
17
  provided
18
18
  }
19
19
 
20
- version = "0.4.0"
20
+ version = "0.5.0"
21
21
 
22
22
  sourceCompatibility = 1.7
23
23
  targetCompatibility = 1.7
@@ -5,7 +5,9 @@ import com.google.common.base.Optional;
5
5
  import com.google.common.base.Throwables;
6
6
  import com.mongodb.MongoClient;
7
7
  import com.mongodb.MongoClientURI;
8
+ import com.mongodb.MongoCredential;
8
9
  import com.mongodb.MongoException;
10
+ import com.mongodb.ServerAddress;
9
11
  import com.mongodb.client.MongoCollection;
10
12
  import com.mongodb.client.MongoCursor;
11
13
  import com.mongodb.client.MongoDatabase;
@@ -42,6 +44,8 @@ import javax.validation.constraints.Min;
42
44
 
43
45
  import java.io.IOException;
44
46
  import java.net.UnknownHostException;
47
+ import java.util.ArrayList;
48
+ import java.util.Arrays;
45
49
  import java.util.HashMap;
46
50
  import java.util.LinkedHashMap;
47
51
  import java.util.List;
@@ -50,12 +54,40 @@ import java.util.Map;
50
54
  public class MongodbInputPlugin
51
55
  implements InputPlugin
52
56
  {
57
+ public interface HostTask
58
+ extends Task
59
+ {
60
+ @Config("host")
61
+ String getHost();
62
+
63
+ @Config("port")
64
+ @ConfigDefault("27017")
65
+ int getPort();
66
+ }
67
+
53
68
  public interface PluginTask
54
69
  extends Task
55
70
  {
56
71
  // MongoDB connection string URI
57
72
  @Config("uri")
58
- String getUri();
73
+ @ConfigDefault("null")
74
+ Optional<String> getUri();
75
+
76
+ @Config("hosts")
77
+ @ConfigDefault("null")
78
+ Optional<List<HostTask>> getHosts();
79
+
80
+ @Config("user")
81
+ @ConfigDefault("null")
82
+ Optional<String> getUser();
83
+
84
+ @Config("password")
85
+ @ConfigDefault("null")
86
+ Optional<String> getPassword();
87
+
88
+ @Config("database")
89
+ @ConfigDefault("null")
90
+ Optional<String> getDatabase();
59
91
 
60
92
  @Config("collection")
61
93
  String getCollection();
@@ -261,15 +293,56 @@ public class MongodbInputPlugin
261
293
 
262
294
  private MongoDatabase connect(final PluginTask task) throws UnknownHostException, MongoException
263
295
  {
264
- MongoClientURI uri = new MongoClientURI(task.getUri());
265
- MongoClient mongoClient = new MongoClient(uri);
296
+ MongoClient mongoClient;
297
+ String database;
298
+
299
+ if (!task.getUri().isPresent() && !task.getHosts().isPresent()) {
300
+ throw new ConfigException("'uri' or 'hosts' is required");
301
+ }
302
+
303
+ if (task.getUri().isPresent()) {
304
+ MongoClientURI uri = new MongoClientURI(task.getUri().get());
305
+ database = uri.getDatabase();
306
+ mongoClient = new MongoClient(uri);
307
+ }
308
+ else {
309
+ mongoClient = createClientFromParams(task);
310
+ database = task.getDatabase().get();
311
+ }
266
312
 
267
- MongoDatabase db = mongoClient.getDatabase(uri.getDatabase());
313
+ MongoDatabase db = mongoClient.getDatabase(database);
268
314
  // Get collection count for throw Exception
269
315
  db.getCollection(task.getCollection()).count();
270
316
  return db;
271
317
  }
272
318
 
319
+ private MongoClient createClientFromParams(PluginTask task)
320
+ {
321
+ if (!task.getHosts().isPresent()) {
322
+ throw new ConfigException("'hosts' option's value is required but empty");
323
+ }
324
+ if (!task.getDatabase().isPresent()) {
325
+ throw new ConfigException("'database' option's value is required but empty");
326
+ }
327
+
328
+ List<ServerAddress> addresses = new ArrayList<>();
329
+ for (HostTask host : task.getHosts().get()) {
330
+ addresses.add(new ServerAddress(host.getHost(), host.getPort()));
331
+ }
332
+
333
+ if (task.getUser().isPresent()) {
334
+ MongoCredential credential = MongoCredential.createCredential(
335
+ task.getUser().get(),
336
+ task.getDatabase().get(),
337
+ task.getPassword().get().toCharArray()
338
+ );
339
+ return new MongoClient(addresses, Arrays.asList(credential));
340
+ }
341
+ else {
342
+ return new MongoClient(addresses);
343
+ }
344
+ }
345
+
273
346
  private Map<String, String> buildIncrementalCondition(PluginTask task)
274
347
  {
275
348
  Map<String, String> result = new HashMap<>();
@@ -4,7 +4,9 @@ import com.fasterxml.jackson.databind.JsonNode;
4
4
  import com.fasterxml.jackson.databind.ObjectMapper;
5
5
  import com.google.common.base.Optional;
6
6
  import com.google.common.collect.ImmutableList;
7
+ import com.google.common.collect.ImmutableMap;
7
8
  import com.google.common.collect.Lists;
9
+ import com.mongodb.MongoClientURI;
8
10
  import com.mongodb.client.MongoCollection;
9
11
  import com.mongodb.client.MongoDatabase;
10
12
  import org.bson.BsonBinary;
@@ -198,6 +200,28 @@ public class TestMongodbInputPlugin
198
200
  assertValidRecords(getFieldSchema(), output);
199
201
  }
200
202
 
203
+ @Test
204
+ public void testRunWithConnectionParams() throws Exception
205
+ {
206
+ MongoClientURI uri = new MongoClientURI(MONGO_URI);
207
+ String host = uri.getHosts().get(0);
208
+ Integer port = (host.split(":")[1] != null) ? Integer.valueOf(host.split(":")[1]) : 27017;
209
+ ConfigSource config = Exec.newConfigSource()
210
+ .set("hosts", Arrays.asList(ImmutableMap.of("host", host.split(":")[0], "port", port)))
211
+ .set("user", uri.getUsername())
212
+ .set("password", uri.getPassword())
213
+ .set("database", uri.getDatabase())
214
+ .set("collection", MONGO_COLLECTION);
215
+ PluginTask task = config.loadConfig(PluginTask.class);
216
+
217
+ dropCollection(task, MONGO_COLLECTION);
218
+ createCollection(task, MONGO_COLLECTION);
219
+ insertDocument(task, createValidDocuments());
220
+
221
+ plugin.transaction(config, new Control());
222
+ assertValidRecords(getFieldSchema(), output);
223
+ }
224
+
201
225
  @Test
202
226
  public void testRunWithIncrementalLoad() throws Exception
203
227
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-mongodb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyuki Honda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2016-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -47,6 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
49
  - .travis.yml
50
+ - CHANGELOG.md
50
51
  - LICENSE.txt
51
52
  - README.md
52
53
  - build.gradle
@@ -67,7 +68,7 @@ files:
67
68
  - src/test/resources/id_field_name.yml
68
69
  - src/test/resources/id_field_name_expected.csv
69
70
  - src/test/resources/my_collection.jsonl
70
- - classpath/embulk-input-mongodb-0.4.0.jar
71
+ - classpath/embulk-input-mongodb-0.5.0.jar
71
72
  - classpath/mongo-java-driver-3.2.2.jar
72
73
  homepage: https://github.com/hakobera/embulk-input-mongodb
73
74
  licenses: