patriot-gcp 0.2.0 → 0.2.1
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 +4 -4
- data/lib/patriot_gcp/command.rb +1 -0
- data/lib/patriot_gcp/command/gcs.rb +49 -0
- data/lib/patriot_gcp/command/load_to_bigquery.rb +11 -9
- data/lib/patriot_gcp/ext.rb +1 -0
- data/lib/patriot_gcp/ext/gcs.rb +48 -0
- data/lib/patriot_gcp/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81b383e24c1eca0ce26184a3733b83c00cb99c7a
|
4
|
+
data.tar.gz: be33d70fe45f2ab0f4b6651e7d37629acb2185a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40cdf2da551b80e21116912feed4cc763c81d9a03cb745374ffca04cd113350ed5a77abe2803a5aeaaebf0101fd2894a477b732a18016bc08e50f0dd059c6a86
|
7
|
+
data.tar.gz: db77fab705229b11e38a6b99aafdc325ddbac113570f39eaede598b4ea7a759a3fc54638da1098da998921e63dff33e511657d306fa1498f3882601981fd9747
|
data/lib/patriot_gcp/command.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
module PatriotGCP
|
2
|
+
module Command
|
3
|
+
class GCSCommand < Patriot::Command::Base
|
4
|
+
declare_command_name :gcs
|
5
|
+
include PatriotGCP::Ext::GCS
|
6
|
+
|
7
|
+
command_attr :inifile, :project_id, :bucket, :command, :source_file, :dest_file, :name_suffix
|
8
|
+
validate_existence :inifile, :project_id, :bucket, :command, :name_suffix
|
9
|
+
|
10
|
+
class GCSException < Exception; end
|
11
|
+
class GoogleCloudPlatformException < Exception; end
|
12
|
+
|
13
|
+
def job_id
|
14
|
+
"#{command_name}_#{@command}_#{@project_id}_#{@bucket}_#{@name_suffix}"
|
15
|
+
end
|
16
|
+
|
17
|
+
# @see Patriot::Command::Base#configure
|
18
|
+
def configure
|
19
|
+
if @name_suffix == _date_
|
20
|
+
raise ArgumentError, 'To set _date_ only is not allowed here to avoid job name duplication.'
|
21
|
+
end
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute
|
26
|
+
@logger.info "start gcs #{@command}"
|
27
|
+
|
28
|
+
ini = IniFile.load(@inifile)
|
29
|
+
if ini.nil?
|
30
|
+
raise Exception, "inifile not found"
|
31
|
+
end
|
32
|
+
|
33
|
+
gcs_keyfile = ini["gcp"]["gcs_keyfile"]
|
34
|
+
|
35
|
+
stat_info = gcs(
|
36
|
+
gcs_keyfile,
|
37
|
+
@project_id,
|
38
|
+
@bucket,
|
39
|
+
@command,
|
40
|
+
@source_file,
|
41
|
+
@dest_file
|
42
|
+
)
|
43
|
+
|
44
|
+
@logger.info "gcs #{@command} execution succeeded: #{stat_info}"
|
45
|
+
@logger.info "end gcs #{@command}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -30,16 +30,18 @@ module PatriotGCP
|
|
30
30
|
|
31
31
|
bigquery_keyfile = ini["gcp"]["bigquery_keyfile"]
|
32
32
|
|
33
|
-
unless
|
34
|
-
|
33
|
+
unless @input_file.start_with? 'gs://'
|
34
|
+
unless File.exist?(@input_file)
|
35
|
+
raise Exception, "The given file doesn't exist."
|
36
|
+
end
|
37
|
+
|
38
|
+
unless File.size?(@input_file)
|
39
|
+
@logger.warn "The target file is empty"
|
40
|
+
return
|
41
|
+
end
|
35
42
|
end
|
36
43
|
|
37
|
-
|
38
|
-
@logger.warn "The target file is empty"
|
39
|
-
return
|
40
|
-
end
|
41
|
-
|
42
|
-
@logger.info "start uploading"
|
44
|
+
@logger.info "start loading"
|
43
45
|
stat_info = bq_load(@input_file,
|
44
46
|
bigquery_keyfile,
|
45
47
|
@project_id,
|
@@ -49,7 +51,7 @@ module PatriotGCP
|
|
49
51
|
@options,
|
50
52
|
@polling_interval)
|
51
53
|
|
52
|
-
@logger.info "
|
54
|
+
@logger.info "load succeeded: #{stat_info}"
|
53
55
|
@logger.info "end load_to_bigquery"
|
54
56
|
end
|
55
57
|
end
|
data/lib/patriot_gcp/ext.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "google/cloud/storage"
|
2
|
+
require 'patriot_gcp/version'
|
3
|
+
|
4
|
+
|
5
|
+
module PatriotGCP
|
6
|
+
module Ext
|
7
|
+
module GCS
|
8
|
+
|
9
|
+
def self.included(cls)
|
10
|
+
cls.send(:include, Patriot::Util::System)
|
11
|
+
end
|
12
|
+
|
13
|
+
class GCSException < Exception; end
|
14
|
+
|
15
|
+
def gcs(gcs_keyfile, project_id, bucket, command, source_file, dest_file)
|
16
|
+
ENV['GOOGLE_CLOUD_KEYFILE'] = gcs_keyfile
|
17
|
+
|
18
|
+
storage = Google::Cloud::Storage.new(
|
19
|
+
project: project_id,
|
20
|
+
retries: 3, # default value
|
21
|
+
timeout: 3600
|
22
|
+
)
|
23
|
+
|
24
|
+
bucket = storage.bucket bucket
|
25
|
+
|
26
|
+
if command == 'create_file'
|
27
|
+
bucket.create_file(source_file, dest_file)
|
28
|
+
elsif command == 'download'
|
29
|
+
file = bucket.file source_file
|
30
|
+
|
31
|
+
if file.nil?
|
32
|
+
raise GCSException, "File not found."
|
33
|
+
end
|
34
|
+
|
35
|
+
file.download dest_file
|
36
|
+
elsif command == 'delete'
|
37
|
+
file = bucket.file source_file
|
38
|
+
|
39
|
+
if file.nil?
|
40
|
+
@logger.info "File not found."
|
41
|
+
else
|
42
|
+
file.delete
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/patriot_gcp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patriot-gcp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hitoshi Tsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-bigquery
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: google-cloud-storage
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: patriot-workflow-scheduler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,9 +60,11 @@ extensions: []
|
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
48
62
|
- lib/patriot_gcp/command/bq.rb
|
63
|
+
- lib/patriot_gcp/command/gcs.rb
|
49
64
|
- lib/patriot_gcp/command/load_to_bigquery.rb
|
50
65
|
- lib/patriot_gcp/command.rb
|
51
66
|
- lib/patriot_gcp/ext/bigquery.rb
|
67
|
+
- lib/patriot_gcp/ext/gcs.rb
|
52
68
|
- lib/patriot_gcp/ext.rb
|
53
69
|
- lib/patriot_gcp/version.rb
|
54
70
|
- lib/patriot_gcp.rb
|