Search in sources :

Example 76 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class AbstractContentManagementTest method getPhysicalStorageFile.

protected File getPhysicalStorageFile(Location location, String path) {
    String homeDir = fixture.getBootOptions().getHomeDir();
    String storageDir = "var/lib/indy/storage";
    StoreKey storeKey = ((KeyedLocation) location).getKey();
    File ret = cacheProvider.asAdminView().getDetachedFile(new ConcreteResource(location, path));
    // if ( !isPathMappedStorageEnabled() )
    // {
    // ret = Paths.get( homeDir, storageDir, storeKey.getPackageType(),
    // storeKey.getType().singularEndpointName() + "-" + storeKey.getName(), path ).toFile();
    // }
    // else
    // {
    // ret = ( (PathMappedCacheProvider) cacheProvider ).getDetachedFile( new ConcreteResource( location, path ) );
    // }
    logger.debug("Get physical storage file: {}", ret);
    return ret;
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) StoreKey(org.commonjava.indy.model.core.StoreKey) File(java.io.File)

Example 77 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class DeleteHostedRepoWithContentTest method run.

@Test
public void run() throws Exception {
    final HostedRepository repo = new HostedRepository(MAVEN_PKG_KEY, "build_perftest-20200229T021845");
    final StoreKey key = repo.getKey();
    final HostedRepository result = client.stores().create(repo, name.getMethodName(), HostedRepository.class);
    assertThat(result.getName(), equalTo(repo.getName()));
    assertThat(result.equals(repo), equalTo(true));
    // Store files
    client.content().store(repo.getKey(), path_1, new ByteArrayInputStream(content.getBytes()));
    client.content().store(repo.getKey(), path_2, new ByteArrayInputStream(content.getBytes()));
    ConcreteResource r1 = new ConcreteResource(LocationUtils.toLocation(repo), path_1);
    ConcreteResource r2 = new ConcreteResource(LocationUtils.toLocation(repo), path_2);
    // Verify files exist
    assertTrue(cacheProvider.exists(r1));
    assertTrue(cacheProvider.exists(r2));
    // Delete repo with deleteContent flag
    client.stores().delete(key, "Delete", true);
    assertThat(client.stores().exists(key), equalTo(false));
    // Verify files were deleted
    assertFalse(cacheProvider.exists(r1));
    assertFalse(cacheProvider.exists(r2));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 78 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class DeleteGroupWithContentTest method run.

@Test
@Category(EventDependent.class)
public void run() throws Exception {
    // Create hosted repo
    final HostedRepository repo = new HostedRepository(MAVEN_PKG_KEY, "test_1");
    assertThat(client.stores().create(repo, name.getMethodName(), HostedRepository.class), notNullValue());
    // Store pom file in hosted repo
    client.content().store(repo.getKey(), pomPath, new ByteArrayInputStream(pomContent.getBytes()));
    // Generate metadata file in hosted repo
    try (InputStream in = client.content().get(repo.getKey(), metadataPath)) {
        IOUtils.toString(in);
    }
    // Verify the hosted meta file exists
    ConcreteResource r_meta_hosted = new ConcreteResource(LocationUtils.toLocation(repo), metadataPath);
    assertTrue(cacheProvider.exists(r_meta_hosted));
    // Create group with hosted member
    final Group group = new Group(MAVEN_PKG_KEY, "test_1", repo.getKey());
    assertThat(client.stores().create(group, name.getMethodName(), Group.class), notNullValue());
    // Generate group metadata file
    try (InputStream in = client.content().get(group.getKey(), metadataPath)) {
        IOUtils.toString(in);
    }
    // Verify the group meta file exists
    ConcreteResource r_meta = new ConcreteResource(LocationUtils.toLocation(group), metadataPath);
    assertTrue(cacheProvider.exists(r_meta));
    // Delete group
    client.stores().delete(group.getKey(), "Delete", true);
    assertThat(client.stores().exists(group.getKey()), equalTo(false));
    // Verify the group meta file gone
    assertFalse(cacheProvider.exists(r_meta));
    // Verify hosted files not change (delete group not affect the files in hosted repo)
    ConcreteResource r1 = new ConcreteResource(LocationUtils.toLocation(repo), pomPath);
    assertTrue(cacheProvider.exists(r1));
    assertTrue(cacheProvider.exists(r_meta_hosted));
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 79 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class FoloPomDownloadListener method onFileUpload.

public void onFileUpload(@Observes final FileStorageEvent event) {
    // check for a TransferOperation of DOWNLOAD
    final TransferOperation op = event.getType();
    if (op != TransferOperation.DOWNLOAD) {
        logger.trace("Not a download transfer operation. No pom existence check performed.");
        return;
    }
    // check if it is a path that doesn't end in with ".pom"
    final Transfer transfer = event.getTransfer();
    if (transfer == null) {
        logger.trace("No transfer. No pom existence check performed.");
        return;
    }
    String txfrPath = transfer.getPath();
    if (txfrPath.endsWith(".pom")) {
        logger.trace("This is a pom download.");
        return;
    }
    // use ArtifactPathInfo to parse into a GAV, just to verify that it's looking at an artifact download
    ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
    if (artPathInfo == null) {
        logger.trace("Not an artifact download ({}). No pom existence check performed.", txfrPath);
        return;
    }
    // verify that the associated .pom file exists
    String pomFilename = String.format("%s-%s.pom", artPathInfo.getArtifactId(), artPathInfo.getVersion());
    ConcreteResource pomResource = transfer.getResource().getParent().getChild(pomFilename);
    if (cacheProvider.exists(pomResource)) {
        logger.trace("Pom {} already exists.", cacheProvider.getFilePath(pomResource));
        return;
    }
    // trigger pom download by requesting it from the same repository as the original artifact
    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;
    }
    try {
        logger.debug("Downloading POM as automatic response to associated artifact download: {}/{}", storeKey, pomResource.getPath());
        contentManager.retrieve(store, pomResource.getPath(), event.getEventMetadata());
    } catch (final IndyWorkflowException ex) {
        logger.error("Error while retrieving pom artifact " + pomResource.getPath() + " from store " + store, ex);
        return;
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 80 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class ScheduleDBManager method setProxyTimeouts.

public void setProxyTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
    if (!schedulerConfig.isEnabled()) {
        logger.debug("Scheduler disabled.");
        return;
    }
    RemoteRepository repo = null;
    try {
        repo = (RemoteRepository) dataManager.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
    }
    if (repo == null) {
        return;
    }
    int timeout = config.getPassthroughTimeoutSeconds();
    final ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(repo), path);
    final SpecialPathInfo info = specialPathManager.getSpecialPathInfo(resource, key.getPackageType());
    if (!repo.isPassthrough()) {
        if ((info != null && info.isMetadata()) && repo.getMetadataTimeoutSeconds() >= 0) {
            if (repo.getMetadataTimeoutSeconds() == 0) {
                logger.debug("Using default metadata timeout for: {}", resource);
                timeout = config.getRemoteMetadataTimeoutSeconds();
            } else {
                logger.debug("Using metadata timeout for: {}", resource);
                timeout = repo.getMetadataTimeoutSeconds();
            }
        } else {
            if (info == null) {
                logger.debug("No special path info for: {}", resource);
            } else {
                logger.debug("{} is a special path, but not metadata.", resource);
            }
            timeout = repo.getCacheTimeoutSeconds();
        }
    }
    if (timeout > 0) {
        // logger.info( "[PROXY TIMEOUT SET] {}/{}; {}", repo.getKey(), path, new Date( System.currentTimeMillis()
        // + timeout ) );
        scheduleContentExpiration(key, path, timeout);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Aggregations

ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)206 Test (org.junit.Test)138 Transfer (org.commonjava.maven.galley.model.Transfer)92 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)55 Location (org.commonjava.maven.galley.model.Location)45 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)36 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)33 OutputStream (java.io.OutputStream)30 InputStream (java.io.InputStream)26 Group (org.commonjava.indy.model.core.Group)25 ArrayList (java.util.ArrayList)23 HostedRepository (org.commonjava.indy.model.core.HostedRepository)23 TransferException (org.commonjava.maven.galley.TransferException)23 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)23 HashSet (java.util.HashSet)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)18 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)18 Logger (org.slf4j.Logger)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)16