flydata 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -2
  3. data/VERSION +1 -1
  4. data/bin/fdredshift +78 -0
  5. data/circle.yml +1 -1
  6. data/ext/flydata/{parser/mysql → source_mysql/parser}/.gitignore +0 -0
  7. data/ext/flydata/{parser/mysql → source_mysql/parser}/dump_parser_ext.cpp +3 -3
  8. data/ext/flydata/source_mysql/parser/extconf.rb +3 -0
  9. data/ext/flydata/{parser/mysql → source_mysql/parser}/parser.txt +0 -0
  10. data/ext/flydata/{parser/mysql → source_mysql/parser}/sql_parser.cpp +0 -0
  11. data/ext/flydata/{parser/mysql → source_mysql/parser}/sql_parser.h +0 -0
  12. data/flydata-core/lib/flydata-core/mysql/binlog_pos.rb +34 -32
  13. data/flydata-core/lib/flydata-core/mysql/compatibility_checker.rb +20 -0
  14. data/flydata-core/lib/flydata-core/table_def/mysql_table_def.rb +12 -4
  15. data/flydata-core/lib/flydata-core/table_def/redshift_table_def.rb +60 -6
  16. data/flydata-core/spec/mysql/binlog_pos_spec.rb +474 -0
  17. data/flydata-core/spec/table_def/mysql_table_def_spec.rb +57 -0
  18. data/flydata-core/spec/table_def/mysql_to_redshift_table_def_spec.rb +174 -20
  19. data/flydata-core/spec/table_def/mysqldump_test_col_comment_with_AUTO_INCREMENT_keyword.dump +43 -0
  20. data/flydata-core/spec/table_def/mysqldump_test_col_comment_with_not_null_keyword.dump +43 -0
  21. data/flydata-core/spec/table_def/mysqldump_test_col_comment_with_unique_keyword.dump +43 -0
  22. data/flydata-core/spec/table_def/mysqldump_test_col_comment_with_unsigned_keyword.dump +43 -0
  23. data/flydata-core/spec/table_def/redshift_table_def_spec.rb +41 -8
  24. data/flydata.gemspec +0 -0
  25. data/lib/flydata/cli.rb +11 -5
  26. data/lib/flydata/command/base.rb +14 -1
  27. data/lib/flydata/command/exclusive_runnable.rb +42 -12
  28. data/lib/flydata/command/helper.rb +6 -6
  29. data/lib/flydata/command/sender.rb +4 -3
  30. data/lib/flydata/command/setup.rb +30 -381
  31. data/lib/flydata/command/stop.rb +1 -0
  32. data/lib/flydata/command/sync.rb +273 -301
  33. data/lib/flydata/compatibility_check.rb +24 -117
  34. data/lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb +3 -3
  35. data/lib/flydata/fluent-plugins/mysql/alter_table_query_handler.rb +2 -2
  36. data/lib/flydata/fluent-plugins/mysql/binlog_record_handler.rb +6 -6
  37. data/lib/flydata/fluent-plugins/mysql/truncate_table_query_handler.rb +0 -1
  38. data/lib/flydata/parser.rb +14 -0
  39. data/lib/flydata/{parser_provider.rb → parser/parser_provider.rb} +6 -4
  40. data/lib/flydata/parser/source_table.rb +33 -0
  41. data/lib/flydata/source.rb +105 -0
  42. data/lib/flydata/source/component.rb +21 -0
  43. data/lib/flydata/source/errors.rb +7 -0
  44. data/lib/flydata/source/generate_source_dump.rb +72 -0
  45. data/lib/flydata/source/parse_dump_and_send.rb +52 -0
  46. data/lib/flydata/source/setup.rb +31 -0
  47. data/lib/flydata/source/source_pos.rb +45 -0
  48. data/lib/flydata/source/sync.rb +56 -0
  49. data/lib/flydata/source/sync_generate_table_ddl.rb +43 -0
  50. data/lib/flydata/source_file/setup.rb +17 -0
  51. data/lib/flydata/source_file/sync.rb +14 -0
  52. data/lib/flydata/{command → source_mysql/command}/mysql.rb +2 -1
  53. data/lib/flydata/{command → source_mysql/command}/mysql_command_base.rb +2 -4
  54. data/lib/flydata/{command → source_mysql/command}/mysqlbinlog.rb +2 -1
  55. data/lib/flydata/{command → source_mysql/command}/mysqldump.rb +2 -1
  56. data/lib/flydata/source_mysql/generate_source_dump.rb +53 -0
  57. data/lib/flydata/source_mysql/mysql_compatibility_check.rb +114 -0
  58. data/lib/flydata/source_mysql/parse_dump_and_send.rb +28 -0
  59. data/lib/flydata/{parser/mysql → source_mysql/parser}/.gitignore +0 -0
  60. data/lib/flydata/{parser/mysql → source_mysql/parser}/dump_parser.rb +32 -67
  61. data/lib/flydata/{parser/mysql → source_mysql/parser}/mysql_alter_table.treetop +0 -0
  62. data/lib/flydata/source_mysql/setup.rb +24 -0
  63. data/lib/flydata/source_mysql/source_pos.rb +21 -0
  64. data/lib/flydata/source_mysql/sync.rb +45 -0
  65. data/lib/flydata/source_mysql/sync_generate_table_ddl.rb +40 -0
  66. data/lib/flydata/{mysql → source_mysql}/table_ddl.rb +6 -17
  67. data/lib/flydata/source_zendesk/sync_generate_table_ddl.rb +30 -0
  68. data/lib/flydata/source_zendesk/zendesk_flydata_tabledefs.rb +133 -0
  69. data/lib/flydata/sync_file_manager.rb +132 -73
  70. data/lib/flydata/table_ddl.rb +18 -0
  71. data/spec/flydata/cli_spec.rb +1 -0
  72. data/spec/flydata/command/exclusive_runnable_spec.rb +19 -8
  73. data/spec/flydata/command/sender_spec.rb +1 -1
  74. data/spec/flydata/command/setup_spec.rb +4 -4
  75. data/spec/flydata/command/sync_spec.rb +97 -134
  76. data/spec/flydata/compatibility_check_spec.rb +16 -289
  77. data/spec/flydata/fluent-plugins/mysql/alter_table_query_handler_spec.rb +3 -3
  78. data/spec/flydata/fluent-plugins/mysql/dml_record_handler_spec.rb +1 -1
  79. data/spec/flydata/fluent-plugins/mysql/shared_query_handler_context.rb +4 -2
  80. data/spec/flydata/fluent-plugins/mysql/truncate_query_handler_spec.rb +1 -1
  81. data/spec/flydata/source_mysql/generate_source_dump_spec.rb +69 -0
  82. data/spec/flydata/source_mysql/mysql_compatibility_check_spec.rb +280 -0
  83. data/spec/flydata/{parser/mysql → source_mysql/parser}/alter_table_parser_spec.rb +2 -2
  84. data/spec/flydata/{parser/mysql → source_mysql/parser}/dump_parser_spec.rb +75 -70
  85. data/spec/flydata/source_mysql/sync_generate_table_ddl_spec.rb +137 -0
  86. data/spec/flydata/{mysql → source_mysql}/table_ddl_spec.rb +2 -2
  87. data/spec/flydata/source_spec.rb +140 -0
  88. data/spec/flydata/source_zendesk/sync_generate_table_ddl_spec.rb +33 -0
  89. data/spec/flydata/sync_file_manager_spec.rb +157 -77
  90. data/tmpl/redshift_mysql_data_entry.conf.tmpl +1 -1
  91. metadata +56 -23
  92. data/ext/flydata/parser/mysql/extconf.rb +0 -3
  93. data/lib/flydata/mysql/binlog_position.rb +0 -22
  94. data/spec/flydata/mysql/binlog_position_spec.rb +0 -35
