use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ImpliedReposQueryDelegate method maybeFilter.
private List<ArtifactStore> maybeFilter(String groupName, List<ArtifactStore> delegateResult) {
Logger logger = LoggerFactory.getLogger(getClass());
if (delegateResult == null || delegateResult.isEmpty() || config.isEnabledForGroup(groupName)) {
logger.trace("Implied repositories are enabled for group: '{}'. Returning all membership from delegate result.", groupName);
return delegateResult;
}
logger.trace("Filtering stores with metadata: '{}' value of '{}' from membership results", METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
List<ArtifactStore> result = new ArrayList<>();
delegateResult.stream().filter((store) -> !IMPLIED_REPO_ORIGIN.equals(store.getMetadata(METADATA_ORIGIN))).forEach((store) -> result.add(store));
return result;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ImpliedRepoMetadataManager method addImpliedMetadata.
// TODO: Need to deal with pre-existing implications.
public void addImpliedMetadata(final ArtifactStore origin, final List<ArtifactStore> implied) throws ImpliedReposException {
try {
final List<StoreKey> impliedKeys = new ArrayList<>(implied.size());
for (final ArtifactStore store : implied) {
impliedKeys.add(store.getKey());
updateImpliedBy(store, origin);
}
origin.setMetadata(IMPLIED_STORES, mapper.writeValueAsString(new ImpliedRemotesWrapper(impliedKeys)));
} catch (final JsonProcessingException e) {
throw new ImpliedReposException("Failed to serialize implied stores: %s to JSON: %s. Error: %s", e, implied, origin.getKey(), e.getMessage());
}
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class KojiBuildAuthority method isAuthorized.
@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_BUILDAUTHORITY_ISAUTHORIZED + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_BUILDAUTHORITY_ISAUTHORIZED + IndyMetricsNames.METER)))
public boolean isAuthorized(String path, EventMetadata eventMetadata, ProjectRef ref, KojiBuildInfo build, KojiSessionInfo session, Map<Integer, KojiBuildArchiveCollection> seenBuildArchives) throws KojiClientException {
ArtifactStore authoritativeStore = getAuthoritativeStore();
if (authoritativeStore != null) {
KojiBuildArchiveCollection archiveCollection = seenBuildArchives.get(build.getId());
if (archiveCollection == null) {
archiveCollection = kojiClient.listArchivesForBuild(build, session);
seenBuildArchives.put(build.getId(), archiveCollection);
}
if (archiveCollection == null) {
throw new KojiClientException("Failed to retrieve archives for build: %s", build);
}
// @formatter:off
Predicate<KojiArchiveInfo> archiveInfoFilter = (archive) -> EXCLUDED_FILE_ENDINGS.stream().allMatch(ending -> !archive.getFilename().endsWith(ending));
List<KojiArchiveInfo> sortedArchives = archiveCollection.getArchives().stream().filter(archiveInfoFilter).sorted((a1, a2) -> {
TypePriority t1 = TypePriority.get(a1.getExtension());
TypePriority t2 = TypePriority.get(a2.getExtension());
return Integer.valueOf(t1.ordinal()).compareTo(t2.ordinal());
}).collect(Collectors.toList());
for (KojiArchiveInfo archive : sortedArchives) {
try {
if (isMavenArtifact(archive)) {
// skip non-Maven artifacts
continue;
}
if (containsPlaceholders(archive)) {
return false;
}
String artifactPath = ArtifactPathUtils.formatArtifactPath(archive.asArtifact(), typeMapper);
String md5 = checksumArtifact(authoritativeStore, artifactPath, eventMetadata);
if (isNotBlank(md5)) {
//FIXME: not sure if all koji archives are using md5 as checksum type for maven build
String kojiMd5 = archive.getChecksum();
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("Checking checksum for {} (path: {}) in auth store {}, auth store checksum:{}, koji build check sum:{}", ref, path, authoritativeStore, md5, kojiMd5);
if (!md5.equals(kojiMd5)) {
// if checksum is not the same, it means the artifact in koji is DIFFERENT from the one in the authoritative store. Reject this.
return false;
}
}
} catch (Exception e) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.error("SHOULD NEVER HAPPEN: Failed to transform artifact to path: " + e.getMessage(), e);
}
}
}
return true;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ImpliedRepoMaintainer method processImpliedRepos.
private boolean processImpliedRepos(final ImpliedRepoMaintJob job) {
final Set<StoreKey> processed = new HashSet<>();
// implications. Reachable means they could be in nested groups.
for (final ArtifactStore member : job.reachableMembers) {
processed.add(member.getKey());
}
logger.debug("Preset processed-implications to reachable members:\n {}", new JoinString("\n ", processed));
int lastLen = 0;
boolean changed = false;
job.added = new ArrayList<>();
// As soon as we go an iteration without adding a new member, we've captured everything.
do {
lastLen = job.members.size();
for (final ArtifactStore member : new ArrayList<>(job.members)) {
logger.debug("Processing member: {} for implied repos within group: {}", member.getKey(), job.group.getKey());
processed.add(member.getKey());
List<StoreKey> implied;
try {
implied = metadataManager.getStoresImpliedBy(member);
} catch (final ImpliedReposException e) {
logger.error("Failed to retrieve implied-store metadata for: " + member.getKey(), e);
continue;
}
if (implied == null || implied.isEmpty()) {
continue;
}
implied.removeAll(processed);
for (final StoreKey key : implied) {
logger.debug("Found implied store: {} not already in group: {}", key, job.group.getKey());
ArtifactStore impliedStore;
try {
impliedStore = storeManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error("Failed to retrieve store: " + key + " implied by: " + member.getKey(), e);
continue;
}
logger.info("Adding: {} to group: {} (implied by POMs in: {})", key, job.group.getKey(), member.getKey());
processed.add(key);
job.added.add(key);
job.group.addConstituent(key);
job.members.add(impliedStore);
changed = true;
}
}
} while (job.members.size() > lastLen);
return changed;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ImpliedRepoMaintainer method loadMemberStores.
private List<ArtifactStore> loadMemberStores(final Group group, final ImpliedRepoMaintJob job) throws IndyDataException {
final List<StoreKey> constituents = new ArrayList<>(group.getConstituents());
final List<ArtifactStore> members = new ArrayList<>(constituents.size());
for (final StoreKey memberKey : constituents) {
ArtifactStore store = job.currentStores.get(memberKey);
if (store == null) {
store = storeManager.getArtifactStore(memberKey);
}
if (store == null) {
logger.warn("Store not found for key: {} (member of: {})", memberKey, group.getKey());
continue;
}
members.add(store);
}
return members;
}
Aggregations