Search in sources :

Example 66 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class RelateGenerationManager method generateRelationshipFile.

/**
     * Generate relationship file for pom transfer.
     * @param transfer
     * @param op
     * @return transfer pointing to the generated rel file.
     */
public Transfer generateRelationshipFile(Transfer transfer, TransferOperation op) {
    final Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Relate generation for {}", transfer);
    if (transfer == null) {
        logger.debug("No transfer. No .rel generation performed.");
        return null;
    }
    String txfrPath = transfer.getPath();
    if (!txfrPath.endsWith(".pom")) {
        logger.debug("This is not a pom transfer.");
        return null;
    }
    ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
    if (artPathInfo == null) {
        logger.debug("Not an artifact download ({}). No .rel generation performed.", txfrPath);
        return null;
    }
    ConcreteResource pomResource = transfer.getResource();
    StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
    ArtifactStore store;
    try {
        store = storeManager.getArtifactStore(storeKey);
    } catch (final IndyDataException ex) {
        logger.error("Error retrieving artifactStore with key " + storeKey, ex);
        return null;
    }
    logger.debug("Generate .rel corresponding to associated POM download: {}/{}", storeKey, pomResource.getPath());
    try {
        URI source = new URI(pomResource.getLocation().getUri() + REL_SUFFIX);
        ProjectVersionRef ref = artPathInfo.getProjectId();
        // get all groups that this store is a member of
        Set<ArtifactStore> stores = new HashSet<>();
        stores.add(store);
        stores.addAll(storeManager.query().getGroupsContaining(store.getKey()));
        List<? extends Location> supplementalLocations = LocationUtils.toLocations(stores.toArray(new ArtifactStore[0]));
        MavenPomView pomView = mavenPomReader.read(ref, transfer, supplementalLocations, ALL_PROFILES);
        EProjectDirectRelationships rel = mavenModelProcessor.readRelationships(pomView, source, new ModelProcessorConfig());
        Transfer transferRel = transfer.getSiblingMeta(REL_SUFFIX);
        writeRelationships(rel, transferRel, op);
        return transferRel;
    } catch (Exception e) {
        logger.error("Error generating .rel file for " + txfrPath + " from store " + store, e);
        return null;
    }
}
Also used : Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) IOException(java.io.IOException) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) ArtifactPathInfo(org.commonjava.maven.atlas.ident.util.ArtifactPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) ModelProcessorConfig(org.commonjava.maven.galley.maven.rel.ModelProcessorConfig) Transfer(org.commonjava.maven.galley.model.Transfer) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) HashSet(java.util.HashSet)

Example 67 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class RepositoryDataManagerTCK method createAndDeleteCentralRepoProxy.

@Test
public void createAndDeleteCentralRepoProxy() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final RemoteRepository repo = new RemoteRepository("central", "http://repo1.maven.apache.org/maven2/");
    storeRemoteRepository(repo, false);
    manager.deleteArtifactStore(repo.getKey(), summary, new EventMetadata());
    final ArtifactStore result = manager.query().packageType(MAVEN_PKG_KEY).storeType(RemoteRepository.class).getByName(repo.getName());
    assertThat(result, nullValue());
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreDataManager(org.commonjava.indy.data.StoreDataManager) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 68 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class GroupDataManagerTCK method createGroupAndRetrieveRepositoryConstituents.

@Test
public void createGroupAndRetrieveRepositoryConstituents() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final Group grp = new Group("test", new StoreKey(StoreType.remote, "central"), new StoreKey(StoreType.remote, "repo2"));
    store(grp);
    final List<ArtifactStore> result = manager.query().packageType(MAVEN_PKG_KEY).getOrderedConcreteStoresInGroup(grp.getName());
    assertThat(result, notNullValue());
    assertThat(result.size(), equalTo(2));
    ArtifactStore repo = result.get(0);
    assertThat(repo, notNullValue());
    assertThat(repo.getName(), equalTo("central"));
    repo = result.get(1);
    assertThat(repo, notNullValue());
    assertThat(repo.getName(), equalTo("repo2"));
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreDataManager(org.commonjava.indy.data.StoreDataManager) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 69 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class GroupDataManagerTCK method createGroupAndRetrieveReposForThatGroupInOrder.

@Test
public void createGroupAndRetrieveReposForThatGroupInOrder() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final Group grp = new Group("test", new StoreKey(StoreType.remote, "repo2"), new StoreKey(StoreType.remote, "central"));
    store(grp);
    final List<ArtifactStore> repos = manager.query().packageType(MAVEN_PKG_KEY).getOrderedConcreteStoresInGroup(grp.getName());
    assertThat(repos, notNullValue());
    assertThat(repos.size(), equalTo(2));
    assertThat(repos.get(0).getName(), equalTo("repo2"));
    assertThat(repos.get(1).getName(), equalTo("central"));
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreDataManager(org.commonjava.indy.data.StoreDataManager) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 70 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class IndexingContentManagerDecorator method getTransfer.

@Override
public Transfer getTransfer(final StoreKey storeKey, final String path, final TransferOperation op) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    Transfer transfer = getIndexedTransfer(storeKey, null, path, TransferOperation.DOWNLOAD);
    if (transfer != null) {
        logger.debug("Returning indexed transfer: {}", transfer);
        return transfer;
    }
    ArtifactStore store;
    try {
        store = storeDataManager.getArtifactStore(storeKey);
    } catch (IndyDataException e) {
        throw new IndyWorkflowException("Failed to lookup ArtifactStore: %s for NFC handling. Reason: %s", e, storeKey, e.getMessage());
    }
    ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
    StoreType type = storeKey.getType();
    if (StoreType.group == type) {
        Group g = (Group) store;
        if (g == null) {
            throw new IndyWorkflowException("Cannot find requested group: %s", storeKey);
        }
        if (nfc.isMissing(resource)) {
            logger.debug("NFC / MISSING: {}", resource);
            return null;
        }
        logger.debug("No group index hits. Devolving to member store indexes.");
        for (StoreKey key : g.getConstituents()) {
            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 member path: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
                }
                return null;
            });
            if (transfer != null) {
                logger.debug("Returning indexed transfer: {} from member: {}", transfer, key);
                return transfer;
            }
        }
    }
    transfer = delegate.getTransfer(storeKey, path, op);
    if (transfer != null) {
        logger.debug("Indexing transfer: {}", transfer);
        indexManager.indexTransferIn(transfer, storeKey);
    }
    return transfer;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey)

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