Search in sources :

Example 1 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 2 with Source

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

the class TestRegistryReportActionProvider method setup.

@Before
public void setup() {
    metacard = new MetacardImpl();
    source = mock(Source.class);
    configurationAdmin = mock(ConfigurationAdmin.class);
    configuration = mock(Configuration.class);
    actionProvider = new RegistryReportActionProvider(ACTION_PROVIDER_ID);
    metacard.setId(SAMPLE_ID);
    metacard.setTags(SAMPLE_REGISTRY_TAGS);
    metacard.setSourceId(SAMPLE_SOURCE_ID);
    metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, SAMPLE_REGISTRY_ID);
}
Also used : Configuration(org.osgi.service.cm.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Source(ddf.catalog.source.Source) Before(org.junit.Before)

Example 3 with Source

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

the class FederationAdminTest method testRegistryStatusNotConfiguredService.

@Test
public void testRegistryStatusNotConfiguredService() throws Exception {
    Source source = mock(Source.class);
    when(helper.getRegistrySources()).thenReturn(Collections.singletonList(source));
    assertThat(federationAdmin.registryStatus("servicePid"), is(false));
}
Also used : Source(ddf.catalog.source.Source) Test(org.junit.Test)

Example 4 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 5 with Source

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

the class SourceMetricsImpl method createMetric.

private boolean createMetric(List<? extends Source> sources, String sourceId) {
    for (Source source : sources) {
        if (source.getId().equals(sourceId)) {
            LOGGER.debug("Found sourceId = {} in sources list", sourceId);
            if (sourceToSourceIdMap.containsKey(source)) {
                // Source's ID must have changed since it is in this map but not in the metrics
                // map
                // Delete SourceMetrics for Source's "old" sourceId
                String oldSourceId = sourceToSourceIdMap.get(source);
                LOGGER.debug("CASE 2: source {} exists but has oldSourceId = {}", sourceId, oldSourceId);
                deleteMetric(oldSourceId, QUERIES_TOTAL_RESULTS_SCOPE);
                deleteMetric(oldSourceId, QUERIES_SCOPE);
                deleteMetric(oldSourceId, EXCEPTIONS_SCOPE);
                // Create metrics for Source with new sourceId
                createMetric(sourceId, QUERIES_TOTAL_RESULTS_SCOPE, MetricType.HISTOGRAM);
                createMetric(sourceId, QUERIES_SCOPE, MetricType.METER);
                createMetric(sourceId, EXCEPTIONS_SCOPE, MetricType.METER);
                // Add Source to map with its new sourceId
                sourceToSourceIdMap.put(source, sourceId);
            } else {
                // This is a brand new Source - create metrics for it
                // (Should rarely happen since Sources typically have their metrics created
                // when the Source itself is created via the addingSource() method. This could
                // happen if sourceId = null when Source originally created and then its metric
                // needs updating because client, e.g., SortedFederationStrategy, knows the
                // Source exists.)
                LOGGER.debug("CASE 3: New source {} detected - creating metrics", sourceId);
                createMetric(sourceId, QUERIES_TOTAL_RESULTS_SCOPE, MetricType.HISTOGRAM);
                createMetric(sourceId, QUERIES_SCOPE, MetricType.METER);
                createMetric(sourceId, EXCEPTIONS_SCOPE, MetricType.METER);
                sourceToSourceIdMap.put(source, sourceId);
            }
            return true;
        }
    }
    LOGGER.debug("Did not find source {} in Sources - cannot create metrics", sourceId);
    return false;
}
Also used : Source(ddf.catalog.source.Source) FederatedSource(ddf.catalog.source.FederatedSource)

Aggregations

Source (ddf.catalog.source.Source)65 QueryRequest (ddf.catalog.operation.QueryRequest)36 Test (org.junit.Test)36 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)22 QueryResponse (ddf.catalog.operation.QueryResponse)21 ArrayList (java.util.ArrayList)21 FederatedSource (ddf.catalog.source.FederatedSource)17 Query (ddf.catalog.operation.Query)13 SourceResponse (ddf.catalog.operation.SourceResponse)13 Result (ddf.catalog.data.Result)12 HashMap (java.util.HashMap)12 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)11 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)11 List (java.util.List)11 Map (java.util.Map)10 ByteSource (com.google.common.io.ByteSource)9 CatalogProvider (ddf.catalog.source.CatalogProvider)8 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 ContentType (ddf.catalog.data.ContentType)6 SourceStatus (org.codice.ddf.catalog.sourcepoller.SourceStatus)6