Search in sources :

Example 56 with EventMetadata

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);
                }
            }
        });
    }
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactStoreEnablementEvent(org.commonjava.indy.change.event.ArtifactStoreEnablementEvent) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) EventUtils.fireEvent(org.commonjava.indy.change.EventUtils.fireEvent) Map(java.util.Map) ArtifactStoreDeletePostEvent(org.commonjava.indy.change.event.ArtifactStoreDeletePostEvent) CoreEventManagerConstants(org.commonjava.indy.change.event.CoreEventManagerConstants) DownloadManager(org.commonjava.indy.content.DownloadManager) ArtifactStoreDeletePreEvent(org.commonjava.indy.change.event.ArtifactStoreDeletePreEvent) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreEventDispatcher(org.commonjava.indy.data.StoreEventDispatcher) Event(javax.enterprise.event.Event) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Executor(java.util.concurrent.Executor) Collectors(java.util.stream.Collectors) List(java.util.List) ArtifactStorePreUpdateEvent(org.commonjava.indy.change.event.ArtifactStorePreUpdateEvent) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ArtifactStoreUpdateType(org.commonjava.indy.change.event.ArtifactStoreUpdateType) ArtifactStorePostUpdateEvent(org.commonjava.indy.change.event.ArtifactStorePostUpdateEvent) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) HashMap(java.util.HashMap) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey) ArtifactStoreDeletePostEvent(org.commonjava.indy.change.event.ArtifactStoreDeletePostEvent)

Example 57 with EventMetadata

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);
    }
}
Also used : Arrays(java.util.Arrays) HTTP_METADATA_EXT(org.commonjava.maven.galley.io.SpecialPathConstants.HTTP_METADATA_EXT) ContentDigester(org.commonjava.indy.content.ContentDigester) GroupRepositoryFilterManager(org.commonjava.indy.core.content.group.GroupRepositoryFilterManager) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CHECK_CACHE_ONLY(org.commonjava.indy.IndyContentConstants.CHECK_CACHE_ONLY) LoggerFactory(org.slf4j.LoggerFactory) ContentUtils.dedupeListing(org.commonjava.indy.util.ContentUtils.dedupeListing) StringUtils(org.apache.commons.lang3.StringUtils) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) TransferManager(org.commonjava.maven.galley.TransferManager) CASCADE(org.commonjava.indy.IndyContentConstants.CASCADE) DownloadManager(org.commonjava.indy.content.DownloadManager) ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreType.group(org.commonjava.indy.model.core.StoreType.group) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) IOException(java.io.IOException) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) Collectors(java.util.stream.Collectors) ContentManager(org.commonjava.indy.content.ContentManager) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IGNORE_READONLY(org.commonjava.indy.data.StoreDataManager.IGNORE_READONLY) IndyConfiguration(org.commonjava.indy.conf.IndyConfiguration) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreResource(org.commonjava.indy.content.StoreResource) StoreType.hosted(org.commonjava.indy.model.core.StoreType.hosted) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) HttpExchangeMetadata(org.commonjava.maven.galley.transport.htcli.model.HttpExchangeMetadata) InputStream(java.io.InputStream) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 58 with EventMetadata

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);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) IndySchedulerException(org.commonjava.indy.core.expire.IndySchedulerException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 59 with EventMetadata

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());
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) HashSet(java.util.HashSet) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) ApiResponse(io.swagger.annotations.ApiResponse)

Example 60 with 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);
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

EventMetadata (org.commonjava.maven.galley.event.EventMetadata)154 Transfer (org.commonjava.maven.galley.model.Transfer)65 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)49 Test (org.junit.Test)47 IndyDataException (org.commonjava.indy.data.IndyDataException)44 StoreKey (org.commonjava.indy.model.core.StoreKey)40 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)38 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)37 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)35 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)28 Group (org.commonjava.indy.model.core.Group)26 ApiOperation (io.swagger.annotations.ApiOperation)23 Path (javax.ws.rs.Path)23 Logger (org.slf4j.Logger)23 ApiResponses (io.swagger.annotations.ApiResponses)22 IOException (java.io.IOException)21 InputStream (java.io.InputStream)20 HostedRepository (org.commonjava.indy.model.core.HostedRepository)20 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)20 ArrayList (java.util.ArrayList)18