use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class KojiMavenMetadataProvider method executeKojiMetadataLookup.
@Measure
private Metadata executeKojiMetadataLookup(ProjectRef ga, String path) throws KojiClientException, IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
// short-term caches to help improve performance a bit by avoiding xml-rpc calls.
List<KojiArchiveInfo> archives = kojiContentProvider.listArchivesMatching(ga, null);
Map<Integer, KojiBuildArchiveCollection> seenBuildArchives = new ConcurrentHashMap<>();
Set<Integer> seenBuilds = new ConcurrentHashSet<>();
DrainingExecutorCompletionService<SingleVersion> svc = new DrainingExecutorCompletionService<>(kojiMDService);
detectOverloadVoid(() -> {
for (KojiArchiveInfo archive : archives) {
svc.submit(archiveScanner(path, ga, archive, seenBuilds, seenBuildArchives));
}
});
Set<SingleVersion> versions = new ConcurrentHashSet<>();
try {
svc.drain(v -> {
if (v != null) {
versions.add(v);
}
});
} catch (InterruptedException | ExecutionException e) {
logger.warn("Failed to scan for Koji metadata related to: " + ga, e);
}
if (versions.isEmpty()) {
logger.debug("No versions found in Koji builds for metadata: {}", path);
return null;
}
List<SingleVersion> sortedVersions = new ArrayList<>(versions);
Collections.sort(sortedVersions);
Metadata md = new Metadata();
md.setGroupId(ga.getGroupId());
md.setArtifactId(ga.getArtifactId());
Versioning versioning = new Versioning();
versioning.setRelease(sortedVersions.get(versions.size() - 1).renderStandard());
versioning.setLatest(sortedVersions.get(versions.size() - 1).renderStandard());
versioning.setVersions(sortedVersions.stream().map(SingleVersion::renderStandard).collect(Collectors.toList()));
Date lastUpdated = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
versioning.setLastUpdated(new SimpleDateFormat(LAST_UPDATED_FORMAT).format(lastUpdated));
md.setVersioning(versioning);
return md;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class KojiContentManagerDecorator method findKojiBuildAnd.
@Measure
private <T> T findKojiBuildAnd(ArtifactStore store, String path, EventMetadata eventMetadata, T defValue, KojiBuildAction<T> action) throws IndyWorkflowException {
if (!config.getEnabled()) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Koji content-manager decorator is disabled.");
logger.debug("When koji addon is disenabled , path:{},config instance is {}", path, config.toString());
return defValue;
}
if (!config.isEnabledFor(store)) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Koji content-manager decorator not enabled for: {}.", store.getKey());
logger.debug("When the group is disenabled , path:{},config instance is {}", path, config.toString());
return defValue;
}
logger.debug("When the koji is enabled , path:{},config instance is {}", path, config.toString());
// TODO: This won't work for maven-metadata.xml files! We need to hit a POM or jar or something first.
// FIXME: This won't work for NPM!
ArtifactPathInfo pathInfo = ArtifactPathInfo.parse(path);
if (pathInfo != null) {
ArtifactRef artifactRef = pathInfo.getArtifact();
logger.info("Searching for Koji build: {}", artifactRef);
return proxyKojiBuild(store.getKey(), artifactRef, path, eventMetadata, defValue, action);
} else {
logger.info("Path is not a maven artifact reference: {}", path);
}
return defValue;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class KojiContentManagerDecorator method retrieve.
@Override
@Measure
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("KOJI: Delegating initial retrieval attempt for: {}/{}", store.getKey(), path);
Transfer result = delegate.retrieve(store, path, eventMetadata);
if (result == null && kojiUtils.isVersionSignatureAllowedWithPath(path) && StoreType.group == store.getKey().getType()) {
logger.info("KOJI: Checking for Koji build matching: {}", path);
Group group = (Group) store;
RemoteRepository kojiProxy = findKojiBuildAnd(store, path, eventMetadata, null, this::createRemoteRepository);
if (kojiProxy != null) {
adjustTargetGroup(kojiProxy, group);
result = delegate.retrieve(kojiProxy, path, eventMetadata);
}
if (result != null) {
nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
}
}
// Finally, pass the Transfer back.
return result;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class KojiContentManagerDecorator method exists.
@Override
@Measure
public boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("KOJI: Delegating initial existence check for: {}/{}", store.getKey(), path);
boolean result = delegate.exists(store, path);
if (!result && kojiUtils.isVersionSignatureAllowedWithPath(path) && StoreType.group == store.getKey().getType()) {
Group group = (Group) store;
logger.info("KOJI: Checking whether Koji contains a build matching: {}", path);
RemoteRepository kojiProxy = findKojiBuildAnd(store, path, new EventMetadata(), null, this::createRemoteRepository);
if (kojiProxy != null) {
adjustTargetGroup(kojiProxy, group);
result = delegate.exists(kojiProxy, path);
}
if (result) {
nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
}
}
return result;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class MavenMetadataGenerator method generateFileContent.
@Override
@Measure
public Transfer generateFileContent(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
// metadata merging is something else...don't handle it here.
if (StoreType.group == store.getKey().getType()) {
return null;
}
if (!canProcess(path)) {
return null;
}
boolean generated;
// TODO: Generation of plugin metadata files (groupId-level) is harder, and requires cracking open the jar file
// This is because that's the only place the plugin prefix can be reliably retrieved from.
// regardless, we will need this first level of listings. What we do with it will depend on the logic below...
final String parentPath = Paths.get(path).getParent().toString();
List<StoreResource> firstLevel;
try {
firstLevel = fileManager.listRaw(store, parentPath);
} catch (final IndyWorkflowException e) {
logger.error(String.format("SKIP: Failed to generate maven-metadata.xml from listing of directory contents for: %s under path: %s", store, parentPath), e);
return null;
}
String toGenPath = path;
if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
toGenPath = normalize(normalize(parentPath(toGenPath)), MavenMetadataMerger.METADATA_NAME);
}
ArtifactPathInfo snapshotPomInfo = null;
if (parentPath.endsWith(LOCAL_SNAPSHOT_VERSION_PART)) {
// If we're in a version directory, first-level listing should include a .pom file
for (final StoreResource resource : firstLevel) {
if (resource.getPath().endsWith(".pom")) {
snapshotPomInfo = ArtifactPathInfo.parse(resource.getPath());
break;
}
}
}
if (snapshotPomInfo != null) {
logger.debug("Generating maven-metadata.xml for snapshots, store: {}", store.getKey());
generated = writeSnapshotMetadata(snapshotPomInfo, firstLevel, store, toGenPath, eventMetadata);
} else {
logger.debug("Generating maven-metadata.xml for releases, store: {}", store.getKey());
generated = writeVersionMetadata(firstLevel, store, toGenPath, eventMetadata);
}
logger.debug("[Result] Generating maven-metadata.xml for store: {}, result: {}", store.getKey(), generated);
return generated ? fileManager.getTransfer(store, path) : null;
}
Aggregations