This repository has been archived by the owner on Oct 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from cloudify-cosmo/feature/CFY-780-events-api
Feature/cfy 780 events api
- Loading branch information
Showing
10 changed files
with
136 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,3 @@ install: | |
|
||
script: | ||
- flake8 . | ||
- nosetests cosmo_manager_rest_client/tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
######## | ||
# Copyright (c) 2014 GigaSpaces Technologies Ltd. All rights reserved | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# * See the License for the specific language governing permissions and | ||
# * limitations under the License. | ||
|
||
__author__ = 'idanmo' | ||
|
||
|
||
class EventsClient(object): | ||
|
||
def __init__(self, api): | ||
self.api = api | ||
|
||
@staticmethod | ||
def _create_events_query(execution_id, include_logs): | ||
query = { | ||
"bool": { | ||
"must": [ | ||
{"match": {"context.execution_id": execution_id}}, | ||
] | ||
} | ||
} | ||
match_cloudify_event = {"match": {"type": "cloudify_event"}} | ||
if include_logs: | ||
match_cloudify_log = {"match": {"type": "cloudify_log"}} | ||
query['bool']['should'] = [ | ||
match_cloudify_event, match_cloudify_log | ||
] | ||
else: | ||
query['bool']['must'].append(match_cloudify_event) | ||
return query | ||
|
||
def get(self, | ||
execution_id, | ||
from_event=0, | ||
batch_size=100, | ||
include_logs=False): | ||
""" | ||
Returns event for the provided execution id. | ||
:param execution_id: Id of execution to get events for. | ||
:param from_event: Index of first event to retrieve on pagination. | ||
:param batch_size: Maximum number of events to retrieve per call. | ||
:param include_logs: Whether to also get logs. | ||
:return: Events list and total number of currently available | ||
events (tuple). | ||
""" | ||
body = { | ||
"from": from_event, | ||
"size": batch_size, | ||
"sort": [{"@timestamp": {"order": "asc"}}], | ||
"query": self._create_events_query(execution_id, include_logs) | ||
} | ||
response = self.api.get('/events', data=body) | ||
events = map(lambda x: x['_source'], response['hits']['hits']) | ||
total_events = response['hits']['total'] | ||
return events, total_events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.