Class: SmartMachine::Grids::Solr

Inherits:
Base
  • Object
show all
Defined in:
lib/smart_machine/grids/solr.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#machine_has_engine_installed?, #platform_on_machine?, #user_bash

Methods included from Logger

configure_logger_for, included, #logger, logger_for

Constructor Details

#initializeSolr

Returns a new instance of Solr.



5
6
# File 'lib/smart_machine/grids/solr.rb', line 5

def initialize
end

Class Method Details

.create_core(*args) ⇒ Object

TODO: self.create_core method must be checked line by line to see if its working properly for solr8 and above



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/smart_machine/grids/solr.rb', line 62

def self.create_core(*args)
	args.flatten!
	corename = args.empty? ? '' : args.shift

	if SmartMachine::Docker.running?
		puts "-----> Creating core #{corename} ... "
		if system("docker exec -it --user=solr solr solr create_core -c #{corename}")
			system("docker exec -it --user=solr solr solr config -c #{corename} -p 8983 -action set-user-property -property update.autoCreateFields -value false")
			puts "done"

			print "-----> Copying core files ... "
			system("sudo cp -r #{SmartMachine.config.root_path}/lib/smart_machine/grids/solr/sunspot/conf/* #{SmartMachine.config.user_home_path}/.smartmachine/grids/solr/data/#{corename}/conf/")
			if system("sudo chown -R 8983:8983 #{SmartMachine.config.user_home_path}/.smartmachine/grids/solr/data/#{corename}/conf", out: File::NULL)
				puts "done"
			end
		else
			puts "error"
		end
	end
end

.destroy_core(*args) ⇒ Object

TODO: self.destroy_core method must be checked line by line to see if its working properly for solr8 and above



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/smart_machine/grids/solr.rb', line 84

def self.destroy_core(*args)
	args.flatten!
	corename = args.empty? ? '' : args.shift

	if SmartMachine::Docker.running?
		puts "-----> Removing core #{corename} ... "
		if system("docker exec -it --user=solr solr solr delete -c #{corename}")
			puts "done"
		else
			puts "error"
		end
	end
end

Instance Method Details

#downObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/smart_machine/grids/solr.rb', line 41

def down
	if SmartMachine::Docker.running?
		# Stopping & Removing containers - in reverse order
		print "-----> Stopping container solr ... "
		if system("docker stop 'solr'", out: File::NULL)
			puts "done"
			print "-----> Removing container solr ... "
			if system("docker rm 'solr'", out: File::NULL)
				puts "done"
			end
		end

		# Removing networks
		print "-----> Removing network solr-network ... "
		if system("docker network rm solr-network", out: File::NULL)
			puts "done"
		end
	end
end

#up(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/smart_machine/grids/solr.rb', line 8

def up(*args)
	args.flatten!
	exposed = args.empty? ? '' : args.shift

	if SmartMachine::Docker.running?
		# Creating networks
		unless system("docker network inspect solr-network", [:out, :err] => File::NULL)
			print "-----> Creating network solr-network ... "
			if system("docker network create solr-network", out: File::NULL)
				puts "done"
			end
		end

		# Creating & Starting containers
		print "-----> Creating container solr ... "
		if system("docker create \
			--name='solr' \
			--user `id -u`:`id -g` \
			#{"--publish='8983:8983'" if exposed == '--exposed'} \
			--volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/solr/solr:/var/solr' \
			--restart='always' \
			--network='solr-network' \
			solr:8.2.0", out: File::NULL)

			puts "done"
			print "-----> Starting container solr ... "
			if system("docker start solr", out: File::NULL)
				puts "done"
			end
		end
	end
end