use of ddf.catalog.operation.SourceInfoResponse 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.operation.SourceInfoResponse 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.operation.SourceInfoResponse 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.operation.SourceInfoResponse 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());
}
use of ddf.catalog.operation.SourceInfoResponse 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());
}
Aggregations