Search in sources :

Example 11 with Source

use of ddf.catalog.source.Source in project admin-console-beta by connexta.

the class SourceUtilCommons method getAllSourceReferences.

public static List<Source> getAllSourceReferences(ConfiguratorFactory configuratorFactory) {
    List<Source> sources = new ArrayList<>();
    ConfigReader configReader = configuratorFactory.getConfigReader();
    sources.addAll(configReader.getServices(FederatedSource.class, null));
    sources.addAll(configReader.getServices(ConnectedSource.class, null));
    return sources;
}
Also used : FederatedSource(ddf.catalog.source.FederatedSource) ConnectedSource(ddf.catalog.source.ConnectedSource) ConfigReader(org.codice.ddf.admin.configurator.ConfigReader) ArrayList(java.util.ArrayList) Source(ddf.catalog.source.Source) ConnectedSource(ddf.catalog.source.ConnectedSource) InputSource(org.xml.sax.InputSource) FederatedSource(ddf.catalog.source.FederatedSource)

Example 12 with Source

use of ddf.catalog.source.Source in project ddf by codice.

the class CatalogBundle method waitForSource.

private <T extends Source> T waitForSource(String id, Class<T> type) throws InterruptedException, InvalidSyntaxException {
    T source = null;
    long timeoutLimit = System.currentTimeMillis() + CATALOG_PROVIDER_TIMEOUT;
    boolean available = false;
    while (!available) {
        ServiceReference<CatalogFramework> frameworkRef = serviceManager.getServiceReference(CatalogFramework.class);
        CatalogFramework framework = null;
        if (frameworkRef != null) {
            framework = serviceManager.getService(frameworkRef);
        }
        if (source == null) {
            source = serviceManager.getServiceReferences(type, null).stream().map(serviceManager::getService).filter(src -> id.equals(src.getId())).findFirst().orElse(null);
        }
        if (source != null && framework != null) {
            SourceInfoRequestEnterprise sourceInfoRequestEnterprise = new SourceInfoRequestEnterprise(true);
            try {
                SourceInfoResponse sources = framework.getSourceInfo(sourceInfoRequestEnterprise);
                Set<SourceDescriptor> sourceInfo = sources.getSourceInfo();
                for (SourceDescriptor sourceDescriptor : sourceInfo) {
                    if (sourceDescriptor.getSourceId().equals(source.getId())) {
                        available = sourceDescriptor.isAvailable() && source.isAvailable();
                        LOGGER.info("Source.isAvailable = {} Framework.isAvailable = {}", source.isAvailable(), sourceDescriptor.isAvailable());
                    }
                }
            } catch (SourceUnavailableException e) {
                available = false;
            }
        } else {
            LOGGER.info("Currently no source of type {} and name {} could be found", type.getName(), id);
        }
        if (!available) {
            if (System.currentTimeMillis() > timeoutLimit) {
                fail("Source (" + id + ") was not created in a timely manner.");
            }
            Thread.sleep(1000);
        }
    }
    LOGGER.info("Source {} is available.", id);
    return source;
}
Also used : SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Logger(org.slf4j.Logger) SourceInfoRequestLocal(ddf.catalog.operation.impl.SourceInfoRequestLocal) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CatalogStore(ddf.catalog.source.CatalogStore) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CatalogFramework(ddf.catalog.CatalogFramework) FederatedSource(ddf.catalog.source.FederatedSource) LoggerFactory(org.slf4j.LoggerFactory) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) Set(java.util.Set) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) Source(ddf.catalog.source.Source) SourceDescriptor(ddf.catalog.source.SourceDescriptor) List(java.util.List) Configuration(org.osgi.service.cm.Configuration) CatalogProvider(ddf.catalog.source.CatalogProvider) Map(java.util.Map) Optional(java.util.Optional) Assert.fail(org.junit.Assert.fail) Hashtable(java.util.Hashtable) ServiceReference(org.osgi.framework.ServiceReference) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) CatalogFramework(ddf.catalog.CatalogFramework) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse)

Example 13 with Source

use of ddf.catalog.source.Source in project ddf by codice.

the class TagsFilterQueryPluginTest method setup.

