{"action":"created","comment":{"url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/comments/30162449","id":30162449,"diff_hunk":"@@ -7,50 +7,158 @@\n \n import java.io.IOException;\n import java.util.Collection;\n+import java.util.LinkedList;\n+import java.util.List;\n+import java.util.logging.Level;\n+import java.util.logging.Logger;\n import javax.annotation.CheckForNull;\n import javax.annotation.Nonnull;\n import jenkins.model.FingerprintFacet;\n+import org.apache.commons.collections.CollectionUtils;\n \n /**\n  * Entry point into fingerprint related functionalities in Docker.\n+ * This class provide basic methods for both images and containers\n  */\n public class DockerFingerprints {\n+    \n+    private static final Logger LOGGER = Logger.getLogger(DockerFingerprints.class.getName());\n+    \n     private DockerFingerprints() {} // no instantiation\n  \n     /**\n-     * Gets a fingerprint hash for Docker image ID.\n+     * Gets a fingerprint hash for Docker ID (image or container).\n      * This method calculates image hash without retrieving a fingerprint by \n      * {@link DockerFingerprints#of(java.lang.String)}, which may be a high-cost call.\n      * \n-     * @param imageId Docker image ID.\n-     *      Only 64-char full image IDs are supported.\n+     * @param id Docker ID (image or container).\n+     *      Only 64-char full IDs are supported.\n      * @return 32-char fingerprint hash\n-     * @throws IllegalArgumentException Invalid image ID\n+     * @throws IllegalArgumentException Invalid ID\n      */\n-    public static @Nonnull String getImageFingerprintHash(@Nonnull String imageId) {\n-        if (imageId.length() != 64) {\n-            throw new IllegalArgumentException(\"Expecting 64-char full image ID, but got \" + imageId);\n+    public static @Nonnull String getFingerprintHash(@Nonnull String id) {\n+        if (id.length() != 64) {\n+            throw new IllegalArgumentException(\"Expecting 64-char full image ID, but got \" + id);\n         }\n-        return imageId.substring(0, 32);\n+        return id.substring(0, 32);\n     }\n \n     /**\n-     * Gets {@link Fingerprint} for a given docker image.\n+     * Gets {@link Fingerprint} for a given docker ID.\n+     * @param id Docker ID (image or container). Only 64-char full IDs are supported.\n+     * @return Created fingerprint or null if it is not found\n+     * @throws IOException Fingerprint loading error\n      */\n-    public static @CheckForNull Fingerprint of(@Nonnull String imageId) throws IOException {\n-        return Jenkins.getInstance().getFingerprintMap().get(getImageFingerprintHash(imageId));\n+    public static @CheckForNull Fingerprint of(@Nonnull String id) throws IOException {\n+        return Jenkins.getInstance().getFingerprintMap().get(getFingerprintHash(id));\n     }\n-\n-    private static @Nonnull Fingerprint make(@Nonnull Run<?,?> run, @Nonnull String imageId) throws IOException {\n-        return Jenkins.getInstance().getFingerprintMap().getOrCreate(run, \"<docker-image>\", getImageFingerprintHash(imageId));\n+    \n+    private static @CheckForNull Fingerprint ofNoException(@Nonnull String id) {\n+        try {\n+            return of(id);\n+        } catch (IOException ex) { // The error is not a hazard in CheckForNull logic\n+            LOGGER.log(Level.WARNING, \"Cannot retrieve a fingerprint for Docker id=\"+id, ex);\n+        }\n+        return null;\n+    }\n+    \n+    /**\n+     * Get or create a {@link Fingerprint} for the image.\n+     * @param run Origin of the fingerprint (if available)\n+     * @param id Image ID. Only 64-char full IDs are supported.\n+     * @return Fingerprint for the specified ID\n+     * @throws IOException Fingerprint load/save error\n+     */\n+    public static @Nonnull Fingerprint makeForImage(@CheckForNull Run<?,?> run, @Nonnull String id) throws IOException {\n+        return Jenkins.getInstance().getFingerprintMap().getOrCreate(run, \"<docker-image>\", getFingerprintHash(id));\n+    }\n+    \n+    /**\n+     * Get or create a {@link Fingerprint} for the container.\n+     * @param run Origin of the fingerprint (if available)\n+     * @param id Image ID. Only 64-char full IDs are supported.\n+     * @return Fingerprint for the specified ID\n+     * @throws IOException Fingerprint load/save error\n+     */\n+    public static @Nonnull Fingerprint makeForContainer(@CheckForNull Run<?,?> run, @Nonnull String id) throws IOException {\n+        return Jenkins.getInstance().getFingerprintMap().getOrCreate(run, \"<docker-container>\", getFingerprintHash(id));\n     }\n \n     /**\n+     * Retrieves a facet from the {@link Fingerprint}.\n+     * The method suppresses {@link IOException} if a fingerprint loading fails.\n+     * @param <TFacet> Facet type to be retrieved\n+     * @param id Docker item ID. Only 64-char full IDs are supported\n+     * @param facetClass Class to be retrieved\n+     * @return First matching facet. Null may be returned if the loading fails","path":"src/main/java/org/jenkinsci/plugins/docker/commons/fingerprint/DockerFingerprints.java","position":101,"original_position":101,"commit_id":"1ad28ce146b2e726d2f5ad0a37043c7b1652d675","original_commit_id":"1ad28ce146b2e726d2f5ad0a37043c7b1652d675","user":{"login":"oleg-nenashev","id":3000480,"avatar_url":"https://avatars.githubusercontent.com/u/3000480?v=3","gravatar_id":"","url":"https://api.github.com/users/oleg-nenashev","html_url":"https://github.com/oleg-nenashev","followers_url":"https://api.github.com/users/oleg-nenashev/followers","following_url":"https://api.github.com/users/oleg-nenashev/following{/other_user}","gists_url":"https://api.github.com/users/oleg-nenashev/gists{/gist_id}","starred_url":"https://api.github.com/users/oleg-nenashev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oleg-nenashev/subscriptions","organizations_url":"https://api.github.com/users/oleg-nenashev/orgs","repos_url":"https://api.github.com/users/oleg-nenashev/repos","events_url":"https://api.github.com/users/oleg-nenashev/events{/privacy}","received_events_url":"https://api.github.com/users/oleg-nenashev/received_events","type":"User","site_admin":false},"body":"yes. I'll fix javadoc","created_at":"2015-05-12T18:05:55Z","updated_at":"2015-05-12T18:05:55Z","html_url":"https://github.com/jenkinsci/docker-commons-plugin/pull/30#discussion_r30162449","pull_request_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/30","_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/comments/30162449"},"html":{"href":"https://github.com/jenkinsci/docker-commons-plugin/pull/30#discussion_r30162449"},"pull_request":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/30","id":35082123,"html_url":"https://github.com/jenkinsci/docker-commons-plugin/pull/30","diff_url":"https://github.com/jenkinsci/docker-commons-plugin/pull/30.diff","patch_url":"https://github.com/jenkinsci/docker-commons-plugin/pull/30.patch","issue_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/issues/30","number":30,"state":"open","locked":false,"title":"DockerFingerprints API update","user":{"login":"oleg-nenashev","id":3000480,"avatar_url":"https://avatars.githubusercontent.com/u/3000480?v=3","gravatar_id":"","url":"https://api.github.com/users/oleg-nenashev","html_url":"https://github.com/oleg-nenashev","followers_url":"https://api.github.com/users/oleg-nenashev/followers","following_url":"https://api.github.com/users/oleg-nenashev/following{/other_user}","gists_url":"https://api.github.com/users/oleg-nenashev/gists{/gist_id}","starred_url":"https://api.github.com/users/oleg-nenashev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oleg-nenashev/subscriptions","organizations_url":"https://api.github.com/users/oleg-nenashev/orgs","repos_url":"https://api.github.com/users/oleg-nenashev/repos","events_url":"https://api.github.com/users/oleg-nenashev/events{/privacy}","received_events_url":"https://api.github.com/users/oleg-nenashev/received_events","type":"User","site_admin":false},"body":"- [x] - Class can be also used for container fingerprints\r\n- [x] - make() methods are accessible via API\r\n- [x] - Extra helper methods, which allow to easily retrieve facets from Docker fingerprints\r\n\r\n@reviewbybees","created_at":"2015-05-10T12:49:11Z","updated_at":"2015-05-12T18:05:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"95926a30552e353b42693d2f2dd6ae84938f0a18","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/30/commits","review_comments_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/30/comments","review_comment_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/issues/30/comments","statuses_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/statuses/1ad28ce146b2e726d2f5ad0a37043c7b1652d675","head":{"label":"oleg-nenashev:helper-class-rework","ref":"helper-class-rework","sha":"1ad28ce146b2e726d2f5ad0a37043c7b1652d675","user":{"login":"oleg-nenashev","id":3000480,"avatar_url":"https://avatars.githubusercontent.com/u/3000480?v=3","gravatar_id":"","url":"https://api.github.com/users/oleg-nenashev","html_url":"https://github.com/oleg-nenashev","followers_url":"https://api.github.com/users/oleg-nenashev/followers","following_url":"https://api.github.com/users/oleg-nenashev/following{/other_user}","gists_url":"https://api.github.com/users/oleg-nenashev/gists{/gist_id}","starred_url":"https://api.github.com/users/oleg-nenashev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oleg-nenashev/subscriptions","organizations_url":"https://api.github.com/users/oleg-nenashev/orgs","repos_url":"https://api.github.com/users/oleg-nenashev/repos","events_url":"https://api.github.com/users/oleg-nenashev/events{/privacy}","received_events_url":"https://api.github.com/users/oleg-nenashev/received_events","type":"User","site_admin":false},"repo":{"id":34303898,"name":"docker-commons-plugin","full_name":"oleg-nenashev/docker-commons-plugin","owner":{"login":"oleg-nenashev","id":3000480,"avatar_url":"https://avatars.githubusercontent.com/u/3000480?v=3","gravatar_id":"","url":"https://api.github.com/users/oleg-nenashev","html_url":"https://github.com/oleg-nenashev","followers_url":"https://api.github.com/users/oleg-nenashev/followers","following_url":"https://api.github.com/users/oleg-nenashev/following{/other_user}","gists_url":"https://api.github.com/users/oleg-nenashev/gists{/gist_id}","starred_url":"https://api.github.com/users/oleg-nenashev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oleg-nenashev/subscriptions","organizations_url":"https://api.github.com/users/oleg-nenashev/orgs","repos_url":"https://api.github.com/users/oleg-nenashev/repos","events_url":"https://api.github.com/users/oleg-nenashev/events{/privacy}","received_events_url":"https://api.github.com/users/oleg-nenashev/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/oleg-nenashev/docker-commons-plugin","description":"","fork":true,"url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin","forks_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/forks","keys_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/teams","hooks_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/hooks","issue_events_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/events","assignees_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/tags","blobs_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/languages","stargazers_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/stargazers","contributors_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/contributors","subscribers_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/subscribers","subscription_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/subscription","commits_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/merges","archive_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/downloads","issues_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/labels{/name}","releases_url":"https://api.github.com/repos/oleg-nenashev/docker-commons-plugin/releases{/id}","created_at":"2015-04-21T04:21:20Z","updated_at":"2015-04-30T01:23:27Z","pushed_at":"2015-05-10T12:47:14Z","git_url":"git://github.com/oleg-nenashev/docker-commons-plugin.git","ssh_url":"git@github.com:oleg-nenashev/docker-commons-plugin.git","clone_url":"https://github.com/oleg-nenashev/docker-commons-plugin.git","svn_url":"https://github.com/oleg-nenashev/docker-commons-plugin","homepage":"","size":279,"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":"jenkinsci:master","ref":"master","sha":"e7b513fe658421ce9071a669018bb900abae2a92","user":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.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":33572296,"name":"docker-commons-plugin","full_name":"jenkinsci/docker-commons-plugin","owner":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.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/docker-commons-plugin","description":"","fork":false,"url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin","forks_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/forks","keys_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/teams","hooks_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/hooks","issue_events_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/events","assignees_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/tags","blobs_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/languages","stargazers_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/stargazers","contributors_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/contributors","subscribers_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/subscribers","subscription_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/subscription","commits_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/merges","archive_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/downloads","issues_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/labels{/name}","releases_url":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/releases{/id}","created_at":"2015-04-07T22:49:23Z","updated_at":"2015-05-07T15:29:56Z","pushed_at":"2015-05-12T12:24:01Z","git_url":"git://github.com/jenkinsci/docker-commons-plugin.git","ssh_url":"git@github.com:jenkinsci/docker-commons-plugin.git","clone_url":"https://github.com/jenkinsci/docker-commons-plugin.git","svn_url":"https://github.com/jenkinsci/docker-commons-plugin","homepage":"","size":830,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":2,"forks":6,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/30"},"html":{"href":"https://github.com/jenkinsci/docker-commons-plugin/pull/30"},"issue":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/issues/30"},"comments":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/jenkinsci/docker-commons-plugin/statuses/1ad28ce146b2e726d2f5ad0a37043c7b1652d675"}}}}