use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class SourceOperations method getFanoutSourceInfo.
/**
* Retrieves the {@link SourceDescriptor} info for all {@link FederatedSource}s in the fanout
* configuration, but the all of the source info, e.g., content types, for all of the available
* {@link FederatedSource}s is packed into one {@link SourceDescriptor} for the fanout
* configuration with the fanout's site name in it. This keeps the individual {@link
* FederatedSource}s' source info hidden from the external client.
*/
private SourceInfoResponse getFanoutSourceInfo(SourceInfoRequest sourceInfoRequest) throws SourceUnavailableException {
SourceInfoResponse response;
SourceDescriptorImpl sourceDescriptor;
try {
// request
if (sourceInfoRequest == null) {
throw new IllegalArgumentException("SourceInfoRequest was null");
}
Set<SourceDescriptor> sourceDescriptors = new LinkedHashSet<>();
Set<String> ids = sourceInfoRequest.getSourceIds();
// specified
if (ids != null) {
Optional<String> notLocal = ids.stream().filter(s -> !s.equals(getId())).findFirst();
if (notLocal.isPresent()) {
SourceUnavailableException sourceUnavailableException = new SourceUnavailableException("Unknown source: " + notLocal.get());
LOGGER.debug("Throwing SourceUnavailableException for unknown source: {}", notLocal.get(), sourceUnavailableException);
throw sourceUnavailableException;
}
}
// Fanout will only add one source descriptor with all the contents
// Using a List here instead of a Set because we should not rely on how Sources are compared
final List<Source> availableSources = frameworkProperties.getFederatedSources().stream().filter(this::isSourceAvailable).collect(Collectors.toList());
final Set<ContentType> contentTypes = availableSources.stream().map(source -> contentTypesCache.getCachedValueForSource(source).orElseGet(() -> {
LOGGER.debug("Unknown content types for source id={}", source.getId());
return Collections.emptySet();
})).flatMap(Collection::stream).collect(Collectors.toSet());
if (isSourceAvailable(catalog)) {
availableSources.add(catalog);
final Optional<Set<ContentType>> catalogContentTypes = contentTypesCache.getCachedValueForSource(catalog);
if (catalogContentTypes.isPresent()) {
contentTypes.addAll(catalogContentTypes.get());
} else {
LOGGER.debug("Unknown content types for the localSource");
}
}
List<Action> actions = getSourceActions(catalog);
// only reveal this sourceDescriptor, not the federated sources
sourceDescriptor = new SourceDescriptorImpl(this.getId(), contentTypes, actions);
if (this.getVersion() != null) {
sourceDescriptor.setVersion(this.getVersion());
}
sourceDescriptor.setAvailable(!availableSources.isEmpty());
sourceDescriptors.add(sourceDescriptor);
response = new SourceInfoResponseImpl(sourceInfoRequest, null, sourceDescriptors);
} catch (RuntimeException re) {
throw new SourceUnavailableException(GET_SOURCE_EXCEPTION_MSG, re);
}
return response;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class SourceOperations method getSourceInfo.
public SourceInfoResponse getSourceInfo(SourceInfoRequest sourceInfoRequest, boolean fanoutEnabled) throws SourceUnavailableException {
SourceInfoResponse response;
Set<SourceDescriptor> sourceDescriptors;
if (fanoutEnabled) {
return getFanoutSourceInfo(sourceInfoRequest);
}
boolean addCatalogProviderDescriptor = false;
try {
validateSourceInfoRequest(sourceInfoRequest);
// Obtain the source information based on the sourceIds in the
// request
sourceDescriptors = new LinkedHashSet<>();
Set<String> requestedSourceIds = sourceInfoRequest.getSourceIds();
// If it is an enterprise request than add all source information for the enterprise
if (sourceInfoRequest.isEnterprise()) {
sourceDescriptors = getFederatedSourceDescriptors(frameworkProperties.getFederatedSources(), true);
// If Ids are specified check if they are known sources
} else if (requestedSourceIds != null) {
LOGGER.debug("getSourceRequest contains requested source ids");
Set<FederatedSource> discoveredSources = new HashSet<>();
for (String requestedSourceId : requestedSourceIds) {
// Check if the requestedSourceId can be found in the known federatedSources
final List<FederatedSource> sources = frameworkProperties.getFederatedSources().stream().filter(e -> e.getId().equals(requestedSourceId)).collect(Collectors.toList());
if (!sources.isEmpty()) {
String logMsg = (sources.size() == 1) ? "Found federated source: {}" : "Multiple FederatedSources found for id: {}";
LOGGER.debug(logMsg, requestedSourceId);
discoveredSources.add(sources.get(0));
} else {
LOGGER.debug("Unable to find source: {}", requestedSourceId);
// Check for the local catalog provider, DDF sourceId represents this
if (requestedSourceId.equals(getId())) {
LOGGER.debug("adding CatalogSourceDescriptor since it was in sourceId list as: {}", requestedSourceId);
addCatalogProviderDescriptor = true;
}
}
}
sourceDescriptors = getFederatedSourceDescriptors(discoveredSources, addCatalogProviderDescriptor);
} else {
// only add the local catalogProviderDescriptor
addCatalogSourceDescriptor(sourceDescriptors);
}
response = new SourceInfoResponseImpl(sourceInfoRequest, null, sourceDescriptors);
} catch (RuntimeException re) {
LOGGER.debug(GET_SOURCE_EXCEPTION_MSG, re);
throw new SourceUnavailableException(GET_SOURCE_EXCEPTION_MSG);
}
return response;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class GazetteerQueryCatalog method getSuggestedNames.
@Override
public List<Suggestion> getSuggestedNames(String queryString, int maxResults) throws GeoEntryQueryException {
Map<String, Serializable> suggestProps = new HashMap<>();
suggestProps.put(SUGGESTION_QUERY_KEY, queryString);
suggestProps.put(SUGGESTION_CONTEXT_KEY, GAZETTEER_METACARD_TAG);
suggestProps.put(SUGGESTION_DICT_KEY, SUGGEST_PLACE_KEY);
Query suggestionQuery = new QueryImpl(filterBuilder.attribute(Core.TITLE).text(queryString));
QueryRequest suggestionRequest = new QueryRequestImpl(suggestionQuery, suggestProps);
try {
QueryResponse suggestionResponse = catalogFramework.query(suggestionRequest);
if (suggestionResponse.getPropertyValue(SUGGESTION_RESULT_KEY) instanceof List) {
List<Map.Entry<String, String>> suggestions = (List<Map.Entry<String, String>>) suggestionResponse.getPropertyValue(SUGGESTION_RESULT_KEY);
return suggestions.stream().map(suggestion -> new SuggestionImpl(suggestion.getKey(), suggestion.getValue())).limit(maxResults).collect(Collectors.toList());
}
} catch (SourceUnavailableException | FederationException | UnsupportedQueryException e) {
throw new GeoEntryQueryException("Failed to execute suggestion query", e);
}
return Collections.emptyList();
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogFeatureQueryable method query.
@Override
public List<SimpleFeature> query(String queryString, String featureCode, int maxResults) throws FeatureQueryException {
Validate.notNull(queryString, "queryString can't be null");
if (maxResults < 0) {
throw new IllegalArgumentException("maxResults can't be negative");
}
Query query = catalogHelper.getQueryForName(queryString);
QueryRequest queryRequest = new QueryRequestImpl(query);
SourceResponse response;
try {
response = catalogFramework.query(queryRequest);
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
throw new FeatureQueryException("Failed to query catalog", e);
}
return response.getResults().stream().map(Result::getMetacard).map(this::getFeatureForMetacard).filter(Objects::nonNull).limit(maxResults).collect(Collectors.toList());
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class GeoNamesCatalogIndexer method executeCreateMetacardRequest.
private void executeCreateMetacardRequest(List<Metacard> metacards) {
int totalMetacards = metacards.size();
for (int i = 0; i < totalMetacards; i += BATCH_SIZE) {
int lastIndex = i + BATCH_SIZE;
if (lastIndex > metacards.size()) {
lastIndex = metacards.size();
}
List<Metacard> sublist = metacards.subList(i, lastIndex);
Map<String, Serializable> properties = new HashMap<>();
CreateRequest createRequest = new CreateRequestImpl(sublist, properties);
try {
CreateResponse createResponse = catalogFramework.create(createRequest);
List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
LOGGER.trace("Created {} metacards.", createdMetacards == null ? 0 : createdMetacards.size());
} catch (IngestException | SourceUnavailableException e) {
LOGGER.debug("Unable to create Metacards", e);
}
}
LOGGER.trace("Created {} metacards.", totalMetacards);
}
Aggregations