Author: adc
Date: Sun Mar 29 17:58:35 2015
New Revision: 1669943
URL: http://svn.apache.org/r1669943
Log:
Sketched out elastic search bit
Modified:
steve/steve-web/requirements.txt
steve/steve-web/src/asf/steve/backends/elastic.py
Modified: steve/steve-web/requirements.txt
URL:
http://svn.apache.org/viewvc/steve/steve-web/requirements.txt?rev=1669943&r1=1669942&r2=1669943&view=diff
==============================================================================
--- steve/steve-web/requirements.txt (original)
+++ steve/steve-web/requirements.txt Sun Mar 29 17:58:35 2015
@@ -1,4 +1,5 @@
click==3.3
+elasticsearch==1.4.0
Flask==0.10.1
Flask-WTF==0.9.5
Flask-Principal==0.4.0
Modified: steve/steve-web/src/asf/steve/backends/elastic.py
URL:
http://svn.apache.org/viewvc/steve/steve-web/src/asf/steve/backends/elastic.py?rev=1669943&r1=1669942&r2=1669943&view=diff
==============================================================================
--- steve/steve-web/src/asf/steve/backends/elastic.py (original)
+++ steve/steve-web/src/asf/steve/backends/elastic.py Sun Mar 29 17:58:35 2015
@@ -16,6 +16,54 @@
# specific language governing permissions and limitations
# under the License.
#
+from elasticsearch import Elasticsearch
+
class ElasticStorageBackend(object):
- pass
\ No newline at end of file
+ def __init__(self, host, port, uri, secure):
+ self.host = host
+ self.port = port
+ self.uri = uri
+ self.secure = secure
+
+ self.client = Elasticsearch([
+ {
+ 'host': host,
+ 'port': int(port),
+ 'url_prefix': uri,
+ 'use_ssl': bool(secure)
+ },
+ ])
+
+ if not self.client.indices.exists('steve'):
+ self.client.indices.create(index='steve', body={
+ 'settings': {
+ 'number_of_shards': 3,
+ 'number_of_replicas': 1
+ }
+ })
+
+ def create_election(self, eid, title, owner, monitors, starts, ends,
is_open):
+ """ Create an election
+ :param str eid: Election ID
+ :param str title: the title (name) of the election
+ :param str owner: the owner of this election
+ :param list monitors: email addresses to use for monitoring
+ :param str starts: the start date of the election
+ :param str ends: the end date of the election
+ :param bool is_open: flag that indicates if election is open to the
public or not
+ """
+ election_hash = hashlib.sha512("%f-stv-%s" % (time.time(),
os.environ['REMOTE_ADDR'] if 'REMOTE_ADDR' in os.environ else random.randint(1,
99999999999))).hexdigest(),
+
+ base_data = {
+ 'id': eid,
+ 'title': title,
+ 'owner': owner,
+ 'monitors': monitors,
+ 'starts': starts,
+ 'ends': ends,
+ 'hash': election_hash,
+ 'open': is_open
+ }
+
+ self.client.index(index='steve', doc_type='elections', id=eid,
body=base_data)