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);
}
}
}
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations