use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class IndexingContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD);
if (transfer != null) {
return transfer;
}
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
StoreType type = store.getKey().getType();
if (StoreType.group == type) {
if (!nfc.isMissing(resource)) {
logger.debug("No group index hits. Devolving to member store indexes.");
transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
try {
return delegate.getTransfer(member, path, op);
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to getTransfer() for: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
}
return null;
});
if (transfer != null) {
return transfer;
}
} else {
logger.debug("NFC marks {} as missing. Returning null.", resource);
return null;
}
}
transfer = delegate.getTransfer(store, path, op);
// index the transfer only if it exists, it cannot be null at this point
if (transfer != null && transfer.exists()) {
indexManager.indexTransferIn(transfer, store.getKey());
}
logger.debug("Returning transfer: {}", transfer);
return transfer;
}
use of org.commonjava.indy.model.core.ArtifactStore 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.model.core.ArtifactStore 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.model.core.ArtifactStore 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.model.core.ArtifactStore 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;
}
Aggregations