Search in sources :

Example 1 with KojiRepairResult

use of org.commonjava.indy.koji.model.KojiRepairResult 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 2 with KojiRepairResult

use of org.commonjava.indy.koji.model.KojiRepairResult 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 3 with KojiRepairResult

use of org.commonjava.indy.koji.model.KojiRepairResult in project indy by Commonjava.

the class KojiRepairManager method repairVol.

public KojiRepairResult repairVol(KojiRepairRequest request, String user, String baseUrl) throws KojiRepairException, KojiClientException {
    boolean flag = opLock.tryLock();
    if (flag) {
        try {
            StoreKey storeKey = request.getSource();
            KojiRepairResult ret = new KojiRepairResult(request);
            ArtifactStore store;
            try {
                store = storeManager.getArtifactStore(storeKey);
            } catch (IndyDataException e) {
                String error = String.format("Cannot get store: %s, error: %s", storeKey, e);
                logger.warn(error, e);
                return ret.withError(error);
            }
            if (store == null) {
                String error = String.format("No such store: %s.", storeKey);
                return ret.withError(error);
            }
            if (storeKey.getType() == group) {
                return repairGroupVol(request, (Group) store, user);
            } else if (storeKey.getType() == remote) {
                return repairRemoteRepositoryVol(request, (RemoteRepository) store, user);
            } else {
                String error = String.format("Not a group or remote koji store: %s", storeKey);
                return ret.withError(error);
            }
        } finally {
            opLock.unlock();
        }
    } else {
        throw new KojiRepairException("opLock held by other");
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 4 with KojiRepairResult

use of org.commonjava.indy.koji.model.KojiRepairResult 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 KojiRepairResult

use of org.commonjava.indy.koji.model.KojiRepairResult in project indy by Commonjava.

the class IndyKojiClientModule method repairVol.

public KojiRepairResult repairVol(final String packageType, final StoreType storeType, final String storeName, final boolean dryRun) throws IndyClientException {
    KojiRepairRequest req = new KojiRepairRequest(new StoreKey(packageType, storeType, storeName), dryRun);
    KojiRepairResult result = http.postWithResponse(REPAIR_KOJI_VOL, req, KojiRepairResult.class, HttpStatus.SC_OK);
    return result;
}
Also used : KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

KojiRepairResult (org.commonjava.indy.koji.model.KojiRepairResult)9 StoreKey (org.commonjava.indy.model.core.StoreKey)8 KojiBuildInfo (com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)5 KojiSessionInfo (com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo)5 IndyDataException (org.commonjava.indy.data.IndyDataException)5 KojiMultiRepairResult (org.commonjava.indy.koji.model.KojiMultiRepairResult)5 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)5 KojiClientException (com.redhat.red.build.koji.KojiClientException)4 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)4 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)4 KojiArchiveInfo (com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo)3 ArrayList (java.util.ArrayList)3 ArtifactRef (org.commonjava.atlas.maven.ident.ref.ArtifactRef)3 SimpleArtifactRef (org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef)3 KojiRepairRequest (org.commonjava.indy.koji.model.KojiRepairRequest)3 KojiClient (com.redhat.red.build.koji.KojiClient)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 Objects (java.util.Objects)2