Skip to content

Commit

Permalink
Remove search from deployer (replaced by store)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukrit007 committed Jul 31, 2015
1 parent d9a6796 commit e0707ba
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 362 deletions.
3 changes: 0 additions & 3 deletions bin/supervisord-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ export MONGODB_DB='${MONGODB_DB:-totem}'
export BROKER_URL='${BROKER_URL}'
export SSH_PASSPHRASE='${SSH_PASSPHRASE}'
export GITHUB_TOKEN='${GITHUB_TOKEN}'
export ELASTICSEARCH_HOST='${ELASTICSEARCH_HOST:-172.17.42.1}'
export ELASTICSEARCH_PORT='${ELASTICSEARCH_PORT:-9200}'
export FLEET_HOST='${FLEET_HOST:-172.17.42.1}'
export CLUSTER_NAME='${CLUSTER_NAME:-local}'
export TOTEM_ENV='${TOTEM_ENV:-local}'
export QUAY_ORGANIZATION='${QUAY_ORGANIZATION:-totem}'
export QUAY_PREFIX='${QUAY_PREFIX:-totem-}'
export SEARCH_ENABLED=${SEARCH_ENABLED:-false}
export C_FORCE_ROOT=true
export ENCRYPTION_PASSPHRASE='${ENCRYPTION_PASSPHRASE:-changeit}'
export ENCRYPTION_S3_BUCKET='${ENCRYPTION_S3_BUCKET:-not-set}'
Expand Down
12 changes: 1 addition & 11 deletions conf/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,11 @@

TOTEM_ETCD_SETTINGS = {
'base': os.getenv('ETCD_TOTEM_BASE', '/totem'),
'host': os.getenv('ETCD_HOST', '172.17.42.1'),
'host': os.getenv('ETCD_HOST', '127.0.0.1'),
'port': int(os.getenv('ETCD_PORT', '4001')),
'yoda_base': os.getenv('ETCD_YODA_BASE', '/yoda'),
}

SEARCH_INDEX = os.getenv('SEARCH_INDEX', 'totem-{0}'.format(TOTEM_ENV))

SEARCH_SETTINGS = {
'enabled': os.getenv('SEARCH_ENABLED', 'false').strip().lower() in
BOOLEAN_TRUE_VALUES,
'host': os.getenv('ELASTICSEARCH_HOST', '172.17.42.1'),
'port': os.getenv('ELASTICSEARCH_PORT', '9200'),
'default-index': SEARCH_INDEX
}

