Search in sources :

Example 1 with SourceInfoRequestEnterprise

use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise 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 SourceInfoRequestEnterprise

use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise 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);
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) MalformedURLException(java.net.MalformedURLException) WebApplicationException(javax.ws.rs.WebApplicationException) UnknownHostException(java.net.UnknownHostException) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) UriBuilderException(javax.ws.rs.core.UriBuilderException) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) UriBuilder(javax.ws.rs.core.UriBuilder) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with SourceInfoRequestEnterprise

use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise in project ddf by codice.

the class FanoutCatalogFrameworkTest method testNullContentTypesInGetSourceInfo.

/**
     * This test is to verify that an NPE will not be thrown if {@code source.getContentTypes}
     * returns null.
     *
     * @throws SourceUnavailableException
     */
@Test
public void testNullContentTypesInGetSourceInfo() throws SourceUnavailableException {
    SourcePollerRunner runner = new SourcePollerRunner();
    SourcePoller poller = new SourcePoller(runner);
    ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<PostIngestPlugin>();
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    List<FederatedSource> fedSources = new ArrayList<FederatedSource>();
    FederatedSource mockFederatedSource = mock(FederatedSource.class);
    when(mockFederatedSource.isAvailable()).thenReturn(true);
    // Mockito would not accept Collections.emptySet() as the parameter for
    // thenReturn for mockFederatedSource.getContentTypes()
    when(mockFederatedSource.getContentTypes()).thenReturn(null);
    fedSources.add(mockFederatedSource);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setSourcePoller(poller);
    frameworkProperties.setFederationStrategy(new MockFederationStrategy());
    frameworkProperties.setPostIngest(postIngestPlugins);
    Map<String, FederatedSource> sourceMap = new HashMap<>();
    for (FederatedSource federatedSource : fedSources) {
        sourceMap.put(federatedSource.getId(), federatedSource);
    }
    frameworkProperties.setFederatedSources(sourceMap);
    CatalogFrameworkImpl framework = createCatalogFramework(frameworkProperties);
    // Assert not null simply to prove that we returned an object.
    assertNotNull(framework.getSourceInfo(request));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) SourcePoller(ddf.catalog.util.impl.SourcePoller) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourcePollerRunner(ddf.catalog.util.impl.SourcePollerRunner) Test(org.junit.Test)

Example 4 with SourceInfoRequestEnterprise

use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise in project ddf by codice.

the class CatalogFrameworkImplTest method testGetFederatedSourcesDuplicates.

@Test
public void testGetFederatedSourcesDuplicates() {
    List<FederatedSource> federatedSources = createDefaultFederatedSourceList(true);
    // Duplicate Site
    FederatedSource siteC2 = new MockSource("C", "Site C2", "v1.0", "DDF", null, true, new Date());
    federatedSources.add(siteC2);
    // Expected Sites
    List<FederatedSource> expectedSources = createDefaultFederatedSourceList(true);
    // Mock register the federated sources in the container
    // Mock the source poller
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setSourcePoller(mockPoller);
    Map<String, FederatedSource> sources = new HashMap<>();
    for (FederatedSource federatedSource : expectedSources) {
        sources.put(federatedSource.getId(), federatedSource);
    }
    frameworkProperties.setFederatedSources(sources);
    CatalogFrameworkImpl framework = createFramework(frameworkProperties);
    // Returned Sites
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    SourceInfoResponse response = null;
    try {
        response = framework.getSourceInfo(request);
    } catch (SourceUnavailableException e) {
        LOGGER.debug("SourceUnavilable", e);
        fail();
    }
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    // should contain ONLY the original federated sites and the catalog framework's
    // site info (even though it has no local catalog provider configured) - hence,
    // the "+1"
    assertEquals(expectedSources.size(), sourceDescriptors.size());
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) Date(java.util.Date) 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) FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Test(org.junit.Test)

Example 5 with SourceInfoRequestEnterprise

use of ddf.catalog.operation.impl.SourceInfoRequestEnterprise in project ddf by codice.

the class CatalogFrameworkImplTest method testGetUnavailableFederatedSources.

@Test
public void testGetUnavailableFederatedSources() {
    List<FederatedSource> federatedSources = createDefaultFederatedSourceList(false);
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    // Mock register the federated sources in the container
    SourcePollerRunner runner = new SourcePollerRunner();
    SourcePoller poller = new SourcePoller(runner);
    for (FederatedSource source : federatedSources) {
        runner.bind(source);
    }
    runner.bind(catalogProvider);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setSourcePoller(poller);
    Map<String, FederatedSource> sources = new HashMap<>();
    for (FederatedSource federatedSource : federatedSources) {
        sources.put(federatedSource.getId(), federatedSource);
    }
    frameworkProperties.setFederatedSources(sources);
    frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
    CatalogFrameworkImpl framework = createFramework(frameworkProperties);
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    SourceInfoResponse response = null;
    try {
        response = framework.getSourceInfo(request);
    } catch (SourceUnavailableException e) {
        fail();
    }
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    for (SourceDescriptor descriptor : sourceDescriptors) {
        LOGGER.debug("Descriptor id: {}", descriptor.getSourceId());
        if (StringUtils.isNotBlank(descriptor.getId())) {
            assertFalse(descriptor.isAvailable());
            // No contentTypes should be listed if the source is unavailable
            assertTrue(descriptor.getContentTypes().isEmpty());
        }
    }
    // The "+1" is to account for the CatalogFramework source descriptor.
    // Even if no local catalog provider is configured, the catalog
    // framework's
    // site info is included in the SourceDescriptos list.
    assertEquals(federatedSources.size() + 1, sourceDescriptors.size());
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) SourcePoller(ddf.catalog.util.impl.SourcePoller) FederatedSource(ddf.catalog.source.FederatedSource) CatalogProvider(ddf.catalog.source.CatalogProvider) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourcePollerRunner(ddf.catalog.util.impl.SourcePollerRunner) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Test(org.junit.Test)

Aggregations

SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)10 SourceDescriptor (ddf.catalog.source.SourceDescriptor)9 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)9 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)8 FederatedSource (ddf.catalog.source.FederatedSource)6 SourceInfoRequest (ddf.catalog.operation.SourceInfoRequest)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 CatalogProvider (ddf.catalog.source.CatalogProvider)4 Source (ddf.catalog.source.Source)4 SourcePoller (ddf.catalog.util.impl.SourcePoller)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ByteSource (com.google.common.io.ByteSource)2 ContentType (ddf.catalog.data.ContentType)2 CachedSource (ddf.catalog.util.impl.CachedSource)2 SourcePollerRunner (ddf.catalog.util.impl.SourcePollerRunner)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2