Commit 985383ef5016dec1d3380e87563cb73d2e2763cc

Authored by Gust
1 parent 310d050a

Updated fabfile to suport solr 4.6

Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Signed-off-by: Matheus Faria <matheus.sousa.faria@gmail.com>
Showing 1 changed file with 71 additions and 4 deletions   Show diff stats
fabfile.py
... ... @@ -5,7 +5,7 @@ from fabric.contrib.files import exists
5 5 from fabric.decorators import with_settings
6 6 from fabric.context_managers import prefix, cd, settings
7 7  
8   -env.user = 'colab' # key depends on env
  8 +env.user = 'colab' # key depends on env
9 9 env.use_shell = False
10 10  
11 11 environments = {
... ... @@ -17,7 +17,7 @@ environments = {
17 17 'live': {
18 18 'hosts': ['10.1.2.153'],
19 19 'key_filename': '~/.ssh/id_rsa',
20   - 'port': 22,
  20 + 'port': 22,
21 21 },
22 22 'demo': {
23 23 'hosts': ['colab-demo.tracy.com.br'],
... ... @@ -90,8 +90,9 @@ def deploy(update=False):
90 90 sudo('supervisorctl restart all')
91 91  
92 92  
  93 +@with_settings(user='vagrant')
93 94 def rebuild_index(age=None, batch=None):
94   - with cd('~/colab/src/'), prefix(WORKON_COLAB):
  95 + with cd('/vagrant/src/'), prefix(WORKON_COLAB):
95 96 age_arg = ''
96 97 if age:
97 98 age_arg = '--age={}'.format(age)
... ... @@ -100,8 +101,22 @@ def rebuild_index(age=None, batch=None):
100 101 if batch:
101 102 batch_arg = '--batch-size={}'.format(batch)
102 103  
  104 + cmd = 'python manage.py rebuild_index {} {}'.format(age_arg, batch_arg)
  105 + returnMessage = run(cmd)
  106 + if 'error: [Errno 111] Connection refused' in returnMessage:
  107 + print red("Please run fab solr to start solr first")
  108 + else:
  109 + print green("All the index were updated")
103 110  
104   - run('python manage.py rebuild_index {} {}'.format(age_arg, batch_arg))
  111 +
  112 +@with_settings(user='vagrant')
  113 +def solr_update_index():
  114 + with cd('/vagrant/src/'), prefix(WORKON_COLAB):
  115 + returnMessage = run('python manage.py update_index')
  116 + if 'error: [Errno 111] Connection refused' in returnMessage:
  117 + print red("Please run fab solr to start solr first")
  118 + else:
  119 + print green("All the index were updated")
105 120  
106 121  
107 122 @with_settings(user='vagrant')
... ... @@ -128,3 +143,55 @@ def runserver(update_requirements=False):
128 143 run('python manage.py syncdb')
129 144 run('python manage.py migrate')
130 145 run('python manage.py runserver 0.0.0.0:7000')
  146 +
  147 +
  148 +@with_settings(user='vagrant')
  149 +def solr(port=8983):
  150 + with cd('/vagrant/src/'), prefix(WORKON_COLAB):
  151 + run('cd ~/solr-4.6.1/example; java -jar start.jar -Djetty.port={}'.format(port))
  152 +
  153 +
  154 +@with_settings(user='vagrant')
  155 +def solr_rebuild_index():
  156 + with cd('/vagrant/src/'), prefix(WORKON_COLAB):
  157 + returnMessage = run('python manage.py rebuild_index')
  158 + if 'error: [Errno 111] Connection refused' in returnMessage:
  159 + print red("Please run fab solr to start solr first")
  160 + else:
  161 + print green("All the index were updated")
  162 +
  163 +
  164 +@with_settings(user='vagrant')
  165 +def install_solr_4_6():
  166 + with cd('/vagrant/src/'), prefix(WORKON_COLAB):
  167 + if not exists('~/solr-4.6.1'):
  168 + run('wget https://archive.apache.org/dist/lucene/solr/4.6.1/solr-4.6.1.tgz -O /tmp/solr-4.6.1.tgz')
  169 + run('tar xzf /tmp/solr-4.6.1.tgz -C /tmp/')
  170 + run('cp -rf /tmp/solr-4.6.1 ~/solr-4.6.1')
  171 + run('rm /tmp/solr-4.6.1')
  172 +
  173 + with cd('~/solr-4.6.1/example/solr/collection1/conf/'), prefix(WORKON_COLAB):
  174 + if not exists('stopwords_en.txt'):
  175 + run('cp stopwords.txt stopwords_en.txt')
  176 +
  177 +
  178 +@with_settings(user='vagrant')
  179 +def import_emails():
  180 + with cd('/vagrant/src/'), prefix(WORKON_COLAB):
  181 + run('python manage.py import_emails')
  182 +
  183 +
  184 +@with_settings(user='vagrant')
  185 +def solr_4_build_schema():
  186 + with cd('/vagrant/src/'), prefix(WORKON_COLAB):
  187 + solr_schema_file = '~/solr-4.6.1/example/solr/collection1/conf/schema.xml'
  188 + run('python manage.py build_solr_schema -f {}'.format(solr_schema_file))
  189 + run(r'sed -i "s/<fields>/<fields>\n<field name=\"_version_\" type=\"long\" indexed=\"true\" stored =\"true\"\/>/" {}'.format(solr_schema_file))
  190 +
  191 +
  192 +def red(message):
  193 + return "\033[0;31m" + message + "\033[0m"
  194 +
  195 +
  196 +def green(message):
  197 + return "\033[0;32m" + message + "\033[0m"
... ...