@@ -0,0 +1,114 @@
1
+ require 'mysql2'
2
+ require 'flydata/compatibility_check'
3
+ require 'flydata-core/mysql/config'
4
+ require 'flydata-core/mysql/command_generator'
5
+ require 'flydata-core/mysql/compatibility_checker'
6
+ require 'flydata-core/errors'
7
+
8
+ module Flydata
9
+ module SourceMysql
10
+
11
+ class MysqlCompatibilityCheck < CompatibilityCheck
12
+ include InitialSyncChecks
13
+
14
+ def initialize(dp_hash, de_hash, options={})
15
+ super
16
+ @db_opts = FlydataCore::Mysql::Config.build_mysql_db_opts(de_hash)
17
+ @dump_dir = options[:dump_dir] || nil
18
+ @backup_dir = options[:backup_dir] || nil
19
+ @tables = de_hash['tables']
20
+ end
21
+
22
+ def print_errors
23
+ return if @errors.empty?
24
+ log_error_stderr "There may be some compatibility issues with your MySQL credentials: "
25
+ @errors.each do |error|
26
+ log_error_stderr " * #{error.message}"
27
+ end
28
+ raise "Please correct these errors if you wish to run FlyData Sync"
29
+ end
30
+
31
+ def check_compatibility56_variable
32
+ FlydataCore::Mysql::MySqlVersion57CompabilityChecker.new(@db_opts).do_check
33
+ end
34
+
35
+ def check_mysql_user_compat
36
+ FlydataCore::Mysql::SyncPermissionChecker.new(@db_opts).do_check
37
+ end
38
+
39
+ def check_mysql_protocol_tcp_compat
40
+ query = FlydataCore::Mysql::CommandGenerator.generate_mysql_show_grants_cmd(@db_opts)
41
+
42
+ Open3.popen3(query) do |stdin, stdout, stderr|
43
+ stdin.close
44
+ while !stderr.eof?
45
+ lines = []
46
+ while line = stderr.gets; lines << line.strip; end
47
+ err_reason = lines.join(" ")
48
+ log_error("Error occured during access to mysql server.", {err: err_reason})
49
+
50
+ unless /Warning: Using a password on the command line interface can be insecure/ === err_reason
51
+ raise FlydataCore::MysqlCompatibilityError, "Cannot connect to MySQL database. Please make sure you can connect with this command:\n $ mysql -u #{@db_opts[:username]} -h #{@db_opts[:host]} -P #{@db_opts[:port]} #{@db_opts[:database]} --protocol=tcp -p"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def check_mysql_parameters_compat
58
+ begin
59
+ FlydataCore::Mysql::OptionalBinlogParameterChecker.new(@db_opts).do_check
60
+ rescue FlydataCore::MysqlCompatibilityError => e
61
+ log_warn_stderr(e.to_s)
62
+ end
63
+ FlydataCore::Mysql::RequiredBinlogParameterChecker.new(@db_opts).do_check
64
+ end
65
+
66
+ def check_rds_master_status
67
+ if is_rds?
68
+ FlydataCore::Mysql::RdsMasterStatusChecker.new(@db_opts).do_check
69
+ end
70
+ end
71
+
72
+ def check_mysql_binlog_retention
73
+ if is_rds?
74
+ run_rds_retention_check
75
+ else
76
+ run_mysql_retention_check
77
+ end
78
+ end
79
+
80
+ # If table_type='VIEW' or engine='MEMORY', raise error.
81
+ def check_mysql_table_types
82
+ return if @tables.empty?
83
+ option = @db_opts.dup.merge(tables: @tables)
84
+ FlydataCore::Mysql::TableTypeChecker.new(option).do_check
85
+ end
86
+
87
+ def run_mysql_retention_check
88
+ FlydataCore::Mysql::NonRdsRetentionChecker.new(@db_opts).do_check
89
+ end
90
+
91
+ def run_rds_retention_check
92
+ FlydataCore::Mysql::RdsRetentionChecker.new(@db_opts).do_check
93
+ rescue Mysql2::Error => e
94
+ if e.message =~ /command denied to user/
95
+ retention_hours = FlydataCore::Mysql::RdsRetentionChecker::BINLOG_RETENTION_HOURS
96
+ log_warn_stderr("[WARNING]Cannot verify RDS retention period on current MySQL user account.\n" +
97
+ "To see retention period, please run this on your RDS:\n" +
98
+ " $> call mysql.rds_show_configuration;\n" +
99
+ "Please verify that the hours is not nil and is at least #{retention_hours} hours\n" +
100
+ "To set binlog retention hours, you can run this on your RDS:\n" +
101
+ " $> call mysql.rds_set_configuration('binlog retention hours', #{retention_hours});\n"
102
+ )
103
+ else
104
+ raise e
105
+ end
106
+ end
107
+
108
+ def is_rds?(hostname = @db_opts[:host])
109
+ hostname.match(/rds.amazonaws.com$/) != nil
110
+ end
111
+ end
112
+
113
+ end
114
+ end
@@ -0,0 +1,28 @@
1
+ require 'flydata/source/parse_dump_and_send'
2
+ require 'flydata-core/table_def/mysql_table_def'
3
+ require 'flydata/source_mysql/parser/dump_parser'
4
+ require 'flydata-core/mysql/binlog_pos'
5
+
6
+ module Flydata
7
+ module SourceMysql
8
+
9
+ class ParseDumpAndSend < Source::ParseDumpAndSend
10
+ def value_converters
11
+ FlydataCore::TableDef::MysqlTableDef::VALUE_CONVERTERS
12
+ end
13
+
14
+ def parse_dump(dump_pos_info, dmpio,
15
+ create_table_block, insert_record_block, check_point_source_pos_block)
16
+
17
+ check_point_binlog_block = Proc.new { |source_table, last_pos, bytesize, binlog_hash, state, substate|
18
+ source_pos = FlydataCore::Mysql::BinlogPos.new(binlog_hash) # SourcePos object is BinlogPos in SourceMysql
19
+
20
+ check_point_source_pos_block.call(source_table, last_pos, bytesize, source_pos, state, substate)
21
+ }
22
+ Parser::MysqlDumpParser.new(dump_pos_info).parse(dmpio,
23
+ create_table_block, insert_record_block, check_point_binlog_block)
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -1,13 +1,16 @@
1
1
  require 'fiber'
