Search in sources :

Example 96 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 (!isIgnoreReadonly(eventMetadata) && storeManager.isReadonly(store)) {
            logger.debug("The store {} is readonly, store operation not allowed", store.getKey());
            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)

Example 97 with HostedRepository

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

the class ScheduleDBManager method setSnapshotTimeouts.

public 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 98 with HostedRepository

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

the class AbstractFoloContentManagementTest method before.

@Before
public void before() throws Exception {
    final String changelog = "Setup: " + name.getMethodName();
    final HostedRepository hosted = this.client.stores().create(new HostedRepository(STORE), changelog, HostedRepository.class);
    RemoteRepository central = null;
    if (client.stores().exists(remote, CENTRAL)) {
        client.stores().delete(remote, CENTRAL, "removing existing remote:central definition");
    }
    central = client.stores().create(new RemoteRepository(CENTRAL, centralServer.getBaseUri()), changelog, RemoteRepository.class);
    Group g;
    if (client.stores().exists(group, PUBLIC)) {
        g = client.stores().load(group, PUBLIC, Group.class);
    } else {
        g = client.stores().create(new Group(PUBLIC), changelog, Group.class);
    }
    g.setConstituents(Arrays.asList(hosted.getKey(), central.getKey()));
    client.stores().update(g, changelog);
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Before(org.junit.Before)

Example 99 with HostedRepository

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

the class ArtifactStoreValidatorTest method testRepoValidation.

@Test
public void testRepoValidation() throws Exception {
    // RemoteRepository validRepo = new RemoteRepository( "test", "http://www.foo.com" );
    // assertTrue( validator.isValid( validRepo ) );
    RemoteRepository inValidRepo = new RemoteRepository("test", "this.is.not.valid.repo");
    assertFalse(validator.isValid(inValidRepo));
    Group group = new Group("group");
    assertTrue(validator.isValid(group));
    HostedRepository hostedRepository = new HostedRepository("hosted");
    assertTrue(validator.isValid(hostedRepository));
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 100 with HostedRepository

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

the class MeasuringStoreQuery method getAllHostedRepositories.

@Override
public List<HostedRepository> getAllHostedRepositories(String packageType, Boolean enabled) throws IndyDataException {
    AtomicReference<IndyDataException> errorRef = new AtomicReference<>();
    List<HostedRepository> result = metricsManager.wrapWithStandardMetrics(() -> {
        try {
            return query.getAllHostedRepositories(packageType, enabled);
        } catch (IndyDataException e) {
            errorRef.set(e);
        }
        return null;
    }, () -> "getAllHostedRepositories");
    IndyDataException error = errorRef.get();
    if (error != null) {
        throw error;
    }
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) AtomicReference(java.util.concurrent.atomic.AtomicReference) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Aggregations

HostedRepository (org.commonjava.indy.model.core.HostedRepository)169 Test (org.junit.Test)90 ByteArrayInputStream (java.io.ByteArrayInputStream)83 Group (org.commonjava.indy.model.core.Group)80 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)32 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 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)11 IndyClientException (org.commonjava.indy.client.core.IndyClientException)10 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)10 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)9