Search in sources :

Example 66 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 67 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 68 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 69 with HostedRepository

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

the class DefaultDownloadManagerTest method getTransferFromStoreList_DownloadOp_SkipIfDoesntExist.

@Test
public void getTransferFromStoreList_DownloadOp_SkipIfDoesntExist() throws IndyDataException, IndyWorkflowException {
    ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test setup");
    HostedRepository hosted1 = new HostedRepository(MAVEN_PKG_KEY, "one");
    HostedRepository hosted2 = new HostedRepository(MAVEN_PKG_KEY, "two");
    storeManager.storeArtifactStore(hosted1, summary, false, true, new EventMetadata());
    storeManager.storeArtifactStore(hosted2, summary, false, true, new EventMetadata());
    String path = "/some/path.txt";
    Transfer transfer = downloadManager.getStorageReference(Arrays.asList(hosted1, hosted2), path, TransferOperation.DOWNLOAD);
    assertThat(transfer, nullValue());
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 70 with HostedRepository

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

the class DefaultDownloadManager method store.

/*
     * (non-Javadoc)
     * @see org.commonjava.indy.core.rest.util.FileManager#upload(java.util.List, java.lang.String,
     * java.io.InputStream)
     */
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    final ContentQuality quality = getQuality(path);
    HostedRepository selected = null;
    for (final ArtifactStore store : stores) {
        if (storeManager.isReadonly(store)) {
            logger.info("The store {} is readonly, store operation not allowed");
            continue;
        }
        if (storeIsSuitableFor(store, quality, op)) {
            selected = (HostedRepository) store;
            break;
        }
    }
    if (selected == null) {
        logger.warn("Cannot deploy. No valid deploy points in group.");
        throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No deployment locations available.");
    }
    logger.info("Storing: {} in selected: {} with event metadata: {}", path, selected, eventMetadata);
    store(selected, path, stream, op, eventMetadata);
    return getStorageReference(selected.getKey(), path);
}
Also used : ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Aggregations

HostedRepository (org.commonjava.indy.model.core.HostedRepository)77 Test (org.junit.Test)47 Group (org.commonjava.indy.model.core.Group)44 ByteArrayInputStream (java.io.ByteArrayInputStream)37 Transfer (org.commonjava.maven.galley.model.Transfer)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)18 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 Before (org.junit.Before)15 InputStream (java.io.InputStream)13 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)11 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)11 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)10 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)9 PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)7 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)7 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)7 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)6 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)6 MetadataXpp3Reader (org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader)6 IndyDataException (org.commonjava.indy.data.IndyDataException)6