Search in sources :

Example 46 with EventMetadata

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

the class DeprecatedContentAccessResource method doHead.

@ApiOperation("Store 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("/{path: (.*)}")
public Response doHead(@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, @QueryParam(CHECK_CACHE_ONLY) final Boolean cacheOnly, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
    String packageType = MavenPackageTypeDescriptor.MAVEN_PKG_KEY;
    final String baseUri = uriInfo.getBaseUriBuilder().path(IndyDeployment.API_PREFIX).build().toString();
    final Consumer<Response.ResponseBuilder> deprecated = builder -> {
        String alt = Paths.get("/api/maven", type, name, path).toString();
        responseHelper.markDeprecated(builder, alt);
    };
    return handler.doHead(packageType, type, name, path, cacheOnly, baseUri, request, new EventMetadata(), deprecated);
}
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) 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) HttpServletRequest(javax.servlet.http.HttpServletRequest) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) QueryParam(javax.ws.rs.QueryParam) Api(io.swagger.annotations.Api) URI(java.net.URI) STORE_HTTP_HEADERS(org.commonjava.maven.galley.spi.cache.CacheProvider.STORE_HTTP_HEADERS) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) RequestUtils(org.commonjava.indy.core.bind.jaxrs.util.RequestUtils) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) StreamingOutput(javax.ws.rs.core.StreamingOutput) Consumer(java.util.function.Consumer) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ApplicationScoped(javax.enterprise.context.ApplicationScoped) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) HEAD(javax.ws.rs.HEAD) 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)

Example 47 with EventMetadata

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

the class DeprecatedContentAccessResource method doCreate.

@ApiOperation("Store 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(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) {
    String packageType = MavenPackageTypeDescriptor.MAVEN_PKG_KEY;
    final Supplier<URI> uriSupplier = () -> uriInfo.getBaseUriBuilder().path(getClass()).path(path).build(packageType, type, name);
    final Consumer<Response.ResponseBuilder> deprecated = builder -> {
        String alt = Paths.get("/api/maven", type, name, path).toString();
        responseHelper.markDeprecated(builder, alt);
    };
    final EventMetadata metadata = new EventMetadata().set(STORE_HTTP_HEADERS, RequestUtils.extractRequestHeadersToMap(request));
    return handler.doCreate(packageType, type, name, path, request, metadata, uriSupplier, deprecated);
}
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) 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) HttpServletRequest(javax.servlet.http.HttpServletRequest) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) QueryParam(javax.ws.rs.QueryParam) Api(io.swagger.annotations.Api) URI(java.net.URI) STORE_HTTP_HEADERS(org.commonjava.maven.galley.spi.cache.CacheProvider.STORE_HTTP_HEADERS) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) RequestUtils(org.commonjava.indy.core.bind.jaxrs.util.RequestUtils) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) StreamingOutput(javax.ws.rs.core.StreamingOutput) Consumer(java.util.function.Consumer) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ApplicationScoped(javax.enterprise.context.ApplicationScoped) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) HEAD(javax.ws.rs.HEAD) URI(java.net.URI) 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 48 with EventMetadata

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

the class GroupDataManagerTCK method seedRepositoriesForGroupTests.

