use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class IndexingContentManagerDecorator method getIndexedTransfer.
private Transfer getIndexedTransfer(final StoreKey storeKey, final StoreKey topKey, final String path, final TransferOperation op) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Looking for indexed path: {} in: {} (entry point: {})", path, storeKey, topKey);
try {
ArtifactStore store = storeDataManager.getArtifactStore(storeKey);
if (store.isDisabled()) {
logger.info("Content not available in index caching layer due to store disabled for {} in group {}", storeKey, topKey);
return null;
}
} catch (IndyDataException e) {
logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", storeKey, topKey, e.getMessage()), e);
//TODO: Need further check if it is suitable to throw a IndyWorkflowException here.
return null;
}
IndexedStorePath storePath = indexManager.getIndexedStorePath(storeKey, path);
if (storePath != null) {
Transfer transfer = delegate.getTransfer(storeKey, path, op);
if (transfer == null || !transfer.exists()) {
logger.trace("Found obsolete index entry: {}. De-indexing from: {} and {}", storeKey, topKey);
// something happened to the underlying Transfer...de-index it, and don't return it.
indexManager.deIndexStorePath(storeKey, path);
if (topKey != null) {
indexManager.deIndexStorePath(topKey, path);
}
} else {
logger.trace("Found it!");
return transfer;
}
}
return null;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class MemoryArtifactStoreQuery method getGroupOrdering.
private List<ArtifactStore> getGroupOrdering(final String groupName, final Map<StoreKey, ArtifactStore> stores, final boolean includeGroups, final boolean recurseGroups) throws IndyDataException {
if (packageType == null) {
throw new IndyDataException("packageType must be set on the query before calling this method!");
}
final Group master = (Group) stores.get(new StoreKey(packageType, StoreType.group, groupName));
if (master == null) {
return Collections.emptyList();
}
final List<ArtifactStore> result = new ArrayList<>();
recurseGroup(master, stores, result, new HashSet<>(), includeGroups, recurseGroups);
return result;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class MemoryStoreDataManager method deleteArtifactStore.
@Override
public void deleteArtifactStore(final StoreKey key, final ChangeSummary summary, final EventMetadata eventMetadata) throws IndyDataException {
Logger logger = LoggerFactory.getLogger(getClass());
ReentrantLock opLock = getOpLock(key);
try {
logger.info("DELETE operation starting for store: {}", key);
opLock.lock();
final ArtifactStore store = stores.get(key);
if (store == null) {
logger.warn("No store found for: {}", key);
return;
}
if (isReadonly(store)) {
throw new IndyDataException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to delete this store, please modify it to non-readonly", store.getKey());
}
preDelete(store, summary, true, eventMetadata);
ArtifactStore removed = stores.remove(key);
logger.info("REMOVED store: {}", removed);
postDelete(store, summary, true, eventMetadata);
} finally {
opLock.unlock();
logger.trace("Delete operation complete: {}", key);
}
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class DataFileStoreDataManager method store.
private void store(final boolean skipIfExists, final ChangeSummary summary, final ArtifactStore... stores) throws IndyDataException {
for (final ArtifactStore store : stores) {
final DataFile f = manager.getDataFile(INDY_STORE, store.getPackageType(), store.getType().singularEndpointName(), store.getName() + ".json");
if (skipIfExists && f.exists()) {
continue;
}
final DataFile d = f.getParent();
if (!d.mkdirs()) {
throw new IndyDataException("Cannot create storage directory: {} for definition: {}", d, store);
}
try {
final String json = serializer.writeValueAsString(store);
f.writeString(json, "UTF-8", summary);
logger.debug("Persisted {} to disk at: {}\n{}", store, f, json);
} catch (final IOException e) {
throw new IndyDataException("Cannot write definition: {} to: {}. Reason: {}", e, store, f, e.getMessage());
}
}
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class NfcController method getMissing.
public NotFoundCacheDTO getMissing(final StoreKey key) throws IndyWorkflowException {
final NotFoundCacheDTO dto = new NotFoundCacheDTO();
if (key.getType() == group) {
List<ArtifactStore> stores;
try {
stores = storeManager.query().packageType(key.getPackageType()).getOrderedConcreteStoresInGroup(key.getName());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to retrieve concrete constituent ArtifactStores for: %s.", e, key);
}
final List<? extends KeyedLocation> locations = toLocations(stores);
for (final KeyedLocation location : locations) {
final Set<String> missing = cache.getMissing(location);
if (missing != null && !missing.isEmpty()) {
final List<String> paths = new ArrayList<String>(missing);
Collections.sort(paths);
dto.addSection(location.getKey(), paths);
}
}
} else {
ArtifactStore store;
try {
store = storeManager.getArtifactStore(key);
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to retrieve ArtifactStore: %s.", e, key);
}
if (store != null) {
final Set<String> missing = cache.getMissing(toLocation(store));
final List<String> paths = new ArrayList<String>(missing);
Collections.sort(paths);
dto.addSection(key, paths);
}
}
return dto;
}
Aggregations