use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class FoloTrackingListener method createEntry.
private TrackedContentEntry createEntry(final TrackingKey trackingKey, final StoreKey affectedStore, final AccessChannel accessChannel, final String path, final StoreEffect effect, final EventMetadata eventMetadata) throws IndyWorkflowException {
TrackedContentEntry entry = null;
final Transfer txfr = downloadManager.getStorageReference(affectedStore, path);
if (txfr != null) {
try {
String remoteUrl = null;
if (StoreType.remote == affectedStore.getType()) {
final RemoteRepository repo = (RemoteRepository) storeManager.getArtifactStore(affectedStore);
if (repo != null) {
remoteUrl = UrlUtils.buildUrl(repo.getUrl(), path);
}
}
TransferMetadata artifactData = contentDigester.digest(affectedStore, path, eventMetadata);
Map<ContentDigest, String> digests = artifactData.getDigests();
//TODO: As localUrl needs a apiBaseUrl which is from REST service context, to avoid deep propagate
// of it, this step will be done in REST layer. Will think better way in the future.
entry = new TrackedContentEntry(trackingKey, affectedStore, accessChannel, remoteUrl, path, effect, artifactData.getSize(), digests.get(ContentDigest.MD5), digests.get(ContentDigest.SHA_1), digests.get(ContentDigest.SHA_256));
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Cannot retrieve RemoteRepository: %s to calculate remote URL for: %s. Reason: %s", e, trackingKey, path, e.getMessage());
} catch (final MalformedURLException e) {
throw new IndyWorkflowException("Cannot format URL. Reason: %s", e, e.getMessage());
}
}
return entry;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class AutoProxDataManagerDecorator method getHostedRepository.
private HostedRepository getHostedRepository(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
HostedRepository repo = (HostedRepository) dataManager.getArtifactStore(key);
if (!catalog.isEnabled()) {
logger.debug("AutoProx decorator disabled; returning: {}", repo);
return repo;
}
logger.debug("AutoProx decorator active");
if (repo == null) {
logger.info("AutoProx: creating repository for: {}", key);
try {
repo = catalog.createHostedRepository(key);
} catch (final AutoProxRuleException e) {
throw new IndyDataException("[AUTOPROX] Failed to create new hosted repository from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
}
if (repo != null) {
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating hosted repository for: '" + key + "'");
final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? repo.getKey() : impliedBy);
dataManager.storeArtifactStore(repo, changeSummary, false, true, eventMetadata);
}
}
return repo;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class AutoProxDataManagerDecorator method checkValidity.
/**
* Validates the remote connection, produced from rule-set for given key,
* for a remote repo or group containing a remote. If:
*
* <ul>
* <li>rule.isValidationEnabled() == false, return true</li>
* <li>rule.getValidationRemote() == null, return true</li>
* <li>
* rule.getRemoteValidationPath() != null, validate remote.getUrl() + validationPath
* <ul>
* <li>if response code is 200 OK, then return true</li>
* <li>otherwise, return false</li>
* </ul>
* </li>
* </ul>
* @throws IndyDataException if the selected rule encounters an error while creating the new group/repository instance(s).
*/
private boolean checkValidity(final StoreKey key) throws IndyDataException {
if (catalog.isValidationEnabled(key)) {
try {
final RemoteRepository validationRepo = catalog.createValidationRemote(key);
if (validationRepo == null) {
logger.info("No validation repository was created: assuming {} is valid.", key);
return true;
}
String path = catalog.getRemoteValidationPath(key);
if (path == null) {
path = PathUtils.ROOT;
}
logger.debug("\n\n\n\n\n[AutoProx] Checking path: {} under remote URL: {}", path, validationRepo.getUrl());
boolean result = false;
try {
result = transferManager.exists(new ConcreteResource(LocationUtils.toLocation(validationRepo), path));
} catch (final TransferException e) {
logger.warn("[AutoProx] Cannot connect to target repository: '{}'. Reason: {}", validationRepo, e.getMessage());
logger.debug("[AutoProx] exception from validation attempt for: " + validationRepo, e);
}
logger.debug("Validation result for: {} is: {}", validationRepo, result);
return result;
} catch (final AutoProxRuleException e) {
throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
}
}
return true;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class PackageTypedStorageMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
Set<ArtifactStore> stores;
try {
stores = storeDataManager.getAllArtifactStores();
} catch (IndyDataException e) {
throw new IndyLifecycleException("Cannot retrieve list of repositories and groups in order to review storage locations. Reason: %s", e, e.getMessage());
}
File storageRoot = config.getStorageRootDirectory();
File nfsStorageRoot = config.getNFSStorageRootDirectory();
int migrations = 0;
Map<File, File> unmigratedNfs = new HashMap<>();
for (ArtifactStore store : stores) {
File old = deprecatedStoragePath(storageRoot, store);
File migrated = packageTypedStoragePath(storageRoot, store);
if (old.exists()) {
logger.info("Attempting to migrate existing storage from old directory structure: {} " + "to package-typed structure: {}", old, migrated);
try {
if (migrated.exists()) {
FileUtils.copyDirectory(old, migrated);
FileUtils.forceDelete(old);
} else {
FileUtils.moveDirectory(old, migrated);
}
migrations++;
} catch (IOException e) {
throw new IndyLifecycleException("Failed to migrate: %s to: %s. Reason: %s", e, old, migrated);
}
}
if (nfsStorageRoot != null) {
File oldNfs = deprecatedStoragePath(nfsStorageRoot, store);
File migratedNfs = packageTypedStoragePath(nfsStorageRoot, store);
if (oldNfs.exists() && !migratedNfs.exists()) {
unmigratedNfs.put(oldNfs, migratedNfs);
}
}
}
if (!unmigratedNfs.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("ERROR: Un-migrated directories detected on NFS storage!!!!");
sb.append("\n\nThese directories still use the old <type>/<name> directory format. Indy now supports");
sb.append("\nmultiple package types, and the storage format has changed accordingly. The new format is:");
sb.append("\n\n <package-type>/<type>/<name>");
sb.append("\n\nPlease migrate these NFS directories manually. For Maven repositories:");
sb.append("\n\n maven/<type>/<name>");
sb.append("\n\nFor HTTProx repositories (httprox_*):");
sb.append("\n\n generic-http/<type>/<name>");
sb.append("\n\nThe following directories were detected:\n");
unmigratedNfs.forEach((o, n) -> sb.append("\n ").append(o).append(" => ").append(n));
sb.append("\n\n");
logger.error(sb.toString());
throw new IndyLifecycleException("Un-migrated NFS directories detected. Indy cannot start until this has been resolved.");
}
return migrations > 0;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class MemoryStoreDataManager method store.
private boolean store(final ArtifactStore store, final ChangeSummary summary, final boolean skipIfExists, final boolean fireEvents, final EventMetadata eventMetadata) throws IndyDataException {
ReentrantLock opLock = getOpLock(store.getKey());
try {
opLock.lock();
ArtifactStore original = stores.get(store.getKey());
if (original == store) {
// if they're the same instance, warn that preUpdate events may not work correctly!
logger.warn("Storing changes on existing instance of: {}! You forgot to call {}.copyOf(), so preUpdate events may not accurately reflect before/after differences for this change!", store, store.getClass().getSimpleName());
}
if (!skipIfExists || original == null) {
preStore(store, original, summary, original != null, fireEvents, eventMetadata);
final ArtifactStore old = stores.put(store.getKey(), store);
try {
postStore(store, original, summary, original != null, fireEvents, eventMetadata);
return true;
} catch (final IndyDataException e) {
logger.error("postStore() failed for: {}. Rolling back to old value: {}", store, old);
stores.put(old.getKey(), old);
}
}
return false;
} finally {
opLock.unlock();
}
}
Aggregations