protected void seedRepositoriesForGroupTests() throws Exception {
    manager = getFixtureProvider().getDataManager();
    manager.storeArtifactStore(new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo1.maven.apache.org/maven2/"), summary, false, false, new EventMetadata());
    manager.storeArtifactStore(new RemoteRepository(MAVEN_PKG_KEY, "repo2", "http://repo1.maven.org/maven2/"), summary, false, false, new EventMetadata());
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 49 with EventMetadata

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

the class KojiRepairManager method repairPathMask.

public KojiRepairResult repairPathMask(KojiRepairRequest request, String user, boolean skipLock) throws KojiRepairException {
    KojiRepairResult ret = new KojiRepairResult(request);
    if (skipLock || opLock.tryLock()) {
        try {
            ArtifactStore store = getRequestedStore(request, ret);
            if (store == null) {
                return ret;
            }
            store = store.copyOf();
            StoreKey remoteKey = request.getSource();
            if (remoteKey.getType() == remote) {
                final String nvr = kojiUtils.getBuildNvr(remoteKey);
                if (nvr == null) {
                    String error = String.format("Not a koji store: %s", remoteKey);
                    return ret.withError(error);
                }
                try {
                    KojiSessionInfo session = null;
                    KojiBuildInfo build = kojiCachedClient.getBuildInfo(nvr, session);
                    List<KojiArchiveInfo> archives = kojiCachedClient.listArchivesForBuild(build.getId(), session);
                    ArtifactRef artifactRef = SimpleArtifactRef.parse(store.getMetadata(CREATION_TRIGGER_GAV));
                    if (artifactRef == null) {
                        String error = String.format("Koji remote repository: %s does not have %s metadata. Cannot retrieve accurate path masks.", remoteKey, CREATION_TRIGGER_GAV);
                        return ret.withError(error);
                    }
                    // set pathMaskPatterns using build output paths
                    Set<String> patterns = kojiPathFormatter.getPatterns(store.getKey(), artifactRef, archives, true);
                    logger.debug("For repo: {}, resetting path_mask_patterns to:\n\n{}\n\n", store.getKey(), patterns);
                    KojiRepairResult.RepairResult repairResult = new KojiRepairResult.RepairResult(remoteKey);
                    repairResult.withPropertyChange("path_mask_patterns", store.getPathMaskPatterns(), patterns);
                    ret.withResult(repairResult);
                    store.setPathMaskPatterns(patterns);
                    final ChangeSummary changeSummary = new ChangeSummary(user, "Repairing remote repository path masks to Koji build: " + build.getNvr());
                    storeManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
                } catch (KojiClientException e) {
                    String error = String.format("Cannot getBuildInfo: %s, error: %s", remoteKey, e);
                    logger.debug(error, e);
                    return ret.withError(error, e);
                } catch (IndyDataException e) {
                    String error = String.format("Failed to store changed remote repository: %s, error: %s", remoteKey, e);
                    logger.debug(error, e);
                    return ret.withError(error, e);
                }
            } else {
                String error = String.format("Not a remote koji repository: %s", remoteKey);
                return ret.withError(error);
            }
        } finally {
            if (!skipLock) {
                opLock.unlock();
            }
        }
    } else {
        throw new KojiRepairException("Koji repair manager is busy.");
    }
    return ret;
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) KojiClientException(com.redhat.red.build.koji.KojiClientException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo)

Example 50 with EventMetadata

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

the class ImpliedRepositoryDetector method updateExistingGroups.

private boolean updateExistingGroups(final ImplicationsJob job) {
    final StoreKey key = job.store.getKey();
    boolean anyChanged = false;
    try {
        final Set<Group> groups = storeManager.query().getGroupsContaining(key);
        if (groups != null) {
            logger.debug("{} groups contain: {}\n  {}", groups.size(), key, new JoinString("\n  ", groups));
            final String message = String.format("Adding repositories implied by: %s\n\n  %s", key, StringUtils.join(job.implied, "\n  "));
            final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, message);
            for (final Group g : groups) {
                if (config.isEnabledForGroup(g.getName())) {
                    Group group = g.copyOf();
                    boolean changed = false;
                    for (final ArtifactStore implied : job.implied) {
                        boolean groupChanged = group.addConstituent(implied);
                        changed = groupChanged || changed;
                        logger.debug("After attempting to add: {} to group: {}, changed status is: {}", implied, group, changed);
                    }
                    if (changed) {
                        storeManager.storeArtifactStore(group, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_REPOS, job.implied));
                    }
                    anyChanged = changed || anyChanged;
                }
            }
        }
    } catch (final IndyDataException e) {
        logger.error("Failed to lookup groups containing: " + key, e);
    }
    return anyChanged;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

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