Search in sources :

Example 86 with ArtifactStore

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);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException)

Example 87 with ArtifactStore

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);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) StoreResource(org.commonjava.indy.content.StoreResource) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException)

Example 88 with ArtifactStore

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);
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger)

Example 89 with ArtifactStore

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));
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) AutoProxCalculation(org.commonjava.indy.autoprox.rest.dto.AutoProxCalculation) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 90 with ArtifactStore

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;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) HashMap(java.util.HashMap) IOException(java.io.IOException) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) File(java.io.File)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)93 IndyDataException (org.commonjava.indy.data.IndyDataException)54 StoreKey (org.commonjava.indy.model.core.StoreKey)46 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)35 Logger (org.slf4j.Logger)30 ArrayList (java.util.ArrayList)25 Transfer (org.commonjava.maven.galley.model.Transfer)25 Group (org.commonjava.indy.model.core.Group)20 StoreType (org.commonjava.indy.model.core.StoreType)19 IOException (java.io.IOException)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)17 HashSet (java.util.HashSet)15 List (java.util.List)15 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 StoreDataManager (org.commonjava.indy.data.StoreDataManager)10 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 Test (org.junit.Test)9 ApiOperation (io.swagger.annotations.ApiOperation)8