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);
}
}
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;
}
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()]));
}
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;
}
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;
}
Aggregations