use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class IngestCommand method processBatch.
private boolean processBatch(CatalogFacade catalog, ArrayList<Metacard> metacards) throws SourceUnavailableException {
CreateResponse createResponse = null;
try {
createResponse = createMetacards(catalog, metacards);
} catch (IngestException e) {
printErrorMessage("Error executing command: " + e.getMessage());
if (INGEST_LOGGER.isWarnEnabled()) {
INGEST_LOGGER.warn("Error ingesting metacard batch {}", buildIngestLog(metacards), e);
}
} catch (SourceUnavailableException e) {
if (INGEST_LOGGER.isWarnEnabled()) {
INGEST_LOGGER.warn("Error on process batch, local Provider not available. {}" + " metacards failed to ingest. {}", metacards.size(), buildIngestLog(metacards), e);
}
} finally {
IntStream range = IntStream.range(0, metacards.size());
range.forEach(i -> phaser.arriveAndDeregister());
range.close();
}
if (createResponse != null) {
ingestCount.getAndAdd(metacards.size());
}
return createResponse != null;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class MigrateCommand method query.
@Override
protected SourceResponse query(CatalogFacade framework, Filter filter, int startIndex, long querySize) {
QueryImpl query = new QueryImpl(filter);
query.setRequestsTotalResultsCount(true);
query.setPageSize((int) querySize);
query.setSortBy(new SortByImpl(Metacard.MODIFIED, SortOrder.DESCENDING));
QueryRequest queryRequest = new QueryRequestImpl(query);
query.setStartIndex(startIndex);
SourceResponse response;
try {
LOGGER.debug("Querying with startIndex: {}", startIndex);
response = framework.query(queryRequest);
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
printErrorMessage(String.format("Received error from Frameworks: %s%n", e.getMessage()));
return null;
}
if (response.getProcessingDetails() != null && !response.getProcessingDetails().isEmpty()) {
for (SourceProcessingDetails details : response.getProcessingDetails()) {
LOGGER.debug("Got Issues: {}", details.getWarnings());
}
return null;
}
return response;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class FederationStrategyTest method testQueryTimeout.
/**
* Tests that the framework properly times out using the default federation strategy.
*/
@Test
public void testQueryTimeout() throws Exception {
long queryDelay = 100;
UuidGenerator uuidGenerator = mock(UuidGenerator.class);
when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
MockDelayProvider provider = new MockDelayProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
provider.setQueryDelayMillis(queryDelay);
// Mock register the provider in the container
SourcePollerRunner runner = new SourcePollerRunner();
SourcePoller poller = new SourcePoller(runner);
runner.bind(provider);
// Must have more than one thread or sleeps will block the monitor
SortedFederationStrategy fedStrategy = new SortedFederationStrategy(executor, new ArrayList<>(), new ArrayList<>());
FrameworkProperties props = new FrameworkProperties();
props.setCatalogProviders(Collections.singletonList(provider));
props.setFederationStrategy(fedStrategy);
props.setSourcePoller(poller);
props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
props.setFilterBuilder(new GeotoolsFilterBuilder());
props.setDefaultAttributeValueRegistry(new DefaultAttributeValueRegistryImpl());
OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
MetacardFactory metacardFactory = new MetacardFactory(props.getMimeTypeToTransformerMapper(), uuidGenerator);
OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(props, metacardFactory);
Historian historian = new Historian();
historian.setHistoryEnabled(false);
SourceOperations sourceOperations = new SourceOperations(props);
QueryOperations queryOperations = new QueryOperations(props, sourceOperations, opsSecurity, opsMetacard);
OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(props, sourceOperations);
CreateOperations createOperations = new CreateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
UpdateOperations updateOperations = new UpdateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
DeleteOperations deleteOperations = new DeleteOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard);
opsStorage.setHistorian(historian);
updateOperations.setHistorian(historian);
deleteOperations.setHistorian(historian);
deleteOperations.setOpsCatStoreSupport(opsCatStore);
CatalogFrameworkImpl framework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, null, null, null);
sourceOperations.bind(provider);
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
CreateResponse createResponse = null;
try {
try {
createResponse = framework.create(new CreateRequestImpl(metacards, null));
} catch (SourceUnavailableException e) {
long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
//this is a hack because the unit test is flaky and should be removed once a better test is possible
while (System.currentTimeMillis() < timeout) {
Thread.sleep(1000);
try {
createResponse = framework.create(new CreateRequestImpl(metacards, null));
break;
} catch (SourceUnavailableException e1) {
//ignore
}
}
}
if (createResponse == null) {
fail();
}
} catch (IngestException e) {
fail();
}
assertEquals(createResponse.getCreatedMetacards().size(), provider.size());
for (Metacard curCard : createResponse.getCreatedMetacards()) {
assertNotNull(curCard.getId());
}
QueryImpl query = new QueryImpl(filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(createResponse.getCreatedMetacards().get(0).getId())));
query.setTimeoutMillis(SHORT_TIMEOUT);
query.setSortBy(new FilterFactoryImpl().sort(Result.RELEVANCE, SortOrder.ASCENDING));
QueryRequest fedQueryRequest = new QueryRequestImpl(query);
try {
QueryResponse response = framework.query(fedQueryRequest);
assertEquals("Timeout should happen before results return", 0, response.getHits());
} catch (UnsupportedQueryException e) {
fail();
} catch (FederationException e) {
LOGGER.error("Unexpected federation exception during test", e);
fail();
}
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogMetrics method recordSourceQueryExceptions.
private void recordSourceQueryExceptions(QueryResponse response) {
Set<ProcessingDetails> processingDetails = (Set<ProcessingDetails>) response.getProcessingDetails();
if (processingDetails == null || processingDetails.iterator() == null) {
return;
}
Iterator<ProcessingDetails> iterator = processingDetails.iterator();
while (iterator.hasNext()) {
ProcessingDetails next = iterator.next();
if (next != null && next.getException() != null) {
if (next.getException() instanceof UnsupportedQueryException) {
unsupportedQueryExceptions.mark();
} else if (next.getException() instanceof SourceUnavailableException) {
sourceUnavailableExceptions.mark();
} else if (next.getException() instanceof FederationException) {
federationExceptions.mark();
}
exceptions.mark();
}
}
return;
}
use of ddf.catalog.source.SourceUnavailableException in project ddf by codice.
the class CatalogMetricsTest method catalogExceptionMetric.
@Test
public void catalogExceptionMetric() throws Exception {
QueryResponse response = new QueryResponseImpl(new QueryRequestImpl(new QueryImpl(idFilter)));
Set<ProcessingDetails> details = response.getProcessingDetails();
details.addAll(new HashSet<ProcessingDetails>() {
{
add(new ProcessingDetailsImpl("source1", new UnsupportedQueryException()));
add(new ProcessingDetailsImpl("source2", new SourceUnavailableException()));
add(new ProcessingDetailsImpl("source3", new FederationException()));
add(new ProcessingDetailsImpl("source4", new Exception()));
}
});
underTest.process(response);
assertThat(underTest.exceptions.getCount(), is(4L));
assertThat(underTest.unsupportedQueryExceptions.getCount(), is(1L));
assertThat(underTest.sourceUnavailableExceptions.getCount(), is(1L));
assertThat(underTest.federationExceptions.getCount(), is(1L));
}
Aggregations