Search in sources :

Example 1 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloContentAccessResource method doCreate.

@ApiOperation("Store and track file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 201, message = "Content was stored successfully"), @ApiResponse(code = 400, message = "No appropriate storage location was found in the specified store (this store, or a member if a group is specified).") })
@PUT
@Path("/{path: (.*)}")
public Response doCreate(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam("Package type (eg. maven, npm)") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @PathParam("name") final String name, @PathParam("path") final String path, @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.MAVEN_REPO);
    return handler.doCreate(packageType, type, name, path, request, metadata, () -> uriInfo.getBaseUriBuilder().path(getClass()).path(path).build(id, packageType, type, name));
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 2 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloBackupListener method onCacheEntryRemoved.

@CacheEntryRemoved
public void onCacheEntryRemoved(final CacheEntryRemovedEvent<TrackingKey, TrackedContent> event) {
    if (event.isPre()) {
        return;
    }
    TrackingKey key = event.getKey();
    logger.debug("Cache entry with key {} removed in cache {}", key, event.getCache());
    adminController.removeFromSerialized(key);
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved)

Example 3 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloChecksumAdvisor method getChecksumWriteAdvice.

@Override
public Optional<ChecksummingDecoratorAdvisor.ChecksumAdvice> getChecksumWriteAdvice(final Transfer transfer, final TransferOperation operation, final EventMetadata eventMetadata) {
    final TrackingKey trackingKey = (TrackingKey) eventMetadata.get(FoloConstants.TRACKING_KEY);
    if (trackingKey == null) {
        return Optional.empty();
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Enabling checksumming for {} of: {} with tracking key: {}", operation, transfer, trackingKey);
    return Optional.of(CALCULATE_NO_WRITE);
}
Also used : Logger(org.slf4j.Logger) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 4 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloAdminController method recalculateRecord.

public TrackedContentDTO recalculateRecord(final String id, final String baseUrl) throws IndyWorkflowException {
    TrackingKey trackingKey = new TrackingKey(id);
    TrackedContent record = recordManager.get(trackingKey);
    AtomicBoolean failed = new AtomicBoolean(false);
    Set<TrackedContentEntry> recalculatedUploads = recalculateEntrySet(record.getUploads(), id, failed);
    Set<TrackedContentEntry> recalculatedDownloads = null;
    if (!failed.get()) {
        recalculatedDownloads = recalculateEntrySet(record.getDownloads(), id, failed);
    }
    if (failed.get()) {
        throw new IndyWorkflowException("Failed to recalculate tracking record: %s. See Indy logs for more information", id);
    }
    TrackedContent recalculated = new TrackedContent(record.getKey(), recalculatedUploads, recalculatedDownloads);
    recordManager.replaceTrackingRecord(recalculated);
    return constructContentDTO(recalculated, baseUrl);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) FoloUtils.zipTrackedContent(org.commonjava.indy.folo.FoloUtils.zipTrackedContent) FoloUtils.backupTrackedContent(org.commonjava.indy.folo.FoloUtils.backupTrackedContent) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 5 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloAdminController method renderRepositoryZip.

public File renderRepositoryZip(final String id) throws IndyWorkflowException {
    final TrackingKey tk = new TrackingKey(id);
    File file = filer.getRepositoryZipFile(tk).getDetachedFile();
    file.getParentFile().mkdirs();
    logger.debug("Retrieving tracking record for: {}", tk);
    final TrackedContent record = recordManager.get(tk);
    logger.debug("Got: {}", record);
    if (record == null) {
        throw new IndyWorkflowException(ApplicationStatus.NOT_FOUND.code(), "No tracking record available for: %s. Maybe you forgot to seal it?", tk);
    }
    final Set<String> seenPaths = new HashSet<>();
    final List<Transfer> items = new ArrayList<>();
    addTransfers(record.getUploads(), items, id, seenPaths);
    addTransfers(record.getDownloads(), items, id, seenPaths);
    logger.debug("Retrieved {} files. Creating zip.", items.size());
    Collections.sort(items, (f, s) -> f.getPath().compareTo(s.getPath()));
    try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(file))) {
        for (final Transfer item : items) {
            // logger.info( "Adding: {}", item );
            if (item != null) {
                final String path = item.getPath();
                final ZipEntry ze = new ZipEntry(path);
                stream.putNextEntry(ze);
                InputStream itemStream = null;
                try {
                    itemStream = item.openInputStream();
                    copy(itemStream, stream);
                } finally {
                    closeQuietly(itemStream);
                }
            }
        }
    } catch (final IOException e) {
        throw new IndyWorkflowException("Failed to generate repository zip from tracking record: {}. Reason: {}", e, id, e.getMessage());
    }
    return file;
}
Also used : FoloUtils.toInputStream(org.commonjava.indy.folo.FoloUtils.toInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) ZipOutputStream(java.util.zip.ZipOutputStream) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) FileOutputStream(java.io.FileOutputStream) FoloUtils.zipTrackedContent(org.commonjava.indy.folo.FoloUtils.zipTrackedContent) FoloUtils.backupTrackedContent(org.commonjava.indy.folo.FoloUtils.backupTrackedContent) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) Transfer(org.commonjava.maven.galley.model.Transfer) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

TrackingKey (org.commonjava.indy.folo.model.TrackingKey)46 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Path (javax.ws.rs.Path)12 StoreKey (org.commonjava.indy.model.core.StoreKey)11 Test (org.junit.Test)11 TrackedContent (org.commonjava.indy.folo.model.TrackedContent)10 TrackedContentEntry (org.commonjava.indy.folo.model.TrackedContentEntry)10 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)8 GET (javax.ws.rs.GET)6 HEAD (javax.ws.rs.HEAD)6 PUT (javax.ws.rs.PUT)6 AccessChannel (org.commonjava.indy.model.core.AccessChannel)6 Inject (javax.inject.Inject)4 Context (javax.ws.rs.core.Context)4 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)4 Location (org.commonjava.maven.galley.model.Location)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 Logger (org.slf4j.Logger)4