Search in sources :

Example 1 with FederatedSource

use of ddf.catalog.source.FederatedSource in project ddf by codice.

the class ResourceOperations method getOptionsFromFederatedSource.

/**
     * Get the supported options from the {@link ResourceReader} that matches the scheme in the
     * specified {@link Metacard}'s URI. Only look in the specified source for the {@link Metacard}.
     *
     * @param metacard the {@link Metacard} to get the supported options for
     * @param sourceId the ID of the federated source to look for the {@link Metacard}
     * @return the {@link Set} of supported options for the metacard
     * @throws ResourceNotFoundException if the {@link ddf.catalog.source.Source} cannot be found for the source ID
     */
@Deprecated
private Set<String> getOptionsFromFederatedSource(Metacard metacard, String sourceId) throws ResourceNotFoundException {
    LOGGER.trace("ENTERING: getOptionsFromFederatedSource");
    FederatedSource source = frameworkProperties.getFederatedSources().get(sourceId);
    if (source != null) {
        LOGGER.trace("EXITING: getOptionsFromFederatedSource");
        return source.getOptions(metacard);
    } else {
        String message = "Unable to find source corresponding to given site name: " + sourceId;
        LOGGER.trace("EXITING: getOptionsFromFederatedSource");
        throw new ResourceNotFoundException(message);
    }
}
Also used : FederatedSource(ddf.catalog.source.FederatedSource) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 2 with FederatedSource

use of ddf.catalog.source.FederatedSource in project ddf by codice.

the class TestFanout method startCswSource.

private void startCswSource() throws Exception {
    getServiceManager().waitForHttpEndpoint(CSW_PATH + "?_wadl");
    getServiceManager().createManagedService(CSW_FEDERATED_SOURCE_FACTORY_PID, getCswSourceProperties(CSW_SOURCE_ID, CSW_PATH.getUrl(), getServiceManager()));
    long timeout = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(10);
    boolean available = false;
    FederatedSource source = null;
    while (!available) {
        if (source == null) {
            source = getServiceManager().getServiceReferences(FederatedSource.class, null).stream().map(getServiceManager()::getService).filter(src -> CSW_SOURCE_ID.equals(src.getId())).findFirst().orElse(null);
        } else {
            available = source.isAvailable();
        }
        if (System.currentTimeMillis() > timeout) {
            fail("CSW source failed to initialize in time.");
        }
        Thread.sleep(1000);
    }
}
Also used : PaxExam(org.ops4j.pax.exam.junit.PaxExam) RunWith(org.junit.runner.RunWith) HttpStatus(org.apache.http.HttpStatus) RestAssured.given(com.jayway.restassured.RestAssured.given) CSW_FEDERATED_SOURCE_FACTORY_PID(org.codice.ddf.itests.common.csw.CswTestCommons.CSW_FEDERATED_SOURCE_FACTORY_PID) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) BeforeExam(org.codice.ddf.itests.common.annotations.BeforeExam) After(org.junit.After) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) AfterExam(org.codice.ddf.itests.common.annotations.AfterExam) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CatalogTestCommons(org.codice.ddf.itests.common.catalog.CatalogTestCommons) LoggingUtils(org.codice.ddf.itests.common.utils.LoggingUtils) Before(org.junit.Before) JsonPath(com.jayway.restassured.path.json.JsonPath) FederatedSource(ddf.catalog.source.FederatedSource) IOException(java.io.IOException) Test(org.junit.Test) RestAssured.get(com.jayway.restassured.RestAssured.get) TimeUnit(java.util.concurrent.TimeUnit) ExamReactorStrategy(org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy) PerSuite(org.ops4j.pax.exam.spi.reactors.PerSuite) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) CswTestCommons.getCswSourceProperties(org.codice.ddf.itests.common.csw.CswTestCommons.getCswSourceProperties) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) FederatedSource(ddf.catalog.source.FederatedSource)

Example 3 with FederatedSource

use of ddf.catalog.source.FederatedSource in project ddf by codice.

the class CatalogFrameworkImplTest method testUpdateWithStores.

// TODO (DDF-2436) -
@Ignore
@Test
public void testUpdateWithStores() throws Exception {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
    List<CatalogStore> storeList = new ArrayList<>();
    List<FederatedSource> sourceList = new ArrayList<>();
    MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
    storeList.add(store);
    sourceList.add(store);
    CatalogFramework framework = createDummyCatalogFramework(provider, storeList, sourceList, eventAdmin);
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
    List<Metacard> metacards = new ArrayList<>();
    String id = UUID.randomUUID().toString();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(id);
    newCard.setAttribute("myKey", "myValue1");
    metacards.add(newCard);
    Map<String, Serializable> reqProps = new HashMap<>();
    HashSet<String> destinations = new HashSet<>();
    destinations.add("mockMemoryProvider");
    destinations.add("catalogStoreId-1");
    framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    MetacardImpl updateCard = new MetacardImpl();
    updateCard.setId(id);
    updateCard.setAttribute("myKey", "myValue2");
    List<Entry<Serializable, Metacard>> updates = new ArrayList<>();
    updates.add(new SimpleEntry<>(id, updateCard));
    destinations.remove("mockMemoryProvider");
    framework.update(new UpdateRequestImpl(updates, Metacard.ID, new HashMap<>(), destinations));
    assertThat(provider.hasReceivedUpdateByIdentifier(), is(false));
    assertThat(store.hasReceivedUpdateByIdentifier(), is(true));
    QueryResponse storeResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
    assertThat(storeResponse.getResults().size(), is(1));
    assertThat(storeResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue2"));
    destinations.clear();
    QueryResponse providerResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
    assertThat(providerResponse.getResults().size(), is(1));
    assertThat(providerResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue1"));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FilterFactory(org.opengis.filter.FilterFactory) CatalogStore(ddf.catalog.source.CatalogStore) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) QueryImpl(ddf.catalog.operation.impl.QueryImpl) CatalogFramework(ddf.catalog.CatalogFramework) HashSet(java.util.HashSet) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with FederatedSource

use of ddf.catalog.source.FederatedSource in project ddf by codice.

the class CatalogFrameworkImplTest method createDefaultFederatedSourceList.

private List<FederatedSource> createDefaultFederatedSourceList(boolean isAvailable) {
    FederatedSource siteA = new MockSource("A", "Site A", "v1.0", "DDF", null, isAvailable, new Date());
    FederatedSource siteB = new MockSource("B", "Site B", "v1.0", "DDF", null, isAvailable, new Date());
    FederatedSource siteC = new MockSource("C", "Site C", "v1.0", "DDF", null, isAvailable, new Date());
    ArrayList<FederatedSource> federatedSources = new ArrayList<FederatedSource>();
    federatedSources.add(siteC);
    federatedSources.add(siteB);
    federatedSources.add(siteA);
    return federatedSources;
}
Also used : FederatedSource(ddf.catalog.source.FederatedSource) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 5 with FederatedSource

use of ddf.catalog.source.FederatedSource in project ddf by codice.

the class CatalogFrameworkImplTest method createDummyCatalogFramework.

private CatalogFramework createDummyCatalogFramework(CatalogProvider provider, List<CatalogStore> stores, List<FederatedSource> sources, MockEventProcessor eventAdmin) {
    FederationStrategy federationStrategy = new FederationStrategy() {

        @Override
        public QueryResponse federate(List<Source> sources, QueryRequest query) throws FederationException {
            List<Result> results = new ArrayList<>();
            for (Source source : sources) {
                try {
                    SourceResponse response = source.query(query);
                    results.addAll(response.getResults());
                } catch (UnsupportedQueryException e) {
                }
            }
            return new QueryResponseImpl(query, results, results.size());
        }
    };
    ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<>();
    postIngestPlugins.add(eventAdmin);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setCatalogStores(stores);
    frameworkProperties.setPreIngest(new ArrayList<>());
    frameworkProperties.setPostIngest(postIngestPlugins);
    frameworkProperties.setPreQuery(new ArrayList<>());
    frameworkProperties.setPostQuery(new ArrayList<>());
    frameworkProperties.setPolicyPlugins(new ArrayList<>());
    frameworkProperties.setAccessPlugins(new ArrayList<>());
    frameworkProperties.setFederatedSources(sources);
    frameworkProperties.setConnectedSources(new ArrayList<>());
    frameworkProperties.setFederationStrategy(federationStrategy);
    frameworkProperties.setQueryResponsePostProcessor(new QueryResponsePostProcessor(null, null));
    frameworkProperties.setFilterBuilder(new GeotoolsFilterBuilder());
    frameworkProperties.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
    return createFramework(frameworkProperties);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) FederationStrategy(ddf.catalog.federation.FederationStrategy) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) FederatedSource(ddf.catalog.source.FederatedSource) Result(ddf.catalog.data.Result) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

FederatedSource (ddf.catalog.source.FederatedSource)21 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 HashSet (java.util.HashSet)10 Date (java.util.Date)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)7 HashMap (java.util.HashMap)7 CatalogFramework (ddf.catalog.CatalogFramework)6 Metacard (ddf.catalog.data.Metacard)6 SourceInfoRequest (ddf.catalog.operation.SourceInfoRequest)6 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)6 QueryImpl (ddf.catalog.operation.impl.QueryImpl)6 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)6 CatalogProvider (ddf.catalog.source.CatalogProvider)6 List (java.util.List)6 Set (java.util.Set)6 Result (ddf.catalog.data.Result)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5 QueryRequest (ddf.catalog.operation.QueryRequest)5