Merge "lastStatus introduced"
This commit is contained in:
commit
7c86a1f411
@ -11,6 +11,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
from muranoapi.common.utils import build_entity_map
|
||||||
|
|
||||||
from muranoapi.openstack.common import wsgi
|
from muranoapi.openstack.common import wsgi
|
||||||
from muranoapi.db.models import Deployment, Status, Environment
|
from muranoapi.db.models import Deployment, Status, Environment
|
||||||
@ -48,11 +49,8 @@ class Controller(object):
|
|||||||
if 'services' in environment:
|
if 'services' in environment:
|
||||||
for service in environment['services']:
|
for service in environment['services']:
|
||||||
if service['id'] in service_id_set:
|
if service['id'] in service_id_set:
|
||||||
entity_ids.append(service['id'])
|
id_map = build_entity_map(service)
|
||||||
if 'units' in service:
|
entity_ids = entity_ids + id_map.keys()
|
||||||
unit_ids = [u['id'] for u in service['units']
|
|
||||||
if 'id' in u]
|
|
||||||
entity_ids = entity_ids + unit_ids
|
|
||||||
if entity_ids:
|
if entity_ids:
|
||||||
query = query.filter(Status.entity_id.in_(entity_ids))
|
query = query.filter(Status.entity_id.in_(entity_ids))
|
||||||
else:
|
else:
|
||||||
|
@ -13,10 +13,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
|
from muranoapi.common.utils import build_entity_map
|
||||||
|
from sqlalchemy import desc
|
||||||
from webob import exc
|
from webob import exc
|
||||||
from muranoapi.common import config
|
from muranoapi.common import config
|
||||||
from muranoapi.db.session import get_session
|
from muranoapi.db.session import get_session
|
||||||
from muranoapi.db.models import Environment
|
from muranoapi.db.models import Environment, Status
|
||||||
from muranoapi.db.services.core_services import CoreServices
|
from muranoapi.db.services.core_services import CoreServices
|
||||||
from muranoapi.db.services.environments import EnvironmentServices
|
from muranoapi.db.services.environments import EnvironmentServices
|
||||||
from muranoapi.openstack.common import wsgi
|
from muranoapi.openstack.common import wsgi
|
||||||
@ -113,6 +115,27 @@ class Controller(object):
|
|||||||
|
|
||||||
EnvironmentServices.delete(environment_id, request.context.auth_token)
|
EnvironmentServices.delete(environment_id, request.context.auth_token)
|
||||||
|
|
||||||
|
def last(self, request, environment_id):
|
||||||
|
session_id = None
|
||||||
|
if hasattr(request, 'context') and request.context.session:
|
||||||
|
session_id = request.context.session
|
||||||
|
services = CoreServices.get_data(environment_id, '/services',
|
||||||
|
session_id)
|
||||||
|
db_session = get_session()
|
||||||
|
result = {}
|
||||||
|
for service in services:
|
||||||
|
service_id = service['id']
|
||||||
|
entity_ids = build_entity_map(service).keys()
|
||||||
|
last_status = db_session.query(Status). \
|
||||||
|
filter(Status.entity_id.in_(entity_ids)). \
|
||||||
|
order_by(desc(Status.created)). \
|
||||||
|
first()
|
||||||
|
if last_status:
|
||||||
|
result[service_id] = last_status.to_dict()
|
||||||
|
else:
|
||||||
|
result[service_id] = None
|
||||||
|
return {'lastStatuses': result}
|
||||||
|
|
||||||
|
|
||||||
def create_resource():
|
def create_resource():
|
||||||
return wsgi.Resource(Controller())
|
return wsgi.Resource(Controller())
|
||||||
|
@ -82,6 +82,10 @@ class API(wsgi.Router):
|
|||||||
controller=environments_resource,
|
controller=environments_resource,
|
||||||
action='delete',
|
action='delete',
|
||||||
conditions={'method': ['DELETE']})
|
conditions={'method': ['DELETE']})
|
||||||
|
mapper.connect('/environments/{environment_id}/lastStatus',
|
||||||
|
controller=environments_resource,
|
||||||
|
action='last',
|
||||||
|
conditions={'method': ['GET']})
|
||||||
|
|
||||||
deployments_resource = deployments.create_resource()
|
deployments_resource = deployments.create_resource()
|
||||||
mapper.connect('/environments/{environment_id}/deployments',
|
mapper.connect('/environments/{environment_id}/deployments',
|
||||||
|
@ -136,6 +136,22 @@ def auto_id(value):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def build_entity_map(value):
|
||||||
|
def build_entity_map_recursive(value, id_map):
|
||||||
|
if isinstance(value, types.DictionaryType):
|
||||||
|
if 'id' in value:
|
||||||
|
id_map[value['id']] = value
|
||||||
|
for k, v in value.iteritems():
|
||||||
|
build_entity_map_recursive(v, id_map)
|
||||||
|
if isinstance(value, types.ListType):
|
||||||
|
for item in value:
|
||||||
|
build_entity_map_recursive(item, id_map)
|
||||||
|
|
||||||
|
id_map = {}
|
||||||
|
build_entity_map_recursive(value, id_map)
|
||||||
|
return id_map
|
||||||
|
|
||||||
|
|
||||||
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2):
|
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2):
|
||||||
"""Retry calling the decorated function using an exponential backoff.
|
"""Retry calling the decorated function using an exponential backoff.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user