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;
}
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;
}
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;
}
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);
}
Aggregations