{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-myriad/pulls/comments/82331962","pull_request_review_id":3245098,"id":82331962,"diff_hunk":"@@ -81,83 +83,115 @@ public void onEvent(ResourceOffersEvent event, long sequence, boolean endOfBatch\n       }\n       return;\n     }\n-    LOGGER.debug(\"Received offers {}\", offers.size());\n+\n+    List<Offer> reserved = new ArrayList<>();\n+    List<Offer> normals = new ArrayList<>();\n+\n+    for (Offer offer : offers) {\n+      if (isReserved(offer)) {\n+        reserved.add(offer);\n+      } else {\n+        normals.add(offer);\n+      }\n+    }\n+\n+    LOGGER.debug(\"Received total offers {}, including reserved offers {}\", offers.size(), reserved.size());\n     LOGGER.debug(\"Pending tasks: {}\", this.schedulerState.getPendingTaskIds());\n+\n     driverOperationLock.lock();\n     try {\n-      for (Iterator<Offer> iterator = offers.iterator(); iterator.hasNext(); ) {\n-        Offer offer = iterator.next();\n-        Set<NodeTask> nodeTasks = schedulerState.getNodeTasks(offer.getSlaveId());\n-        for (NodeTask nodeTask : nodeTasks) {\n-          nodeTask.setSlaveAttributes(offer.getAttributesList());\n-        }\n-        // keep this in case SchedulerState gets out of sync. This should not happen with\n-        // synchronizing addNodes method in SchedulerState\n-        // but to keep it safe\n-        final Set<Protos.TaskID> missingTasks = Sets.newHashSet();\n-        Set<Protos.TaskID> pendingTasks = schedulerState.getPendingTaskIds();\n-        if (CollectionUtils.isNotEmpty(pendingTasks)) {\n-          for (Protos.TaskID pendingTaskId : pendingTasks) {\n-            NodeTask taskToLaunch = schedulerState.getTask(pendingTaskId);\n-            if (taskToLaunch == null) {\n-              missingTasks.add(pendingTaskId);\n-              LOGGER.warn(\"Node task for TaskID: {} does not exist\", pendingTaskId);\n-              continue;\n-            }\n-            String taskPrefix = taskToLaunch.getTaskPrefix();\n-            ServiceResourceProfile profile = taskToLaunch.getProfile();\n-            Constraint constraint = taskToLaunch.getConstraint();\n-\n-            Set<NodeTask> launchedTasks = new HashSet<>();\n-            launchedTasks.addAll(schedulerState.getActiveTasksByType(taskPrefix));\n-            launchedTasks.addAll(schedulerState.getStagingTasksByType(taskPrefix));\n-\n-            ResourceOfferContainer resourceOfferContainer = new ResourceOfferContainer(offer, taskToLaunch.getProfile(), role);\n-            if (SchedulerUtils.isUniqueHostname(offer, taskToLaunch, launchedTasks)\n-                && resourceOfferContainer.satisfies(taskToLaunch.getProfile(), constraint)) {\n-              try {\n-                final TaskInfo task = taskFactoryMap.get(taskPrefix).createTask(resourceOfferContainer,\n-                    schedulerState.getFrameworkID().get(), pendingTaskId, taskToLaunch);\n-                LOGGER.info(\"Launching task: {} using offer: {}\", task.getTaskId().getValue(), offer.getId());\n-                LOGGER.debug(\"Launching task: {} with profile: {} using offer: {}\", task, profile, offer);\n-                driver.launchTasks(Collections.singleton(offer.getId()), Collections.singleton(task));\n-                schedulerState.makeTaskStaging(pendingTaskId);\n-                // For every NM Task that we launch, we currently\n-                // need to backup the ExecutorInfo for that NM Task in the State Store.\n-                // Without this, we will not be able to launch tasks corresponding to yarn\n-                // containers. This is specially important in case the RM restarts.\n-                taskToLaunch.setExecutorInfo(task.getExecutor());\n-                taskToLaunch.setHostname(offer.getHostname());\n-                taskToLaunch.setSlaveId(offer.getSlaveId());\n-                schedulerState.addTask(pendingTaskId, taskToLaunch);\n-                iterator.remove(); // remove the used offer from offers list\n-                break;\n-              } catch (Throwable t) {\n-                LOGGER.error(\"Exception thrown while trying to create a task for {}\", taskPrefix, t);\n-              }\n-            }\n+      dispatchTasks(driver, reserved);","path":"myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ResourceOffersEventHandler.java","position":82,"original_position":82,"commit_id":"c942e0ce3af094d2af473df77ccd46cad49a8b17","original_commit_id":"c942e0ce3af094d2af473df77ccd46cad49a8b17","user":{"login":"yufeldman","id":3076038,"avatar_url":"https://avatars.githubusercontent.com/u/3076038?v=3","gravatar_id":"","url":"https://api.github.com/users/yufeldman","html_url":"https://github.com/yufeldman","followers_url":"https://api.github.com/users/yufeldman/followers","following_url":"https://api.github.com/users/yufeldman/following{/other_user}","gists_url":"https://api.github.com/users/yufeldman/gists{/gist_id}","starred_url":"https://api.github.com/users/yufeldman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yufeldman/subscriptions","organizations_url":"https://api.github.com/users/yufeldman/orgs","repos_url":"https://api.github.com/users/yufeldman/repos","events_url":"https://api.github.com/users/yufeldman/events{/privacy}","received_events_url":"https://api.github.com/users/yufeldman/received_events","type":"User","site_admin":false},"body":"You could concatenate the list (unreserved add after reserved) and call dispatchTasks just once","created_at":"2016-10-07T05:49:19Z","updated_at":"2016-10-07T05:52:52Z","html_url":"https://github.com/apache/incubator-myriad/pull/94#discussion_r82331962","pull_request_url":"https://api.github.com/repos/apache/incubator-myriad/pulls/94","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-myriad/pulls/comments/82331962"},"html":{"href":"https://github.com/apache/incubator-myriad/pull/94#discussion_r82331962"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-myriad/pulls/94"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-myriad/pulls/94","id":87845531,"html_url":"https://github.com/apache/incubator-myriad/pull/94","diff_url":"https://github.com/apache/incubator-myriad/pull/94.diff","patch_url":"https://github.com/apache/incubator-myriad/pull/94.patch","issue_url":"https://api.github.com/repos/apache/incubator-myriad/issues/94","number":94,"state":"open","locked":false,"title":"Used reserved resources firstly","user":{"login":"k82cn","id":18107181,"avatar_url":"https://avatars.githubusercontent.com/u/18107181?v=3","gravatar_id":"","url":"https://api.github.com/users/k82cn","html_url":"https://github.com/k82cn","followers_url":"https://api.github.com/users/k82cn/followers","following_url":"https://api.github.com/users/k82cn/following{/other_user}","gists_url":"https://api.github.com/users/k82cn/gists{/gist_id}","starred_url":"https://api.github.com/users/k82cn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/k82cn/subscriptions","organizations_url":"https://api.github.com/users/k82cn/orgs","repos_url":"https://api.github.com/users/k82cn/repos","events_url":"https://api.github.com/users/k82cn/events{/privacy}","received_events_url":"https://api.github.com/users/k82cn/received_events","type":"User","site_admin":false},"body":"Used reserved resources firstly.","created_at":"2016-10-04T07:38:51Z","updated_at":"2016-10-07T05:52:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"71703636db50b0fec172c2c3e622301e529ac201","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-myriad/pulls/94/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-myriad/pulls/94/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-myriad/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-myriad/issues/94/comments","statuses_url":"https://api.github.com/repos/apache/incubator-myriad/statuses/c942e0ce3af094d2af473df77ccd46cad49a8b17","head":{"label":"k82cn:reserved_first","ref":"reserved_first","sha":"c942e0ce3af094d2af473df77ccd46cad49a8b17","user":{"login":"k82cn","id":18107181,"avatar_url":"https://avatars.githubusercontent.com/u/18107181?v=3","gravatar_id":"","url":"https://api.github.com/users/k82cn","html_url":"https://github.com/k82cn","followers_url":"https://api.github.com/users/k82cn/followers","following_url":"https://api.github.com/users/k82cn/following{/other_user}","gists_url":"https://api.github.com/users/k82cn/gists{/gist_id}","starred_url":"https://api.github.com/users/k82cn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/k82cn/subscriptions","organizations_url":"https://api.github.com/users/k82cn/orgs","repos_url":"https://api.github.com/users/k82cn/repos","events_url":"https://api.github.com/users/k82cn/events{/privacy}","received_events_url":"https://api.github.com/users/k82cn/received_events","type":"User","site_admin":false},"repo":{"id":62121562,"name":"incubator-myriad","full_name":"k82cn/incubator-myriad","owner":{"login":"k82cn","id":18107181,"avatar_url":"https://avatars.githubusercontent.com/u/18107181?v=3","gravatar_id":"","url":"https://api.github.com/users/k82cn","html_url":"https://github.com/k82cn","followers_url":"https://api.github.com/users/k82cn/followers","following_url":"https://api.github.com/users/k82cn/following{/other_user}","gists_url":"https://api.github.com/users/k82cn/gists{/gist_id}","starred_url":"https://api.github.com/users/k82cn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/k82cn/subscriptions","organizations_url":"https://api.github.com/users/k82cn/orgs","repos_url":"https://api.github.com/users/k82cn/repos","events_url":"https://api.github.com/users/k82cn/events{/privacy}","received_events_url":"https://api.github.com/users/k82cn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/k82cn/incubator-myriad","description":"Mirror of Apache Myriad (Incubating)","fork":true,"url":"https://api.github.com/repos/k82cn/incubator-myriad","forks_url":"https://api.github.com/repos/k82cn/incubator-myriad/forks","keys_url":"https://api.github.com/repos/k82cn/incubator-myriad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/k82cn/incubator-myriad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/k82cn/incubator-myriad/teams","hooks_url":"https://api.github.com/repos/k82cn/incubator-myriad/hooks","issue_events_url":"https://api.github.com/repos/k82cn/incubator-myriad/issues/events{/number}","events_url":"https://api.github.com/repos/k82cn/incubator-myriad/events","assignees_url":"https://api.github.com/repos/k82cn/incubator-myriad/assignees{/user}","branches_url":"https://api.github.com/repos/k82cn/incubator-myriad/branches{/branch}","tags_url":"https://api.github.com/repos/k82cn/incubator-myriad/tags","blobs_url":"https://api.github.com/repos/k82cn/incubator-myriad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/k82cn/incubator-myriad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/k82cn/incubator-myriad/git/refs{/sha}","trees_url":"https://api.github.com/repos/k82cn/incubator-myriad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/k82cn/incubator-myriad/statuses/{sha}","languages_url":"https://api.github.com/repos/k82cn/incubator-myriad/languages","stargazers_url":"https://api.github.com/repos/k82cn/incubator-myriad/stargazers","contributors_url":"https://api.github.com/repos/k82cn/incubator-myriad/contributors","subscribers_url":"https://api.github.com/repos/k82cn/incubator-myriad/subscribers","subscription_url":"https://api.github.com/repos/k82cn/incubator-myriad/subscription","commits_url":"https://api.github.com/repos/k82cn/incubator-myriad/commits{/sha}","git_commits_url":"https://api.github.com/repos/k82cn/incubator-myriad/git/commits{/sha}","comments_url":"https://api.github.com/repos/k82cn/incubator-myriad/comments{/number}","issue_comment_url":"https://api.github.com/repos/k82cn/incubator-myriad/issues/comments{/number}","contents_url":"https://api.github.com/repos/k82cn/incubator-myriad/contents/{+path}","compare_url":"https://api.github.com/repos/k82cn/incubator-myriad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/k82cn/incubator-myriad/merges","archive_url":"https://api.github.com/repos/k82cn/incubator-myriad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/k82cn/incubator-myriad/downloads","issues_url":"https://api.github.com/repos/k82cn/incubator-myriad/issues{/number}","pulls_url":"https://api.github.com/repos/k82cn/incubator-myriad/pulls{/number}","milestones_url":"https://api.github.com/repos/k82cn/incubator-myriad/milestones{/number}","notifications_url":"https://api.github.com/repos/k82cn/incubator-myriad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/k82cn/incubator-myriad/labels{/name}","releases_url":"https://api.github.com/repos/k82cn/incubator-myriad/releases{/id}","deployments_url":"https://api.github.com/repos/k82cn/incubator-myriad/deployments","created_at":"2016-06-28T07:56:58Z","updated_at":"2016-06-28T07:56:59Z","pushed_at":"2016-10-05T01:07:33Z","git_url":"git://github.com/k82cn/incubator-myriad.git","ssh_url":"git@github.com:k82cn/incubator-myriad.git","clone_url":"https://github.com/k82cn/incubator-myriad.git","svn_url":"https://github.com/k82cn/incubator-myriad","homepage":null,"size":20048,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"577c30b1abdaa30313251c887c014aebac3fd93c","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":33397227,"name":"incubator-myriad","full_name":"apache/incubator-myriad","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-myriad","description":"Mirror of Apache Myriad (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-myriad","forks_url":"https://api.github.com/repos/apache/incubator-myriad/forks","keys_url":"https://api.github.com/repos/apache/incubator-myriad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-myriad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-myriad/teams","hooks_url":"https://api.github.com/repos/apache/incubator-myriad/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-myriad/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-myriad/events","assignees_url":"https://api.github.com/repos/apache/incubator-myriad/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-myriad/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-myriad/tags","blobs_url":"https://api.github.com/repos/apache/incubator-myriad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-myriad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-myriad/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-myriad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-myriad/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-myriad/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-myriad/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-myriad/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-myriad/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-myriad/subscription","commits_url":"https://api.github.com/repos/apache/incubator-myriad/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-myriad/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-myriad/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-myriad/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-myriad/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-myriad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-myriad/merges","archive_url":"https://api.github.com/repos/apache/incubator-myriad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-myriad/downloads","issues_url":"https://api.github.com/repos/apache/incubator-myriad/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-myriad/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-myriad/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-myriad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-myriad/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-myriad/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-myriad/deployments","created_at":"2015-04-04T07:00:05Z","updated_at":"2016-10-04T05:27:49Z","pushed_at":"2016-10-05T01:07:33Z","git_url":"git://github.com/apache/incubator-myriad.git","ssh_url":"git@github.com:apache/incubator-myriad.git","clone_url":"https://github.com/apache/incubator-myriad.git","svn_url":"https://github.com/apache/incubator-myriad","homepage":null,"size":9313,"stargazers_count":69,"watchers_count":69,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":45,"mirror_url":"git://git.apache.org/incubator-myriad.git","open_issues_count":6,"forks":45,"open_issues":6,"watchers":69,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-myriad/pulls/94"},"html":{"href":"https://github.com/apache/incubator-myriad/pull/94"},"issue":{"href":"https://api.github.com/repos/apache/incubator-myriad/issues/94"},"comments":{"href":"https://api.github.com/repos/apache/incubator-myriad/issues/94/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-myriad/pulls/94/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-myriad/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-myriad/pulls/94/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-myriad/statuses/c942e0ce3af094d2af473df77ccd46cad49a8b17"}}}}
{"actor":{"display_login":"yufeldman"}}