Search in sources :

Example 1 with SourceInfoRequest

use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.

the class SourceOperationsTest method testGettingSourceActions.

@Test
public void testGettingSourceActions() throws SourceUnavailableException {
    Action action = mock(Action.class);
    FrameworkProperties frameworkProperties = mock(FrameworkProperties.class);
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    when(frameworkProperties.getCatalogProviders()).thenReturn(Collections.singletonList(catalogProvider));
    ActionRegistry actionRegistry = mock(ActionRegistry.class);
    when(actionRegistry.list(any(Source.class))).thenReturn(Collections.singletonList(action));
    final SourcePoller<SourceStatus> mockStatusSourcePoller = mock(SourcePoller.class);
    when(mockStatusSourcePoller.getCachedValueForSource(isA(Source.class))).thenReturn(Optional.empty());
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties, actionRegistry, mockStatusSourcePoller, mock(SourcePoller.class));
    sourceOperations.bind((CatalogProvider) null);
    SourceInfoRequest sourceInfoRequest = mock(SourceInfoRequest.class);
    SourceInfoResponse sourceInfoResponse = sourceOperations.getSourceInfo(sourceInfoRequest, true);
    assertThat(sourceInfoResponse.getSourceInfo(), hasSize(1));
    SourceDescriptor sourceDescriptor = sourceInfoResponse.getSourceInfo().toArray(new SourceDescriptor[0])[0];
    assertThat(sourceDescriptor.getActions(), is(Collections.singletonList(action)));
}
Also used : FrameworkProperties(ddf.catalog.impl.FrameworkProperties) Action(ddf.action.Action) SourceDescriptor(ddf.catalog.source.SourceDescriptor) CatalogProvider(ddf.catalog.source.CatalogProvider) SourceStatus(org.codice.ddf.catalog.sourcepoller.SourceStatus) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) ActionRegistry(ddf.action.ActionRegistry) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Source(ddf.catalog.source.Source) SourcePoller(org.codice.ddf.catalog.sourcepoller.SourcePoller) Test(org.junit.Test)

Example 2 with SourceInfoRequest

use of ddf.catalog.operation.SourceInfoRequest 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.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 3 with SourceInfoRequest

use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.

the class FanoutCatalogFrameworkTest method testNullContentTypesInGetSourceInfo.

/**
 * This test is to verify that an NPE will not be thrown if {@code source.getContentTypes} returns
 * null.
 *
 * @throws SourceUnavailableException
 */
@Test
public void testNullContentTypesInGetSourceInfo() throws SourceUnavailableException {
    ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<PostIngestPlugin>();
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    List<FederatedSource> fedSources = new ArrayList<FederatedSource>();
    FederatedSource mockFederatedSource = mock(FederatedSource.class);
    when(mockFederatedSource.isAvailable()).thenReturn(true);
    when(mockFederatedSource.getContentTypes()).thenReturn(Collections.emptySet());
    fedSources.add(mockFederatedSource);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setFederationStrategy(new MockFederationStrategy());
    frameworkProperties.setPostIngest(postIngestPlugins);
    List<FederatedSource> sourceList = new ArrayList<>(fedSources);
    frameworkProperties.setFederatedSources(sourceList);
    CatalogFrameworkImpl framework = createCatalogFramework(frameworkProperties);
    // Assert not null simply to prove that we returned an object.
    assertNotNull(framework.getSourceInfo(request));
}
Also used : FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) ArrayList(java.util.ArrayList) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) Test(org.junit.Test)

Example 4 with SourceInfoRequest

use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.

the class SourceOperations method getFanoutSourceInfo.

/**
 * Retrieves the {@link SourceDescriptor} info for all {@link FederatedSource}s in the fanout
 * configuration, but the all of the source info, e.g., content types, for all of the available
 * {@link FederatedSource}s is packed into one {@link SourceDescriptor} for the fanout
 * configuration with the fanout's site name in it. This keeps the individual {@link
 * FederatedSource}s' source info hidden from the external client.
 */