CORS_SETTINGS = {
'enabled': os.getenv('CORS_ENABLED', 'true').strip().lower() in
BOOLEAN_TRUE_VALUES,
Expand Down
14 changes: 0 additions & 14 deletions deployer/celery.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
from __future__ import absolute_import
from celery import Celery
from celery.signals import celeryd_init
from deployer import elasticsearch

app = Celery(__name__)
app.config_from_object('conf.celeryconfig')


@celeryd_init.connect
def configure_search(**kwargs):
"""
Creates the index mapping for elastic search on startup.
If mappings already exists, this will be ignored
:param kwargs:
:return:
"""
elasticsearch.create_index_mapping()
77 changes: 0 additions & 77 deletions deployer/elasticsearch.py

This file was deleted.

15 changes: 1 addition & 14 deletions deployer/services/health.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from functools import wraps
import sys
from etcd import client
from conf.appconfig import HEALTH_OK, HEALTH_FAILED, TOTEM_ETCD_SETTINGS, \
SEARCH_SETTINGS
from deployer.elasticsearch import get_search_client
from conf.appconfig import HEALTH_OK, HEALTH_FAILED, TOTEM_ETCD_SETTINGS
from deployer.services.storage.factory import get_store
from deployer.tasks.common import ping
from deployer.util import timeout
Expand Down Expand Up @@ -42,15 +40,6 @@ def inner(*args, **kwargs):
return inner


@timeout(HEALTH_TIMEOUT_SECONDS)
@_check
def _check_elasticsearch():
"""
Checks elasticsearch health by querying info.
"""
return get_search_client().info()


@timeout(HEALTH_TIMEOUT_SECONDS)
@_check
def _check_etcd():
Expand Down Expand Up @@ -97,6 +86,4 @@ def get_health(check_celery=True):
}
if check_celery:
health_status['celery'] = _check_celery()
if SEARCH_SETTINGS['enabled']:
health_status['elasticsearch'] = _check_elasticsearch()
return health_status
32 changes: 31 additions & 1 deletion deployer/views/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get(self, name=None):
}, default=MIME_APP_LIST_V1)
def list(self, **kwargs):
"""
Lists all applications. Require search to be enabled.
Lists all applications.
:param kwargs:
:return:
Expand Down Expand Up @@ -163,6 +163,36 @@ def delete(self, name, version, accept_mimetype=None, **kwargs):
return created_task(result)


class StateApi(MethodView):
"""
API for managing state of a given deployment
"""

@hypermedia.produces({
MIME_TASK_V1: SCHEMA_TASK_V1,
MIME_JSON: SCHEMA_TASK_V1,
MIME_APP_VERSION_DELETE_V1: None
}, default=MIME_TASK_V1)
def update_state(self, name, version, accept_mimetype=None, **kwargs):
"""
Deletes applications with given name and version
:param name: Name of the application
:type name: str
:param version: Version of the application
:type version: str
:return: Flask response code for 202.
"""
result = delete.delay(name, version=version)

if accept_mimetype == MIME_APP_VERSION_DELETE_V1:
task_client.ready(result.id, wait=True, raise_error=True)
return deleted(mimetype=accept_mimetype)

else:
return created_task(result)


class UnitApi(MethodView):
"""
API for units of a deployed application version
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ uWSGI==2.0.7
supervisor==3.1.2
python-etcd==0.3.2
elasticsearch==1.2.0
future==0.14.1
future==0.15.0
pytz==2015.4
urllib3==1.10.4
requests[security]==2.7.0
urllib3==1.11
https://github.com/totem/fleet-py/archive/master.tar.gz
https://github.com/totem/yoda-py/archive/develop.tar.gz
https://github.com/totem/flask-hyperschema/archive/master.tar.gz
Expand Down
57 changes: 2 additions & 55 deletions tests/unit/services/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,17 @@
__author__ = 'sukrit'


@patch.dict('deployer.services.health.SEARCH_SETTINGS', {
'enabled': True
})
@patch('deployer.services.health.ping')
@patch('deployer.services.health.get_search_client')
@patch('deployer.services.health.client')
@patch('deployer.services.health.get_store')
def test_get_health_when_elasticsearch_is_enabled(
get_store, client, get_es, ping):
def test_get_health(
get_store, client, ping):
"""
Should get the health status when elastic search is enabled
"""

# Given: Operational external services"
ping.delay().get.return_value = 'pong'
get_es().info.return_value = 'mock'
EtcdInfo = namedtuple('Info', ('machines',))
client.Client.return_value = EtcdInfo(['machine1'])
get_store.return_value.health.return_value = {'type': 'mock'}
Expand All @@ -52,61 +47,13 @@ def test_get_health_when_elasticsearch_is_enabled(
'type': 'mock'
}
},
'elasticsearch': {
'status': HEALTH_OK,
'details': 'mock'
},
'celery': {
'status': HEALTH_OK,
'details': 'Celery ping:pong'
}
})


@patch.dict('deployer.services.health.SEARCH_SETTINGS', {
'enabled': False
})
@patch('deployer.services.health.ping')
@patch('deployer.services.health.client')
@patch('deployer.services.health.get_store')
def test_get_health_when_elasticsearch_is_disabled(get_store, client, ping):
"""
Should get the health status when elastic search is enabled
"""

# Given: Operational external services"
ping.delay().get.return_value = 'pong'
EtcdInfo = namedtuple('Info', ('machines',))
client.Client.return_value = EtcdInfo(['machine1'])
get_store.return_value.health.return_value = {'type': 'mock'}

# When: I get the health of external services
health_status = health.get_health()

# Then: Expected health status is returned
dict_compare(health_status, {
'etcd': {
'status': HEALTH_OK,
'details': {
'machines': ['machine1']
}
},
'store': {
'status': HEALTH_OK,
'details': {
'type': 'mock'
}
},
'celery': {
'status': HEALTH_OK,
'details': 'Celery ping:pong'
},
})


@patch.dict('deployer.services.health.SEARCH_SETTINGS', {
'enabled': False
})
@patch('deployer.services.health.ping')
@patch('deployer.services.health.client')
@patch('deployer.services.health.get_store')
Expand Down
Loading

0 comments on commit e0707ba

Please sign in to comment.