solr_makr 0.0.4 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.agignore +1 -0
  3. data/README.md +24 -2
  4. data/Rakefile +1 -1
  5. data/bin/console +13 -0
  6. data/exe/solr-makr +9 -0
  7. data/lib/solr_makr.rb +76 -23
  8. data/lib/solr_makr/application.rb +24 -44
  9. data/lib/solr_makr/application_action.rb +182 -0
  10. data/lib/solr_makr/application_dispatch.rb +85 -0
  11. data/lib/solr_makr/collection.rb +17 -0
  12. data/lib/solr_makr/commands.rb +14 -0
  13. data/lib/solr_makr/commands/abstract_command.rb +60 -0
  14. data/lib/solr_makr/commands/buffer.rb +98 -0
  15. data/lib/solr_makr/commands/create_collection.rb +57 -0
  16. data/lib/solr_makr/commands/delete_collection.rb +13 -0
  17. data/lib/solr_makr/commands/execute.rb +67 -0
  18. data/lib/solr_makr/commands/fetch_collection_list.rb +17 -0
  19. data/lib/solr_makr/commands/push_config.rb +36 -0
  20. data/lib/solr_makr/commands/reload_collection.rb +13 -0
  21. data/lib/solr_makr/commands/set_up_local_configuration.rb +27 -0
  22. data/lib/solr_makr/commands/write_yaml.rb +28 -19
  23. data/lib/solr_makr/configsets.rb +15 -0
  24. data/lib/solr_makr/configsets/directory.rb +32 -0
  25. data/lib/solr_makr/configsets/get_nodes.rb +33 -0
  26. data/lib/solr_makr/configsets/install_default.rb +17 -0
  27. data/lib/solr_makr/configsets/lookup_dependent_collections.rb +20 -0
  28. data/lib/solr_makr/configsets/node.rb +56 -0
  29. data/lib/solr_makr/configsets/push_to_zookeeper.rb +19 -0
  30. data/lib/solr_makr/configsets/remote.rb +30 -0
  31. data/lib/solr_makr/configuration.rb +45 -0
  32. data/lib/solr_makr/errors/halt_execution.rb +4 -0
  33. data/lib/solr_makr/files/default-configset/README.md +1 -0
  34. data/lib/solr_makr/files/default-configset/conf/_rest_managed.json +1 -0
  35. data/lib/solr_makr/files/default-configset/conf/admin-extra.html +31 -0
  36. data/lib/solr_makr/files/default-configset/conf/currency.xml +67 -0
  37. data/lib/solr_makr/files/default-configset/conf/elevate.xml +1672 -0
  38. data/lib/solr_makr/files/default-configset/conf/lang/stopwords_en.txt +54 -0
  39. data/lib/solr_makr/files/default-configset/conf/mapping-ISOLatin1Accent.txt +2586 -0
  40. data/lib/solr_makr/files/default-configset/conf/protwords.txt +1613 -0
  41. data/lib/{files → solr_makr/files/default-configset/conf}/schema.xml +132 -40
  42. data/lib/solr_makr/files/default-configset/conf/scripts.conf +1623 -0
  43. data/lib/{files → solr_makr/files/default-configset/conf}/solrconfig.xml +294 -328
  44. data/lib/solr_makr/files/default-configset/conf/spellings.txt +1534 -0
  45. data/lib/solr_makr/files/default-configset/conf/synonyms.txt +1646 -0
  46. data/lib/solr_makr/local_configuration.rb +42 -0
  47. data/lib/solr_makr/local_configuration/cache.rb +21 -0
  48. data/lib/solr_makr/local_configuration/config_directory.rb +17 -0
  49. data/lib/solr_makr/local_configuration/directory.rb +17 -0
  50. data/lib/solr_makr/local_configuration/helper.rb +19 -0
  51. data/lib/solr_makr/local_configuration/save_settings.rb +9 -0
  52. data/lib/solr_makr/local_configuration/settings.rb +50 -0
  53. data/lib/solr_makr/meta/abstract_runner.rb +36 -0
  54. data/lib/solr_makr/meta/application_logger.rb +13 -0
  55. data/lib/solr_makr/meta/buffer_interaction.rb +41 -0
  56. data/lib/solr_makr/meta/disable_paging.rb +6 -0
  57. data/lib/solr_makr/meta/has_solr_attributes.rb +13 -0
  58. data/lib/solr_makr/meta/indifferent_options.rb +13 -0
  59. data/lib/solr_makr/meta/option_definition.rb +105 -0
  60. data/lib/solr_makr/meta/option_mapping.rb +38 -0
  61. data/lib/solr_makr/meta/pathlike.rb +9 -0
  62. data/lib/solr_makr/meta/set_global_options.rb +23 -0
  63. data/lib/solr_makr/meta/utility.rb +99 -0
  64. data/lib/solr_makr/meta/wraps_directory.rb +27 -0
  65. data/lib/solr_makr/meta/wraps_path.rb +18 -0
  66. data/lib/solr_makr/solr_api.rb +12 -0
  67. data/lib/solr_makr/solr_api/client.rb +32 -0
  68. data/lib/solr_makr/solr_api/client_macros.rb +61 -0
  69. data/lib/solr_makr/solr_api/cluster_response.rb +21 -0
  70. data/lib/solr_makr/solr_api/endpoint.rb +15 -0
  71. data/lib/solr_makr/solr_api/list_response.rb +19 -0
  72. data/lib/solr_makr/solr_api/request_params.rb +50 -0
  73. data/lib/solr_makr/solr_api/response.rb +69 -0
  74. data/lib/solr_makr/sunspot_configuration.rb +49 -0
  75. data/lib/solr_makr/version.rb +1 -1
  76. data/solr_makr.gemspec +17 -9
  77. metadata +171 -31
  78. data/bin/solr-makr +0 -7
  79. data/lib/solr_makr/commands/create_core.rb +0 -21
  80. data/lib/solr_makr/commands/destroy_core.rb +0 -17
  81. data/lib/solr_makr/commands/list_cores.rb +0 -17
  82. data/lib/solr_makr/commands/shared.rb +0 -84
  83. data/lib/solr_makr/core.rb +0 -94
  84. data/lib/solr_makr/core_status.rb +0 -56
  85. data/lib/solr_makr/solr_configuration.rb +0 -84
  86. data/lib/solr_makr/solr_request.rb +0 -23
