You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by ad...@apache.org on 2015/03/29 19:58:35 UTC

svn commit: r1669943 - in /steve/steve-web: requirements.txt src/asf/steve/backends/elastic.py

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)



Re: svn commit: r1669943 - in /steve/steve-web: requirements.txt src/asf/steve/backends/elastic.py

Posted by Greg Stein <gs...@gmail.com>.
On Sun, Mar 29, 2015 at 7:37 PM, Alan D. Cabrera <li...@toolazydogs.com>
wrote:

>
> > On Mar 29, 2015, at 12:00 PM, Greg Stein <gs...@gmail.com> wrote:
> >
> > On Sun, Mar 29, 2015 at 12:58 PM, <ad...@apache.org> wrote:
> >> ...
> >>
> >> +++ steve/steve-web/requirements.txt Sun Mar 29 17:58:35 2015
> >> @@ -1,4 +1,5 @@
> >> click==3.3
> >> +elasticsearch==1.4.0
> >>
> >
> > Shouldn't this be optional? I don't want to install ElasticSearch.
>
> Yes, it should be and will be.  The elastic search plugin, along with its
> dependencies, will be in its own distribution.  But for now I think it's
> best to keep all this together as I refactor the code.
>

Gotcha!

Thx,
-g

Re: svn commit: r1669943 - in /steve/steve-web: requirements.txt src/asf/steve/backends/elastic.py

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
> On Mar 29, 2015, at 12:00 PM, Greg Stein <gs...@gmail.com> wrote:
> 
> On Sun, Mar 29, 2015 at 12:58 PM, <ad...@apache.org> wrote:
>> ...
>> 
>> +++ steve/steve-web/requirements.txt Sun Mar 29 17:58:35 2015
>> @@ -1,4 +1,5 @@
>> click==3.3
>> +elasticsearch==1.4.0
>> 
> 
> Shouldn't this be optional? I don't want to install ElasticSearch.

Yes, it should be and will be.  The elastic search plugin, along with its dependencies, will be in its own distribution.  But for now I think it’s best to keep all this together as I refactor the code.


Regards,
Alan
.

Re: svn commit: r1669943 - in /steve/steve-web: requirements.txt src/asf/steve/backends/elastic.py

Posted by Greg Stein <gs...@gmail.com>.
On Sun, Mar 29, 2015 at 12:58 PM, <ad...@apache.org> wrote:
>...
>
> +++ steve/steve-web/requirements.txt Sun Mar 29 17:58:35 2015
> @@ -1,4 +1,5 @@
>  click==3.3
> +elasticsearch==1.4.0
>

Shouldn't this be optional? I don't want to install ElasticSearch.

>...

Cheers,
-g