use of org.commonjava.atlas.maven.ident.ref.InvalidRefException in project indy by Commonjava.
the class KojiMavenMetadataProvider method getMetadata.
@Override
@Measure
public Metadata getMetadata(StoreKey targetKey, String path) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
if (group != targetKey.getType()) {
logger.debug("Not a group. Cannot supplement with metadata from Koji builds");
return null;
}
if (!kojiConfig.isEnabled()) {
logger.debug("Koji add-on is disabled.");
return null;
}
try {
ArtifactStore target = storeDataManager.getArtifactStore(targetKey);
if (!kojiConfig.isEnabledFor(target)) {
logger.debug("Koji integration is not enabled for group: {}", targetKey);
return null;
}
} catch (IndyDataException e) {
logger.error("Failed to get metadata for path {} in store {}: {}", path, targetKey, e.getMessage());
}
File mdFile = new File(path);
File artifactDir = mdFile.getParentFile();
File groupDir = artifactDir == null ? null : artifactDir.getParentFile();
if (artifactDir == null || groupDir == null) {
logger.debug("Invalid groupId / artifactId directory structure: '{}' / '{}'", groupDir, artifactDir);
return null;
}
String groupId = groupDir.getPath().replace(File.separatorChar, '.');
String artifactId = artifactDir.getName();
ProjectRef ref = null;
try {
ref = new SimpleProjectRef(groupId, artifactId);
} catch (InvalidRefException e) {
logger.warn("Not a valid Maven GA: {}:{}. Skipping Koji metadata retrieval.", groupId, artifactId);
}
if (ref == null) {
logger.debug("Could not render a valid Maven GA for path: '{}'", path);
return null;
}
ProjectRef ga = ref;
AtomicReference<IndyWorkflowException> wfError = new AtomicReference<>();
return versionMetadataLocks.lockAnd(ga, kojiConfig.getLockTimeoutSeconds(), k -> {
Metadata metadata = versionMetadata.get(ga);
if (metadata == null) {
try {
metadata = executeKojiMetadataLookup(ga, path);
} catch (IndyWorkflowException e) {
wfError.set(e);
metadata = null;
} catch (KojiClientException e) {
// FIXME: Should this bubble up like IndyWorkflowException does in the case of overloaded threadpool?
Throwable cause = e.getCause();
logger.error(String.format("Failed to retrieve version metadata for: %s from Koji. Reason: %s", ga, e.getMessage()), e);
if (cause instanceof RuntimeException) {
logger.error("Previous exception's nested cause was a RuntimeException variant:", cause);
}
metadata = null;
}
if (metadata != null) {
Metadata md = metadata;
// FIXME: Need a way to listen for cache expiration and re-request this?
versionMetadata.execute((cache) -> cache.put(ga, md, kojiConfig.getMetadataTimeoutSeconds(), TimeUnit.SECONDS));
} else {
logger.debug("Returning null metadata result for unknown reason (path: '{}')", path);
}
}
return metadata;
}, (k, lock) -> {
logger.error("Failed to acquire Koji GA version metadata lock on: '{}' in {} seconds.", ga, kojiConfig.getLockTimeoutSeconds());
return false;
});
}
Aggregations