use of org.commonjava.indy.data.IndyDataException 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.data.IndyDataException 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.data.IndyDataException in project indy by Commonjava.
the class ReplicationController method replicate.
public Set<StoreKey> replicate(final ReplicationDTO dto, final String user) throws IndyWorkflowException {
final ReplicationRepositoryCreator creator = createRepoCreator();
if (creator == null) {
throw new IndyWorkflowException(500, "Cannot replicate; ReplicationRepositoryCreator could not be instantiated.");
}
try {
dto.validate();
} catch (final IndyException e) {
throw new IndyWorkflowException("Invalid replication request DTO: %s", e, e.getMessage());
}
List<? extends ArtifactStore> remoteStores = null;
List<EndpointView> remoteEndpoints = null;
final boolean overwrite = dto.isOverwrite();
final Set<StoreKey> replicated = new HashSet<StoreKey>();
for (final ReplicationAction action : dto) {
if (action == null) {
continue;
}
logger.info("Processing replication action:\n\n {}\n\nin DTO: {}\n\n", action, dto);
final String include = action.getInclude();
final String exclude = action.getExclude();
try {
if (action.getType() == ActionType.PROXY) {
if (remoteEndpoints == null) {
remoteEndpoints = getEndpoints(dto);
}
for (final EndpointView view : remoteEndpoints) {
final String key = "remote-" + view.getType() + "_" + view.getName();
if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
final StoreKey sk = new StoreKey(StoreType.remote, key);
if (overwrite || !data.hasArtifactStore(sk)) {
RemoteRepository repo = creator.createRemoteRepository(key, view);
repo.setMetadata(ArtifactStore.METADATA_ORIGIN, REPLICATION_ORIGIN);
setProxyAttributes(repo, action);
data.storeArtifactStore(repo, new ChangeSummary(user, "REPLICATION: Proxying remote indy repository: " + view.getResourceUri()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
replicated.add(repo.getKey());
}
}
}
} else if (action.getType() == ActionType.MIRROR) {
if (remoteStores == null) {
remoteStores = getRemoteStores(dto);
}
for (final ArtifactStore store : remoteStores) {
final String key = store.getKey().toString();
if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
if (overwrite || !data.hasArtifactStore(store.getKey())) {
if (store instanceof RemoteRepository) {
setProxyAttributes(((RemoteRepository) store), action);
}
data.storeArtifactStore(store, new ChangeSummary(user, "REPLICATION: Mirroring remote indy store: " + store.getKey()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
replicated.add(store.getKey());
}
}
}
}
} catch (final IndyDataException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException(e.getMessage(), e);
}
}
return replicated;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class SchedulerController method getDisabledStores.
public ExpirationSet getDisabledStores() throws IndyWorkflowException {
try {
// This key matcher will compare with the cache key group to see if the group ends with the "Disable-Timeout"(jobtype)
ExpirationSet expirations = scheduleManager.findMatchingExpirations(cacheHandle -> cacheHandle.execute(Cache::keySet).stream().filter(key -> key.getType().equals(StoreEnablementManager.DISABLE_TIMEOUT)).collect(Collectors.toSet()));
// TODO: This seems REALLY inefficient...
storeDataManager.getAllArtifactStores().forEach((store) -> {
if (store.isDisabled()) {
expirations.getItems().add(indefiniteDisable(store));
}
});
return expirations;
} catch (IndyDataException e) {
throw new IndyWorkflowException("Failed to load stores to check for indefinite disable. Reason: %s", e, e.getMessage());
}
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class ContentController method rescanAll.
public void rescanAll(final EventMetadata eventMetadata) throws IndyWorkflowException {
try {
final List<ArtifactStore> stores = storeManager.query().concreteStores().getAll();
contentManager.rescanAll(stores, eventMetadata);
} catch (final IndyDataException e) {
throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to retrieve list of concrete stores. Reason: {}", e, e.getMessage());
}
}
Aggregations