Search in sources :

Example 6 with KojiRepairResult

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

the class KojiRepairManager method repairAllPathMasks.

public KojiMultiRepairResult repairAllPathMasks(final String user) throws KojiRepairException, IndyWorkflowException {
    KojiMultiRepairResult result = new KojiMultiRepairResult();
    if (opLock.tryLock()) {
        try {
            List<RemoteRepository> kojiRemotes = getAllKojiRemotes();
            DrainingExecutorCompletionService<KojiRepairResult> repairService = new DrainingExecutorCompletionService<>(repairExecutor);
            detectOverloadVoid(() -> kojiRemotes.forEach(r -> repairService.submit(() -> {
                logger.info("Attempting to repair path masks in Koji remote: {}", r.getKey());
                KojiRepairRequest request = new KojiRepairRequest(r.getKey(), false);
                try {
                    return repairPathMask(request, user, true);
                } catch (KojiRepairException e) {
                    logger.error("Failed to execute repair for: " + r.getKey(), e);
                }
                return null;
            })));
            List<KojiRepairResult> results = new ArrayList<>();
            try {
                repairService.drain(r -> {
                    if (r != null) {
                        results.add(r);
                    }
                });
            } catch (InterruptedException | ExecutionException e) {
                logger.error("Failed to repair path masks.", e);
            }
            result.setResults(results);
        } catch (IndyDataException e) {
            throw new KojiRepairException("Failed to list Koji remote repositories for repair. Reason: %s", e, e.getMessage());
        } finally {
            opLock.unlock();
        }
    } else {
        throw new KojiRepairException("Koji repair manager is busy.");
    }
    return result;
}
Also used : ChangeSummary(org.commonjava.indy.audit.ChangeSummary) IndyKojiContentProvider(org.commonjava.indy.koji.content.IndyKojiContentProvider) LoggerFactory(org.slf4j.LoggerFactory) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SingleThreadedExecutorService(org.commonjava.cdi.util.weft.SingleThreadedExecutorService) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) KojiPathPatternFormatter(org.commonjava.indy.koji.content.KojiPathPatternFormatter) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) KOJI_ORIGIN_BINARY(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN_BINARY) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) KojiClientException(com.redhat.red.build.koji.KojiClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreType.group(org.commonjava.indy.model.core.StoreType.group) Logger(org.slf4j.Logger) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ReentrantLock(java.util.concurrent.locks.ReentrantLock) MalformedURLException(java.net.MalformedURLException) KojiClient(com.redhat.red.build.koji.KojiClient) CREATION_TRIGGER_GAV(org.commonjava.indy.koji.content.KojiContentManagerDecorator.CREATION_TRIGGER_GAV) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) KojiUtils(org.commonjava.indy.koji.util.KojiUtils) Collectors(java.util.stream.Collectors) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KOJI_ORIGIN(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) List(java.util.List) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreType.remote(org.commonjava.indy.model.core.StoreType.remote) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) PoolUtils.detectOverloadVoid(org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid) IndyKojiConfig(org.commonjava.indy.koji.conf.IndyKojiConfig) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) IndyDataException(org.commonjava.indy.data.IndyDataException) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with KojiRepairResult

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

the class KojiRepairManager method repairAllMetadataTimeout.

public KojiMultiRepairResult repairAllMetadataTimeout(final String user, boolean isDryRun) throws KojiRepairException, IndyWorkflowException {
    KojiMultiRepairResult result = new KojiMultiRepairResult();
    if (opLock.tryLock()) {
        try {
            List<RemoteRepository> kojiRemotes = getAllKojiRemotes();
            DrainingExecutorCompletionService<KojiRepairResult> repairService = new DrainingExecutorCompletionService<>(repairExecutor);
            detectOverloadVoid(() -> kojiRemotes.forEach(r -> repairService.submit(() -> {
                logger.info("Attempting to repair path masks in Koji remote: {}", r.getKey());
                KojiRepairRequest request = new KojiRepairRequest(r.getKey(), isDryRun);
                try {
                    return repairMetadataTimeout(request, user, true);
                } catch (KojiRepairException e) {
                    logger.error("Failed to execute repair for: " + r.getKey(), e);
                }
                return null;
            })));
            List<KojiRepairResult> results = new ArrayList<>();
            try {
                repairService.drain(r -> {
                    if (r != null) {
                        results.add(r);
                    }
                });
            } catch (InterruptedException | ExecutionException e) {
                logger.error("Failed to repair metadata timeout.", e);
            }
            result.setResults(results);
        } catch (IndyDataException e) {
            throw new KojiRepairException("Failed to list Koji remote repositories for repair. Reason: %s", e, e.getMessage());
        } finally {
            opLock.unlock();
        }
    } else {
        throw new KojiRepairException("Koji repair manager is busy.");
    }
    return result;
}
Also used : ChangeSummary(org.commonjava.indy.audit.ChangeSummary) IndyKojiContentProvider(org.commonjava.indy.koji.content.IndyKojiContentProvider) LoggerFactory(org.slf4j.LoggerFactory) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SingleThreadedExecutorService(org.commonjava.cdi.util.weft.SingleThreadedExecutorService) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) KojiPathPatternFormatter(org.commonjava.indy.koji.content.KojiPathPatternFormatter) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) KOJI_ORIGIN_BINARY(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN_BINARY) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) KojiClientException(com.redhat.red.build.koji.KojiClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreType.group(org.commonjava.indy.model.core.StoreType.group) Logger(org.slf4j.Logger) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ReentrantLock(java.util.concurrent.locks.ReentrantLock) MalformedURLException(java.net.MalformedURLException) KojiClient(com.redhat.red.build.koji.KojiClient) CREATION_TRIGGER_GAV(org.commonjava.indy.koji.content.KojiContentManagerDecorator.CREATION_TRIGGER_GAV) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) KojiUtils(org.commonjava.indy.koji.util.KojiUtils) Collectors(java.util.stream.Collectors) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KOJI_ORIGIN(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) List(java.util.List) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreType.remote(org.commonjava.indy.model.core.StoreType.remote) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) PoolUtils.detectOverloadVoid(org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid) IndyKojiConfig(org.commonjava.indy.koji.conf.IndyKojiConfig) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) IndyDataException(org.commonjava.indy.data.IndyDataException) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with KojiRepairResult

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

the class KojiRepairManager method repairMetadataTimeout.

public KojiRepairResult repairMetadataTimeout(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 {
                    final int NEVER_TIMEOUT_VALUE = -1;
                    if (!request.isDryRun()) {
                        ((RemoteRepository) store).setMetadataTimeoutSeconds(NEVER_TIMEOUT_VALUE);
                        final ChangeSummary changeSummary = new ChangeSummary(user, "Repairing remote repository path masks to Koji build: " + nvr);
                        storeManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
                    }
                    KojiRepairResult.RepairResult repairResult = new KojiRepairResult.RepairResult(remoteKey);
                    repairResult.withPropertyChange("metadata_timeout", ((RemoteRepository) store).getMetadataTimeoutSeconds(), NEVER_TIMEOUT_VALUE);
                    ret.withResult(repairResult);
                } 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 : 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) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult)

Example 9 with KojiRepairResult

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

the class RepairKojiRepositoryTest method run.

/**
 * For this test to pass, below settings are needed in koji.conf:
 *
 * tag.patterns.enabled=false
 * proxy.binary.builds=true
 */
@Ignore
@Test
public void run() throws Exception {
    // 0. trigger koji repo creation
    contentDownloadTime(pseudoGroupName, path);
    contentDownloadTime(pseudoGroupName, binaryPath);
    List<RemoteRepository> repos = getKojiRemoteRepositories();
    RemoteRepository repository = null;
    RemoteRepository repositoryBinary = null;
    for (RemoteRepository r : repos) {
        String name = r.getName();
        if (name.startsWith(KOJI_ORIGIN_BINARY)) {
            repositoryBinary = r;
        } else {
            repository = r;
        }
    }
    assertThat(repositoryBinary, notNullValue());
    assertThat(repository, notNullValue());
    // 1. repair remote
    IndyKojiClientModule module = client.module(IndyKojiClientModule.class);
    KojiRepairResult ret = module.repairVol("maven", remote, repository.getName(), true);
    boolean succeeded = ret.succeeded();
    assertTrue(succeeded);
    printResults(ret);
    // 2. repair group
    String groupName = "brew-proxies";
    ret = module.repairVol("maven", group, groupName, true);
    succeeded = ret.succeeded();
    assertTrue(succeeded);
    printResults(ret);
}
Also used : IndyKojiClientModule(org.commonjava.indy.koji.client.IndyKojiClientModule) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

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