use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class DefaultStoreEventDispatcher method deleted.
@Override
public void deleted(final EventMetadata eventMetadata, final ArtifactStore... stores) {
if (postDelEvent != null) {
final List<StoreKey> storeList = Arrays.asList(stores).stream().map(store -> store.getKey()).collect(Collectors.toList());
logger.trace("Dispatch post-delete event for: {}", storeList);
executor.execute(() -> {
String oldName = Thread.currentThread().getName();
try {
Thread.currentThread().setName("POST-DELETE-EVENT: " + storeList);
final Map<ArtifactStore, Transfer> storeRoots = new HashMap<>();
for (final ArtifactStore store : stores) {
if (store == null) {
continue;
}
final Transfer root = fileManager.getStoreRootDirectory(store);
storeRoots.put(store, root);
}
final ArtifactStoreDeletePostEvent event = new ArtifactStoreDeletePostEvent(eventMetadata, storeRoots);
fireEvent(postDelEvent, event);
} finally {
if (oldName != null) {
Thread.currentThread().setName(oldName);
}
}
});
}
}
use of org.commonjava.maven.galley.event.EventMetadata 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.maven.galley.event.EventMetadata in project indy by Commonjava.
the class StoreEnablementManager method onStoreError.
@Measure
public void onStoreError(@Observes IndyStoreErrorEvent evt) {
Logger logger = LoggerFactory.getLogger(getClass());
StoreKey key = evt.getStoreKey();
Throwable error = evt.getError();
try {
ArtifactStore store = storeDataManager.getArtifactStore(key);
if (store == null) {
logger.warn("Attempt to disable missing repo! Skipping.");
return;
}
store = store.copyOf();
int disableTimeout = store.getDisableTimeout();
if (disableTimeout <= TIMEOUT_NEVER_DISABLE) {
logger.debug("Disable-timeout set to {}, will never disable the repo", disableTimeout);
store.setDisabled(false);
} else {
store.setDisabled(true);
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, String.format("Disabling %s due to error: %s\n\nStack Trace:\n %s", key, error, StringUtils.join(error.getStackTrace(), "\n ")));
storeDataManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
logger.warn("{} has been disabled due to store-level error: {}\n Will re-enable in {} seconds.", key, error, disableTimeout == TIMEOUT_USE_DEFAULT ? config.getStoreDisableTimeoutSeconds() : disableTimeout);
// TODO: How is it this doesn't duplicate the event handler method onStoreUpdate()...we're updating the store just above here.
setReEnablementTimeout(key);
}
} catch (IndyDataException e) {
logger.error(String.format("Failed to disable %s on error: %s", key, error), e);
} catch (IndySchedulerException e) {
logger.error(String.format("Failed to schedule re-enablement of %s for retry.", key), e);
}
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class FoloAdminResource method doDelete.
@ApiOperation("Batch delete files uploaded through FOLO trackingID under the given storeKey.")
@ApiResponse(code = 200, message = "Batch delete operation finished.")
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON object, specifying trackingID and storeKey, with other configuration options", required = true, dataType = "org.commonjava.indy.model.core.BatchDeleteRequest")
@Path("/batch/delete")
@POST
@Produces(application_json)
public Response doDelete(@Context final UriInfo uriInfo, final BatchDeleteRequest request) {
String trackingID = request.getTrackingID();
if (trackingID == null || request.getStoreKey() == null) {
Response.ResponseBuilder builder = Response.status(400);
return builder.build();
}
if (request.getPaths() == null || request.getPaths().isEmpty()) {
final String baseUrl = uriInfo.getBaseUriBuilder().path("api").build().toString();
try {
final TrackedContentDTO record = controller.getRecord(trackingID, baseUrl);
if (record == null || record.getUploads().isEmpty()) {
Response.ResponseBuilder builder = Response.status(400);
return builder.build();
}
Set<String> paths = new HashSet<>();
for (TrackedContentEntryDTO entry : record.getUploads()) {
if (!paths.contains(entry.getPath())) {
paths.add(entry.getPath());
}
}
request.setPaths(paths);
} catch (IndyWorkflowException e) {
responseHelper.throwError(e);
}
}
return handler.doDelete(request, new EventMetadata());
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class FoloNPMContentAccessResource method doHead.
@ApiOperation("Store and track file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 200, message = "Header metadata for content (or rendered listing when path ends with '/index.html' or '/'") })
@HEAD
@Path("/{packageName}/{versionTarball: (.*)}")
public Response doHead(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @PathParam("name") final String name, @PathParam("packageName") final String packageName, @PathParam("versionTarball") final String versionTarball, @QueryParam(CHECK_CACHE_ONLY) final Boolean cacheOnly, @Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
final TrackingKey tk = new TrackingKey(id);
EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.NATIVE);
RequestContextHelper.setContext(CONTENT_TRACKING_ID, id);
final String baseUri = getBasePath(uriInfo, id);
final String path = Paths.get(packageName, versionTarball).toString();
return handler.doHead(NPM_PKG_KEY, type, name, path, cacheOnly, baseUri, request, metadata);
}
Aggregations