Search in sources :

Example 91 with HostedRepository

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

the class AutoProxCalculationTest method jsonRoundTrip_GroupCreation.

@Test
public void jsonRoundTrip_GroupCreation() throws IOException {
    HostedRepository first = new HostedRepository("first");
    HostedRepository second = new HostedRepository("second");
    Group repo = new Group("test", first.getKey(), second.getKey());
    AutoProxCalculation in = new AutoProxCalculation(repo, Arrays.asList(first, second), "test-rule.groovy");
    IndyObjectMapper mapper = new IndyObjectMapper(true);
    String json = mapper.writeValueAsString(in);
    AutoProxCalculation out = mapper.readValue(json, AutoProxCalculation.class);
    assertThat(out, notNullValue());
    assertThat(out.getRuleName(), equalTo(in.getRuleName()));
    assertThat(out.getStore(), equalTo(in.getStore()));
    assertThat(out, equalTo(in));
    List<ArtifactStore> supplementalStores = out.getSupplementalStores();
    assertThat(supplementalStores, notNullValue());
    assertThat(supplementalStores.size(), equalTo(2));
    assertThat(supplementalStores.get(0), equalTo(first));
    assertThat(supplementalStores.get(1), equalTo(second));
}
Also used : Group(org.commonjava.indy.model.core.Group) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 92 with HostedRepository

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

the class DeleteHostedRepoWithContentTest method deleteHostedRepoWithContent_RepoNotReCreatedWhenContentIsDeleted.

@Test
@Category(EventDependent.class)
public void deleteHostedRepoWithContent_RepoNotReCreatedWhenContentIsDeleted() throws Exception {
    final String named = "test";
    final String path = "path/to/foo.txt";
    final String content = "This is a test";
    client.content().store(StoreType.hosted, named, path, new ByteArrayInputStream(content.getBytes()));
    final InputStream stream = client.content().get(StoreType.hosted, named, path);
    final String retrieved = IOUtils.toString(stream);
    stream.close();
    assertThat(retrieved, equalTo(content));
    System.out.println("Waiting for server events to clear...");
    waitForEventPropagation();
    client.stores().delete(StoreType.hosted, named, "Removing test repo");
    System.out.println("Waiting for server events to clear...");
    waitForEventPropagation();
    final StoreListingDTO<HostedRepository> repos = client.stores().listHostedRepositories();
    boolean found = false;
    for (final HostedRepository repo : repos) {
        if (repo.getName().equals(named)) {
            found = true;
            break;
        }
    }
    assertThat(found, equalTo(false));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 93 with HostedRepository

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

the class ScheduleManager method setSnapshotTimeouts.

public synchronized void setSnapshotTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
    if (!schedulerConfig.isEnabled()) {
        logger.debug("Scheduler disabled.");
        return;
    }
    HostedRepository deploy = null;
    try {
        final ArtifactStore store = dataManager.getArtifactStore(key);
        if (store == null) {
            return;
        }
        if (store instanceof HostedRepository) {
            deploy = (HostedRepository) store;
        } else if (store instanceof Group) {
            final Group group = (Group) store;
            deploy = findDeployPoint(group);
        }
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve deploy point for: %s. Reason: %s", key, e.getMessage()), e);
    }
    if (deploy == null) {
        return;
    }
    final ContentAdvisor advisor = StreamSupport.stream(Spliterators.spliteratorUnknownSize(contentAdvisor.iterator(), Spliterator.ORDERED), false).filter(Objects::nonNull).findFirst().orElse(null);
    final ContentQuality quality = advisor == null ? null : advisor.getContentQuality(path);
    if (quality == null) {
        return;
    }
    if (ContentQuality.SNAPSHOT == quality && deploy.getSnapshotTimeoutSeconds() > 0) {
        final int timeout = deploy.getSnapshotTimeoutSeconds();
        //            //            logger.info( "[SNAPSHOT TIMEOUT SET] {}/{}; {}", deploy.getKey(), path, new Date( timeout ) );
        //            cancel( new StoreKeyMatcher( key, CONTENT_JOB_TYPE ), path );
        scheduleContentExpiration(key, path, timeout);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ContentAdvisor(org.commonjava.indy.spi.pkg.ContentAdvisor) ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Objects(java.util.Objects) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 94 with HostedRepository

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

the class RepoChangelogStoreDisableTest method test.

@Test
public void test() throws Exception {
    HostedRepository repo = new HostedRepository(MAVEN_PKG_KEY, newName());
    final StoreKey hostedKey = repo.getKey();
    repo = client.stores().create(repo, name.getMethodName(), HostedRepository.class);
    repo.setAllowReleases(!repo.isAllowReleases());
    client.stores().update(repo, name.getMethodName());
    repo.setReadonly(true);
    client.stores().update(repo, name.getMethodName());
    IndyRepoChangelogClientModule repoChangelogClientModule = client.module(IndyRepoChangelogClientModule.class);
    List<ChangeEvent> logs = null;
    try {
        logs = repoChangelogClientModule.getByStoreKey(repo.getKey());
    } catch (IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(404));
    }
    assertNotNull(logs);
    assertTrue(logs.isEmpty());
    try {
        repoChangelogClientModule.getAll();
    } catch (IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(404));
    }
    assertNotNull(logs);
    assertTrue(logs.isEmpty());
}
Also used : IndyRepoChangelogClientModule(org.commonjava.indy.changelog.client.IndyRepoChangelogClientModule) ChangeEvent(org.commonjava.auditquery.history.ChangeEvent) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 95 with HostedRepository

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

the class AbstractFoloUrlsTest method before.

@Before
public void before() throws Exception {
    content = client.module(IndyFoloContentClientModule.class);
    admin = client.module(IndyFoloAdminClientModule.class);
    if (!createStandardTestStructures()) {
        return;
    }
    final String changelog = "Create test structures";
    final HostedRepository hosted = this.client.stores().create(new HostedRepository(STORE), changelog, HostedRepository.class);
    Group g;
    if (client.stores().exists(group, PUBLIC)) {
        System.out.println("Loading pre-existing public group.");
        g = client.stores().load(group, PUBLIC, Group.class);
    } else {
        System.out.println("Creating new group 'public'");
        g = client.stores().create(new Group(PUBLIC), changelog, Group.class);
    }
    g.setConstituents(Collections.singletonList(hosted.getKey()));
    client.stores().update(g, changelog);
}
Also used : Group(org.commonjava.indy.model.core.Group) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Before(org.junit.Before)

Aggregations

HostedRepository (org.commonjava.indy.model.core.HostedRepository)173 Test (org.junit.Test)91 ByteArrayInputStream (java.io.ByteArrayInputStream)84 Group (org.commonjava.indy.model.core.Group)81 InputStream (java.io.InputStream)42 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)41 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)37 Before (org.junit.Before)37 StoreKey (org.commonjava.indy.model.core.StoreKey)34 Transfer (org.commonjava.maven.galley.model.Transfer)23 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)19 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)16 IndyDataException (org.commonjava.indy.data.IndyDataException)15 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)15 PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)13 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)12 IndyClientException (org.commonjava.indy.client.core.IndyClientException)11 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)11 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)10 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)9