@Before
public void setup() {
    CatalogProvider catProvider1 = mock(CatalogProvider.class);
    CatalogProvider catProvider2 = mock(CatalogProvider.class);
    CatalogProvider catProvider3 = mock(CatalogProvider.class);
    when(catProvider1.getId()).thenReturn("cat1");
    when(catProvider2.getId()).thenReturn("cat2");
    when(catProvider3.getId()).thenReturn("cat3");
    ImmutableList<CatalogProvider> catalogProviders = ImmutableList.of(catProvider1, catProvider2, catProvider3);
    filterAdapter = mock(FilterAdapter.class);
    filterBuilder = mock(FilterBuilder.class);
    plugin = new TagsFilterQueryPlugin(catalogProviders, filterAdapter, filterBuilder);
    source = mock(Source.class);
    when(source.getId()).thenReturn("cat2");
    cache = mock(SourceCache.class);
    when(cache.getId()).thenReturn("cache");
    queryRequest = mock(QueryRequest.class);
    query = mock(Query.class);
    when(queryRequest.getQuery()).thenReturn(query);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query) CatalogProvider(ddf.catalog.source.CatalogProvider) FilterBuilder(ddf.catalog.filter.FilterBuilder) FilterAdapter(ddf.catalog.filter.FilterAdapter) SourceCache(ddf.catalog.source.SourceCache) Source(ddf.catalog.source.Source) Before(org.junit.Before)

Example 14 with Source

use of ddf.catalog.source.Source in project ddf by codice.

the class CatalogFrameworkImplTest method createDummyCatalogFramework.

private CatalogFramework createDummyCatalogFramework(CatalogProvider provider, StorageProvider storageProvider, BundleContext context, MockEventProcessor admin, boolean sourceAvailability) {
    // Mock register the provider in the container
    // Mock the source poller
    SourcePoller mockPoller = mock(SourcePoller.class);
    CachedSource mockSource = mock(CachedSource.class);
    when(mockSource.isAvailable()).thenReturn(sourceAvailability);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(mockSource);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setSourcePoller(mockPoller);
    frameworkProperties.setBundleContext(context);
    frameworkProperties.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
    return createFramework(frameworkProperties);
}
Also used : CachedSource(ddf.catalog.util.impl.CachedSource) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) SourcePoller(ddf.catalog.util.impl.SourcePoller)

Example 15 with Source

use of ddf.catalog.source.Source in project ddf by codice.

the class CachingFederationStrategyTest method testFederateQueryNoUpdateToCache.

@Test
public void testFederateQueryNoUpdateToCache() throws Exception {
    properties.put(QUERY_MODE, NATIVE_QUERY_MODE);
    QueryRequest fedQueryRequest = new QueryRequestImpl(mockQuery, properties);
    Source mockSource = mock(Source.class);
    when(mockSource.query(any(QueryRequest.class))).thenReturn(mockResponse);
    QueryResponse federateResponse = strategy.federate(Arrays.asList(mockSource), fedQueryRequest);
    assertThat(requestArgumentCaptor.getValue().getPropertyValue(QUERY_MODE), is(NATIVE_QUERY_MODE));
    verify(mockSource).query(any(QueryRequest.class));
    verify(cache, times(0)).query(any(QueryRequest.class));
    verifyCacheNotUpdated();
    assertThat(federateResponse.getRequest().getQuery(), is(requestArgumentCaptor.getValue().getQuery()));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Source(ddf.catalog.source.Source) Test(org.junit.Test)

Aggregations

Source (ddf.catalog.source.Source)46 Test (org.junit.Test)24 QueryRequest (ddf.catalog.operation.QueryRequest)22 ArrayList (java.util.ArrayList)16 FederatedSource (ddf.catalog.source.FederatedSource)15 QueryResponse (ddf.catalog.operation.QueryResponse)14 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)11 Result (ddf.catalog.data.Result)10 CatalogProvider (ddf.catalog.source.CatalogProvider)10 ContentType (ddf.catalog.data.ContentType)9 Query (ddf.catalog.operation.Query)9 SourceResponse (ddf.catalog.operation.SourceResponse)9 CachedSource (ddf.catalog.util.impl.CachedSource)8 SourcePoller (ddf.catalog.util.impl.SourcePoller)8 ByteSource (com.google.common.io.ByteSource)7 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)7 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)7 SourceDescriptor (ddf.catalog.source.SourceDescriptor)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 HashMap (java.util.HashMap)6