use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class DefaultContentManager method getTransfer.
@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
logger.debug("Getting transfer for: {}/{} (op: {})", store.getKey(), path, op);
if (group == store.getKey().getType()) {
KeyedLocation location = LocationUtils.toLocation(store);
SpecialPathInfo spInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
if (spInfo == null || !spInfo.isMergable()) {
try {
final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
logger.debug("Trying to retrieve suitable transfer for: {} in group: {} members:\n{}", path, store.getName(), allMembers);
return getTransfer(allMembers, path, op);
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
} else {
logger.debug("Detected mergable special path: {}/{}.", store.getKey(), path);
}
}
logger.debug("Retrieving storage reference (Transfer) directly for: {}/{}", store.getKey(), path);
return downloadManager.getStorageReference(store, path, op);
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class DefaultContentManager method list.
@Override
public List<StoreResource> list(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
List<StoreResource> listed;
if (group == store.getKey().getType()) {
List<ArtifactStore> members;
try {
members = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
listed = new ArrayList<>();
for (final ContentGenerator generator : contentGenerators) {
final List<StoreResource> generated = generator.generateGroupDirectoryContent((Group) store, members, path, eventMetadata);
if (generated != null) {
listed.addAll(generated);
}
}
for (final ArtifactStore member : members) {
List<StoreResource> storeListing = null;
try {
storeListing = list(member, path, eventMetadata);
} catch (IndyWorkflowException e) {
e.filterLocationErrors();
}
if (storeListing != null) {
listed.addAll(storeListing);
}
}
} else {
if (checkListingMask(store, path)) {
listed = downloadManager.list(store, path);
} else {
listed = new ArrayList<>();
}
for (final ContentGenerator producer : contentGenerators) {
final List<StoreResource> produced = producer.generateDirectoryContent(store, path, listed, eventMetadata);
if (produced != null) {
listed.addAll(produced);
}
}
}
return dedupeListing(listed);
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class DefaultContentManager method getTransfer.
@Override
public Transfer getTransfer(final List<ArtifactStore> stores, final String path, final TransferOperation op) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Looking for path: '{}' in stores: {}", path, stores.stream().map(ArtifactStore::getKey).collect(Collectors.toList()));
return downloadManager.getStorageReference(stores, path, op);
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class CalculateGroupTest method calculate.
@Test
public void calculate() throws Exception {
final String name = "test";
final AutoProxCalculation calculation = module.calculateRuleOutput(StoreType.group, name);
assertThat(calculation.getRuleName(), equalTo("0001-simple-rule"));
final List<ArtifactStore> supplemental = calculation.getSupplementalStores();
assertThat(supplemental.size(), equalTo(4));
final Group store = (Group) calculation.getStore();
assertThat(store.getName(), equalTo(name));
int idx = 0;
ArtifactStore supp = supplemental.get(idx);
assertThat(supp.getName(), equalTo(name));
assertThat(supp instanceof HostedRepository, equalTo(true));
final HostedRepository hosted = (HostedRepository) supp;
assertThat(hosted.isAllowReleases(), equalTo(true));
assertThat(hosted.isAllowSnapshots(), equalTo(true));
idx++;
supp = supplemental.get(idx);
assertThat(supp.getName(), equalTo(name));
assertThat(supp instanceof RemoteRepository, equalTo(true));
final RemoteRepository remote = (RemoteRepository) supp;
assertThat(remote.getUrl(), equalTo("http://localhost:1000/target/" + name));
}
use of org.commonjava.indy.model.core.ArtifactStore 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;
}
Aggregations