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