Skip to content

Commit

Permalink
Merge pull request #37 from oleg-nenashev/named-fingerprints
Browse files Browse the repository at this point in the history
[FIXED JENKINS-28657] - Support the creation of named fingerprints
  • Loading branch information
oleg-nenashev committed Jul 13, 2015
2 parents e09ead3 + 39b57e7 commit ae64ac1
Showing 1 changed file with 39 additions and 5 deletions.
Expand Up @@ -38,6 +38,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.FingerprintFacet;
import org.apache.commons.lang.StringUtils;

/**
* Entry point into fingerprint related functionalities in Docker.
Expand Down Expand Up @@ -85,26 +86,59 @@ private DockerFingerprints() {} // no instantiation
return null;
}

/**
* @deprecated Use {@link #forImage(hudson.model.Run, java.lang.String, java.lang.String)}
*/
public static @Nonnull Fingerprint forImage(@CheckForNull Run<?,?> run, @Nonnull String id) throws IOException {
return forImage(run, id, null);
}

/**
* Get or create a {@link Fingerprint} for the image.
* @param run Origin of the fingerprint (if available)
* @param id Image ID. Only 64-char full IDs are supported.
* @param name Optional name of the image. If null, the image name will be
* constructed using the specified ID.
* @return Fingerprint for the specified ID
* @throws IOException Fingerprint load/save error
* @since TODO
*/
public static @Nonnull Fingerprint forImage(@CheckForNull Run<?,?> run, @Nonnull String id) throws IOException {
return Jenkins.getInstance().getFingerprintMap().getOrCreate(run, "<docker-image>", getFingerprintHash(id));
public static @Nonnull Fingerprint forImage(@CheckForNull Run<?,?> run,
@Nonnull String id, @CheckForNull String name) throws IOException {
return forDockerInstance(run, id, name, "Docker image ");
}

/**
* @deprecated Use {@link #forContainer(hudson.model.Run, java.lang.String, java.lang.String)}
*/
@Deprecated
public static @Nonnull Fingerprint forContainer(@CheckForNull Run<?,?> run, @Nonnull String id) throws IOException {
return forContainer(run, id, null);
}

/**
* Get or create a {@link Fingerprint} for the container.
* @param run Origin of the fingerprint (if available)
* @param id Image ID. Only 64-char full IDs are supported.
* @param id Container ID. Only 64-char full IDs are supported.
* @param name Optional name of the container. If null, the container name will be
* constructed using the specified ID.
* @return Fingerprint for the specified ID
* @throws IOException Fingerprint load/save error
* @since TODO
*/
public static @Nonnull Fingerprint forContainer(@CheckForNull Run<?,?> run, @Nonnull String id) throws IOException {
return Jenkins.getInstance().getFingerprintMap().getOrCreate(run, "<docker-container>", getFingerprintHash(id));
public static @Nonnull Fingerprint forContainer(@CheckForNull Run<?,?> run,
@Nonnull String id, @CheckForNull String name) throws IOException {
return forDockerInstance(run, id, name, "Docker container ");
}

private static @Nonnull Fingerprint forDockerInstance(@CheckForNull Run<?,?> run,
@Nonnull String id, @CheckForNull String name, @Nonnull String prefix) throws IOException {
final Jenkins j = Jenkins.getInstance();
if (j == null) {
throw new IOException("Jenkins instance is not ready");
}
final String imageName = prefix + (StringUtils.isNotBlank(name) ? name : id);
return j.getFingerprintMap().getOrCreate(run, imageName, getFingerprintHash(id));
}

/**
Expand Down

0 comments on commit ae64ac1

Please sign in to comment.