Search in sources :

Example 1 with SourceInfoRequestLocal

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;
}
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 2 with SourceInfoRequestLocal

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());
}
Also used : Set(java.util.Set) SourceInfoRequestLocal(ddf.catalog.operation.impl.SourceInfoRequestLocal) RetryPolicy(net.jodah.failsafe.RetryPolicy) Predicate(net.jodah.failsafe.function.Predicate)

Example 3 with SourceInfoRequestLocal

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()]));
}
Also used : SourceDescriptor(ddf.catalog.source.SourceDescriptor) SourceInfoRequestLocal(ddf.catalog.operation.impl.SourceInfoRequestLocal) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) Test(org.junit.Test)

Example 4 with SourceInfoRequestLocal

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()]));
}
Also used : SourceDescriptor(ddf.catalog.source.SourceDescriptor) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) SourceInfoRequestLocal(ddf.catalog.operation.impl.SourceInfoRequestLocal) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) Test(org.junit.Test)

Example 5 with SourceInfoRequestLocal

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;
}
Also used : SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Awaitility.await(org.awaitility.Awaitility.await) SourceInfoRequestLocal(ddf.catalog.operation.impl.SourceInfoRequestLocal) Logger(org.slf4j.Logger) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CatalogFramework(ddf.catalog.CatalogFramework) FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CatalogProvider(ddf.catalog.source.CatalogProvider) Configuration(org.osgi.service.cm.Configuration) Map(java.util.Map) Optional(java.util.Optional) DictionaryMap(org.codice.ddf.configuration.DictionaryMap) ServiceReference(org.osgi.framework.ServiceReference) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CatalogProvider(ddf.catalog.source.CatalogProvider) CatalogFramework(ddf.catalog.CatalogFramework) SourceInfoRequestLocal(ddf.catalog.operation.impl.SourceInfoRequestLocal) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse)

Aggregations

SourceInfoRequestLocal (ddf.catalog.operation.impl.SourceInfoRequestLocal)5 SourceDescriptor (ddf.catalog.source.SourceDescriptor)3 CatalogFramework (ddf.catalog.CatalogFramework)2 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)2 SourceInfoResponseImpl (ddf.catalog.operation.impl.SourceInfoResponseImpl)2 CatalogProvider (ddf.catalog.source.CatalogProvider)2 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)2 Test (org.junit.Test)2 SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)1 FederatedSource (ddf.catalog.source.FederatedSource)1 SourceDescriptorImpl (ddf.catalog.source.impl.SourceDescriptorImpl)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1 Predicate (net.jodah.failsafe.function.Predicate)1