use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogFrameworkImplTest method testNullIdsDelete.
@Test(expected = IngestException.class)
public void testNullIdsDelete() throws IngestException {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
// call framework with null request
try {
framework.delete(null);
} catch (SourceUnavailableException e) {
fail();
}
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogFrameworkImplTest method testNullEntriesUpdate.
@Test(expected = IngestException.class)
public void testNullEntriesUpdate() throws IngestException {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
// call framework with null request
try {
framework.update((UpdateRequest) null);
} catch (SourceUnavailableException e) {
fail();
}
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class SearchControllerTest method createFramework.
private CatalogFramework createFramework() {
final long COUNT = 2;
CatalogFramework framework = mock(CatalogFramework.class);
List<Result> results = new ArrayList<Result>();
for (int i = 0; i < COUNT; i++) {
Result result = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("Metacard_" + i);
metacard.setTitle("Metacard " + i);
metacard.setLocation("POINT(" + i + " " + i + ")");
metacard.setType(BasicTypes.BASIC_METACARD);
metacard.setCreatedDate(TIMESTAMP);
metacard.setEffectiveDate(TIMESTAMP);
metacard.setExpirationDate(TIMESTAMP);
metacard.setModifiedDate(TIMESTAMP);
metacard.setContentTypeName("TEST");
metacard.setContentTypeVersion("1.0");
metacard.setTargetNamespace(URI.create(getClass().getPackage().getName()));
when(result.getDistanceInMeters()).thenReturn(100.0 * i);
when(result.getRelevanceScore()).thenReturn(100.0 * (COUNT - i) / COUNT);
when(result.getMetacard()).thenReturn(metacard);
results.add(result);
}
QueryResponse response = new QueryResponseImpl(mock(QueryRequest.class), new ArrayList<Result>(), COUNT);
response.getResults().addAll(results);
try {
when(framework.query(any(QueryRequest.class))).thenReturn(response);
} catch (UnsupportedQueryException e) {
LOGGER.debug("Error querying framework", e);
} catch (SourceUnavailableException e) {
LOGGER.debug("Error querying framework", e);
} catch (FederationException e) {
LOGGER.debug("Error querying framework", e);
}
return framework;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class QueryRunnable method queryCatalog.
protected QueryResponse queryCatalog(String sourceId, SearchRequest searchRequest, Subject subject, Map<String, Serializable> properties) {
Query query = searchRequest.getQuery();
QueryResponse response = getEmptyResponse(sourceId);
long startTime = System.currentTimeMillis();
try {
if (query != null) {
List<String> sourceIds;
if (sourceId == null) {
sourceIds = new ArrayList<>(searchRequest.getSourceIds());
} else {
sourceIds = Collections.singletonList(sourceId);
}
QueryRequest request = new QueryRequestImpl(query, false, sourceIds, properties);
if (subject != null) {
LOGGER.debug("Adding {} property with value {} to request.", SecurityConstants.SECURITY_SUBJECT, subject);
request.getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
}
LOGGER.debug("Sending query: {}", query);
response = searchController.getFramework().query(request);
}
} catch (UnsupportedQueryException | FederationException e) {
LOGGER.info("Error executing query. {}. Set log level to DEBUG for more information", e.getMessage());
LOGGER.debug("Error executing query", e);
response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
} catch (SourceUnavailableException e) {
LOGGER.info("Error executing query because the underlying source was unavailable. {}. Set log level to DEBUG for more information", e.getMessage());
LOGGER.debug("Error executing query because the underlying source was unavailable.", e);
response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
} catch (RuntimeException e) {
// Account for any runtime exceptions and send back a server error
// this prevents full stacktraces returning to the client
// this allows for a graceful server error to be returned
LOGGER.info("RuntimeException on executing query. {}. Set log level to DEBUG for more information", e.getMessage());
LOGGER.debug("RuntimeException on executing query", e);
response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
}
long estimatedTime = System.currentTimeMillis() - startTime;
response.getProperties().put("elapsed", estimatedTime);
return response;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class KmlEndpoint method getAvailableSources.
/**
* Creates a list of {@link NetworkLink}s, one for each {@link ddf.catalog.source.Source} including the local
* catalog.
*
* @param uriInfo - injected resource provding the URI.
* @return - {@link Kml} containing a folder of {@link NetworkLink}s.
*/
@GET
@Path(FORWARD_SLASH + "sources")
@Produces(KML_MIME_TYPE)
public Kml getAvailableSources(@Context UriInfo uriInfo) {
try {
SourceInfoResponse response = framework.getSourceInfo(new SourceInfoRequestEnterprise(false));
Kml kml = KmlFactory.createKml();
Folder folder = kml.createAndSetFolder();
folder.setOpen(true);
for (SourceDescriptor descriptor : response.getSourceInfo()) {
UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
builder = generateEndpointUrl(SystemBaseUrl.getRootContext() + FORWARD_SLASH + CATALOG_URL_PATH + FORWARD_SLASH + OPENSEARCH_URL_PATH, builder);
builder = builder.queryParam(SOURCE_PARAM, descriptor.getSourceId());
builder = builder.queryParam(OPENSEARCH_SORT_KEY, OPENSEARCH_DEFAULT_SORT);
builder = builder.queryParam(OPENSEARCH_FORMAT_KEY, KML_TRANSFORM_PARAM);
NetworkLink networkLink = generateViewBasedNetworkLink(builder.build().toURL(), descriptor.getSourceId());
folder.getFeature().add(networkLink);
}
return kml;
} catch (SourceUnavailableException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (UnknownHostException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (MalformedURLException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (IllegalArgumentException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
} catch (UriBuilderException e) {
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations