Search in sources :

Example 96 with EventMetadata

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

the class DeprecatedFoloContentAccessResource 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(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);
    final Supplier<URI> uriSupplier = () -> uriInfo.getBaseUriBuilder().path(getClass()).path(path).build(id, type, name);
    final Consumer<Response.ResponseBuilder> deprecation = builder -> {
        String alt = Paths.get("/api/folo/track/", id, MAVEN_PKG_KEY, type, name, path).toString();
        responseHelper.markDeprecated(builder, alt);
    };
    return handler.doCreate(MAVEN_PKG_KEY, type, name, path, request, metadata, uriSupplier, deprecation);
}
Also used : PathParam(javax.ws.rs.PathParam) IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) REST(org.commonjava.indy.bind.jaxrs.util.REST) CHECK_CACHE_ONLY(org.commonjava.indy.IndyContentConstants.CHECK_CACHE_ONLY) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryParam(javax.ws.rs.QueryParam) Api(io.swagger.annotations.Api) URI(java.net.URI) ACCESS_CHANNEL(org.commonjava.indy.folo.ctl.FoloConstants.ACCESS_CHANNEL) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) ContentAccessHandler(org.commonjava.indy.core.bind.jaxrs.ContentAccessHandler) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) AccessChannel(org.commonjava.indy.model.core.AccessChannel) StreamingOutput(javax.ws.rs.core.StreamingOutput) Consumer(java.util.function.Consumer) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) TRACKING_KEY(org.commonjava.indy.folo.ctl.FoloConstants.TRACKING_KEY) ApiResponse(io.swagger.annotations.ApiResponse) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) HEAD(javax.ws.rs.HEAD) URI(java.net.URI) 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 97 with EventMetadata

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

the class FoloMavenContentAccessResource 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(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.NATIVE).set(STORE_HTTP_HEADERS, RequestUtils.extractRequestHeadersToMap(request));
    Class cls = FoloMavenContentAccessResource.class;
    return handler.doCreate(PKG_TYPE_MAVEN, type, name, path, request, metadata, () -> uriInfo.getBaseUriBuilder().path(cls).path(path).build(id, PKG_TYPE_MAVEN, 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 98 with EventMetadata

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

the class FoloNPMContentAccessResource method doCreate.

@ApiOperation("Store NPM artifact content under the given artifact store (type/name), packageName and versionTarball (/version or /-/tarball).")
@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("/{packageName}/{versionTarball: (.*)}")
public Response doCreate(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @PathParam("packageName") final String packageName, @PathParam("versionTarball") final String versionTarball, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
    final TrackingKey tk = new TrackingKey(id);
    EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.NATIVE);
    final String path = Paths.get(packageName, versionTarball).toString();
    Class cls = FoloNPMContentAccessResource.class;
    return handler.doCreate(NPM_PKG_KEY, type, name, path, request, metadata, () -> uriInfo.getBaseUriBuilder().path(cls).path(path).build(NPM_PKG_KEY, 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 99 with EventMetadata

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

the class AdminController method delete.

public void delete(final StoreKey key, final String user, final String changelog, final boolean deleteContent) throws IndyWorkflowException {
    // safe check
    if (deleteContent) {
        if (!key.getName().matches(indyConfiguration.getDisposableStorePattern())) {
            throw new IndyWorkflowException(ApplicationStatus.FORBIDDEN.code(), "Content deletion not allowed");
        }
    }
    try {
        ArtifactStore store = storeManager.getArtifactStore(key);
        if (store != null && deleteContent) {
            logger.info("Delete content of {}", key);
            deleteContent(store);
        }
        storeManager.deleteArtifactStore(key, new ChangeSummary(user, changelog), new EventMetadata());
    } catch (final IndyDataException e) {
        int status = ApplicationStatus.SERVER_ERROR.code();
        if (e.getStatus() > 0) {
            status = e.getStatus();
        }
        throw new IndyWorkflowException(status, "Failed to delete: {}. Reason: {}", e, key, e.getMessage());
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 100 with EventMetadata

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

the class ReplicationController method replicate.

public Set<StoreKey> replicate(final ReplicationDTO dto, final String user) throws IndyWorkflowException {
    final ReplicationRepositoryCreator creator = createRepoCreator();
    if (creator == null) {
        throw new IndyWorkflowException(500, "Cannot replicate; ReplicationRepositoryCreator could not be instantiated.");
    }
    try {
        dto.validate();
    } catch (final IndyException e) {
        throw new IndyWorkflowException("Invalid replication request DTO: %s", e, e.getMessage());
    }
    List<? extends ArtifactStore> remoteStores = null;
    List<EndpointView> remoteEndpoints = null;
    final boolean overwrite = dto.isOverwrite();
    final Set<StoreKey> replicated = new HashSet<StoreKey>();
    for (final ReplicationAction action : dto) {
        if (action == null) {
            continue;
        }
        logger.info("Processing replication action:\n\n  {}\n\nin DTO: {}\n\n", action, dto);
        final String include = action.getInclude();
        final String exclude = action.getExclude();
        try {
            if (action.getType() == ActionType.PROXY) {
                if (remoteEndpoints == null) {
                    remoteEndpoints = getEndpoints(dto);
                }
                for (final EndpointView view : remoteEndpoints) {
                    final String key = "remote-" + view.getType() + "_" + view.getName();
                    if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
                        final StoreKey sk = new StoreKey(StoreType.remote, key);
                        if (overwrite || !data.hasArtifactStore(sk)) {
                            RemoteRepository repo = creator.createRemoteRepository(key, view);
                            repo.setMetadata(ArtifactStore.METADATA_ORIGIN, REPLICATION_ORIGIN);
                            setProxyAttributes(repo, action);
                            data.storeArtifactStore(repo, new ChangeSummary(user, "REPLICATION: Proxying remote indy repository: " + view.getResourceUri()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
                            replicated.add(repo.getKey());
                        }
                    }
                }
            } else if (action.getType() == ActionType.MIRROR) {
                if (remoteStores == null) {
                    remoteStores = getRemoteStores(dto);
                }
                for (final ArtifactStore store : remoteStores) {
                    final String key = store.getKey().toString();
                    if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
                        if (overwrite || !data.hasArtifactStore(store.getKey())) {
                            if (store instanceof RemoteRepository) {
                                setProxyAttributes(((RemoteRepository) store), action);
                            }
                            data.storeArtifactStore(store, new ChangeSummary(user, "REPLICATION: Mirroring remote indy store: " + store.getKey()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
                            replicated.add(store.getKey());
                        }
                    }
                }
            }
        } catch (final IndyDataException e) {
            logger.error(e.getMessage(), e);
            throw new IndyWorkflowException(e.getMessage(), e);
        }
    }
    return replicated;
}
Also used : EndpointView(org.commonjava.indy.model.core.dto.EndpointView) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyException(org.commonjava.indy.IndyException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ReplicationAction(org.commonjava.indy.model.core.dto.ReplicationAction) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HashSet(java.util.HashSet)

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