Search in sources :

Example 36 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class PromotionHelper method clearStoreNFC.

/**
 * Clear NFC for the source store and affected groups.
 *
 * @param sourcePaths The set of paths that need to be cleared from the NFC.
 * @param store The store whose affected groups should have their NFC entries cleared
 */
public void clearStoreNFC(final Set<String> sourcePaths, final ArtifactStore store, final Set<Group> affectedGroups) {
    Set<String> paths = sourcePaths.stream().map(sp -> sp.startsWith("/") && sp.length() > 1 ? sp.substring(1) : sp).collect(Collectors.toSet());
    paths.forEach(path -> {
        ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
        logger.trace("Clearing NFC path: {} from: {}\n\tResource: {}", path, store.getKey(), resource);
        nfc.clearMissing(resource);
    });
    Set<Group> groups;
    if (affectedGroups != null) {
        groups = affectedGroups;
    } else {
        try {
            groups = storeManager.query().getGroupsAffectedBy(store.getKey());
        } catch (IndyDataException e) {
            logger.warn("Failed to clear NFC for groups affected by " + store.getKey(), e);
            return;
        }
    }
    if (groups != null) {
        groups.forEach(group -> {
            KeyedLocation gl = LocationUtils.toLocation(group);
            paths.forEach(path -> {
                ConcreteResource resource = new ConcreteResource(gl, path);
                logger.trace("Clearing NFC path: {} from: {}\n\tResource: {}", path, group.getKey(), resource);
                nfc.clearMissing(resource);
            });
        });
    }
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) PathGauges(org.commonjava.indy.promote.metrics.PathGauges) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) DownloadManager(org.commonjava.indy.content.DownloadManager) StoreKey(org.commonjava.indy.model.core.StoreKey) Location(org.commonjava.maven.galley.model.Location) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) Collectors(java.util.stream.Collectors) ContentManager(org.commonjava.indy.content.ContentManager) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) IGNORE_READONLY(org.commonjava.indy.data.StoreDataManager.IGNORE_READONLY) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource)

Example 37 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class ProxyResponseHelper method getRemoteRepositoryName.

/**
 * if repo with this name already exists, we need to use a different name
 */