2
2
  require 'io/wait'
3
3
  require 'mysql2'
4
+ require 'flydata/parser'
5
+ require 'flydata/parser/source_table'
4
6
  require 'flydata-core/mysql/config'
5
7
  require 'flydata-core/mysql/command_generator'
8
+ require 'flydata-core/mysql/binlog_pos'
6
9
  #require 'ruby-prof' # to enable profiling, also set the class' RUN_PROFILE
7
10
 
8
11
  module Flydata
9
- module Parser
10
- module Mysql
12
+ module SourceMysql
13
+ module Parser
11
14
 
12
15
  module MysqlAccessible
13
16
  def mysql_conf(conf)
@@ -29,38 +32,6 @@ module Flydata
29
32
  end
30
33
  end
31
34
 
32
- class MysqlTable
33
- def initialize(table_name, columns = {}, primary_keys = [])
34
- @table_name = table_name
35
- @columns = columns
36
- @column_names = columns.collect{|k,v| v[:column_name]}
37
- @primary_keys = primary_keys
38
- @value_converters = {}
39
- end
40
-
41
- attr_accessor :table_name, :columns, :column_names, :primary_keys, :value_converters
42
-
43
- def add_column(column)
44
- cn = column[:column_name]
45
- @columns[cn] = column
46
- @column_names << cn
47
- end
48
-
49
- def set_value_converters(converter_hash)
50
- @value_converters ||= {} # for backward compatibility with an old marshal dump object
51
- @columns.each_with_index do |(k, v), i|
52
- type = v[:format_type]
53
- if converter_hash.has_key?(type)
54
- @value_converters[i] = converter_hash[type]
55
- end
56
- end
57
- end
58
-
59
- def set_column_names
60
- @column_names = columns.collect{|k,v| v[:column_name]}
61
- end
62
- end
63
-
64
35
  class MysqlDumpGenerator
