Search in sources :

Example 1 with StoreType

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

the class NfcResource method deprecatedGetStore.

@Path("/{type: (hosted|group|remote)}/{name}")
@ApiOperation("[Deprecated] Retrieve all not-found cache entries currently tracked for a given store")
@ApiResponses({ @ApiResponse(code = 200, response = NotFoundCacheDTO.class, message = "The not-found cache for the specified artifact store") })
@GET
@Produces(ApplicationContent.application_json)
public Response deprecatedGetStore(@ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", value = "The name of the store") @PathParam("name") final String name) {
    Response response;
    final StoreType type = StoreType.get(t);
    String altPath = Paths.get("/api/nfc", MAVEN_PKG_KEY, type.singularEndpointName(), name).toString();
    final StoreKey key = new StoreKey(type, name);
    try {
        final NotFoundCacheDTO dto = controller.getMissing(key);
        response = formatOkResponseWithJsonEntity(dto, serializer, rb -> markDeprecated(rb, altPath));
    } catch (final IndyWorkflowException e) {
        response = formatResponse(e, (rb) -> markDeprecated(rb, altPath));
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) PathParam(javax.ws.rs.PathParam) NfcController(org.commonjava.indy.core.ctl.NfcController) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) StringUtils.isNotEmpty(org.apache.commons.lang.StringUtils.isNotEmpty) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ResponseUtils.formatOkResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatOkResponseWithJsonEntity) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Api(io.swagger.annotations.Api) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) DELETE(javax.ws.rs.DELETE) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) ApplicationContent(org.commonjava.indy.util.ApplicationContent) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with StoreType

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

the class SetBackSettingsResource method delete.

