Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

single plugin options for master and slave, more error message cleanu…

…p, unit tests
  • Loading branch information...
commit 731c908493d0549455f2fc854d8781b89f0b7779 1 parent 090aca1
Derek Haynes itsderek23 authored
181 solr_replication/fixtures/sample.html
View
@@ -0,0 +1,181 @@
+<!-- $Id: header.jsp 1031778 2010-11-05 20:29:20Z ryan $ -->
+<html>
+<head>
+<script>
+var host_name="hostname.example.com"
+</script>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<link rel="stylesheet" type="text/css" href="../solr-admin.css">
+<link rel="icon" href="../favicon.ico" type="image/ico" />
+<link rel="shortcut icon" href="../favicon.ico" type="image/ico" />
+<title>Solr replication admin page</title>
+<script type="text/javascript" src="../jquery-1.4.3.min.js"></script>
+</head>
+<body>
+<a href=".."><img border="0" align="right" height="78" width="142" src="../solr_small.png" alt="Solr"></a>
+<h1>Solr replication (sunspot)
+ Master & Slave
+</h1>
+hostname.examp.e.com<br/>
+cwd=/usr/local/solr SolrHome=solr/cores/core1/
+<br clear="all" />
+(<a href="http://wiki.apache.org/solr/SolrReplication">What Is This Page?</a>)
+<br clear="all" />
+<table>
+<tr>
+ <td>
+ <strong>Master</strong>
+ </td>
+ <td>
+ http://192.168.100.1:8983/solr/online/replication
+
+ </td>
+</tr>
+<tr>
+ <td>
+ </td>
+ <td>Latest Index Version:null, Generation: null
+ </td>
+</tr>
+<tr>
+ <td></td>
+ <td>Replicatable Index Version:1305174339477, Generation: 1649043
+ </td>
+</tr>
+<tr>
+ <td>
+ <strong>Poll Interval</strong>
+ </td>
+ <td>
+ 00:00:30
+ </td>
+</tr>
+<tr>
+ <td>
+ <strong>Local Index</strong>
+ </td>
+ <td>
+ Index Version: 1305174339477, Generation: 1649043
+ </td>
+</tr>
+<tr>
+ <td>
+ </td>
+ <td>
+ Location: /usr/local/solr/solr/cores/core1/data/index
+ </td>
+</tr>
+<tr>
+ <td></td>
+ <td>Size: 379.28 MB
+ </td>
+</tr>
+<tr>
+ <td></td>
+ <td>
+ Config Files To Replicate: solrconfig.xml,schema.xml,stopwords.txt
+ </td>
+</tr>
+<tr>
+ <td></td>
+ <td>
+ Trigger Replication On: [commit, startup]
+ </td>
+</tr>
+<tr>
+ <td>
+ </td>
+ <td>
+ Times Replicated Since Startup: 131
+ </td>
+</tr>
+<tr>
+ <td>
+ </td>
+ <td>
+ Previous Replication Done At: Tue Oct 11 10:21:00 EST 2011
+ </td>
+</tr>
+<tr>
+ <td>
+ </td>
+ <td>
+ Config Files Replicated At: null
+ </td>
+</tr>
+<tr>
+ <td>
+ </td>
+ <td>
+ Config Files Replicated: null
+ </td>
+</tr>
+<tr>
+ <td>
+ </td>
+ <td>
+ Times Config Files Replicated Since Startup: null
+ </td>
+</tr>
+<tr>
+ <td>
+ </td>
+ <td>
+ Next Replication Cycle At: Tue Oct 11 10:21:30 EST 2011
+ </td>
+</tr>
+<tr>
+ <td><strong>Controls</strong>
+ </td>
+ <td>
+ <form name=polling method="POST" action="./index.jsp" accept-charset="UTF-8">
+ <input name="poll" type="hidden" value="disable">
+ <input class="stdbutton" type="submit" value="Disable Poll">
+ </form>
+
+ </td>
+</tr>
+<tr>
+ <td></td>
+ <td>
+ <form name=replicate method="POST" action="./index.jsp" accept-charset="UTF-8">
+ <input name="replicate" type="hidden" value="now">
+ <input name="replicateButton" class="stdbutton" type="submit" value="Replicate Now">
+ </form>
+
+ <script type="text/javascript">
+ document["replicate"].replicateButton.disabled = false;
+ document["replicate"].replicateButton.className = 'stdbutton';
+ </script>
+
+ </td>
+</tr>
+<tr>
+ <td><strong>Cores:</strong><br></td>
+ <td>[<a href="../../../offline/admin/index.jsp">offline
+ </a>][<a href="../../../online/admin/index.jsp">online
+ </a>]</td>
+</tr>
+</table>
+<P>
+<p>
+<table>
+ <tr>
+ <td>
+ </td>
+ <td>
+ Current Time: Tue Oct 11 10:21:09 EST 2011
+ </td>
+ </tr>
+ <tr>
+ <td>
+ </td>
+ <td>
+ Server Start At: Tue Oct 11 09:26:41 EST 2011
+ </td>
+ </tr>
+</table>
+<br>
+<a href="..">Return to Admin Page</a>
+</body>
+</html>
23 solr_replication/solr_replication.rb
View
@@ -2,25 +2,23 @@ class SolrReplication < Scout::Plugin
needs 'open-uri'
OPTIONS=<<-EOS
- master_ip:
- default: 192.168.0.1
- master_port:
- default: 8983
- slave_ip:
- default: localhost
- slave_port:
- default: 8765
+ master:
+ default: http://192.168.0.1:8983
+ slave:
+ default: http://localhost:8765
replication_path:
default: /solr/admin/replication/index.jsp
+ notes: The path to the replication index page in the Solr Admin web interface
EOS
def build_report
master_position = position_for(master_host)
slave_position = position_for(slave_host)
+ return if errors.any?
if master_position and slave_position
report 'delay' => master_position.to_i - slave_position.to_i
else
- error "Incorrect values found master:#{master_position.inspect} slave:#{slave_position.inspect}"
+ error "Incorrect master and slave positions found","master:#{master_position.inspect}\nslave:#{slave_position.inspect}"
end
end
@@ -30,15 +28,14 @@ def position_for(host)
generation_regex = /Generation: (\d+)/
open(host).read.match(generation_regex)[1]
rescue => e
- error "Error connecting to #{host}: #{e.message}"
- nil
+ error "Error connecting to #{host}","Unable to connect to Solr Admin interface at: #{host}. Error:\n#{e.message}\n\nEnsure the plugin options are configured correctly."
end
def master_host
- "http://#{option(:master_ip)}:#{option(:master_port)}#{option("replication_path")}"
+ "#{option(:master)}#{option("replication_path")}"
end
def slave_host
- "http://#{option(:slave_ip)}:#{option(:slave_port)}#{option("replication_path")}"
+ "#{option(:slave)}#{option("replication_path")}"
end
end
32 solr_replication/test.rb
View
@@ -0,0 +1,32 @@
+require File.expand_path('../../test_helper.rb', __FILE__)
+require File.expand_path('../solr_replication.rb', __FILE__)
+
+require 'open-uri'
+class SolrReplicationTest < Test::Unit::TestCase
+
+ def teardown
+ FakeWeb.clean_registry
+ end
+
+ def test_should_report
+ master='http://192.168.0.1:8983'
+ slave='http://localhost:8765'
+ rep_path='/solr/admin/replication/index.html'
+ FakeWeb.register_uri(:get, master+rep_path, :body => File.read(File.dirname(__FILE__)+'/fixtures/sample.html'))
+ FakeWeb.register_uri(:get, slave+rep_path, :body => File.read(File.dirname(__FILE__)+'/fixtures/sample.html'))
+
+ @plugin=SolrReplication.new(nil,{},{:master => master, :slave => slave, :replication_path => rep_path})
+ res = @plugin.run()
+ assert res[:errors].empty?
+ assert_equal 0, res[:reports].first["delay"]
+ end
+
+ def test_should_error_with_invalid_master
+ slave='http://localhost:8765'
+ rep_path='/solr/admin/replication/index.html'
+ FakeWeb.register_uri(:get, slave+rep_path, :body => File.read(File.dirname(__FILE__)+'/fixtures/sample.html'))
+ @plugin=SolrReplication.new(nil,{},{:master => 'http://fake', :slave => slave, :replication_path => rep_path})
+ res = @plugin.run()
+ assert_equal 1, res[:errors].size
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.