-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added experimental manual mesos task reconciliation script (orphan killer) #238
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
|
||
from docker import Client | ||
|
||
from paasta_tools import mesos_tools | ||
from paasta_tools.utils import get_docker_host | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
description=( | ||
'Cross references running containers with task ids from the mesos slave', | ||
' and optionally kills them.' | ||
) | ||
) | ||
parser.add_argument('-f', '--force', help="Actually kill the containers. (defaults to dry-run)") | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def get_running_task_ids_from_mesos_slave(): | ||
state = mesos_tools.get_local_slave_state() | ||
frameworks = state.get('frameworks') | ||
executors = [ex for fw in frameworks for ex in fw.get('executors', []) | ||
if u'TASK_RUNNING' in [t[u'state'] for t in ex.get('tasks', [])]] | ||
return [e["id"] for e in executors] | ||
|
||
|
||
def get_running_mesos_docker_containers(client): | ||
running_containers = client.containers() | ||
return [container for container in running_containers if "mesos-" in container["Names"][0]] | ||
|
||
|
||
def get_docker_client(): | ||
base_docker_url = get_docker_host() | ||
return Client(base_url=base_docker_url) | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
docker_client = get_docker_client() | ||
running_mesos_task_ids = get_running_task_ids_from_mesos_slave() | ||
running_mesos_docker_containers = get_running_mesos_docker_containers(docker_client) | ||
print running_mesos_task_ids | ||
|
||
for container in running_mesos_docker_containers: | ||
mesos_task_id = mesos_tools.get_mesos_id_from_container(container=container, client=docker_client) | ||
print mesos_task_id | ||
if mesos_task_id not in running_mesos_task_ids: | ||
if args.force: | ||
print "Killing %s. (%s)" % (container["Names"][0], mesos_task_id) | ||
docker_client.kill(container) | ||
else: | ||
print "Would kill %s. (%s)" % (container["Names"][0], mesos_task_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Could you hint at using the --force option in this message? |
||
else: | ||
print "Not killing %s. (%s)" % (container["Names"][0], mesos_task_id) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return a set here to make this run in linear time instead of quadratic
Line 50 checks if a container id is in the running task ids for every container, and checking membership in a list is O(n) while checking membership in a set is O(1)