Search in sources :

Example 66 with StoreType

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

the class TimeoutEventListener method onStoreUpdate.

public void onStoreUpdate(@Observes final ArtifactStorePostUpdateEvent event) {
    final ArtifactStoreUpdateType eventType = event.getType();
    if (eventType == ArtifactStoreUpdateType.UPDATE) {
        for (final ArtifactStore store : event) {
            final StoreKey key = store.getKey();
            final StoreType type = key.getType();
            if (type == StoreType.hosted) {
                logger.info("[ADJUST TIMEOUTS] Adjusting snapshot expirations in: {}", store.getKey());
                try {
                    scheduleManager.rescheduleSnapshotTimeouts((HostedRepository) store);
                } catch (final IndySchedulerException e) {
                    logger.error("Failed to update snapshot timeouts in: " + store.getKey(), e);
                }
            } else if (type == StoreType.remote) {
                logger.info("[ADJUST TIMEOUTS] Adjusting proxied-file expirations in: {}", store.getKey());
                try {
                    scheduleManager.rescheduleProxyTimeouts((RemoteRepository) store);
                } catch (final IndySchedulerException e) {
                    logger.error("Failed to update proxy-cache timeouts in: " + store.getKey(), e);
                }
            }
        }
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ArtifactStoreUpdateType(org.commonjava.indy.change.event.ArtifactStoreUpdateType) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 67 with StoreType

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

the class ArtifactStoreSubStore method getChildrenNames.

@Override
public String[] getChildrenNames(final ITransaction transaction, final String folderUri) throws WebdavException {
    String[] names;
    final StoreURIMatcher matcher = new StoreURIMatcher(folderUri);
    if (matcher.hasStorePath() || matcher.hasStoreName()) {
        String path = matcher.getStorePath();
        if (isEmpty(path)) {
            path = PathUtils.ROOT;
        }
        final StoreKey key = matcher.getStoreKey();
        try {
            if (key != null && StoreType.group == key.getType()) {
                final List<ArtifactStore> stores = indy.query().getOrderedStoresInGroup(key.getPackageType(), key.getName());
                final Set<String> noms = new TreeSet<>();
                for (final ArtifactStore store : stores) {
                    final Transfer item = fileManager.getStorageReference(store, path);
                    if (!item.exists()) {
                        continue;
                    }
                    if (!item.isDirectory()) {
                        logger.error("Transfer: {} in {} is not a directory.", path, store.getKey());
                        continue;
                    }
                    noms.addAll(Arrays.asList(item.list()));
                }
                names = noms.toArray(new String[noms.size()]);
            } else {
                final ArtifactStore store = indy.getArtifactStore(key);
                if (store == null) {
                    logger.error("Cannot find ArtifactStore to match key: {}.", key);
                    names = new String[] {};
                } else {
                    final Transfer item = fileManager.getStorageReference(store, path);
                    if (!item.exists() || !item.isDirectory()) {
                        logger.error("Transfer: {} in {} is not a directory.", path, store.getKey());
                        names = new String[] {};
                    } else {
                        names = item.list();
                    }
                }
            }
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to lookup ArtifactStore(s) for key: %s. Reason: %s", key, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        } catch (final IOException e) {
            logger.error(String.format("Failed to list %s in %s. Reason: %s", path, key, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        }
    } else if (matcher.hasStoreType()) {
        String packageType = matcher.getPackageType();
        final StoreType type = matcher.getStoreType();
        try {
            List<? extends ArtifactStore> stores = new ArrayList<>();
            if (StoreType.group.equals(type)) {
                stores = indy.query().getAllGroups(packageType);
            } else if (StoreType.hosted.equals(type)) {
                stores = indy.query().getAllHostedRepositories(packageType);
            } else if (StoreType.remote.equals(type)) {
                stores = indy.query().getAllRemoteRepositories(packageType);
            }
            List<String> noms = stores.stream().map(ArtifactStore::getName).collect(Collectors.toList());
            names = noms.toArray(new String[noms.size()]);
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to lookup ArtifactStores of type: %s. Reason: %s", type, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        }
    } else {
        names = new String[] { StoreType.hosted.singularEndpointName(), StoreType.group.singularEndpointName(), StoreType.remote.singularEndpointName() };
    }
    return names;
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) WebdavException(net.sf.webdav.exceptions.WebdavException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreType(org.commonjava.indy.model.core.StoreType) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) TreeSet(java.util.TreeSet) Transfer(org.commonjava.maven.galley.model.Transfer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 68 with StoreType

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

the class SettingsURIMatcher method getStoreKey.

/* (non-Javadoc)
     * @see org.commonjava.indy.dotmaven.util.URIMatcher#getStoreKey()
     */
@Override
public StoreKey getStoreKey() {
    final StoreType type = getStoreType();
    if (type == null) {
        return null;
    }
    final String name = matcher.group(NAME_GRP);
    if (isEmpty(name)) {
        return null;
    }
    return new StoreKey(type, name);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 69 with StoreType

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

the class LocationUtils method toLocation.

public static KeyedLocation toLocation(final ArtifactStore store) {
    if (store == null) {
        return null;
    }
    KeyedLocation location = (KeyedLocation) store.getTransientMetadata(KEYED_LOCATION_METADATA);
    if (location != null) {
        return location;
    }
    final StoreType type = store.getKey().getType();
    switch(type) {
        case group:
            {
                location = new GroupLocation(store.getPackageType(), store.getName());
                break;
            }
        case hosted:
            {
                location = new CacheOnlyLocation((HostedRepository) store);
                break;
            }
        case remote:
        default:
            {
                final RemoteRepository repository = (RemoteRepository) store;
                location = new RepositoryLocation(repository);
                AttributePasswordManager.bind(location, PasswordEntry.KEY_PASSWORD, repository.getKeyPassword());
                AttributePasswordManager.bind(location, PasswordEntry.PROXY_PASSWORD, repository.getProxyPassword());
                AttributePasswordManager.bind(location, PasswordEntry.USER_PASSWORD, repository.getPassword());
            }
    }
    if (location != null) {
        location.setAttribute(PATH_STYLE, store.getPathStyle());
        Map<String, String> metadata = store.getMetadata();
        if (metadata != null) {
            Location loc = location;
            metadata.forEach((k, v) -> {
                if (!loc.getAttributes().containsKey(k)) {
                    loc.setAttribute(k, v);
                }
            });
        }
    }
    store.setTransientMetadata(KEYED_LOCATION_METADATA, location);
    return location;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Example 70 with StoreType

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

the class ChangelogResource method getStoreChangelog.

@ApiOperation("Retrieve the changelog for the Indy group/repository definition with the start-index and number of results")
@ApiResponses({ @ApiResponse(code = 200, message = "JSON containing changelog entries", response = ChangeSummaryDTO.class), @ApiResponse(code = 400, message = "Requested group/repository type is not one of: {remote, hosted, group}") })
@Path("/store/{type}/{name}")
public Response getStoreChangelog(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String t, @PathParam("name") final String storeName, @QueryParam("start") int start, @QueryParam("count") int count) {
    final StoreType storeType = StoreType.get(t);
    if (storeType == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid store type: '" + t + "'").build();
    }
    final StoreKey key = new StoreKey(storeType, storeName);
    if (start < 0) {
        start = 0;
    }
    if (count < 1) {
        count = DEFAULT_CHANGELOG_COUNT;
    }
    Response response;
    try {
        final List<ChangeSummary> dataChangeLog = revisions.getDataChangeLog(key, start, count);
        response = responseHelper.formatOkResponseWithJsonEntity(new ChangeSummaryDTO(dataChangeLog));
        logger.info("\n\n\n\n\n\n{} Sent changelog for: {}\n\n{}\n\n\n\n\n\n\n", new Date(), key, dataChangeLog);
    } catch (final GitSubsystemException e) {
        final String message = String.format("Failed to lookup changelog for: %s. Reason: %s", key, e.getMessage());
        logger.error(message, 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) ChangeSummaryDTO(org.commonjava.indy.revisions.jaxrs.dto.ChangeSummaryDTO) GitSubsystemException(org.commonjava.indy.subsys.git.GitSubsystemException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) Date(java.util.Date) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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