Search in sources :

Example 1 with KojiBuildInfo

use of com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo in project indy by Commonjava.

the class KojiUtilsTest method formatStorageUrl.

@Test
public void formatStorageUrl() throws Exception {
    KojiUtils kojiUtils = new KojiUtils();
    String root = "http://my.koji.hub/kojihub";
    KojiBuildInfo buildInfo = new KojiBuildInfo();
    buildInfo.setName("javax.activation-activation");
    buildInfo.setVersion("1.1.1.redhat_5");
    buildInfo.setRelease("1");
    buildInfo.setVolumeName("DEFAULT");
    String url = kojiUtils.formatStorageUrl(root, buildInfo);
    assertEquals(defaultUrl, url);
    buildInfo.setVolumeName(null);
    url = kojiUtils.formatStorageUrl(root, buildInfo);
    assertEquals(defaultUrl, url);
    buildInfo.setVolumeName("1");
    url = kojiUtils.formatStorageUrl(root, buildInfo);
    assertEquals(volUrl, url);
}
Also used : KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo) Test(org.junit.Test)

Example 2 with KojiBuildInfo

use of com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo in project indy by Commonjava.

the class KojiRepairManager method repairGroupVol.

private KojiRepairResult repairGroupVol(KojiRepairRequest request, Group group, String user) throws KojiClientException {
    KojiRepairResult ret = new KojiRepairResult(request);
    List<StoreKey> stores = group.getConstituents();
    if (stores.isEmpty()) {
        return ret.withNoChange(group.getKey());
    }
    KojiSessionInfo session = null;
    List<Object> args = new ArrayList<>();
    stores.forEach(storeKey -> {
        String nvr = kojiUtils.getBuildNvr(storeKey);
        if (nvr != null) {
            args.add(nvr);
        } else {
            ret.withIgnore(storeKey);
        }
    });
    List<KojiBuildInfo> buildInfoList = kojiCachedClient.getBuildInfo(args, session);
    buildInfoList.forEach(buildInfo -> {
        try {
            KojiRepairResult.RepairResult repairResult = doRepair(group.getPackageType(), null, buildInfo, user, request.isDryRun());
            ret.withResult(repairResult);
        } catch (KojiRepairException e) {
            // we do not fail the whole attempt if one store failed
            logger.debug("Repair failed", e);
            ret.withResult(new KojiRepairResult.RepairResult(e.getStoreKey(), e));
        }
    });
    return ret;
}
Also used : ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)

Example 3 with KojiBuildInfo

use of com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo in project indy by Commonjava.

the class KojiRepairManager method repairPathMask.

public KojiRepairResult repairPathMask(KojiRepairRequest request, String user, boolean skipLock) throws KojiRepairException {
    KojiRepairResult ret = new KojiRepairResult(request);
    if (skipLock || opLock.tryLock()) {
        try {
            ArtifactStore store = getRequestedStore(request, ret);
            if (store == null) {
                return ret;
            }
            store = store.copyOf();
            StoreKey remoteKey = request.getSource();
            if (remoteKey.getType() == remote) {
                final String nvr = kojiUtils.getBuildNvr(remoteKey);
                if (nvr == null) {
                    String error = String.format("Not a koji store: %s", remoteKey);
                    return ret.withError(error);
                }
                try {
                    KojiSessionInfo session = null;
                    KojiBuildInfo build = kojiCachedClient.getBuildInfo(nvr, session);
                    List<KojiArchiveInfo> archives = kojiCachedClient.listArchivesForBuild(build.getId(), session);
                    ArtifactRef artifactRef = SimpleArtifactRef.parse(store.getMetadata(CREATION_TRIGGER_GAV));
                    if (artifactRef == null) {
                        String error = String.format("Koji remote repository: %s does not have %s metadata. Cannot retrieve accurate path masks.", remoteKey, CREATION_TRIGGER_GAV);
                        return ret.withError(error);
                    }
                    // set pathMaskPatterns using build output paths
                    Set<String> patterns = kojiPathFormatter.getPatterns(store.getKey(), artifactRef, archives, true);
                    logger.debug("For repo: {}, resetting path_mask_patterns to:\n\n{}\n\n", store.getKey(), patterns);
                    KojiRepairResult.RepairResult repairResult = new KojiRepairResult.RepairResult(remoteKey);
                    repairResult.withPropertyChange("path_mask_patterns", store.getPathMaskPatterns(), patterns);
                    ret.withResult(repairResult);
                    store.setPathMaskPatterns(patterns);
                    final ChangeSummary changeSummary = new ChangeSummary(user, "Repairing remote repository path masks to Koji build: " + build.getNvr());
                    storeManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
                } catch (KojiClientException e) {
                    String error = String.format("Cannot getBuildInfo: %s, error: %s", remoteKey, e);
                    logger.debug(error, e);
                    return ret.withError(error, e);
                } catch (IndyDataException e) {
                    String error = String.format("Failed to store changed remote repository: %s, error: %s", remoteKey, e);
                    logger.debug(error, e);
                    return ret.withError(error, e);
                }
            } else {
                String error = String.format("Not a remote koji repository: %s", remoteKey);
                return ret.withError(error);
            }
        } finally {
            if (!skipLock) {
                opLock.unlock();
            }
        }
    } else {
        throw new KojiRepairException("Koji repair manager is busy.");
    }
    return ret;
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) KojiClientException(com.redhat.red.build.koji.KojiClientException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)

