use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class IndexingContentManagerDecorator method getIndexedMemberTransfer.
private Transfer getIndexedMemberTransfer(final Group group, final String path, TransferOperation op, ContentManagementFunction func) throws IndyWorkflowException {
StoreKey topKey = group.getKey();
List<StoreKey> toProcess = new ArrayList<>(group.getConstituents());
Set<StoreKey> seen = new HashSet<>();
while (!toProcess.isEmpty()) {
StoreKey key = toProcess.remove(0);
seen.add(key);
final ArtifactStore member;
try {
member = storeDataManager.getArtifactStore(key);
if (member == null) {
continue;
}
} catch (IndyDataException e) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", key, topKey, e.getMessage()), e);
continue;
}
Transfer transfer = getIndexedTransfer(key, topKey, path, op);
if (transfer == null && StoreType.group != key.getType()) {
// don't call this for constituents that are groups...we'll manually traverse the membership below...
transfer = func.apply(member);
}
if (transfer != null) {
indexManager.indexTransferIn(transfer, key, topKey);
return transfer;
} else if (StoreType.group == key.getType()) {
int i = 0;
for (StoreKey memberKey : ((Group) member).getConstituents()) {
if (!seen.contains(memberKey)) {
toProcess.add(i, memberKey);
i++;
}
}
}
}
return null;
}
use of org.commonjava.indy.data.IndyDataException 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().packageType(key.getPackageType()).getOrderedStoresInGroup(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<String> noms = indy.query().packageType(packageType).storeTypes(type).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.data.IndyDataException in project indy by Commonjava.
the class ArtifactStoreSubStore method getStorageAdviceFor.
private StorageAdvice getStorageAdviceFor(final StoreURIMatcher matcher) throws WebdavException {
final String uri = matcher.getURI();
final StoreKey key = matcher.getStoreKey();
ArtifactStore store;
try {
store = indy.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve artifact store: %s for URI: %s\nReason: %s", key, uri, e.getMessage()), e);
throw new WebdavException("Cannot create: " + uri);
}
if (store == null) {
throw new WebdavException("Cannot retrieve ArtifactStore: " + key);
}
StorageAdvice advice;
try {
advice = advisor.getStorageAdvice(store);
} catch (final DotMavenException e) {
logger.error(String.format("Failed to retrieve storage advice for: %s (URI: %s)\nReason: %s", key, uri, e.getMessage()), e);
throw new WebdavException("Cannot create: " + uri);
}
if (!advice.isDeployable()) {
throw new WebdavException("Read-only area. Cannot create: " + uri);
}
return advice;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class ArtifactStoreSubStore method getTransfer.
private Transfer getTransfer(final StoreURIMatcher matcher) throws WebdavException {
final String resourceUri = matcher.getURI();
if (!matcher.hasStorePath()) {
throw new WebdavException("No store-level path specified: '" + resourceUri + "'. This URI references either a list of stores, a root store directory, or something else that cannot be read as a file.");
}
final String path = matcher.getStorePath();
final StoreKey key = matcher.getStoreKey();
Transfer item = null;
try {
if (key != null && StoreType.group == key.getType()) {
final List<ArtifactStore> stores = indy.query().packageType(key.getPackageType()).enabledState(true).getOrderedStoresInGroup(key.getName());
for (final ArtifactStore store : stores) {
// logger.info( "Getting Transfer for: {} from: {}", path, store );
final Transfer si = fileManager.getStorageReference(store, path);
if (si.exists()) {
// logger.info( "Using Transfer: {} for path: {}", si, path );
item = si;
break;
}
}
} else {
final ArtifactStore store = indy.getArtifactStore(key);
if (store == null) {
throw new WebdavException("Cannot find store: " + key);
}
// logger.info( "Getting Transfer for: {} from: {}", path, store );
final Transfer si = fileManager.getStorageReference(store, path);
if (si.exists()) {
// logger.info( "Using Transfer: {} for path: {}", si, path );
item = si;
}
}
} 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 content for: " + resourceUri);
}
return item;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class SettingsSubStore method getChildrenNames.
@Override
public String[] getChildrenNames(final ITransaction transaction, final String folderUri) throws WebdavException {
final SettingsURIMatcher matcher = new SettingsURIMatcher(folderUri);
final Set<String> names = new TreeSet<String>();
if (matcher.isSettingsRootResource()) {
for (final StoreType type : StoreType.values()) {
names.add(type.singularEndpointName());
}
} else if (matcher.isSettingsTypeResource()) {
final StoreType type = matcher.getStoreType();
List<? extends ArtifactStore> all;
try {
all = indy.query().packageType(MAVEN_PKG_KEY).storeTypes(type).getAll();
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve list of artifact stores: %s", e.getMessage()), e);
throw new WebdavException("Failed to retrieve list of settings configurations.");
}
for (final ArtifactStore store : all) {
final String storeName = formatSettingsResourceName(store.getKey().getType(), store.getName());
// logger.info( "\n\nCreating settings resource for: '{}'\n\n", storeName );
names.add(storeName);
}
}
return names.toArray(new String[names.size()]);
}
Aggregations