65
36
  def initialize(conf)
66
37
  @conf = conf
@@ -289,21 +260,15 @@ EOS
289
260
 
290
261
  class MysqlDumpParser
291
262
 
292
- module State
293
- START = 'START'
294
- CREATE_TABLE = 'CREATE_TABLE'
295
- CREATE_TABLE_COLUMNS = 'CREATE_TABLE_COLUMNS'
296
- CREATE_TABLE_CONSTRAINTS = 'CREATE_TABLE_CONSTRAINTS'
297
- INSERT_RECORD = 'INSERT_RECORD'
298
- PARSING_INSERT_RECORD = 'PARSING_INSERT_RECORD'
299
- end
300
-
301
263
  attr_accessor :binlog_pos
302
264
  BINLOG_INV_ERROR_CHUNK_SIZE = 250
303
265
 
304
- def initialize(option = {})
305
- @binlog_pos = option[:binlog_pos] or raise ArgumentError.new("binlog position is required")
306
- @option = option
266
+ def initialize(dump_pos_info = {})
267
+ binlog_pos_object = dump_pos_info[:source_pos]
268
+ raise ArgumentError.new("source position is required") unless binlog_pos_object
269
+
270
+ @binlog_pos = { binfile: binlog_pos_object.filename, pos: binlog_pos_object.pos }
271
+ @dump_pos_info = dump_pos_info
307
272
  end
308
273
 
309
274
  def parse(dmpio, create_table_block, insert_record_block, check_point_block)
@@ -313,7 +278,7 @@ EOS
313
278
 
314
279
  dump_io = nil
315
280
  invalid_file = false
316
- current_state = State::START
281
+ current_state = Flydata::Parser::State::START
317
282
  substate = nil
318
283
  buffered_line = nil
319
284
  bytesize = 0
@@ -336,7 +301,7 @@ EOS
336
301
 
337
302
  # -- Server version 5.6.21-log
338
303
  if line.start_with?('-- Server version')
339
- current_state = State::CREATE_TABLE
304
+ current_state = Flydata::Parser::State::CREATE_TABLE
340
305
  check_point_block.call(nil, dump_io.pos, bytesize, @binlog_pos, current_state)
341
306
  end
342
307
  end
@@ -348,8 +313,8 @@ EOS
348
313
  # CREATE TABLE `active_admin_comments` (
349
314
  m = /^CREATE TABLE `(?<table_name>[^`]+)`/.match(line)
350
315
  if m
351
- current_table = MysqlTable.new(m[:table_name])
352
- current_state = State::CREATE_TABLE_COLUMNS
316
+ current_table = Flydata::Parser::SourceTable.new(m[:table_name])
317
+ current_state = Flydata::Parser::State::CREATE_TABLE_COLUMNS
353
318
  end
354
319
  end
355
320
 
@@ -359,7 +324,7 @@ EOS
359
324
  # PRIMARY KEY (`id`),
360
325
  if line.start_with?(')')
361
326
  create_table_block.call(current_table)
362
- current_state = State::INSERT_RECORD
327
+ current_state = Flydata::Parser::State::INSERT_RECORD
363
328
  check_point_block.call(current_table, dump_io.pos, bytesize, @binlog_pos, current_state)
364
329
  elsif m = /^PRIMARY KEY \((?<primary_keys>[^\)]+)\)/.match(line)
365
330
  current_table.primary_keys = m[:primary_keys].split(',').collect do |pk_str|
@@ -417,7 +382,7 @@ EOS
417
382
 
418
383
  current_table.add_column(column)
419
384
  else
420
- current_state = State::CREATE_TABLE_CONSTRAINTS
385
+ current_state = Flydata::Parser::State::CREATE_TABLE_CONSTRAINTS
421
386
  buffered_line = line
422
387
  state_create_table_constraints.call
423
388
  end
@@ -428,9 +393,9 @@ EOS
428
393
 
429
394
  if line.start_with?('INSERT')
430
395
  buffered_line = line
431
- current_state = State::PARSING_INSERT_RECORD
396
+ current_state = Flydata::Parser::State::PARSING_INSERT_RECORD
432
397
  elsif line.start_with?('UNLOCK')
433
- current_state = State::CREATE_TABLE
398
+ current_state = Flydata::Parser::State::CREATE_TABLE
434
399
  check_point_block.call(current_table, dump_io.pos, bytesize, @binlog_pos, current_state)
435
400
  end
436
401
  end
@@ -446,7 +411,7 @@ EOS
446
411
  newe.set_backtrace(e.backtrace)
447
412
  raise newe
448
413
  end
449
- current_state = State::INSERT_RECORD
414
+ current_state = Flydata::Parser::State::INSERT_RECORD
450
415
 
451
416
  if insert_record_block.call(current_table, values_set)
452
417
  values_set = nil
@@ -457,11 +422,11 @@ EOS
457
422
  # Start reading file from top
458
423
  begin
459
424
  # resume(only when using dump file)
460
- if @option[:last_pos] && (@option[:last_pos].to_i != -1)
461
- dmpio.pos = @option[:last_pos].to_i
462
- current_state = @option[:state]
463
- substate = @option[:substate]
464
- current_table = @option[:mysql_table]
425
+ if @dump_pos_info[:last_pos] && (@dump_pos_info[:last_pos].to_i != -1)
426
+ dmpio.pos = @dump_pos_info[:last_pos].to_i
427
+ current_state = @dump_pos_info[:state]
428
+ substate = @dump_pos_info[:substate]
429
+ current_table = @dump_pos_info[:source_table]
465
430
  bytesize = dmpio.pos
466
431
  end
467
432
 
@@ -469,17 +434,17 @@ EOS
469
434
 
470
435
  until dump_io.eof? do
471
436
  case current_state
472
- when State::START
437
+ when Flydata::Parser::State::START
473
438
  state_start.call
474
- when State::CREATE_TABLE
439
+ when Flydata::Parser::State::CREATE_TABLE
475
440
  state_create_table.call
476
- when State::CREATE_TABLE_COLUMNS
441
+ when Flydata::Parser::State::CREATE_TABLE_COLUMNS
477
442
  state_create_table_columns.call
478
- when State::CREATE_TABLE_CONSTRAINTS
443
+ when Flydata::Parser::State::CREATE_TABLE_CONSTRAINTS
479
444
  state_create_table_constraints.call
480
- when State::INSERT_RECORD
445
+ when Flydata::Parser::State::INSERT_RECORD
481
446
  state_insert_record.call
482
- when State::PARSING_INSERT_RECORD
447
+ when Flydata::Parser::State::PARSING_INSERT_RECORD
483
448
  state_parsing_insert_record.call
484
449
  end
485
450
  end
@@ -747,4 +712,4 @@ EOT
747
712
  end
748
713
  end
749
714
 
750
- require 'flydata/parser/mysql/dump_parser_ext'
715
+ require 'flydata/source_mysql/parser/dump_parser_ext'
@@ -0,0 +1,24 @@
1
+ require 'flydata/source/setup'
2
+ require 'flydata/sync_file_manager'
3
+
4
+ module Flydata
5
+ module SourceMysql
6
+
7
+ class Setup < Source::Setup
8
+ def initial_run_need_restart?
9
+ overinstall?
10
+ end
11
+
12
+ def initial_run_complete_message
13
+ overinstall? ? :all_done : :initial_sync
14
+ end
15
+
16
+ private
17
+
18
+ def overinstall?
19
+ File.exists?(Flydata::SyncFileManager.new(de).source_pos_path)
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'flydata/source/source_pos'
2
+ require 'flydata/compatibility_check'
3
+ require 'flydata-core/mysql/command_generator'
4
+ require 'flydata-core/mysql/binlog_pos'
5
+
6
+ module Flydata
7
+ module SourceMysql
8
+
9
+ class SourcePos < Source::SourcePos
10
+ def create_source_pos(source_pos_str)
11
+ FlydataCore::Mysql::BinlogPos.new(source_pos_str)
12
+ end
13
+
14
+ def resume_pos(source_pos)
15
+ #TODO check Binlog file (source_pos.filename) is available
16
+ FlydataCore::Mysql::BinlogPos.new(source_pos.filename, 4) # 4 is the first position of binlog file
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ require 'flydata/source/sync'
2
+
3
+ module Flydata
4
+ module SourceMysql
5
+
6
+ class Sync < Source::Sync
7
+ def setup
8
+ mp = de['mysql_data_entry_preference']
9
+
10
+ if mp['tables_append_only']
11
+ mp['tables_append_only'] = mp['tables_append_only'].split(",").uniq
12
+ mp['tables'] = (mp['tables'].split(",") + mp['tables_append_only']).uniq
13
+ else
14
+ mp['tables'] = mp['tables'].split(",").uniq
15
+ end
16
+ mp['invalid_tables'] = mp['invalid_tables'].kind_of?(String) ? mp['invalid_tables'].split(",").uniq : []
17
+ mp['new_tables'] = mp['new_tables'].kind_of?(String) ? mp['new_tables'].split(",").uniq : []
18
+
19
+ unless mp['ssl_ca_content'].to_s.strip.empty?
20
+ sync_fm = SyncFileManager.new(de)
21
+ sync_fm.save_ssl_ca(mp['ssl_ca_content'])
22
+ mp['ssl_ca'] = sync_fm.ssl_ca_path
23
+ mp['sslca'] = mp['ssl_ca']
24
+ end
25
+ end
26
+
27
+ def supported?
28
+ true
29
+ end
30
+
31
+ def table_lists
32
+ de['mysql_data_entry_preference'].select {|key, value| %w(tables new_tables invalid_tables tables_append_only).include?(key)}
33
+ end
34
+
35
+ def data_servers
36
+ de['mysql_data_entry_preference']['data_servers']
37
+ end
38
+
39
+ def forwarder
40
+ de['mysql_data_entry_preference']['forwarder']
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ require 'flydata/source/sync_generate_table_ddl'
2
+ require 'flydata/source_mysql/mysql_compatibility_check'
3
+ require 'flydata-core/mysql/command_generator'
4
+
5
+ module Flydata
6
+ module SourceMysql
7
+
8
+ class SyncGenerateTableDdl < Source::SyncGenerateTableDdl
9
+ def run_compatibility_check
10
+ MysqlCompatibilityCheck.new(dp, de['mysql_data_entry_preference']).check
11
+ if `which mysqldump`.empty?
12
+ raise "mysqldump is not installed. mysqldump is required to run the command"
13
+ end
14
+ %w(host username database).each do |conf_name|
15
+ raise "MySQL `#{conf_name}` is neither defined in the data entry nor the local config file" if de['mysql_data_entry_preference'][conf_name].to_s.empty?
16
+ end
17
+ end
18
+
19
+ def generate_flydata_tabledef(tables, options)
20
+ mp = de['mysql_data_entry_preference']
21
+ options = options.merge(mp)
22
+ flydata_tabledefs = []
23
+ error_list = []
24
+ missing_tables = FlydataCore::Mysql::CommandGenerator.each_mysql_tabledef(tables, options) do |mysql_tabledef, error|
25
+ if error
26
+ error_list << error.err_hash
27
+ next
28
+ end
29
+ flydata_tabledefs << mysql_tabledef.to_flydata_tabledef
30
+ end
31
+ if missing_tables
32
+ missing_tables.each {|missing_table| error_list << { error: 'table does not exist in the MySQL database', table: missing_table } }
33
+ end
34
+
35
+ [flydata_tabledefs, error_list]
36
+ end
37
+ end
38
+
39
+ end
40
+ end