{"action":"created","comment":{"url":"https://api.github.com/repos/Yelp/paasta/pulls/comments/84333639","pull_request_review_id":5117971,"id":84333639,"diff_hunk":"@@ -0,0 +1,110 @@\n+# Copyright 2015-2016 Yelp Inc.\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+#     http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+import logging\n+\n+import service_configuration_lib\n+\n+from paasta_tools.utils import deep_merge_dictionaries\n+from paasta_tools.utils import DEFAULT_SOA_DIR\n+from paasta_tools.utils import get_paasta_branch\n+from paasta_tools.utils import InstanceConfig\n+from paasta_tools.utils import load_v2_deployments_json\n+from paasta_tools.utils import NoConfigurationForServiceError\n+from paasta_tools.utils import NoDeploymentsAvailable\n+from paasta_tools.utils import NoTtyError\n+from paasta_tools.utils import prompt_pick_one\n+\n+\n+log = logging.getLogger(__name__)\n+\n+\n+def load_adhoc_job_config(service, instance, cluster, load_deployments=True, soa_dir=DEFAULT_SOA_DIR):\n+    general_config = service_configuration_lib.read_service_configuration(\n+        service,\n+        soa_dir=soa_dir\n+    )\n+    adhoc_conf_file = \"adhoc-%s\" % cluster\n+    log.info(\"Reading adhoc configuration file: %s.yaml\", adhoc_conf_file)\n+    instance_configs = service_configuration_lib.read_extra_service_information(\n+        service,\n+        adhoc_conf_file,\n+        soa_dir=soa_dir\n+    )\n+\n+    if instance not in instance_configs:\n+        raise NoConfigurationForServiceError(\n+            \"%s not found in config file %s/%s/%s.yaml.\" % (instance, soa_dir, service, adhoc_conf_file)\n+        )\n+\n+    general_config = deep_merge_dictionaries(overrides=instance_configs[instance], defaults=general_config)\n+\n+    branch_dict = {}\n+    if load_deployments:\n+        deployments_json = load_v2_deployments_json(service, soa_dir=soa_dir)\n+        branch = general_config.get('branch', get_paasta_branch(cluster, instance))\n+        deploy_group = general_config.get('deploy_group', branch)\n+        branch_dict = deployments_json.get_branch_dict_v2(service, branch, deploy_group)\n+\n+    return AdhocJobConfig(\n+        service=service,\n+        cluster=cluster,\n+        instance=instance,\n+        config_dict=general_config,\n+        branch_dict=branch_dict,\n+    )\n+\n+\n+class AdhocJobConfig(InstanceConfig):\n+\n+    def __init__(self, service, instance, cluster, config_dict, branch_dict):\n+        super(AdhocJobConfig, self).__init__(\n+            cluster=cluster,\n+            instance=instance,\n+            service=service,\n+            config_dict=config_dict,\n+            branch_dict=branch_dict,\n+        )\n+\n+\n+def get_default_interactive_config(service, cluster, soa_dir):\n+    default_job_config = {\n+        'cpus': 1,\n+        'mem': 1024,\n+        'disk': 1024\n+    }\n+\n+    try:\n+        job_config = load_adhoc_job_config(service=service, instance='interactive', cluster=cluster)\n+    except NoConfigurationForServiceError:\n+        job_config = AdhocJobConfig(\n+            service=service,\n+            instance='interactive',\n+            cluster=cluster,\n+            config_dict={},\n+            branch_dict={},\n+        )\n+        deployments_json = load_v2_deployments_json(service, soa_dir=soa_dir)\n+        try:\n+            deploy_group = prompt_pick_one(deployments_json['deployments'].keys())\n+        except NoTtyError:","path":"paasta_tools/adhoc_tools.py","position":100,"original_position":100,"commit_id":"f4473f23be0df5f5ca96b4e4cbe8da1fd8ded415","original_commit_id":"3c912f2b67c95a506bd5fa181f3d32184a1849ae","user":{"login":"mjksmith","id":2931921,"avatar_url":"https://avatars.githubusercontent.com/u/2931921?v=3","gravatar_id":"","url":"https://api.github.com/users/mjksmith","html_url":"https://github.com/mjksmith","followers_url":"https://api.github.com/users/mjksmith/followers","following_url":"https://api.github.com/users/mjksmith/following{/other_user}","gists_url":"https://api.github.com/users/mjksmith/gists{/gist_id}","starred_url":"https://api.github.com/users/mjksmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjksmith/subscriptions","organizations_url":"https://api.github.com/users/mjksmith/orgs","repos_url":"https://api.github.com/users/mjksmith/repos","events_url":"https://api.github.com/users/mjksmith/events{/privacy}","received_events_url":"https://api.github.com/users/mjksmith/received_events","type":"User","site_admin":false},"body":"I had a big response typed out but I realized you were right so I changed it.","created_at":"2016-10-20T17:22:21Z","updated_at":"2016-10-20T17:22:21Z","html_url":"https://github.com/Yelp/paasta/pull/825#discussion_r84333639","pull_request_url":"https://api.github.com/repos/Yelp/paasta/pulls/825","_links":{"self":{"href":"https://api.github.com/repos/Yelp/paasta/pulls/comments/84333639"},"html":{"href":"https://github.com/Yelp/paasta/pull/825#discussion_r84333639"},"pull_request":{"href":"https://api.github.com/repos/Yelp/paasta/pulls/825"}}},"pull_request":{"url":"https://api.github.com/repos/Yelp/paasta/pulls/825","id":88361217,"html_url":"https://github.com/Yelp/paasta/pull/825","diff_url":"https://github.com/Yelp/paasta/pull/825.diff","patch_url":"https://github.com/Yelp/paasta/pull/825.patch","issue_url":"https://api.github.com/repos/Yelp/paasta/issues/825","number":825,"state":"open","locked":false,"title":"added support for adhoc jobs","user":{"login":"mjksmith","id":2931921,"avatar_url":"https://avatars.githubusercontent.com/u/2931921?v=3","gravatar_id":"","url":"https://api.github.com/users/mjksmith","html_url":"https://github.com/mjksmith","followers_url":"https://api.github.com/users/mjksmith/followers","following_url":"https://api.github.com/users/mjksmith/following{/other_user}","gists_url":"https://api.github.com/users/mjksmith/gists{/gist_id}","starred_url":"https://api.github.com/users/mjksmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjksmith/subscriptions","organizations_url":"https://api.github.com/users/mjksmith/orgs","repos_url":"https://api.github.com/users/mjksmith/repos","events_url":"https://api.github.com/users/mjksmith/events{/privacy}","received_events_url":"https://api.github.com/users/mjksmith/received_events","type":"User","site_admin":false},"body":"I still have tests to write but this can start being reviewed\r\n\r\nExample of running an adhoc job:\r\n\r\nWith soa configs adhoc-CLUSTERNAME.yaml:\r\n```\r\ndo_all_the_things:\r\n  cpus: 1\r\n  mem: 1024\r\n  disk: 1024\r\n  cmd: echo \"Hello world\"\r\n  deploy_group: prod.non_canary\r\n```\r\n```\r\n(py27)matts@hostname:~/paasta (adhoc_jobs) $ python paasta_tools/cli/cli.py local-run -s example_happyhour -i do_all_the_things -y ~/soa-configs --pull -c CLUSTERNAME\r\nPlease wait while the image (docker:443/services-example_happyhour:paasta-DEADBEEF) is pulled...\r\n--- CLIP ---\r\nYou're running a container in non-interactive mode.\r\nThis is how Mesos runs containers.\r\nNote that some programs behave differently when running with no\r\ntty attached (as your program is about to run).\r\n\r\nRunning docker command:\r\ndocker run --long --docker --command --here sh -c 'echo \"Hello world\"'\r\n\r\nYour service is now running! Tailing stdout and stderr:\r\nHello world\r\n\r\nStopping and removing the old container 74a8174fc04b3f699b15e5893af491529eb19103668fe0047340e39cb8b43d79...\r\n(Please wait or you may leave an orphaned container.)\r\n...done\r\n```\r\n\r\nExample of using the 'interactive' instance:\r\n```\r\n(py27)matts@hostname:~/example_happyhour (master) $ paasta local-run\r\nPaaSTA on this machine has not been configured with a default cluster.\r\nIn the future this behaviour will be depricated and you'll have to specify a cluster.\r\nFor now the default cluster is being set to 'testland'.\r\ndocker build -t paasta-local-run-example_happyhour-matts .\r\n--- CLIP ---\r\nWarning! You're running a container in interactive mode.\r\nThis is *NOT* how Mesos runs containers.\r\nTo run the container exactly as Mesos does, omit the -I flag.\r\n\r\nRunning docker command:\r\ndocker run --long --docker --command --here sh -c bash\r\nroot@dockerhost:/#\r\n```","created_at":"2016-10-06T23:49:51Z","updated_at":"2016-10-20T17:22:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"43a15097958165cc912a67b51e572b7cc9bff64d","assignee":{"login":"mjksmith","id":2931921,"avatar_url":"https://avatars.githubusercontent.com/u/2931921?v=3","gravatar_id":"","url":"https://api.github.com/users/mjksmith","html_url":"https://github.com/mjksmith","followers_url":"https://api.github.com/users/mjksmith/followers","following_url":"https://api.github.com/users/mjksmith/following{/other_user}","gists_url":"https://api.github.com/users/mjksmith/gists{/gist_id}","starred_url":"https://api.github.com/users/mjksmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjksmith/subscriptions","organizations_url":"https://api.github.com/users/mjksmith/orgs","repos_url":"https://api.github.com/users/mjksmith/repos","events_url":"https://api.github.com/users/mjksmith/events{/privacy}","received_events_url":"https://api.github.com/users/mjksmith/received_events","type":"User","site_admin":false},"assignees":[{"login":"mjksmith","id":2931921,"avatar_url":"https://avatars.githubusercontent.com/u/2931921?v=3","gravatar_id":"","url":"https://api.github.com/users/mjksmith","html_url":"https://github.com/mjksmith","followers_url":"https://api.github.com/users/mjksmith/followers","following_url":"https://api.github.com/users/mjksmith/following{/other_user}","gists_url":"https://api.github.com/users/mjksmith/gists{/gist_id}","starred_url":"https://api.github.com/users/mjksmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjksmith/subscriptions","organizations_url":"https://api.github.com/users/mjksmith/orgs","repos_url":"https://api.github.com/users/mjksmith/repos","events_url":"https://api.github.com/users/mjksmith/events{/privacy}","received_events_url":"https://api.github.com/users/mjksmith/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Yelp/paasta/pulls/825/commits","review_comments_url":"https://api.github.com/repos/Yelp/paasta/pulls/825/comments","review_comment_url":"https://api.github.com/repos/Yelp/paasta/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Yelp/paasta/issues/825/comments","statuses_url":"https://api.github.com/repos/Yelp/paasta/statuses/f4473f23be0df5f5ca96b4e4cbe8da1fd8ded415","head":{"label":"Yelp:adhoc_jobs","ref":"adhoc_jobs","sha":"f4473f23be0df5f5ca96b4e4cbe8da1fd8ded415","user":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"repo":{"id":44998824,"name":"paasta","full_name":"Yelp/paasta","owner":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yelp/paasta","description":"An open, distributed platform as a service","fork":false,"url":"https://api.github.com/repos/Yelp/paasta","forks_url":"https://api.github.com/repos/Yelp/paasta/forks","keys_url":"https://api.github.com/repos/Yelp/paasta/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yelp/paasta/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yelp/paasta/teams","hooks_url":"https://api.github.com/repos/Yelp/paasta/hooks","issue_events_url":"https://api.github.com/repos/Yelp/paasta/issues/events{/number}","events_url":"https://api.github.com/repos/Yelp/paasta/events","assignees_url":"https://api.github.com/repos/Yelp/paasta/assignees{/user}","branches_url":"https://api.github.com/repos/Yelp/paasta/branches{/branch}","tags_url":"https://api.github.com/repos/Yelp/paasta/tags","blobs_url":"https://api.github.com/repos/Yelp/paasta/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yelp/paasta/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yelp/paasta/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yelp/paasta/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yelp/paasta/statuses/{sha}","languages_url":"https://api.github.com/repos/Yelp/paasta/languages","stargazers_url":"https://api.github.com/repos/Yelp/paasta/stargazers","contributors_url":"https://api.github.com/repos/Yelp/paasta/contributors","subscribers_url":"https://api.github.com/repos/Yelp/paasta/subscribers","subscription_url":"https://api.github.com/repos/Yelp/paasta/subscription","commits_url":"https://api.github.com/repos/Yelp/paasta/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yelp/paasta/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yelp/paasta/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yelp/paasta/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yelp/paasta/contents/{+path}","compare_url":"https://api.github.com/repos/Yelp/paasta/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yelp/paasta/merges","archive_url":"https://api.github.com/repos/Yelp/paasta/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yelp/paasta/downloads","issues_url":"https://api.github.com/repos/Yelp/paasta/issues{/number}","pulls_url":"https://api.github.com/repos/Yelp/paasta/pulls{/number}","milestones_url":"https://api.github.com/repos/Yelp/paasta/milestones{/number}","notifications_url":"https://api.github.com/repos/Yelp/paasta/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yelp/paasta/labels{/name}","releases_url":"https://api.github.com/repos/Yelp/paasta/releases{/id}","deployments_url":"https://api.github.com/repos/Yelp/paasta/deployments","created_at":"2015-10-26T21:35:53Z","updated_at":"2016-10-17T05:24:23Z","pushed_at":"2016-10-19T19:35:44Z","git_url":"git://github.com/Yelp/paasta.git","ssh_url":"git@github.com:Yelp/paasta.git","clone_url":"https://github.com/Yelp/paasta.git","svn_url":"https://github.com/Yelp/paasta","homepage":"","size":12804,"stargazers_count":912,"watchers_count":912,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":91,"mirror_url":null,"open_issues_count":64,"forks":91,"open_issues":64,"watchers":912,"default_branch":"master"}},"base":{"label":"Yelp:master","ref":"master","sha":"16b4a85c323a76833af1cc1cacfea88d6a61abb6","user":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"repo":{"id":44998824,"name":"paasta","full_name":"Yelp/paasta","owner":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yelp/paasta","description":"An open, distributed platform as a service","fork":false,"url":"https://api.github.com/repos/Yelp/paasta","forks_url":"https://api.github.com/repos/Yelp/paasta/forks","keys_url":"https://api.github.com/repos/Yelp/paasta/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yelp/paasta/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yelp/paasta/teams","hooks_url":"https://api.github.com/repos/Yelp/paasta/hooks","issue_events_url":"https://api.github.com/repos/Yelp/paasta/issues/events{/number}","events_url":"https://api.github.com/repos/Yelp/paasta/events","assignees_url":"https://api.github.com/repos/Yelp/paasta/assignees{/user}","branches_url":"https://api.github.com/repos/Yelp/paasta/branches{/branch}","tags_url":"https://api.github.com/repos/Yelp/paasta/tags","blobs_url":"https://api.github.com/repos/Yelp/paasta/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yelp/paasta/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yelp/paasta/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yelp/paasta/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yelp/paasta/statuses/{sha}","languages_url":"https://api.github.com/repos/Yelp/paasta/languages","stargazers_url":"https://api.github.com/repos/Yelp/paasta/stargazers","contributors_url":"https://api.github.com/repos/Yelp/paasta/contributors","subscribers_url":"https://api.github.com/repos/Yelp/paasta/subscribers","subscription_url":"https://api.github.com/repos/Yelp/paasta/subscription","commits_url":"https://api.github.com/repos/Yelp/paasta/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yelp/paasta/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yelp/paasta/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yelp/paasta/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yelp/paasta/contents/{+path}","compare_url":"https://api.github.com/repos/Yelp/paasta/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yelp/paasta/merges","archive_url":"https://api.github.com/repos/Yelp/paasta/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yelp/paasta/downloads","issues_url":"https://api.github.com/repos/Yelp/paasta/issues{/number}","pulls_url":"https://api.github.com/repos/Yelp/paasta/pulls{/number}","milestones_url":"https://api.github.com/repos/Yelp/paasta/milestones{/number}","notifications_url":"https://api.github.com/repos/Yelp/paasta/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yelp/paasta/labels{/name}","releases_url":"https://api.github.com/repos/Yelp/paasta/releases{/id}","deployments_url":"https://api.github.com/repos/Yelp/paasta/deployments","created_at":"2015-10-26T21:35:53Z","updated_at":"2016-10-17T05:24:23Z","pushed_at":"2016-10-19T19:35:44Z","git_url":"git://github.com/Yelp/paasta.git","ssh_url":"git@github.com:Yelp/paasta.git","clone_url":"https://github.com/Yelp/paasta.git","svn_url":"https://github.com/Yelp/paasta","homepage":"","size":12804,"stargazers_count":912,"watchers_count":912,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":91,"mirror_url":null,"open_issues_count":64,"forks":91,"open_issues":64,"watchers":912,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Yelp/paasta/pulls/825"},"html":{"href":"https://github.com/Yelp/paasta/pull/825"},"issue":{"href":"https://api.github.com/repos/Yelp/paasta/issues/825"},"comments":{"href":"https://api.github.com/repos/Yelp/paasta/issues/825/comments"},"review_comments":{"href":"https://api.github.com/repos/Yelp/paasta/pulls/825/comments"},"review_comment":{"href":"https://api.github.com/repos/Yelp/paasta/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Yelp/paasta/pulls/825/commits"},"statuses":{"href":"https://api.github.com/repos/Yelp/paasta/statuses/f4473f23be0df5f5ca96b4e4cbe8da1fd8ded415"}}}}
{"actor":{"display_login":"mjksmith"}}