use of org.commonjava.o11yphant.metrics.annotation.Measure 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;
});
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultContentManager method store.
@Override
@Measure
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (group == store.getKey().getType()) {
try {
final List<ArtifactStore> allMembers = storeManager.query().enabledState(true).getOrderedConcreteStoresInGroup(store.getPackageType(), store.getName());
final Transfer txfr = store(allMembers, store.getKey(), path, stream, op, eventMetadata);
logger.debug("Stored: {} for group: {} in: {}", path, store.getKey(), txfr);
return txfr;
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
}
logger.debug("Storing: {} for: {} with event metadata: {}", path, store.getKey(), eventMetadata);
final Transfer txfr = downloadManager.store(store, path, stream, op, eventMetadata);
if (txfr != null) {
final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
ArtifactStore transferStore;
try {
transferStore = storeManager.getArtifactStore(kl.getKey());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
}
contentGeneratorManager.handleContentStorage(transferStore, path, txfr, eventMetadata);
final String name = String.format("ContentNFCClean-StoreSingle-store(%s)-path(%s)", store.getKey(), path);
final String context = String.format("Class: %s, method: %s, store: %s, path: %s", this.getClass().getName(), "store", store.getKey(), path);
storeManager.asyncGroupAffectedBy(new StoreDataManager.ContextualTask(name, context, () -> clearNFCEntries(kl, path, eventMetadata)));
}
return txfr;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultContentManager method retrieve.
@Override
@Measure
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
Transfer item;
if (group == store.getKey().getType()) {
List<ArtifactStore> members = getOrderedConcreteStoresAndFilter((Group) store, path);
if (logger.isDebugEnabled()) {
logger.debug("{} is a group. Attempting downloads from (in order):\n {}", store.getKey(), StringUtils.join(members, "\n "));
}
item = contentGeneratorManager.generateGroupFileContent((Group) store, members, path, eventMetadata);
boolean generated = (item != null);
if (!generated) {
if (PathMaskChecker.checkMask(store, path)) {
for (final ArtifactStore member : members) {
try {
item = doRetrieve(member, path, eventMetadata);
} catch (IndyWorkflowException e) {
logger.error("Failed to retrieve artifact from for path {} from {} in group {}, error is: {}", path, member, store, e.getMessage());
}
if (item != null) {
// get the item from the first member store
break;
}
}
}
}
} else {
item = doRetrieve(store, path, eventMetadata);
}
if (item != null) {
logger.info("Returning transfer {} from {}", item, store.getKey());
} else {
logger.trace("Not found path {} from {}", path, store.getKey());
}
return item;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultContentManager method clearNFCEntries.
@Measure
protected void clearNFCEntries(final KeyedLocation kl, final String path, EventMetadata eventMetadata) {
try {
Set<Group> groups = storeManager.affectedBy(Arrays.asList(kl.getKey()), eventMetadata);
groups.stream().map((g) -> new ConcreteResource(LocationUtils.toLocation(g), path)).forEach((cr) -> nfc.clearMissing(cr));
nfc.clearMissing(new ConcreteResource(kl, path));
} catch (IndyDataException e) {
logger.error(String.format("Failed to clear NFC entries affected by upload of: %s to: %s. Reason: %s", path, kl.getKey(), e.getMessage()), e);
}
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultContentManager method store.
@Override
@Measure
public Transfer store(final List<? extends ArtifactStore> stores, final StoreKey topKey, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
logger.debug("Storing: {} in: {} with event metadata: {}", path, stores, eventMetadata);
final Transfer txfr = downloadManager.store(stores, path, stream, op, eventMetadata);
if (txfr != null) {
final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
ArtifactStore transferStore;
try {
transferStore = storeManager.getArtifactStore(kl.getKey());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
}
contentGeneratorManager.handleContentStorage(transferStore, path, txfr, eventMetadata);
final String name = String.format("ContentNFCClean-StoreList-location(%s)-path(%s)", kl, path);
final String context = String.format("Class: %s, method: %s, location: %s, path: %s", this.getClass().getName(), "store-stores", kl, path);
storeManager.asyncGroupAffectedBy(new StoreDataManager.ContextualTask(name, context, () -> clearNFCEntries(kl, path, eventMetadata)));
}
return txfr;
}
Aggregations