Search in sources :

Example 66 with RemoteRepository

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

the class RemoteRepoTimeoutDisablesThenReEnabledTest method run.

@Test
@Category(TimingDependent.class)
public void run() throws Exception {
    final String repo1 = "repo1";
    final String path = "org/foo/bar/maven-metadata.xml";
    server.expect(server.formatUrl("repo1/"), 200, "OK");
    server.expect("GET", server.formatUrl(repo1, path), (req, resp) -> {
        try {
            Thread.sleep(5000);
        } catch (final InterruptedException e) {
        }
        resp.setStatus(404);
    });
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1.setTimeoutSeconds(1);
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    try (InputStream is = client.content().get(remote, repo1, path)) {
    } catch (final IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(HttpStatus.SC_BAD_GATEWAY));
    }
    Thread.sleep(1000);
    RemoteRepository result = client.stores().load(remote, repo1, RemoteRepository.class);
    assertThat(result.isDisabled(), equalTo(true));
    Thread.sleep(4000);
    result = client.stores().load(remote, repo1, RemoteRepository.class);
    assertThat(result.isDisabled(), equalTo(false));
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 67 with RemoteRepository

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

the class RepositoryPathMaskExistsTest method run.

@Test
public void run() throws Exception {
    final String content = "{\"content\": \"This is a test: " + System.nanoTime() + "\"}";
    final String path_1 = "org/foo/foo-project/1/a.out.txt";
    // not in masks
    final String path_2 = "org/bar/bar-project/1/a.out.txt";
    final String repo1 = "repo1";
    server.expect(server.formatUrl(repo1, path_1), 200, new ByteArrayInputStream(content.getBytes()));
    server.expect(server.formatUrl(repo1, path_2), 200, new ByteArrayInputStream(content.getBytes()));
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    Set<String> pathMaskPatterns = new HashSet<>();
    pathMaskPatterns.add("org/foo");
    remote1.setPathMaskPatterns(pathMaskPatterns);
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    Group g = new Group("test", remote1.getKey());
    g = client.stores().create(g, "adding group", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    // get stream for path-1 via group (success)
    boolean result = client.content().exists(group, g.getName(), path_1);
    assertThat(result, equalTo(true));
    // get stream for path_2 via group (null)
    result = client.content().exists(group, g.getName(), path_2);
    assertThat(result, equalTo(false));
    // get stream for path_1 via concrete store (success)
    result = client.content().exists(remote, remote1.getName(), path_1);
    assertThat(result, equalTo(true));
    // get stream for path_2 via concrete repo (null)
    result = client.content().exists(remote, remote1.getName(), path_2);
    assertThat(result, equalTo(false));
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 68 with RemoteRepository

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

the class AddAndDeleteRemoteRepoTest method addMinimalRemoteRepositoryAndDeleteIt.

@Test
public void addMinimalRemoteRepositoryAndDeleteIt() throws Exception {
    final RemoteRepository repo = new RemoteRepository(newName(), "http://www.foo.com");
    final RemoteRepository result = client.stores().create(repo, name.getMethodName(), RemoteRepository.class);
    assertThat(result.getName(), equalTo(repo.getName()));
    assertThat(result.getUrl(), equalTo(repo.getUrl()));
    assertThat(result.equals(repo), equalTo(true));
    client.stores().delete(StoreType.remote, repo.getName(), name.getMethodName());
    assertThat(client.stores().exists(StoreType.remote, repo.getName()), equalTo(false));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 69 with RemoteRepository

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

the class AddRemoteRepoThenModifyAndVerifyTest method addAndModifyRemoteRepositoryThenRetrieveIt.

@Test
public void addAndModifyRemoteRepositoryThenRetrieveIt() throws Exception {
    final RemoteRepository rr = new RemoteRepository(newName(), "http://www.foo.com");
    client.stores().create(rr, name.getMethodName(), RemoteRepository.class);
    rr.setUrl("https://www.foo.com/");
    assertThat(rr.getUrl(), equalTo("https://www.foo.com/"));
    final boolean updated = client.stores().update(rr, name.getMethodName());
    assertThat(updated, equalTo(true));
    final RemoteRepository result = client.stores().load(StoreType.remote, rr.getName(), RemoteRepository.class);
    assertThat(result.getName(), equalTo(rr.getName()));
    assertThat(result.getUrl(), equalTo(rr.getUrl()));
    assertThat(result.equals(rr), equalTo(true));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 70 with RemoteRepository

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

the class SetBackSettingsManager method updateSettingsForGroup.

private DataFile updateSettingsForGroup(final Group group) throws SetBackDataException {
    if (!config.isEnabled()) {
        throw new SetBackDataException("SetBack is disabled!");
    }
    logger.info("Updating set-back settings.xml for group: {}", group.getName());
    List<ArtifactStore> concreteStores;
    try {
        concreteStores = storeManager.query().packageType(group.getPackageType()).getOrderedConcreteStoresInGroup(group.getName());
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve concrete membership for group: {}. Reason: {}", group.getName(), e.getMessage()), e);
        return null;
    }
    final List<RemoteRepository> remotes = new ArrayList<RemoteRepository>();
    for (final ArtifactStore cs : concreteStores) {
        if (StoreType.remote == cs.getKey().getType()) {
            remotes.add((RemoteRepository) cs);
        }
    }
    return updateSettings(group, concreteStores, remotes);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Aggregations

RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)149 Test (org.junit.Test)99 InputStream (java.io.InputStream)52 Group (org.commonjava.indy.model.core.Group)48 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)32 StoreKey (org.commonjava.indy.model.core.StoreKey)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 File (java.io.File)17 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)17 HostedRepository (org.commonjava.indy.model.core.HostedRepository)17 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)16 IndyDataException (org.commonjava.indy.data.IndyDataException)14 Before (org.junit.Before)13 Category (org.junit.experimental.categories.Category)12 Date (java.util.Date)10 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)10 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9