Search in sources :

Example 1 with FingerprintInfo

use of org.platformlayer.ops.cas.jenkins.JenkinsClient.FingerprintInfo in project platformlayer by platformlayer.

the class JenkinsCasStore method findTag.

@Override
public Md5Hash findTag(String tag) throws OpsException {
    URI uri = client.getBaseUrl();
    // TODO: Match jenkins host??
    String[] tokens = tag.split(":");
    if (tokens.length != 3) {
        return null;
    }
    String jobKey = tokens[0];
    String promotionKey = tokens[1];
    String fileName = tokens[2];
    String treeFilter = "fingerprint[fileName,hash]";
    BuildInfo buildInfo;
    try {
        buildInfo = client.findPromotedBuild(jobKey, promotionKey, treeFilter);
        if (buildInfo == null) {
            return null;
        }
    } catch (JenkinsException e) {
        throw new OpsException("Error communicating with Jenkins", e);
    }
    FingerprintInfo found = null;
    List<FingerprintInfo> fingerprints = buildInfo.getFingerprints();
    for (FingerprintInfo fingerprint : fingerprints) {
        if (fileName.equals(fingerprint.getFileName())) {
            found = fingerprint;
        }
    }
    if (found == null) {
        for (FingerprintInfo fingerprint : fingerprints) {
            String fingerprintFileName = fingerprint.getFileName();
            if (fingerprintFileName.contains(":")) {
                // Strip the maven prefix
                fingerprintFileName = fingerprintFileName.substring(fingerprintFileName.indexOf(':') + 1);
            }
            if (fileName.equals(fingerprintFileName)) {
                found = fingerprint;
            }
        }
    }
    if (found == null) {
        log.warn("Could not find fingerprinted file with name: " + fileName + " in " + buildInfo);
        return null;
    }
    String hash = found.getHash();
    if (hash == null) {
        throw new IllegalStateException();
    }
    // We return the hash in the hope that we've already copied the artifact!
    return new Md5Hash(hash);
}
Also used : OpsException(org.platformlayer.ops.OpsException) BuildInfo(org.platformlayer.ops.cas.jenkins.JenkinsClient.BuildInfo) FingerprintInfo(org.platformlayer.ops.cas.jenkins.JenkinsClient.FingerprintInfo) URI(java.net.URI) Md5Hash(com.fathomdb.hash.Md5Hash)

Example 2 with FingerprintInfo

use of org.platformlayer.ops.cas.jenkins.JenkinsClient.FingerprintInfo in project platformlayer by platformlayer.

the class JenkinsCasStore method findArtifact.

@Override
public CasStoreObject findArtifact(Md5Hash hash) throws OpsException {
    try {
        FingerprintInfo fingerprint = client.findByFingerprint(hash.toHex());
        if (fingerprint == null) {
            return null;
        }
        BuildId build = fingerprint.getOriginalBuild();
        if (build == null) {
            build = fingerprint.getFirstUsage();
            if (build == null) {
                log.warn("Cannot find build for fingerprint: " + hash.toHex());
                return null;
            }
        }
        BuildInfo buildInfo = client.findBuildInfo(build);
        if (buildInfo == null) {
            return null;
        }
        String fingerprintFileName = fingerprint.getFileName();
        ArtifactInfo found = buildInfo.findArtifactByFileName(fingerprintFileName);
        if (found == null) {
            log.warn("Could not find artifact: " + fingerprint + " in " + buildInfo);
            return null;
        }
        URI url = found.getArtifactUrl();
        return new JenkinsCasObject(this, hash, url);
    } catch (JenkinsException e) {
        throw new OpsException("Error communicating with Jenkins", e);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) ArtifactInfo(org.platformlayer.ops.cas.jenkins.JenkinsClient.BuildInfo.ArtifactInfo) BuildId(org.platformlayer.ops.cas.jenkins.JenkinsClient.BuildId) BuildInfo(org.platformlayer.ops.cas.jenkins.JenkinsClient.BuildInfo) FingerprintInfo(org.platformlayer.ops.cas.jenkins.JenkinsClient.FingerprintInfo) URI(java.net.URI)

Aggregations

URI (java.net.URI)2 OpsException (org.platformlayer.ops.OpsException)2 BuildInfo (org.platformlayer.ops.cas.jenkins.JenkinsClient.BuildInfo)2 FingerprintInfo (org.platformlayer.ops.cas.jenkins.JenkinsClient.FingerprintInfo)2 Md5Hash (com.fathomdb.hash.Md5Hash)1 BuildId (org.platformlayer.ops.cas.jenkins.JenkinsClient.BuildId)1 ArtifactInfo (org.platformlayer.ops.cas.jenkins.JenkinsClient.BuildInfo.ArtifactInfo)1