private SourceInfoResponse getFanoutSourceInfo(SourceInfoRequest sourceInfoRequest) throws SourceUnavailableException {
    SourceInfoResponse response;
    SourceDescriptorImpl sourceDescriptor;
    try {
        // request
        if (sourceInfoRequest == null) {
            throw new IllegalArgumentException("SourceInfoRequest was null");
        }
        Set<SourceDescriptor> sourceDescriptors = new LinkedHashSet<>();
        Set<String> ids = sourceInfoRequest.getSourceIds();
        // specified
        if (ids != null) {
            Optional<String> notLocal = ids.stream().filter(s -> !s.equals(getId())).findFirst();
            if (notLocal.isPresent()) {
                SourceUnavailableException sourceUnavailableException = new SourceUnavailableException("Unknown source: " + notLocal.get());
                LOGGER.debug("Throwing SourceUnavailableException for unknown source: {}", notLocal.get(), sourceUnavailableException);
                throw sourceUnavailableException;
            }
        }
        // Fanout will only add one source descriptor with all the contents
        // Using a List here instead of a Set because we should not rely on how Sources are compared
        final List<Source> availableSources = frameworkProperties.getFederatedSources().stream().filter(this::isSourceAvailable).collect(Collectors.toList());
        final Set<ContentType> contentTypes = availableSources.stream().map(source -> contentTypesCache.getCachedValueForSource(source).orElseGet(() -> {
            LOGGER.debug("Unknown content types for source id={}", source.getId());
            return Collections.emptySet();
        })).flatMap(Collection::stream).collect(Collectors.toSet());
        if (isSourceAvailable(catalog)) {
            availableSources.add(catalog);
            final Optional<Set<ContentType>> catalogContentTypes = contentTypesCache.getCachedValueForSource(catalog);
            if (catalogContentTypes.isPresent()) {
                contentTypes.addAll(catalogContentTypes.get());
            } else {
                LOGGER.debug("Unknown content types for the localSource");
            }
        }
        List<Action> actions = getSourceActions(catalog);
        // only reveal this sourceDescriptor, not the federated sources
        sourceDescriptor = new SourceDescriptorImpl(this.getId(), contentTypes, actions);
        if (this.getVersion() != null) {
            sourceDescriptor.setVersion(this.getVersion());
        }
        sourceDescriptor.setAvailable(!availableSources.isEmpty());
        sourceDescriptors.add(sourceDescriptor);
        response = new SourceInfoResponseImpl(sourceInfoRequest, null, sourceDescriptors);
    } catch (RuntimeException re) {
        throw new SourceUnavailableException(GET_SOURCE_EXCEPTION_MSG, re);
    }
    return response;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceStatus(org.codice.ddf.catalog.sourcepoller.SourceStatus) LoggerFactory(org.slf4j.LoggerFactory) TreeSet(java.util.TreeSet) Source(ddf.catalog.source.Source) SourceDescriptor(ddf.catalog.source.SourceDescriptor) HashSet(java.util.HashSet) Action(ddf.action.Action) StorageProvider(ddf.catalog.content.StorageProvider) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) Describable(ddf.catalog.util.Describable) SourceDescriptorComparator(ddf.catalog.util.impl.SourceDescriptorComparator) LinkedHashSet(java.util.LinkedHashSet) DescribableImpl(ddf.catalog.util.impl.DescribableImpl) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) ContentType(ddf.catalog.data.ContentType) SourcePoller(org.codice.ddf.catalog.sourcepoller.SourcePoller) Logger(org.slf4j.Logger) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) FederatedSource(ddf.catalog.source.FederatedSource) Collection(java.util.Collection) Set(java.util.Set) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) Collectors(java.util.stream.Collectors) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) List(java.util.List) CatalogProvider(ddf.catalog.source.CatalogProvider) Optional(java.util.Optional) ActionRegistry(ddf.action.ActionRegistry) Collections(java.util.Collections) Validate(org.apache.commons.lang.Validate) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) Action(ddf.action.Action) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ContentType(ddf.catalog.data.ContentType) SourceDescriptorImpl(ddf.catalog.source.impl.SourceDescriptorImpl) Source(ddf.catalog.source.Source) FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoResponseImpl(ddf.catalog.operation.impl.SourceInfoResponseImpl) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse)

Example 5 with SourceInfoRequest

use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.

the class CatalogFrameworkImplTest method testGetAllSiteNames.

@Test
public void testGetAllSiteNames() {
    String frameworkName = "DDF";
    CatalogProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    List<FederatedSource> federatedSources = createDefaultFederatedSourceList(true);
    // Expected Set of Names
    Set<String> expectedNameSet = new HashSet<String>();
    for (FederatedSource curSite : federatedSources) {
        expectedNameSet.add(curSite.getId());
    }
    expectedNameSet.add(frameworkName);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setFederatedSources(federatedSources);
    frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
    CatalogFrameworkImpl framework = createFramework(frameworkProperties);
    framework.setId(frameworkName);
    // Returned Set of Names
    // Returned Sites
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    SourceInfoResponse response = null;
    try {
        response = framework.getSourceInfo(request);
    } catch (SourceUnavailableException e) {
        LOGGER.debug("SourceUnavailable", e);
        fail();
    }
    assert (response != null);
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    // should contain the original federated sites and the framework
    assertEquals(expectedNameSet.size(), sourceDescriptors.size());
    Set<String> returnedSourceIds = new HashSet<String>();
    for (SourceDescriptor sd : sourceDescriptors) {
        returnedSourceIds.add(sd.getSourceId());
    }
    for (String id : returnedSourceIds) {
        LOGGER.debug("returned sourceId: {}", id);
    }
    assertTrue(expectedNameSet.equals(returnedSourceIds));
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) ContentType(ddf.catalog.data.ContentType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) Date(java.util.Date) FederatedSource(ddf.catalog.source.FederatedSource) CatalogProvider(ddf.catalog.source.CatalogProvider) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SourceInfoRequest (ddf.catalog.operation.SourceInfoRequest)8 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)7 SourceDescriptor (ddf.catalog.source.SourceDescriptor)7 Test (org.junit.Test)7 FederatedSource (ddf.catalog.source.FederatedSource)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)5 CatalogProvider (ddf.catalog.source.CatalogProvider)4 HashSet (java.util.HashSet)3 Action (ddf.action.Action)2 ActionRegistry (ddf.action.ActionRegistry)2 ContentType (ddf.catalog.data.ContentType)2 FrameworkProperties (ddf.catalog.impl.FrameworkProperties)2 Source (ddf.catalog.source.Source)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 SourcePoller (org.codice.ddf.catalog.sourcepoller.SourcePoller)2 SourceStatus (org.codice.ddf.catalog.sourcepoller.SourceStatus)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 StorageProvider (ddf.catalog.content.StorageProvider)1