@@ -0,0 +1,42 @@
1
+ module SolrMakr
2
+ module LocalConfiguration
3
+ extend ActiveSupport::Autoload
4
+
5
+ eager_autoload do
6
+ autoload :Cache
7
+ autoload :ConfigDirectory
8
+ autoload :Directory
9
+ autoload :Helper
10
+ autoload :Settings
11
+
12
+ autoload :SaveSettings
13
+ end
14
+
15
+ class << self
16
+ # @return [SolrMakr::Configsets::Directory]
17
+ def default_configset
18
+ configsets[SolrMakr.configuration.default_configset]
19
+ end
20
+
21
+ # @!attribute [r] cache
22
+ attr_lazy_reader :cache do
23
+ SolrMakr::LocalConfiguration::Cache.new
24
+ end
25
+
26
+ # @!attribute [r] configsets
27
+ attr_lazy_reader :configsets do
28
+ SolrMakr::LocalConfiguration::ConfigDirectory.new
29
+ end
30
+
31
+ # @!attribute [r] directory
32
+ attr_lazy_reader :directory do
33
+ SolrMakr::LocalConfiguration::Directory.new
34
+ end
35
+
36
+ # @!attribute [r] settings
37
+ attr_lazy_reader :settings do
38
+ SolrMakr::LocalConfiguration::Settings.new
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ module SolrMakr
2
+ module LocalConfiguration
3
+ class Cache
4
+ include LocalConfiguration::Helper
5
+ include SolrMakr::WrapsDirectory
6
+
7
+ attr_lazy_reader :path do
8
+ local_configuration.join('cache.lmdb')
9
+ end
10
+
11
+ attr_lazy_reader :managed_db do
12
+ client.database('managed', create: true)
13
+ end
14
+
15
+ # @api private
16
+ attr_lazy_reader :client do
17
+ LMDB.new(path)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module SolrMakr
2
+ module LocalConfiguration
3
+ class ConfigDirectory
4
+ include LocalConfiguration::Helper
5
+ include SolrMakr::WrapsDirectory
6
+
7
+ attr_lazy_reader :path do
8
+ local_configuration.join('configsets')
9
+ end
10
+
11
+ # @return [SolrMakr::Configset::Directory]
12
+ def [](name)
13
+ SolrMakr::Configsets::Directory.new(path: path.join(name))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module SolrMakr
2
+ module LocalConfiguration
3
+ class Directory
4
+ include SolrMakr::WrapsDirectory
5
+
6
+ DEFAULT = ENV.fetch('SOLR_MAKR_HOME') do
7
+ File.join(Dir.home, '.config', 'solr_makr')
8
+ end
9
+
10
+ # @!attribute [r] path
11
+ # @return [Pathname]
12
+ attr_lazy_reader :path do
13
+ Pathname.new(DEFAULT)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module SolrMakr
2
+ module LocalConfiguration
3
+ module Helper
4
+ module_function
5
+
6
+ def local_configuration
7
+ LocalConfiguration.directory
8
+ end
9
+
10
+ def local_settings
11
+ LocalConfiguration.settings
12
+ end
13
+
14
+ def create_local_directory_if_missing!
15
+ local_configuration.create_if_missing!
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module SolrMakr
2
+ module LocalConfiguration
3
+ # TODO: implement ability to save from CLI.
4
+ class SaveSettings < ActiveInteraction::Base
5
+ def execute
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+ module SolrMakr
2
+ module LocalConfiguration
3
+ class Settings
4
+ include LocalConfiguration::Helper
5
+ include SolrMakr::WrapsPath
6
+
7
+ attr_lazy_reader :path do
8
+ local_configuration.join 'settings.toml'
9
+ end
10
+
11
+ # @!attribute [r] parsed
12
+ # @return [ActiveSupport::HashWithIndifferentAccess]
13
+ attr_lazy_accessor :parsed do
14
+ parse_config_file
15
+ end
16
+
17
+ # @return [ActiveSupport::HashWithIndifferentAccess]
18
+ def reparse!
19
+ self.parsed = parse_config_file
20
+ end
21
+
22
+ # @return [void]
23
+ def make_backup!
24
+ return unless exists?
25
+
26
+ backup_path = path.to_s.gsub(/\.toml$/, ".#{Time.now.utc.to_i}.toml")
27
+
28
+ FileUtils.cp_r path.to_s, backup_path
29
+
30
+ return nil
31
+ end
32
+
33
+ # @param [Hash] new_data
34
+ # @return [void]
35
+ def save!(new_data)
36
+ create_local_directory_if_missing!
37
+ end
38
+
39
+ private
40
+ # @return [ActiveSupport::HashWithIndifferentAccess]
41
+ def parse_config_file
42
+ begin
43
+ TOML.load_file path.to_s
44
+ rescue Errno::ENOENT => e
45
+ {}
46
+ end.with_indifferent_access
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,36 @@
1
+ module SolrMakr
2
+ module AbstractRunner
3
+ extend ActiveSupport::Concern
4
+ include ActiveSupport::Callbacks
5
+ include ActiveSupport::Configurable
6
+ include SolrMakr::Utility
7
+
8
+ included do
9
+ config.command_mapping = {}.with_indifferent_access
10
+
11
+ config_accessor :command_mapping
12
+ end
13
+
14
+ class_methods do
15
+ # @param [SolrMakr::Application]
16
+ # @return [void]
17
+ def generate_commands!(application)
18
+ command_mapping.values.each do |action|
19
+ application.command action.command_name do |command|
20
+ action.setup_command! command
21
+ end
22
+ end
23
+ end
24
+
25
+ # @param [<String>] args
26
+ # @param [Commander::Command::Options] options
27
+ def action!(name, **options, &method_body)
28
+ options[:name] = name
29
+
30
+ action = ApplicationAction.new(options).configure(&method_body)
31
+
32
+ command_mapping[name] = action
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ module SolrMakr
2
+ class ApplicationLogger < ::Logger
3
+ ARBITRARY = %w[success failure]
4
+
5
+ def format_severity(level)
6
+ if level.in? ARBITRARY
7
+ level
8
+ else
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ module SolrMakr
2
+ module BufferInteraction
3
+ extend ActiveSupport::Concern
4
+
5
+ # @!attribute [r] buffer
6
+ # @return [SolrMakr::Commands::Buffer]
7
+ attr_lazy_reader :buffer do
8
+ build_buffer
9
+ end
10
+
11
+ # @param [ActiveInteraction::Base, SolrMakr::BufferInteraction] other
12
+ # @param [Boolean] raise_interrupt normal behavior for halting with compose
13
+ # @param [Hash] options
14
+ # @return [Object]
15
+ def compose_buffer(other, raise_interrupt: true, **options, &on_failure)
16
+ outcome = other.run(**options)
17
+
18
+ if outcome.kind_of?(SolrMakr::BufferInteraction)
19
+ buffer.import outcome.buffer
20
+ end
21
+
22
+ if outcome.valid?
23
+ return outcome.result
24
+ else
25
+ if block_given?
26
+ yield outcome
27
+ end
28
+
29
+ if raise_interrupt
30
+ throw :interrupt, outcome.errors
31
+ end
32
+
33
+ return nil
34
+ end
35
+ end
36
+
37
+ def build_buffer
38
+ SolrMakr::Commands::Buffer.new
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,6 @@
1
+ module SolrMakr
2
+ # Disable annoying paging in the Commander gem.
3
+ module DisablePaging
4
+ def enable_paging; nil; end
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module SolrMakr
2
+ module HasSolrAttributes
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ delegate :solr_host, :solr_path, :solr_port, to: :app_configuration
7
+ end
8
+
9
+ def app_configuration
10
+ SolrMakr.configuration
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module SolrMakr
2
+ module IndifferentOptions
3
+ delegate :[], :[]=, to: :@table
4
+
5
+ def initialize
6
+ @table = {}.with_indifferent_access
7
+ end
8
+
9
+ def default(defaults = {})
10
+ @table.reverse_merge! defaults
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,105 @@
1
+ module SolrMakr
2
+ # @api private
3
+ class OptionDefinition
4
+ include Virtus.model
5
+
6
+ attribute :name, String
7
+ attribute :short_name, String, default: nil
8
+ attribute :long_name, String, default: :default_long_name
9
+ attribute :value_name, String, default: ''
10
+ attribute :type, Object, default: nil
11
+ attribute :required, Boolean, default: false
12
+ attribute :description, String, default: ''
13
+ attribute :validator, Proc, default: nil
14
+ attribute :default_value, Object, default: nil
15
+
16
+ # @param [Commander::Command] command
17
+ # @return [void]
18
+ def add_to_command!(command)
19
+ command.option *commander_tuple
20
+ end
21
+
22
+ def has_default?
23
+ !default_value.nil?
24
+ end
25
+
26
+ # @param [<String>] args
27
+ # @param [Commander::Command::Options] options
28
+ # @return [void]
29
+ def set_default!(args, options)
30
+ return unless has_default?
31
+
32
+ case default_value
33
+ when Proc
34
+ options.default name => default_value.call
35
+ when Symbol
36
+ options.default name => options[default_value]
37
+ else
38
+ options.default name => default_value
39
+ end
40
+
41
+ return
42
+ end
43
+
44
+ # @param [Commander::Command::Options] options
45
+ def valid_in?(options)
46
+ if required?
47
+ return options[name].present?
48
+ end
49
+
50
+ return true
51
+ end
52
+
53
+ # @api private
54
+ # @return [String]
55
+ def default_long_name
56
+ name.dasherize
57
+ end
58
+
59
+ # @return [Array]
60
+ def commander_tuple
61
+ [].tap do |ary|
62
+ ary << "-#{short_name}" if short_name.present?
63
+ ary << long_name_with_value
64
+ ary << type if type.present?
65
+ ary << full_description if full_description.present?
66
+ end
67
+ end
68
+
69
+ def long_name_with_value
70
+ [].tap do |ary|
71
+ ary << "--#{long_name}"
72
+
73
+ unless type.blank?
74
+ ary << ( value_name.presence || name.upcase )
75
+ end
76
+ end.join(' ')
77
+ end
78
+
79
+ # @api private
80
+ attr_lazy_reader :full_description do
81
+ [].tap do |ary|
82
+ if required? && !has_default?
83
+ ary << '[REQUIRED]'
84
+ end
85
+
86
+ if description.present?
87
+ ary << description
88
+
89
+ ary << "[default: #{evaluated_default_value}]" if has_default?
90
+ end
91
+ end.join(' ')
92
+ end
93
+
94
+ # @api private
95
+ attr_lazy_reader :evaluated_default_value do
96
+ if default_value.respond_to?(:call)
97
+ default_value.call
98
+ elsif default_value.kind_of?(Symbol)
99
+ "provided #{default_value}"
100
+ else
101
+ default_value
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,38 @@
1
+ module SolrMakr
2
+ # @api private
3
+ class OptionMapping
4
+ include Enumerable
5
+
6
+ def initialize
7
+ @_mapping = {}.with_indifferent_access
8
+ end
9
+
10
+ delegate :[], to: :@_mapping
11
+
12
+ def <<(definition)
13
+ raise TypeError, "not a definition" unless definition.kind_of?(SolrMakr::OptionDefinition)
14
+
15
+ @_mapping[definition.name] = definition
16
+
17
+ return self
18
+ end
19
+
20
+ def each
21
+ return enum_for(:each) unless block_given?
22
+
23
+ @_mapping.each_value do |definition|
24
+ yield definition
25
+ end
26
+ end
27
+
28
+ # @param [Commander::Command] command
29
+ # @return [void]
30
+ def add_to_command!(command)
31
+ each do |definition|
32
+ definition.add_to_command! command
33
+ end
34
+
35
+ return nil
36
+ end
37
+ end
38
+ end