@ApiOperation("DELETE the settings.xml simulation corresponding to the specified Indy group/repository")
@ApiResponses({ @ApiResponse(code = 400, message = "Requested repository is hosted on Indy and cannot be simulated via settings.xml"), @ApiResponse(code = 404, message = "No such repository or group, or the settings.xml has not been generated."), @ApiResponse(code = 204, message = "Deletion succeeded") })
@Path("/{type: (remote|group)}/{name}")
@DELETE
public Response delete(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String t, @PathParam("name") final String n) {
    final StoreType type = StoreType.get(t);
    if (StoreType.hosted == type) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Response response;
    final StoreKey key = new StoreKey(type, n);
    try {
        final boolean found = controller.deleteSetBackSettings(key);
        if (found) {
            response = Response.status(Status.NO_CONTENT).build();
        } else {
            response = Response.status(Status.NOT_FOUND).build();
        }
    } catch (final IndyWorkflowException e) {
        response = ResponseUtils.formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with StoreType

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

the class InfinispanStoreDataManager method initByPkgMap.

public void initByPkgMap() {
    // re-fill the stores by package cache each time when reboot
    if (storesByPkg != null) {
        logger.info("Clean the stores-by-pkg cache");
        storesByPkg.clear();
    }
    final Set<ArtifactStore> allStores = getAllArtifactStores();
    logger.info("There are {} stores need to fill in stores-by-pkg cache", allStores.size());
    for (ArtifactStore store : allStores) {
        final Map<StoreType, Set<StoreKey>> typedKeys = storesByPkg.computeIfAbsent(store.getKey().getPackageType(), k -> new HashMap<>());
        final Set<StoreKey> keys = typedKeys.computeIfAbsent(store.getKey().getType(), k -> new HashSet<>());
        keys.add(store.getKey());
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) HashSet(java.util.HashSet) Set(java.util.Set) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 4 with StoreType

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

the class IndexingContentManagerDecorator method retrieve.

@Override
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (!indexCfg.isEnabled()) {
        return delegate.retrieve(store, path, eventMetadata);
    }
    if (store == null) {
        return null;
    }
    logger.trace("Looking for indexed path: {} in: {}", path, store.getKey());
    Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD, eventMetadata);
    if (transfer != null) {
        logger.debug("Found indexed transfer: {}. Returning.", transfer);
        return transfer;
    } else if (isAuthoritativelyMissing(store)) {
        logger.debug("Not found indexed transfer: {} and authoritative index switched on. Considering not found and return null.", transfer);
        return null;
    }
    StoreType type = store.getKey().getType();
    if (StoreType.group == type) {
        ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
        if (nfc.isMissing(resource)) {
            logger.debug("{} is marked as missing. Returning null.", resource);
            return null;
        }
        logger.debug("No group index hits. Devolving to member store indexes.");
        KeyedLocation location = LocationUtils.toLocation(store);
        SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
        if (specialPathInfo == null || !specialPathInfo.isMergable()) {
            if (PathMaskChecker.checkMask(store, path)) {
                transfer = getTransferFromConstituents(((Group) store).getConstituents(), resource, path, store, memberKey -> {
                    try {
                        ArtifactStore member = storeDataManager.getArtifactStore(memberKey);
                        if (member == null) {
                            logger.trace("Cannot find store for key: {}", memberKey);
                        } else {
                            return retrieve(member, path, eventMetadata);
                        }
                    } catch (IndyDataException e) {
                        logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", memberKey, store.getKey(), e.getMessage()), e);
                    }
                    return null;
                });
                nfcForGroup(store, transfer, resource);
                return transfer;
            } else {
                return null;
            }
        } else {
            logger.debug("Merged content. Delegating to main content manager for: {} in: {}", path, store);
            transfer = delegate.retrieve(store, path, eventMetadata);
            if (!exists(transfer)) {
                Boolean metadataGenerated = (Boolean) eventMetadata.get(GROUP_METADATA_GENERATED);
                Boolean metadataExists = (Boolean) eventMetadata.get(GROUP_METADATA_EXISTS);
                if (Boolean.TRUE.equals(metadataGenerated) || Boolean.TRUE.equals(metadataExists)) {
                    // metadata generated/exists but missing due to membership change, not add to nfc so next req can retry
                    ;
                } else // don't track NFC for hosted repos
                {
                    nfc.addMissing(resource);
                }
            }
            return transfer;
        }
    }
    logger.trace("Delegating retrieve call for concrete repository: {}/{}", store, path);
    transfer = delegate.retrieve(store, path, eventMetadata);
    if (exists(transfer) && indexCfg.isEnabled()) {
        logger.debug("Got transfer from delegate: {} (will index)", transfer);
        indexManager.indexTransferIn(transfer, store.getKey());
    }
    logger.debug("Returning transfer: {}", transfer);
    return transfer;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) Arrays(java.util.Arrays) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) GROUP_METADATA_GENERATED(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_GENERATED) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) GROUP_METADATA_EXISTS(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_EXISTS) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Executor(java.util.concurrent.Executor) PathMaskChecker(org.commonjava.indy.core.content.PathMaskChecker) Collection(java.util.Collection) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ContentIndexConfig(org.commonjava.indy.content.index.conf.ContentIndexConfig) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource)

Example 5 with StoreType

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

the class SettingsURIMatcher method getStoreType.

/* (non-Javadoc)
     * @see org.commonjava.indy.dotmaven.util.URIMatcher#getStoreType()
     */
@Override
public StoreType getStoreType() {
    if (!matches()) {
        return null;
    }
    final String typePart = matcher.group(TYPE_GRP);
    if (typePart == null) {
        return null;
    }
    final StoreType type = StoreType.get(typePart);
    return type;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType)

Aggregations

StoreType (org.commonjava.indy.model.core.StoreType)78 StoreKey (org.commonjava.indy.model.core.StoreKey)64 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)36 Response (javax.ws.rs.core.Response)34 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponse (io.swagger.annotations.ApiResponse)27 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)27 Path (javax.ws.rs.Path)25 ApiResponses (io.swagger.annotations.ApiResponses)24 IOException (java.io.IOException)20 GET (javax.ws.rs.GET)15 Produces (javax.ws.rs.Produces)15 Logger (org.slf4j.Logger)14 Transfer (org.commonjava.maven.galley.model.Transfer)13 List (java.util.List)12 Inject (javax.inject.Inject)12 DELETE (javax.ws.rs.DELETE)12 IndyDataException (org.commonjava.indy.data.IndyDataException)12 JoinString (org.commonjava.atlas.maven.ident.util.JoinString)11 LoggerFactory (org.slf4j.LoggerFactory)11