Search in sources :

Example 1 with SourceDescriptor

use of ddf.catalog.source.SourceDescriptor 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 2 with SourceDescriptor

use of ddf.catalog.source.SourceDescriptor 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 3 with SourceDescriptor

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

the class CatalogFrameworkImplTest method testGetSites.

@Test
public void testGetSites() {
    framework.setId("ddf");
    framework.getSourceOperations().setId("ddf");
    Set<String> ids = new HashSet<String>();
    for (FederatedSource source : federatedSources) {
        ids.add(source.getId());
    }
    ids.add(framework.getId());
    SourceInfoRequest request = new SourceInfoRequestSources(true, ids);
    SourceInfoResponse response = null;
    try {
        response = framework.getSourceInfo(request);
    } catch (SourceUnavailableException e) {
        fail();
    }
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    List<String> siteNames = new ArrayList<String>();
    for (SourceDescriptor descriptor : sourceDescriptors) {
        LOGGER.debug("Descriptor id: {}", descriptor.getSourceId());
        siteNames.add(descriptor.getSourceId());
    }
    // add a plus one for now to simulate that the framework is ad
    // assertTrue( sourceDescriptor.containsAll( federatedSources ) );
    // assertTrue( sourceDescriptor.containsAll( expectedSourceSet ) );
    assertEquals(ids.size(), sourceDescriptors.size());
    String[] expectedOrdering = { "A", "B", "C", framework.getId() };
    assertArrayEquals(expectedOrdering, siteNames.toArray(new String[siteNames.size()]));
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoRequestSources(ddf.catalog.operation.impl.SourceInfoRequestSources) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with SourceDescriptor

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

the class CatalogBundle method waitForCatalogProvider.

public CatalogProvider waitForCatalogProvider() throws InterruptedException {
    LOGGER.info("Waiting for CatalogProvider to become available.");
    serviceManager.printInactiveBundlesInfo();
    CatalogProvider provider = null;
    CatalogFramework framework = null;
    long timeoutLimit = System.currentTimeMillis() + CATALOG_PROVIDER_TIMEOUT;
    boolean available = false;
    while (!available) {
        if (provider == null) {
            ServiceReference<CatalogFramework> frameworkRef = serviceManager.getServiceReference(CatalogFramework.class);
            ServiceReference<CatalogProvider> providerRef = serviceManager.getServiceReference(CatalogProvider.class);
            if (providerRef != null) {
                provider = serviceManager.getService(providerRef);
            }
            if (frameworkRef != null) {
                framework = serviceManager.getService(frameworkRef);
            }
        }
        if (framework != null && provider != null) {
            SourceInfoRequestLocal sourceInfoRequestEnterprise = new SourceInfoRequestLocal(true);
            try {
                SourceInfoResponse sources = framework.getSourceInfo(sourceInfoRequestEnterprise);
                Set<SourceDescriptor> sourceInfo = sources.getSourceInfo();
                for (SourceDescriptor sourceDescriptor : sourceInfo) {
                    if (sourceDescriptor.getSourceId().equals(provider.getId())) {
                        available = sourceDescriptor.isAvailable() && provider.isAvailable();
                        LOGGER.info("CatalogProvider.isAvailable = {}", available);
                    }
                }
            } catch (SourceUnavailableException e) {
                available = false;
            }
        }
        if (!available) {
            if (System.currentTimeMillis() > timeoutLimit) {
                LOGGER.info("CatalogProvider.isAvailable = false");
                serviceManager.printInactiveBundles();
                fail(String.format("Catalog provider timed out after %d minutes.", TimeUnit.MILLISECONDS.toMinutes(CATALOG_PROVIDER_TIMEOUT)));
            }
            Thread.sleep(1000);
        }
    }
    LOGGER.info("CatalogProvider is available.");
    return provider;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) CatalogProvider(ddf.catalog.source.CatalogProvider) CatalogFramework(ddf.catalog.CatalogFramework) SourceInfoRequestLocal(ddf.catalog.operation.impl.SourceInfoRequestLocal) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse)