Example 4 with KojiBuildInfo

use of com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo in project indy by Commonjava.

the class KojiRepairManager method repairRemoteRepositoryVol.

private KojiRepairResult repairRemoteRepositoryVol(KojiRepairRequest request, RemoteRepository repository, String user) throws KojiRepairException {
    StoreKey storeKey = repository.getKey();
    KojiRepairResult ret = new KojiRepairResult(request);
    final String nvr = kojiUtils.getBuildNvr(storeKey);
    if (nvr == null) {
        String error = String.format("Not a koji store: %s", storeKey);
        return ret.withError(error);
    }
    KojiBuildInfo buildInfo;
    try {
        KojiSessionInfo session = null;
        buildInfo = kojiCachedClient.getBuildInfo(nvr, session);
    } catch (KojiClientException e) {
        String error = String.format("Cannot getBuildInfo: %s, error: %s", storeKey, e);
        logger.debug(error, e);
        return ret.withError(error, e);
    }
    KojiRepairResult.RepairResult repairResult = doRepair(repository.getPackageType(), repository, buildInfo, user, request.isDryRun());
    return ret.withResult(repairResult);
}
Also used : KojiClientException(com.redhat.red.build.koji.KojiClientException) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) StoreKey(org.commonjava.indy.model.core.StoreKey) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)

Example 5 with KojiBuildInfo

use of com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo in project indy by Commonjava.

the class KojiMavenMetadataProvider method scanArchive.

private ArchiveScan scanArchive(final KojiArchiveInfo archive, final Set<Integer> seenBuilds) throws KojiClientException {
    Logger logger = LoggerFactory.getLogger(getClass());
    ArchiveScan scan = new ArchiveScan();
    if (!archive.getFilename().endsWith(".pom")) {
        logger.debug("Skipping non-POM: {}", archive.getFilename());
        scan.setDisqualified(true);
        return scan;
    }
    if (!isVerSignedAllowed(archive.getVersion())) {
        logger.debug("version filter pattern not matched: {}", archive.getVersion());
        scan.setDisqualified(true);
        return scan;
    }
    SingleVersion singleVersion = null;
    try {
        singleVersion = VersionUtils.createSingleVersion(archive.getVersion());
        scan.setSingleVersion(singleVersion);
    } catch (InvalidVersionSpecificationException ivse) {
        logger.warn("Skipping mal-formatted version: {}, relPath: {}, buildId: {}", archive.getVersion(), archive.getRelPath(), archive.getBuildId());
        scan.setDisqualified(true);
        return scan;
    }
    KojiBuildInfo build = null;
    if (seenBuilds.contains(archive.getBuildId())) {
        logger.debug("Skipping already seen build: {}", archive.getBuildId());
        scan.setDisqualified(true);
        return scan;
    } else {
        build = kojiContentProvider.getBuildInfo(archive.getBuildId(), null);
        seenBuilds.add(archive.getBuildId());
        scan.setBuild(build);
    }
    if (build == null) {
        logger.debug("Cannot retrieve build info: {}. Skipping: {}", archive.getBuildId(), archive.getFilename());
        scan.setDisqualified(true);
        return scan;
    }
    if (build.getBuildState() != KojiBuildState.COMPLETE) {
        logger.debug("Build: {} is not completed. The state is {}. Skipping.", build.getNvr(), build.getBuildState());
        scan.setDisqualified(true);
        return scan;
    }
    if (build.getTaskId() == null) {
        logger.debug("Build: {} is not a real build. It looks like a binary import. Skipping.", build.getNvr());
        // This is not a real build, it's a binary import.
        scan.setDisqualified(true);
        return scan;
    }
    return scan;
}
Also used : InvalidVersionSpecificationException(org.commonjava.atlas.maven.ident.version.InvalidVersionSpecificationException) Logger(org.slf4j.Logger) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)

Aggregations

KojiBuildInfo (com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)8 KojiSessionInfo (com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo)5 KojiClientException (com.redhat.red.build.koji.KojiClientException)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 KojiRepairResult (org.commonjava.indy.koji.model.KojiRepairResult)3 Logger (org.slf4j.Logger)3 KojiArchiveInfo (com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 IndyDataException (org.commonjava.indy.data.IndyDataException)2 KojiMultiRepairResult (org.commonjava.indy.koji.model.KojiMultiRepairResult)2 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2 KojiClient (com.redhat.red.build.koji.KojiClient)1 KojiBuildArchiveCollection (com.redhat.red.build.koji.model.xmlrpc.KojiBuildArchiveCollection)1 KojiTagInfo (com.redhat.red.build.koji.model.xmlrpc.KojiTagInfo)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 TRUE (java.lang.Boolean.TRUE)1