Search in sources :

Example 76 with ArtifactStore

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

the class SettingsSubStore method getChildrenNames.

@Override
public String[] getChildrenNames(final ITransaction transaction, final String folderUri) throws WebdavException {
    final SettingsURIMatcher matcher = new SettingsURIMatcher(folderUri);
    final Set<String> names = new TreeSet<String>();
    if (matcher.isSettingsRootResource()) {
        for (final StoreType type : StoreType.values()) {
            names.add(type.singularEndpointName());
        }
    } else if (matcher.isSettingsTypeResource()) {
        final StoreType type = matcher.getStoreType();
        List<? extends ArtifactStore> all;
        try {
            all = indy.query().packageType(MAVEN_PKG_KEY).storeTypes(type).getAll();
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to retrieve list of artifact stores: %s", e.getMessage()), e);
            throw new WebdavException("Failed to retrieve list of settings configurations.");
        }
        for (final ArtifactStore store : all) {
            final String storeName = formatSettingsResourceName(store.getKey().getType(), store.getName());
            //                logger.info( "\n\nCreating settings resource for: '{}'\n\n", storeName );
            names.add(storeName);
        }
    }
    return names.toArray(new String[names.size()]);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) SettingsURIMatcher(org.commonjava.indy.dotmaven.util.SettingsURIMatcher) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) TreeSet(java.util.TreeSet) WebdavException(net.sf.webdav.exceptions.WebdavException) List(java.util.List)

Example 77 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore 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 78 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore 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 79 with ArtifactStore

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

the class TimeoutEventListener method onExpirationEvent.

//    @Inject
//    @ExecutorConfig( daemon = true, priority = 7, named = "indy-events" )
//    private Executor executor;
public void onExpirationEvent(@Observes final SchedulerEvent event) {
    if (!(event instanceof SchedulerTriggerEvent) || !event.getJobType().equals(ScheduleManager.CONTENT_JOB_TYPE)) {
        return;
    }
    ContentExpiration expiration;
    try {
        expiration = objectMapper.readValue(event.getPayload(), ContentExpiration.class);
    } catch (final IOException e) {
        logger.error("Failed to read ContentExpiration from event payload.", e);
        return;
    }
    final StoreKey key = expiration.getKey();
    final String path = expiration.getPath();
    try {
        ArtifactStore store = storeManager.getArtifactStore(key);
        boolean deleted = contentManager.delete(store, path);
        if (!deleted) {
            logger.error("Failed to delete Transfer for: {} in: {} (for content timeout).", path, key);
        } else {
            deleteExpiration(key, path);
        }
    } catch (IndyWorkflowException e) {
        logger.error(String.format("Failed to retrieve Transfer for: %s in: %s (for content timeout). Reason: %s", path, key, e), e);
    } catch (IndyDataException e) {
        scheduleManager.deleteJob(scheduleManager.groupName(key, ScheduleManager.CONTENT_JOB_TYPE), path);
        logger.error(String.format("Failed to retrieve ArtifactStore for: %s (for content timeout). Reason: %s", key, e), e);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 80 with ArtifactStore

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

the class TimeoutEventListener method onStoreUpdate.

public void onStoreUpdate(@Observes final ArtifactStorePostUpdateEvent event) {
    final ArtifactStoreUpdateType eventType = event.getType();
    if (eventType == ArtifactStoreUpdateType.UPDATE) {
        for (final ArtifactStore store : event) {
            final StoreKey key = store.getKey();
            final StoreType type = key.getType();
            if (type == StoreType.hosted) {
                logger.info("[ADJUST TIMEOUTS] Adjusting snapshot expirations in: {}", store.getKey());
                try {
                    scheduleManager.rescheduleSnapshotTimeouts((HostedRepository) store);
                } catch (final IndySchedulerException e) {
                    logger.error("Failed to update snapshot timeouts in: " + store.getKey(), e);
                }
            } else if (type == StoreType.remote) {
                logger.info("[ADJUST TIMEOUTS] Adjusting proxied-file expirations in: {}", store.getKey());
                try {
                    scheduleManager.rescheduleProxyTimeouts((RemoteRepository) store);
                } catch (final IndySchedulerException e) {
                    logger.error("Failed to update proxy-cache timeouts in: " + store.getKey(), e);
                }
            }
        }
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ArtifactStoreUpdateType(org.commonjava.indy.change.event.ArtifactStoreUpdateType) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)93 IndyDataException (org.commonjava.indy.data.IndyDataException)54 StoreKey (org.commonjava.indy.model.core.StoreKey)46 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)35 Logger (org.slf4j.Logger)30 ArrayList (java.util.ArrayList)25 Transfer (org.commonjava.maven.galley.model.Transfer)25 Group (org.commonjava.indy.model.core.Group)20 StoreType (org.commonjava.indy.model.core.StoreType)19 IOException (java.io.IOException)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)17 HashSet (java.util.HashSet)15 List (java.util.List)15 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 StoreDataManager (org.commonjava.indy.data.StoreDataManager)10 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 Test (org.junit.Test)9 ApiOperation (io.swagger.annotations.ApiOperation)8