Example 5 with SourceDescriptor

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

the class SourceOperations method getSourceInfo.

public SourceInfoResponse getSourceInfo(SourceInfoRequest sourceInfoRequest, boolean fanoutEnabled) throws SourceUnavailableException {
    SourceInfoResponse response;
    Set<SourceDescriptor> sourceDescriptors;
    if (fanoutEnabled) {
        return getFanoutSourceInfo(sourceInfoRequest);
    }
    boolean addCatalogProviderDescriptor = false;
    try {
        validateSourceInfoRequest(sourceInfoRequest);
        // Obtain the source information based on the sourceIds in the
        // request
        sourceDescriptors = new LinkedHashSet<>();
        Set<String> requestedSourceIds = sourceInfoRequest.getSourceIds();
        // If it is an enterprise request than add all source information for the enterprise
        if (sourceInfoRequest.isEnterprise()) {
            sourceDescriptors = getFederatedSourceDescriptors(frameworkProperties.getFederatedSources().values(), true);
        // If Ids are specified check if they are known sources
        } else if (requestedSourceIds != null) {
            LOGGER.debug("getSourceRequest contains requested source ids");
            Set<FederatedSource> discoveredSources = new HashSet<>();
            boolean containsId = false;
            for (String requestedSourceId : requestedSourceIds) {
                if (frameworkProperties.getFederatedSources().containsKey(requestedSourceId)) {
                    containsId = true;
                    LOGGER.debug("Found federated source: {}", requestedSourceId);
                    discoveredSources.add(frameworkProperties.getFederatedSources().get(requestedSourceId));
                }
                if (!containsId) {
                    LOGGER.debug("Unable to find source: {}", requestedSourceId);
                    // Check for the local catalog provider, DDF sourceId represents this
                    if (requestedSourceId.equals(getId())) {
                        LOGGER.debug("adding CatalogSourceDescriptor since it was in sourceId list as: {}", requestedSourceId);
                        addCatalogProviderDescriptor = true;
                    }
                }
                containsId = false;
            }
            sourceDescriptors = getFederatedSourceDescriptors(discoveredSources, addCatalogProviderDescriptor);
        } else {
            // only add the local catalogProviderdescriptor
            addCatalogSourceDescriptor(sourceDescriptors);
        }
        response = new SourceInfoResponseImpl(sourceInfoRequest, null, sourceDescriptors);
    } catch (RuntimeException re) {
        LOGGER.debug("Exception during runtime while performing getSourceInfo", re);
        throw new SourceUnavailableException("Exception during runtime while performing getSourceInfo");
    }
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse)

Aggregations

SourceDescriptor (ddf.catalog.source.SourceDescriptor)18 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)13 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)13 SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)10 FederatedSource (ddf.catalog.source.FederatedSource)8 Test (org.junit.Test)8 SourceInfoRequest (ddf.catalog.operation.SourceInfoRequest)6 CatalogProvider (ddf.catalog.source.CatalogProvider)6 Source (ddf.catalog.source.Source)6 HashSet (java.util.HashSet)6 SourceInfoResponseImpl (ddf.catalog.operation.impl.SourceInfoResponseImpl)5 SourceDescriptorImpl (ddf.catalog.source.impl.SourceDescriptorImpl)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ContentType (ddf.catalog.data.ContentType)4 SourceInfoRequestLocal (ddf.catalog.operation.impl.SourceInfoRequestLocal)4 HashMap (java.util.HashMap)4 CatalogFramework (ddf.catalog.CatalogFramework)3 SourceDescriptorComparator (ddf.catalog.util.impl.SourceDescriptorComparator)3 SourcePoller (ddf.catalog.util.impl.SourcePoller)3 Set (java.util.Set)3