use of org.commonjava.indy.IndyWorkflowException 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.IndyWorkflowException in project indy by Commonjava.
the class ReplicationController method getRemoteStores.
// FIXME: Find a better solution to the passed-in generic deserialization problem...erasure is a mother...
private List<? extends ArtifactStore> getRemoteStores(final ReplicationDTO dto) throws IndyWorkflowException {
final String apiUrl = dto.getApiUrl();
String remotesUrl = null;
String groupsUrl = null;
String hostedUrl = null;
try {
remotesUrl = buildUrl(apiUrl, "/admin/remotes");
groupsUrl = buildUrl(apiUrl, "/admin/groups");
hostedUrl = buildUrl(apiUrl, "/admin/hosted");
} catch (final MalformedURLException e) {
throw new IndyWorkflowException("Failed to construct store definition-retrieval URL from api-base: {}. Reason: {}", e, apiUrl, e.getMessage());
}
// logger.info( "\n\n\n\n\n[AutoProx] Checking URL: {} from:", new Throwable(), url );
final List<ArtifactStore> result = new ArrayList<ArtifactStore>();
addStoresFrom(result, remotesUrl, dto, RemoteRepository.class);
addStoresFrom(result, groupsUrl, dto, Group.class);
addStoresFrom(result, hostedUrl, dto, HostedRepository.class);
return result;
}
use of org.commonjava.indy.IndyWorkflowException 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.IndyWorkflowException 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.IndyWorkflowException in project indy by Commonjava.
the class StatsController method getActiveAddOnsJavascript.
public String getActiveAddOnsJavascript() throws IndyWorkflowException {
try {
final String json = serializer.writeValueAsString(getActiveAddOns());
final Map<String, Object> params = new HashMap<>();
final Map<String, String> jsMap = new HashMap<>();
if (addons != null) {
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
for (final IndyAddOn addon : addons) {
final String jsRef = addon.getId().getInitJavascriptHref();
if (jsRef == null) {
logger.debug("Add-On has no init javascript: {}", addon);
continue;
}
try (InputStream in = cl.getResourceAsStream(jsRef)) {
if (in == null) {
logger.error("Add-On failed to load: {}. Initialization javascript NOT FOUND in classpath: {}", addon, jsRef);
continue;
}
jsMap.put(jsRef, IOUtils.toString(in));
} catch (final IOException e) {
logger.error("Add-On failed to load: {}. Cannot load initialization javascript from classpath: {}", addon, jsRef);
}
}
}
params.put(ADDONS_KEY, json);
params.put(ADDONS_LOGIC, jsMap);
return templates.render(ACTIVE_ADDONS_JS, params);
} catch (final IndyGroovyException e) {
throw new IndyWorkflowException("Failed to render javascript wrapper for active addons. Reason: %s", e, e.getMessage());
} catch (final JsonProcessingException e) {
throw new IndyWorkflowException("Failed to render javascript wrapper for active addons. Reason: %s", e, e.getMessage());
}
}
Aggregations