{"action":"created","comment":{"url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/comments/112298285","pull_request_review_id":33602674,"id":112298285,"diff_hunk":"@@ -321,24 +413,52 @@ public void setVirtualMachineCount(int newCount) {\n      */\n     public AzureVMAgentTemplate getAzureAgentTemplate(final Label label) {\n         LOGGER.log(Level.FINE, \"AzureVMCloud: getAzureAgentTemplate: Retrieving agent template with label {0}\", label);\n-        for (AzureVMAgentTemplate agentTemplate : instTemplates) {\n-            LOGGER.log(Level.FINE, \"AzureVMCloud: getAzureAgentTemplate: Found agent template {0}\", agentTemplate.getTemplateName());\n-            if (agentTemplate.getUseAgentAlwaysIfAvail() == Node.Mode.NORMAL) {\n-                if (label == null || label.matches(agentTemplate.getLabelDataSet())) {\n-                    LOGGER.log(Level.FINE, \"AzureVMCloud: getAzureAgentTemplate: {0} matches!\", agentTemplate.getTemplateName());\n-                    return agentTemplate;\n-                }\n-            } else if (agentTemplate.getUseAgentAlwaysIfAvail() == Node.Mode.EXCLUSIVE) {\n-                if (label != null && label.matches(agentTemplate.getLabelDataSet())) {\n-                    LOGGER.log(Level.FINE, \"AzureVMCloud: getAzureAgentTemplate: {0} matches!\", agentTemplate.getTemplateName());\n-                    return agentTemplate;\n+        // Lock the templates list rather than using getVMTemplates to avoid unecessary copies.\n+        synchronized (this) {\n+            for (AzureVMAgentTemplate agentTemplate : vmTemplates) {\n+                LOGGER.log(Level.FINE, \"AzureVMCloud: getAzureAgentTemplate: Found agent template {0}\", agentTemplate.getTemplateName());\n+                if (agentTemplate.getUseAgentAlwaysIfAvail() == Node.Mode.NORMAL) {\n+                    if (label == null || label.matches(agentTemplate.getLabelDataSet())) {\n+                        LOGGER.log(Level.FINE, \"AzureVMCloud: getAzureAgentTemplate: {0} matches!\", agentTemplate.getTemplateName());\n+                        return agentTemplate;\n+                    }\n+                } else if (agentTemplate.getUseAgentAlwaysIfAvail() == Node.Mode.EXCLUSIVE) {\n+                    if (label != null && label.matches(agentTemplate.getLabelDataSet())) {\n+                        LOGGER.log(Level.FINE, \"AzureVMCloud: getAzureAgentTemplate: {0} matches!\", agentTemplate.getTemplateName());\n+                        return agentTemplate;\n+                    }\n                 }\n             }\n         }\n         return null;\n     }\n \n     /**\n+     * Determines whether the given template name is unique among all templates\n+     * @param name Name to check\n+     * @return True if the name is unique, false otherwise.\n+     */\n+    public boolean getTemplateNameIsUnique(final String name) {\n+        if (StringUtils.isBlank(name)) {\n+            return true;\n+        }\n+\n+        boolean foundOne = false;","path":"src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java","position":220,"original_position":220,"commit_id":"fbcea3e1f2fc71855e4a2435ef46e43911605153","original_commit_id":"fbcea3e1f2fc71855e4a2435ef46e43911605153","user":{"login":"clguimanMSFT","id":22645093,"avatar_url":"https://avatars2.githubusercontent.com/u/22645093?v=3","gravatar_id":"","url":"https://api.github.com/users/clguimanMSFT","html_url":"https://github.com/clguimanMSFT","followers_url":"https://api.github.com/users/clguimanMSFT/followers","following_url":"https://api.github.com/users/clguimanMSFT/following{/other_user}","gists_url":"https://api.github.com/users/clguimanMSFT/gists{/gist_id}","starred_url":"https://api.github.com/users/clguimanMSFT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clguimanMSFT/subscriptions","organizations_url":"https://api.github.com/users/clguimanMSFT/orgs","repos_url":"https://api.github.com/users/clguimanMSFT/repos","events_url":"https://api.github.com/users/clguimanMSFT/events{/privacy}","received_events_url":"https://api.github.com/users/clguimanMSFT/received_events","type":"User","site_admin":false},"body":"nitpick: looks a bit weird. Can't you use a map instead of a list?","created_at":"2017-04-19T19:54:13Z","updated_at":"2017-04-19T19:54:13Z","html_url":"https://github.com/jenkinsci/azure-vm-agents-plugin/pull/39#discussion_r112298285","pull_request_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/comments/112298285"},"html":{"href":"https://github.com/jenkinsci/azure-vm-agents-plugin/pull/39#discussion_r112298285"},"pull_request":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/39","id":116438466,"html_url":"https://github.com/jenkinsci/azure-vm-agents-plugin/pull/39","diff_url":"https://github.com/jenkinsci/azure-vm-agents-plugin/pull/39.diff","patch_url":"https://github.com/jenkinsci/azure-vm-agents-plugin/pull/39.patch","issue_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/issues/39","number":39,"state":"open","locked":false,"title":"Add synchronized APIs for template management","user":{"login":"mmitche","id":8725170,"avatar_url":"https://avatars2.githubusercontent.com/u/8725170?v=3","gravatar_id":"","url":"https://api.github.com/users/mmitche","html_url":"https://github.com/mmitche","followers_url":"https://api.github.com/users/mmitche/followers","following_url":"https://api.github.com/users/mmitche/following{/other_user}","gists_url":"https://api.github.com/users/mmitche/gists{/gist_id}","starred_url":"https://api.github.com/users/mmitche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmitche/subscriptions","organizations_url":"https://api.github.com/users/mmitche/orgs","repos_url":"https://api.github.com/users/mmitche/repos","events_url":"https://api.github.com/users/mmitche/events{/privacy}","received_events_url":"https://api.github.com/users/mmitche/received_events","type":"User","site_admin":false},"body":"This sets the groundwork for the ability to manage the templates via the script console, CLI, or system groovy steps in jobs.  This will allow for automatic management in the future.\r\n\r\nAlso adds a check for templates being unique.","created_at":"2017-04-18T23:01:34Z","updated_at":"2017-04-19T19:54:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"295fcd6aebfea4645f29b6f9357cabb657b759f2","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/39/commits","review_comments_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/39/comments","review_comment_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/issues/39/comments","statuses_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/statuses/fbcea3e1f2fc71855e4a2435ef46e43911605153","head":{"label":"mmitche:synchronized-templates","ref":"synchronized-templates","sha":"fbcea3e1f2fc71855e4a2435ef46e43911605153","user":{"login":"mmitche","id":8725170,"avatar_url":"https://avatars2.githubusercontent.com/u/8725170?v=3","gravatar_id":"","url":"https://api.github.com/users/mmitche","html_url":"https://github.com/mmitche","followers_url":"https://api.github.com/users/mmitche/followers","following_url":"https://api.github.com/users/mmitche/following{/other_user}","gists_url":"https://api.github.com/users/mmitche/gists{/gist_id}","starred_url":"https://api.github.com/users/mmitche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmitche/subscriptions","organizations_url":"https://api.github.com/users/mmitche/orgs","repos_url":"https://api.github.com/users/mmitche/repos","events_url":"https://api.github.com/users/mmitche/events{/privacy}","received_events_url":"https://api.github.com/users/mmitche/received_events","type":"User","site_admin":false},"repo":{"id":78467558,"name":"azure-vm-agents-plugin","full_name":"mmitche/azure-vm-agents-plugin","owner":{"login":"mmitche","id":8725170,"avatar_url":"https://avatars2.githubusercontent.com/u/8725170?v=3","gravatar_id":"","url":"https://api.github.com/users/mmitche","html_url":"https://github.com/mmitche","followers_url":"https://api.github.com/users/mmitche/followers","following_url":"https://api.github.com/users/mmitche/following{/other_user}","gists_url":"https://api.github.com/users/mmitche/gists{/gist_id}","starred_url":"https://api.github.com/users/mmitche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmitche/subscriptions","organizations_url":"https://api.github.com/users/mmitche/orgs","repos_url":"https://api.github.com/users/mmitche/repos","events_url":"https://api.github.com/users/mmitche/events{/privacy}","received_events_url":"https://api.github.com/users/mmitche/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mmitche/azure-vm-agents-plugin","description":"This repo is for azure vm agents plugin for jenkins. Azure devops CICD is the team which owns it for now","fork":true,"url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin","forks_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/forks","keys_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/teams","hooks_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/hooks","issue_events_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/events","assignees_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/tags","blobs_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/languages","stargazers_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/stargazers","contributors_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/contributors","subscribers_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/subscribers","subscription_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/subscription","commits_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/merges","archive_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/downloads","issues_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/labels{/name}","releases_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/releases{/id}","deployments_url":"https://api.github.com/repos/mmitche/azure-vm-agents-plugin/deployments","created_at":"2017-01-09T20:47:12Z","updated_at":"2017-01-09T20:47:14Z","pushed_at":"2017-04-18T23:00:56Z","git_url":"git://github.com/mmitche/azure-vm-agents-plugin.git","ssh_url":"git@github.com:mmitche/azure-vm-agents-plugin.git","clone_url":"https://github.com/mmitche/azure-vm-agents-plugin.git","svn_url":"https://github.com/mmitche/azure-vm-agents-plugin","homepage":null,"size":685,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"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":"jenkinsci:master","ref":"master","sha":"4a869579bd5a8702393857d7cbe4578920680310","user":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars3.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"repo":{"id":75665906,"name":"azure-vm-agents-plugin","full_name":"jenkinsci/azure-vm-agents-plugin","owner":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars3.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jenkinsci/azure-vm-agents-plugin","description":"This repo is for azure vm agents plugin for jenkins. Azure devops CICD is the team which owns it for now","fork":false,"url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin","forks_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/forks","keys_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/teams","hooks_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/hooks","issue_events_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/events","assignees_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/tags","blobs_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/languages","stargazers_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/stargazers","contributors_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/contributors","subscribers_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/subscribers","subscription_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/subscription","commits_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/merges","archive_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/downloads","issues_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/labels{/name}","releases_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/releases{/id}","deployments_url":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/deployments","created_at":"2016-12-05T21:03:04Z","updated_at":"2017-04-13T14:51:00Z","pushed_at":"2017-04-18T23:01:34Z","git_url":"git://github.com/jenkinsci/azure-vm-agents-plugin.git","ssh_url":"git@github.com:jenkinsci/azure-vm-agents-plugin.git","clone_url":"https://github.com/jenkinsci/azure-vm-agents-plugin.git","svn_url":"https://github.com/jenkinsci/azure-vm-agents-plugin","homepage":null,"size":660,"stargazers_count":9,"watchers_count":9,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":2,"forks":11,"open_issues":2,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/39"},"html":{"href":"https://github.com/jenkinsci/azure-vm-agents-plugin/pull/39"},"issue":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/issues/39"},"comments":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/jenkinsci/azure-vm-agents-plugin/statuses/fbcea3e1f2fc71855e4a2435ef46e43911605153"}}}}
{"actor":{"display_login":"clguimanMSFT"}}