{"action":"created","comment":{"url":"https://api.github.com/repos/vespa-engine/vespa/pulls/comments/170256453","pull_request_review_id":98918207,"id":170256453,"diff_hunk":"@@ -0,0 +1,96 @@\n+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.\n+package com.yahoo.vespa.hosted.controller.deployment;\n+\n+import com.google.common.collect.ImmutableList;\n+import com.yahoo.config.provision.ApplicationId;\n+import com.yahoo.searchlib.rankingexpression.rule.Function;\n+import com.yahoo.vespa.curator.Lock;\n+import com.yahoo.vespa.hosted.controller.Controller;\n+import com.yahoo.vespa.hosted.controller.api.integration.BuildService.BuildJob;\n+import com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType;\n+import com.yahoo.vespa.hosted.controller.persistence.CuratorDb;\n+\n+import java.util.Deque;\n+import java.util.List;\n+import java.util.Optional;\n+import java.util.function.Consumer;\n+\n+/**\n+ * Stores a queue for each type of job, and offers jobs from each of these to a periodic\n+ * polling mechanism which is responsible for triggering the offered jobs in an external build service.\n+ *\n+ * @author jvenstad\n+ */\n+public class DeploymentQueue {\n+\n+    private final Controller controller;\n+    private final CuratorDb curator;\n+\n+    public DeploymentQueue(Controller controller, CuratorDb curator) {\n+        this.controller = controller;\n+        this.curator = curator;\n+    }\n+\n+    /** Add the given application to the queue of the given job type -- in front if first, at the back otherwise. */\n+    public void addJob(ApplicationId applicationId, JobType jobType, boolean first) {\n+        locked(jobType, queue -> {\n+            if ( ! queue.contains(applicationId)) {\n+                if (first)\n+                    queue.addFirst(applicationId);\n+                else\n+                    queue.addLast(applicationId);\n+            }\n+        });\n+    }\n+\n+    /** List all jobs currently enqueued. */\n+    public List<BuildJob> jobs() {\n+        ImmutableList.Builder<BuildJob> builder = ImmutableList.builder();\n+        for (JobType jobType : JobType.values())\n+            for (ApplicationId id : curator.readJobQueue(jobType))\n+                toBuildJob(id, jobType).ifPresent(builder::add);\n+\n+        return builder.build();\n+    }\n+\n+    /** Remove and return a set of jobs to run. This set will contain only one of each job type for capacity constrained zones. */\n+    public List<BuildJob> takeJobsToRun() {\n+        ImmutableList.Builder<BuildJob> builder = ImmutableList.builder();\n+        for (JobType jobType : JobType.values())\n+            locked(jobType, queue ->\n+                    queue.stream()\n+                            .limit(isCapacityConstrained(jobType) ? 1 : 1 << 30)","path":"controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentQueue.java","position":62,"original_position":62,"commit_id":"f3eba4322142a64de07d6759ed935938ffd64f39","original_commit_id":"f3eba4322142a64de07d6759ed935938ffd64f39","user":{"login":"jonmv","id":7009557,"avatar_url":"https://avatars3.githubusercontent.com/u/7009557?v=4","gravatar_id":"","url":"https://api.github.com/users/jonmv","html_url":"https://github.com/jonmv","followers_url":"https://api.github.com/users/jonmv/followers","following_url":"https://api.github.com/users/jonmv/following{/other_user}","gists_url":"https://api.github.com/users/jonmv/gists{/gist_id}","starred_url":"https://api.github.com/users/jonmv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonmv/subscriptions","organizations_url":"https://api.github.com/users/jonmv/orgs","repos_url":"https://api.github.com/users/jonmv/repos","events_url":"https://api.github.com/users/jonmv/events{/privacy}","received_events_url":"https://api.github.com/users/jonmv/received_events","type":"User","site_admin":false},"body":"Yes, of course.","created_at":"2018-02-23T13:55:44Z","updated_at":"2018-02-23T13:55:44Z","html_url":"https://github.com/vespa-engine/vespa/pull/5114#discussion_r170256453","pull_request_url":"https://api.github.com/repos/vespa-engine/vespa/pulls/5114","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/vespa-engine/vespa/pulls/comments/170256453"},"html":{"href":"https://github.com/vespa-engine/vespa/pull/5114#discussion_r170256453"},"pull_request":{"href":"https://api.github.com/repos/vespa-engine/vespa/pulls/5114"}},"in_reply_to_id":170189075},"pull_request":{"url":"https://api.github.com/repos/vespa-engine/vespa/pulls/5114","id":170722003,"html_url":"https://github.com/vespa-engine/vespa/pull/5114","diff_url":"https://github.com/vespa-engine/vespa/pull/5114.diff","patch_url":"https://github.com/vespa-engine/vespa/pull/5114.patch","issue_url":"https://api.github.com/repos/vespa-engine/vespa/issues/5114","number":5114,"state":"open","locked":false,"title":"Revert \"Revert \"Jvenstad/pushing build system\"\"","user":{"login":"jonmv","id":7009557,"avatar_url":"https://avatars3.githubusercontent.com/u/7009557?v=4","gravatar_id":"","url":"https://api.github.com/users/jonmv","html_url":"https://github.com/jonmv","followers_url":"https://api.github.com/users/jonmv/followers","following_url":"https://api.github.com/users/jonmv/following{/other_user}","gists_url":"https://api.github.com/users/jonmv/gists{/gist_id}","starred_url":"https://api.github.com/users/jonmv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonmv/subscriptions","organizations_url":"https://api.github.com/users/jonmv/orgs","repos_url":"https://api.github.com/users/jonmv/repos","events_url":"https://api.github.com/users/jonmv/events{/privacy}","received_events_url":"https://api.github.com/users/jonmv/received_events","type":"User","site_admin":false},"body":"@tokle \r\n\r\nThis reverts commit e65ca655fd3b8a6293fba56d031a973874452412.","created_at":"2018-02-22T11:17:24Z","updated_at":"2018-02-23T13:55:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"da58fefeeaadac0d5b73787f9cc7f57d4d79a502","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/vespa-engine/vespa/pulls/5114/commits","review_comments_url":"https://api.github.com/repos/vespa-engine/vespa/pulls/5114/comments","review_comment_url":"https://api.github.com/repos/vespa-engine/vespa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/vespa-engine/vespa/issues/5114/comments","statuses_url":"https://api.github.com/repos/vespa-engine/vespa/statuses/f3eba4322142a64de07d6759ed935938ffd64f39","head":{"label":"vespa-engine:jvenstad/argh","ref":"jvenstad/argh","sha":"f3eba4322142a64de07d6759ed935938ffd64f39","user":{"login":"vespa-engine","id":29299694,"avatar_url":"https://avatars1.githubusercontent.com/u/29299694?v=4","gravatar_id":"","url":"https://api.github.com/users/vespa-engine","html_url":"https://github.com/vespa-engine","followers_url":"https://api.github.com/users/vespa-engine/followers","following_url":"https://api.github.com/users/vespa-engine/following{/other_user}","gists_url":"https://api.github.com/users/vespa-engine/gists{/gist_id}","starred_url":"https://api.github.com/users/vespa-engine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vespa-engine/subscriptions","organizations_url":"https://api.github.com/users/vespa-engine/orgs","repos_url":"https://api.github.com/users/vespa-engine/repos","events_url":"https://api.github.com/users/vespa-engine/events{/privacy}","received_events_url":"https://api.github.com/users/vespa-engine/received_events","type":"Organization","site_admin":false},"repo":{"id":60377070,"name":"vespa","full_name":"vespa-engine/vespa","owner":{"login":"vespa-engine","id":29299694,"avatar_url":"https://avatars1.githubusercontent.com/u/29299694?v=4","gravatar_id":"","url":"https://api.github.com/users/vespa-engine","html_url":"https://github.com/vespa-engine","followers_url":"https://api.github.com/users/vespa-engine/followers","following_url":"https://api.github.com/users/vespa-engine/following{/other_user}","gists_url":"https://api.github.com/users/vespa-engine/gists{/gist_id}","starred_url":"https://api.github.com/users/vespa-engine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vespa-engine/subscriptions","organizations_url":"https://api.github.com/users/vespa-engine/orgs","repos_url":"https://api.github.com/users/vespa-engine/repos","events_url":"https://api.github.com/users/vespa-engine/events{/privacy}","received_events_url":"https://api.github.com/users/vespa-engine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/vespa-engine/vespa","description":"Vespa - the open big data serving engine","fork":false,"url":"https://api.github.com/repos/vespa-engine/vespa","forks_url":"https://api.github.com/repos/vespa-engine/vespa/forks","keys_url":"https://api.github.com/repos/vespa-engine/vespa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vespa-engine/vespa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vespa-engine/vespa/teams","hooks_url":"https://api.github.com/repos/vespa-engine/vespa/hooks","issue_events_url":"https://api.github.com/repos/vespa-engine/vespa/issues/events{/number}","events_url":"https://api.github.com/repos/vespa-engine/vespa/events","assignees_url":"https://api.github.com/repos/vespa-engine/vespa/assignees{/user}","branches_url":"https://api.github.com/repos/vespa-engine/vespa/branches{/branch}","tags_url":"https://api.github.com/repos/vespa-engine/vespa/tags","blobs_url":"https://api.github.com/repos/vespa-engine/vespa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vespa-engine/vespa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vespa-engine/vespa/git/refs{/sha}","trees_url":"https://api.github.com/repos/vespa-engine/vespa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vespa-engine/vespa/statuses/{sha}","languages_url":"https://api.github.com/repos/vespa-engine/vespa/languages","stargazers_url":"https://api.github.com/repos/vespa-engine/vespa/stargazers","contributors_url":"https://api.github.com/repos/vespa-engine/vespa/contributors","subscribers_url":"https://api.github.com/repos/vespa-engine/vespa/subscribers","subscription_url":"https://api.github.com/repos/vespa-engine/vespa/subscription","commits_url":"https://api.github.com/repos/vespa-engine/vespa/commits{/sha}","git_commits_url":"https://api.github.com/repos/vespa-engine/vespa/git/commits{/sha}","comments_url":"https://api.github.com/repos/vespa-engine/vespa/comments{/number}","issue_comment_url":"https://api.github.com/repos/vespa-engine/vespa/issues/comments{/number}","contents_url":"https://api.github.com/repos/vespa-engine/vespa/contents/{+path}","compare_url":"https://api.github.com/repos/vespa-engine/vespa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vespa-engine/vespa/merges","archive_url":"https://api.github.com/repos/vespa-engine/vespa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vespa-engine/vespa/downloads","issues_url":"https://api.github.com/repos/vespa-engine/vespa/issues{/number}","pulls_url":"https://api.github.com/repos/vespa-engine/vespa/pulls{/number}","milestones_url":"https://api.github.com/repos/vespa-engine/vespa/milestones{/number}","notifications_url":"https://api.github.com/repos/vespa-engine/vespa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vespa-engine/vespa/labels{/name}","releases_url":"https://api.github.com/repos/vespa-engine/vespa/releases{/id}","deployments_url":"https://api.github.com/repos/vespa-engine/vespa/deployments","created_at":"2016-06-03T20:54:20Z","updated_at":"2018-02-23T09:30:59Z","pushed_at":"2018-02-23T13:20:08Z","git_url":"git://github.com/vespa-engine/vespa.git","ssh_url":"git@github.com:vespa-engine/vespa.git","clone_url":"https://github.com/vespa-engine/vespa.git","svn_url":"https://github.com/vespa-engine/vespa","homepage":"http://vespa.ai/","size":63382,"stargazers_count":2427,"watchers_count":2427,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":280,"mirror_url":null,"archived":false,"open_issues_count":41,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":280,"open_issues":41,"watchers":2427,"default_branch":"master"}},"base":{"label":"vespa-engine:master","ref":"master","sha":"371216d2a98b70a9aab317095169be04525b3208","user":{"login":"vespa-engine","id":29299694,"avatar_url":"https://avatars1.githubusercontent.com/u/29299694?v=4","gravatar_id":"","url":"https://api.github.com/users/vespa-engine","html_url":"https://github.com/vespa-engine","followers_url":"https://api.github.com/users/vespa-engine/followers","following_url":"https://api.github.com/users/vespa-engine/following{/other_user}","gists_url":"https://api.github.com/users/vespa-engine/gists{/gist_id}","starred_url":"https://api.github.com/users/vespa-engine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vespa-engine/subscriptions","organizations_url":"https://api.github.com/users/vespa-engine/orgs","repos_url":"https://api.github.com/users/vespa-engine/repos","events_url":"https://api.github.com/users/vespa-engine/events{/privacy}","received_events_url":"https://api.github.com/users/vespa-engine/received_events","type":"Organization","site_admin":false},"repo":{"id":60377070,"name":"vespa","full_name":"vespa-engine/vespa","owner":{"login":"vespa-engine","id":29299694,"avatar_url":"https://avatars1.githubusercontent.com/u/29299694?v=4","gravatar_id":"","url":"https://api.github.com/users/vespa-engine","html_url":"https://github.com/vespa-engine","followers_url":"https://api.github.com/users/vespa-engine/followers","following_url":"https://api.github.com/users/vespa-engine/following{/other_user}","gists_url":"https://api.github.com/users/vespa-engine/gists{/gist_id}","starred_url":"https://api.github.com/users/vespa-engine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vespa-engine/subscriptions","organizations_url":"https://api.github.com/users/vespa-engine/orgs","repos_url":"https://api.github.com/users/vespa-engine/repos","events_url":"https://api.github.com/users/vespa-engine/events{/privacy}","received_events_url":"https://api.github.com/users/vespa-engine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/vespa-engine/vespa","description":"Vespa - the open big data serving engine","fork":false,"url":"https://api.github.com/repos/vespa-engine/vespa","forks_url":"https://api.github.com/repos/vespa-engine/vespa/forks","keys_url":"https://api.github.com/repos/vespa-engine/vespa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vespa-engine/vespa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vespa-engine/vespa/teams","hooks_url":"https://api.github.com/repos/vespa-engine/vespa/hooks","issue_events_url":"https://api.github.com/repos/vespa-engine/vespa/issues/events{/number}","events_url":"https://api.github.com/repos/vespa-engine/vespa/events","assignees_url":"https://api.github.com/repos/vespa-engine/vespa/assignees{/user}","branches_url":"https://api.github.com/repos/vespa-engine/vespa/branches{/branch}","tags_url":"https://api.github.com/repos/vespa-engine/vespa/tags","blobs_url":"https://api.github.com/repos/vespa-engine/vespa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vespa-engine/vespa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vespa-engine/vespa/git/refs{/sha}","trees_url":"https://api.github.com/repos/vespa-engine/vespa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vespa-engine/vespa/statuses/{sha}","languages_url":"https://api.github.com/repos/vespa-engine/vespa/languages","stargazers_url":"https://api.github.com/repos/vespa-engine/vespa/stargazers","contributors_url":"https://api.github.com/repos/vespa-engine/vespa/contributors","subscribers_url":"https://api.github.com/repos/vespa-engine/vespa/subscribers","subscription_url":"https://api.github.com/repos/vespa-engine/vespa/subscription","commits_url":"https://api.github.com/repos/vespa-engine/vespa/commits{/sha}","git_commits_url":"https://api.github.com/repos/vespa-engine/vespa/git/commits{/sha}","comments_url":"https://api.github.com/repos/vespa-engine/vespa/comments{/number}","issue_comment_url":"https://api.github.com/repos/vespa-engine/vespa/issues/comments{/number}","contents_url":"https://api.github.com/repos/vespa-engine/vespa/contents/{+path}","compare_url":"https://api.github.com/repos/vespa-engine/vespa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vespa-engine/vespa/merges","archive_url":"https://api.github.com/repos/vespa-engine/vespa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vespa-engine/vespa/downloads","issues_url":"https://api.github.com/repos/vespa-engine/vespa/issues{/number}","pulls_url":"https://api.github.com/repos/vespa-engine/vespa/pulls{/number}","milestones_url":"https://api.github.com/repos/vespa-engine/vespa/milestones{/number}","notifications_url":"https://api.github.com/repos/vespa-engine/vespa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vespa-engine/vespa/labels{/name}","releases_url":"https://api.github.com/repos/vespa-engine/vespa/releases{/id}","deployments_url":"https://api.github.com/repos/vespa-engine/vespa/deployments","created_at":"2016-06-03T20:54:20Z","updated_at":"2018-02-23T09:30:59Z","pushed_at":"2018-02-23T13:20:08Z","git_url":"git://github.com/vespa-engine/vespa.git","ssh_url":"git@github.com:vespa-engine/vespa.git","clone_url":"https://github.com/vespa-engine/vespa.git","svn_url":"https://github.com/vespa-engine/vespa","homepage":"http://vespa.ai/","size":63382,"stargazers_count":2427,"watchers_count":2427,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":280,"mirror_url":null,"archived":false,"open_issues_count":41,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":280,"open_issues":41,"watchers":2427,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/vespa-engine/vespa/pulls/5114"},"html":{"href":"https://github.com/vespa-engine/vespa/pull/5114"},"issue":{"href":"https://api.github.com/repos/vespa-engine/vespa/issues/5114"},"comments":{"href":"https://api.github.com/repos/vespa-engine/vespa/issues/5114/comments"},"review_comments":{"href":"https://api.github.com/repos/vespa-engine/vespa/pulls/5114/comments"},"review_comment":{"href":"https://api.github.com/repos/vespa-engine/vespa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/vespa-engine/vespa/pulls/5114/commits"},"statuses":{"href":"https://api.github.com/repos/vespa-engine/vespa/statuses/f3eba4322142a64de07d6759ed935938ffd64f39"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"jonmv"}}