26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/logstash/outputs/documentdb.rb', line 26
def register
if @partitioned_collection
raise ArgumentError, 'partition_key must be set in partitioned collection mode' if @partition_key.empty?
if (@auto_create_collection &&
@offer_throughput < AzureDocumentDB::PARTITIONED_COLL_MIN_THROUGHPUT)
raise ArgumentError, sprintf("offer_throughput must be more than and equals to %s",
AzureDocumentDB::PARTITIONED_COLL_MIN_THROUGHPUT)
end
end
begin
@client = nil
if @partitioned_collection
@client = AzureDocumentDB::PartitionedCollectionClient.new(@docdb_account_key,@docdb_endpoint)
else
@client = AzureDocumentDB::Client.new(@docdb_account_key,@docdb_endpoint)
end
res = @client.find_databases_by_name(@docdb_database)
if( res[:body]["_count"].to_i == 0 )
raise RuntimeError, "No database (#{docdb_database}) exists! Enable auto_create_database or create it by useself" if !@auto_create_database
@client.create_database(@docdb_database)
end
database_resource = @client.get_database_resource(@docdb_database)
res = @client.find_collections_by_name(database_resource, @docdb_collection)
if( res[:body]["_count"].to_i == 0 )
raise "No collection (#{docdb_collection}) exists! Enable auto_create_collection or create it by useself" if !@auto_create_collection
if @partitioned_collection
partition_key_paths = ["/#{@partition_key}"]
@client.create_collection(database_resource,
@docdb_collection, partition_key_paths, @offer_throughput)
else
@client.create_collection(database_resource, @docdb_collection)
end
end
@coll_resource = @client.get_collection_resource(database_resource, @docdb_collection)
rescue Exception =>ex
@logger.error("Documentdb output plugin's register Error: '#{ex}'")
exit!
end
end
|