Search in sources :

Example 61 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class FoloNPMContentAccessResource method doGet.

@ApiOperation("Retrieve and track NPM file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 200, response = String.class, message = "Rendered content listing (when path ends with '/index.html' or '/')"), @ApiResponse(code = 200, response = StreamingOutput.class, message = "Content stream") })
@GET
@Path("/{packageName}/{versionTarball: (.*)}")
public Response doGet(@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, @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 path = Paths.get(packageName, versionTarball).toString();
    final String baseUri = getBasePath(uriInfo, id);
    return handler.doGet(NPM_PKG_KEY, type, name, path, baseUri, request, metadata);
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 62 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class PackageMetadataGeneratorTest method generateMetadataWhenMissingForScoped.

@Test
public void generateMetadataWhenMissingForScoped() throws Exception {
    ChangeSummary summary = new ChangeSummary("test", "Init NPM hosted repo.");
    final HostedRepository hostedRepository = new HostedRepository(NPM_PKG_KEY, "npm-builds");
    initStore(hostedRepository, summary);
    final KeyedLocation location = LocationUtils.toLocation(hostedRepository);
    storeFile(location, "@babel/core/-/core-7.7.5.tgz", "tarball/version-1.tgz");
    storeFile(location, "@babel/core/-/core-7.7.7.tgz", "tarball/version-2.tgz");
    storeFile(location, "@babel/core/7.7.5", "metadata/scoped-version-1.json");
    storeFile(location, "@babel/core/7.7.7", "metadata/scoped-version-2.json");
    final String babelCoreMetadataPath = "@babel/core/package.json";
    // Check the package metadata before generation.
    Transfer before = fileManager.retrieve(hostedRepository, babelCoreMetadataPath);
    assertNull(before);
    Transfer metadataFile = generator.generateFileContent(hostedRepository, babelCoreMetadataPath, new EventMetadata());
    assertNotNull(metadataFile);
    verifyScopedMetadata(metadataFile);
    // Check the package metadata after generation.
    Transfer after = fileManager.retrieve(hostedRepository, babelCoreMetadataPath);
    assertNotNull(after);
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 63 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class PackageStoreListener method doClear.

private boolean doClear(final ArtifactStore store, final String path) throws IOException {
    boolean isCleared = false;
    logger.info("Updating merged package metadata file: {} in store: {}", path, store);
    final Transfer[] toDelete = { fileManager.getStorageReference(store, path), fileManager.getStorageReference(store, path + GroupMergeHelper.MERGEINFO_SUFFIX) };
    for (final Transfer item : toDelete) {
        logger.info("Attempting to delete: {}", item);
        if (item.exists()) {
            boolean result = false;
            try {
                result = fileManager.delete(store, item.getPath(), new EventMetadata().set(StoreDataManager.IGNORE_READONLY, true));
            } catch (IndyWorkflowException e) {
                logger.warn("Deletion failed for package metadata clear, transfer is {}, failed reason:{}", item, e.getMessage());
            }
            logger.info("Deleted: {} (success? {})", item, result);
            if (item.getPath().endsWith(NPM_METADATA_NAME)) {
                isCleared = result;
            }
            if (fileEvent != null) {
                logger.trace("Firing deletion event for: {}", item);
                fileEvent.fire(new FileDeletionEvent(item, new EventMetadata()));
            }
        } else if (item.getPath().endsWith(NPM_METADATA_NAME)) {
            // we should return true here to trigger cache cleaning, because file not exists in store does not mean
            // metadata not exists in cache.
            logger.debug("Package metadata clean for {}: metadata not existed in store, so skipped deletion and mark as deleted", item);
            return true;
        }
    }
    return isCleared;
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) FileDeletionEvent(org.commonjava.maven.galley.event.FileDeletionEvent) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 64 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class MavenContentAccessResource method doDelete.

@Override
@ApiOperation("Delete Maven artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 204, message = "Content was deleted successfully") })
@DELETE
@Path("/{path: (.*)}")
public Response doDelete(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @PathParam("path") final String path, @ApiParam(name = CHECK_CACHE_ONLY, value = "true or false") @QueryParam(CHECK_CACHE_ONLY) final Boolean cacheOnly) {
    EventMetadata metadata = new EventMetadata();
    metadata.set(CHECK_CACHE_ONLY, cacheOnly);
    return handler.doDelete(MAVEN_PKG_KEY, type, name, path, metadata);
}
Also used : EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 65 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class MavenContentAccessResource method doCreate.

@Override
@ApiOperation("Store Maven 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(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @PathParam("path") final String path, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
    final EventMetadata metadata = new EventMetadata().set(STORE_HTTP_HEADERS, RequestUtils.extractRequestHeadersToMap(request));
    Class cls = MavenContentAccessResource.class;
    return handler.doCreate(MAVEN_PKG_KEY, type, name, path, request, metadata, () -> uriInfo.getBaseUriBuilder().path(cls).path(path).build(MAVEN_PKG_KEY, type, name));
}
Also used : 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)

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