private String getRemoteRepositoryName(URL url) throws IndyDataException {
    final String name = repoCreator.formatId(url.getHost(), getPort(url), 0, null, StoreType.remote);
    logger.debug("Looking for remote repo starts with name: {}", name);
    AbstractProxyRepositoryCreator abstractProxyRepositoryCreator = null;
    if (repoCreator instanceof AbstractProxyRepositoryCreator) {
        abstractProxyRepositoryCreator = (AbstractProxyRepositoryCreator) repoCreator;
    }
    if (abstractProxyRepositoryCreator == null) {
        return name;
    }
    Predicate<ArtifactStore> filter = abstractProxyRepositoryCreator.getNameFilter(name);
    List<String> l = storeManager.query().getAllRemoteRepositories(GENERIC_PKG_KEY).stream().filter(filter).map(repository -> repository.getName()).collect(Collectors.toList());
    if (l.isEmpty()) {
        return name;
    }
    return abstractProxyRepositoryCreator.getNextName(l);
}
Also used : ProxyCreationResult(org.commonjava.indy.httprox.handler.ProxyCreationResult) URL(java.net.URL) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) LoggerFactory(org.slf4j.LoggerFactory) PATH(org.commonjava.indy.util.RequestContextHelper.PATH) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StringUtils(org.apache.commons.lang3.StringUtils) PACKAGE_TYPE(org.commonjava.indy.util.RequestContextHelper.PACKAGE_TYPE) Group(org.commonjava.indy.model.core.Group) Transfer(org.commonjava.maven.galley.model.Transfer) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) NameUtils.name(org.commonjava.o11yphant.metrics.util.NameUtils.name) TraceManager.addFieldToActiveSpan(org.commonjava.o11yphant.trace.TraceManager.addFieldToActiveSpan) FoloConstants(org.commonjava.indy.folo.ctl.FoloConstants) AbstractProxyRepositoryCreator(org.commonjava.indy.httprox.handler.AbstractProxyRepositoryCreator) ApplicationHeader(org.commonjava.indy.util.ApplicationHeader) MetricsManager(org.commonjava.o11yphant.metrics.MetricsManager) GENERIC_PKG_KEY(org.commonjava.indy.model.core.GenericPackageTypeDescriptor.GENERIC_PKG_KEY) ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) TRACKING_ID(org.commonjava.indy.model.core.ArtifactStore.TRACKING_ID) ArtifactStoreQuery(org.commonjava.indy.data.ArtifactStoreQuery) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ProxyRepositoryCreator(org.commonjava.indy.httprox.handler.ProxyRepositoryCreator) Predicate(java.util.function.Predicate) TraceManager(org.commonjava.o11yphant.trace.TraceManager) StoreType(org.commonjava.indy.model.core.StoreType) AccessChannel(org.commonjava.indy.model.core.AccessChannel) IOException(java.io.IOException) CONTENT_ENTRY_POINT(org.commonjava.indy.util.RequestContextHelper.CONTENT_ENTRY_POINT) METADATA_CONTENT(org.commonjava.indy.util.RequestContextHelper.METADATA_CONTENT) HttpRequest(org.apache.http.HttpRequest) IndyMetricsConfig(org.commonjava.indy.subsys.metrics.conf.IndyMetricsConfig) Collectors(java.util.stream.Collectors) PKG_TYPE_GENERIC_HTTP(org.commonjava.maven.galley.io.SpecialPathConstants.PKG_TYPE_GENERIC_HTTP) RequestContextHelper.setContext(org.commonjava.indy.util.RequestContextHelper.setContext) Timer(org.commonjava.o11yphant.metrics.api.Timer) List(java.util.List) HttproxConfig(org.commonjava.indy.httprox.conf.HttproxConfig) ContentController(org.commonjava.indy.core.ctl.ContentController) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) UserPass(org.commonjava.indy.subsys.http.util.UserPass) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) UrlInfo(org.commonjava.indy.util.UrlInfo) TransferException(org.commonjava.maven.galley.TransferException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) AbstractProxyRepositoryCreator(org.commonjava.indy.httprox.handler.AbstractProxyRepositoryCreator)

Example 38 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class DeprecatedStoreAdminHandler method getAll.

@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
    String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type).toString();
    Consumer<Response.ResponseBuilder> modifier = (rb) -> responseHelper.markDeprecated(rb, altPath);
    final StoreType st = StoreType.get(type);
    Response response;
    try {
        final List<ArtifactStore> stores = adminController.getAllOfType(st);
        logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
        final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
        response = responseHelper.formatOkResponseWithJsonEntity(dto, modifier);
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = responseHelper.formatResponse(e, modifier);
    }
    return response;
}
Also used : Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) ApiOperation(io.swagger.annotations.ApiOperation) Consumes(javax.ws.rs.Consumes) Response.noContent(javax.ws.rs.core.Response.noContent) Response.status(javax.ws.rs.core.Response.status) URI(java.net.URI) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) StoreKey(org.commonjava.indy.model.core.StoreKey) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) Response.notModified(javax.ws.rs.core.Response.notModified) IOUtils(org.apache.commons.io.IOUtils) ApplicationContent(org.commonjava.indy.util.ApplicationContent) List(java.util.List) Response(javax.ws.rs.core.Response) Response.ok(javax.ws.rs.core.Response.ok) ApplicationScoped(javax.enterprise.context.ApplicationScoped) UriInfo(javax.ws.rs.core.UriInfo) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) HEAD(javax.ws.rs.HEAD) PathParam(javax.ws.rs.PathParam) REST(org.commonjava.indy.bind.jaxrs.util.REST) GET(javax.ws.rs.GET) ApplicationContent.application_json(org.commonjava.indy.util.ApplicationContent.application_json) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) SecurityManager(org.commonjava.indy.bind.jaxrs.SecurityManager) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) METADATA_CHANGELOG(org.commonjava.indy.model.core.ArtifactStore.METADATA_CHANGELOG) IOException(java.io.IOException) Consumer(java.util.function.Consumer) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) AdminController(org.commonjava.indy.core.ctl.AdminController) PUT(javax.ws.rs.PUT) InputStream(java.io.InputStream) StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 39 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class StoreAdminHandler method create.

