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()]);
}
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));
}
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);
}
}
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);
}
}
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);
}
}
}
}
}
Aggregations