use of ddf.catalog.operation.impl.SourceInfoRequestLocal 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.operation.impl.SourceInfoRequestLocal in project ddf by codice.
the class ContentProducerDataAccessObject method waitForAvailableSource.
private void waitForAvailableSource(CatalogFramework catalogFramework) throws SourceUnavailableException {
RetryPolicy retryPolicy = new RetryPolicy().withDelay(3, TimeUnit.SECONDS).withMaxDuration(3, TimeUnit.MINUTES).retryIf((Predicate<Set>) Set::isEmpty).retryIf((Set<SourceDescriptor> result) -> !result.stream().findFirst().get().isAvailable());
Failsafe.with(retryPolicy).get(() -> catalogFramework.getSourceInfo(new SourceInfoRequestLocal(false)).getSourceInfo());
}
use of ddf.catalog.operation.impl.SourceInfoRequestLocal in project ddf by codice.
the class SourceInfoResponseImplTest method testSourceInfoResponse.
@Test
public void testSourceInfoResponse() {
SourceDescriptor[] expectedDescriptorArr = new SourceDescriptor[] { firstSource, nextSource, lastSource };
SourceInfoResponse response = new SourceInfoResponseImpl(new SourceInfoRequestLocal(false), null, sourceDescriptors);
Set<SourceDescriptor> sources = response.getSourceInfo();
assertArrayEquals(expectedDescriptorArr, sources.toArray(new SourceDescriptor[sources.size()]));
}
use of ddf.catalog.operation.impl.SourceInfoRequestLocal in project ddf by codice.
the class SourceInfoResponseImplTest method testSourceInfoResponseNullSourceId.
@Test
public void testSourceInfoResponseNullSourceId() {
SourceDescriptor desc = new SourceDescriptorImpl(null, null, Collections.emptyList());
sourceDescriptors.add(desc);
SourceDescriptor[] expectedDescriptorArr = new SourceDescriptor[] { firstSource, nextSource, lastSource, desc };
SourceInfoResponse response = new SourceInfoResponseImpl(new SourceInfoRequestLocal(true), null, sourceDescriptors);
Set<SourceDescriptor> sources = response.getSourceInfo();
assertArrayEquals(expectedDescriptorArr, sources.toArray(new SourceDescriptor[sources.size()]));
}
use of ddf.catalog.operation.impl.SourceInfoRequestLocal in project ddf by codice.
the class CatalogBundle method isCatalogProviderReady.
private boolean isCatalogProviderReady() {
CatalogProvider provider = getService(CatalogProvider.class);
CatalogFramework framework = getService(CatalogFramework.class);
if (framework != null && provider != null) {
SourceInfoRequestLocal sourceInfoRequestEnterprise = new SourceInfoRequestLocal(true);
try {
SourceInfoResponse sources = framework.getSourceInfo(sourceInfoRequestEnterprise);
return sources.getSourceInfo().stream().filter(descriptor -> descriptor.getSourceId().equals(provider.getId())).map(descriptor -> descriptor.isAvailable() && provider.isAvailable()).findFirst().orElse(false);
} catch (SourceUnavailableException ignored) {
}
}
return false;
}
Aggregations