@ApiOperation("Create a new store")
@ApiResponses({ @ApiResponse(code = 201, response = ArtifactStore.class, message = "The store was created"), @ApiResponse(code = 409, message = "A store with the specified type and name already exists") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.model.core.ArtifactStore", value = "The artifact store definition JSON") })
@POST
@Consumes(ApplicationContent.application_json)
@Produces(ApplicationContent.application_json)
public Response create(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @Context final UriInfo uriInfo, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
    final StoreType st = StoreType.get(type);
    Response response = null;
    String json = null;
    try {
        json = IOUtils.toString(request.getInputStream());
        // logger.warn("=> JSON: " + json);
        json = objectMapper.patchLegacyStoreJson(json);
    } catch (final IOException e) {
        final String message = "Failed to read " + st.getStoreClass().getSimpleName() + " from request body.";
        logger.error(message, e);
        response = responseHelper.formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    ArtifactStore store = null;
    try {
        store = objectMapper.readValue(json, st.getStoreClass());
    } catch (final IOException e) {
        final String message = "Failed to parse " + st.getStoreClass().getSimpleName() + " from request body.";
        logger.error(message, e);
        response = responseHelper.formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    logger.info("\n\nGot artifact store: {}\n\n", store);
    try {
        String user = securityManager.getUser(securityContext, request);
        if (adminController.store(store, user, false)) {
            final URI uri = uriInfo.getBaseUriBuilder().path("/api/admin/stores").path(store.getPackageType()).path(store.getType().singularEndpointName()).build(store.getName());
            response = responseHelper.formatCreatedResponseWithJsonEntity(uri, store);
        } else {
            response = status(CONFLICT).entity("{\"error\": \"Store already exists.\"}").type(application_json).build();
        }
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) IOException(java.io.IOException) URI(java.net.URI) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 40 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class StoreAdminHandler method revalidateArtifactStores.

@ApiOperation("Revalidation of Artifacts Stored on demand")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repositories was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/revalidate/all/")
@POST
public Response revalidateArtifactStores(@PathParam("packageType") String packageType, @PathParam("type") String type) {
    ArtifactStoreValidateData result = null;
    Map<String, ArtifactStoreValidateData> results = new HashMap<>();
    Response response;
    try {
        StoreType storeType = StoreType.get(type);
        List<ArtifactStore> allArtifactStores = adminController.getAllOfType(packageType, storeType);
        for (ArtifactStore artifactStore : allArtifactStores) {
            // Validate this Store
            result = adminController.validateStore(artifactStore);
            results.put(artifactStore.getKey().toString(), result);
        }
        response = responseHelper.formatOkResponseWithJsonEntity(results);
    } catch (IndyDataException ide) {
        logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
        response = responseHelper.formatResponse(ide);
    } catch (MalformedURLException mue) {
        logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
        response = responseHelper.formatResponse(mue);
    } catch (IndyWorkflowException iwe) {
        logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
        response = responseHelper.formatResponse(iwe);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)168 IndyDataException (org.commonjava.indy.data.IndyDataException)90 StoreKey (org.commonjava.indy.model.core.StoreKey)83 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)54 Logger (org.slf4j.Logger)45 ArrayList (java.util.ArrayList)43 Group (org.commonjava.indy.model.core.Group)42 StoreType (org.commonjava.indy.model.core.StoreType)38 Transfer (org.commonjava.maven.galley.model.Transfer)38 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)33 IOException (java.io.IOException)29 HashSet (java.util.HashSet)29 List (java.util.List)28 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)26 LoggerFactory (org.slf4j.LoggerFactory)25 StoreDataManager (org.commonjava.indy.data.StoreDataManager)24 Set (java.util.Set)23 Inject (javax.inject.Inject)22 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17