Search in sources :

Example 66 with IngestException

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

the class CatalogFrameworkImplTest method testProviderUnavailableUpdateByIdentifier.

/**
 * Tests that the framework properly throws a catalog exception when the local provider is not
 * available for update by identifier.
 *
 * @throws IngestException
 * @throws SourceUnavailableException
 */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableUpdateByIdentifier() throws SourceUnavailableException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
    List<Metacard> metacards = new ArrayList<Metacard>();
    List<URI> uris = new ArrayList<URI>();
    // expected to throw exception due to catalog provider being unavailable
    try {
        MetacardImpl newCard = new MetacardImpl();
        newCard.setId(null);
        newCard.setResourceURI(new URI("uri:///1234"));
        metacards.add(newCard);
        uris.add(new URI("uri:////1234"));
        UpdateRequest update = new UpdateRequestImpl((URI[]) uris.toArray(new URI[uris.size()]), metacards);
        framework.update(update);
    } catch (URISyntaxException e) {
        fail();
    } catch (IngestException e) {
        fail();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) IngestException(ddf.catalog.source.IngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 67 with IngestException

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

the class CatalogFrameworkQueryTest method testDuringQuery.

@Test
public void testDuringQuery() {
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard1 = new MetacardImpl();
    newCard1.setId(null);
    Calendar duringStart = Calendar.getInstance();
    Calendar card1Exp = Calendar.getInstance();
    card1Exp.add(Calendar.YEAR, 1);
    Calendar duringEnd1 = Calendar.getInstance();
    duringEnd1.add(Calendar.YEAR, 2);
    Calendar card2Exp = Calendar.getInstance();
    card2Exp.add(Calendar.YEAR, 3);
    Calendar duringEnd2 = Calendar.getInstance();
    duringEnd2.add(Calendar.YEAR, 4);
    newCard1.setExpirationDate(card1Exp.getTime());
    metacards.add(newCard1);
    MetacardImpl newCard2 = new MetacardImpl();
    newCard2.setId(null);
    newCard2.setExpirationDate(card2Exp.getTime());
    metacards.add(newCard2);
    String mcId1 = null;
    String mcId2 = null;
    CreateResponse createResponse = null;
    try {
        createResponse = framework.create(new CreateRequestImpl(metacards, null));
    } catch (IngestException e1) {
        LOGGER.error("Failure", e1);
        fail();
    } catch (SourceUnavailableException e1) {
        LOGGER.error("Failure", e1);
        fail();
    }
    assertEquals(createResponse.getCreatedMetacards().size(), metacards.size());
    for (Metacard curCard : createResponse.getCreatedMetacards()) {
        if (curCard.getExpirationDate().equals(card1Exp.getTime())) {
            mcId1 = curCard.getId();
        } else {
            mcId2 = curCard.getId();
        }
        assertNotNull(curCard.getId());
    }
    FilterFactory filterFactory = new FilterFactoryImpl();
    Period duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(duringStart.getTime())), new DefaultInstant(new DefaultPosition(duringEnd1.getTime())));
    QueryImpl query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
    QueryRequest queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("Expecting return 1 result.", 1, response.getHits());
        assertEquals("During filter should return metacard[" + mcId1 + "]", mcId1, response.getResults().get(0).getMetacard().getId());
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.error("Failure", e);
        fail();
    }
    duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(card1Exp.getTime())), new DefaultInstant(new DefaultPosition(duringEnd2.getTime())));
    query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
    queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("During filter should return 1 result", 1, response.getHits());
        assertEquals("During filter should return metacard[" + mcId2 + "]", mcId2, response.getResults().get(0).getMetacard().getId());
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.error("Failure", e);
        fail();
    }
    duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(duringStart.getTime())), new DefaultInstant(new DefaultPosition(duringEnd2.getTime())));
    query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
    queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("During filter should return 2 result", 2, response.getHits());
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.error("Failure", e);
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryRequest(ddf.catalog.operation.QueryRequest) CreateResponse(ddf.catalog.operation.CreateResponse) Calendar(java.util.Calendar) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) DefaultInstant(org.geotools.temporal.object.DefaultInstant) FederationException(ddf.catalog.federation.FederationException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterFactory(org.opengis.filter.FilterFactory) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) DefaultPosition(org.geotools.temporal.object.DefaultPosition) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Example 68 with IngestException

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

the class RemoteDeleteOperationsTest method testNonEmptyStoreAvailableExpectsCaughtIngestException.

@Test
public void testNonEmptyStoreAvailableExpectsCaughtIngestException() throws Exception {
    when(opsCatStoreSupport.isCatalogStoreRequest(deleteRequest)).thenReturn(true);
    remoteDeleteOperations.setOpsCatStoreSupport(opsCatStoreSupport);
    CatalogStore catalogStoreMock = mock(CatalogStore.class);
    ArrayList<CatalogStore> stores = new ArrayList<>();
    stores.add(catalogStoreMock);
    IngestException ingestException = new IngestException();
    when(opsCatStoreSupport.getCatalogStoresForRequest(any(), any())).thenReturn(stores);
    when(catalogStoreMock.isAvailable()).thenReturn(true);
    when(catalogStoreMock.delete(any())).thenThrow(ingestException);
    DeleteResponse resultDeleteResponse = remoteDeleteOperations.performRemoteDelete(deleteRequest, deleteResponse);
    assertThat("Assert caught IngestException", resultDeleteResponse.getProcessingErrors().size() >= 1);
    verify(opsCatStoreSupport).isCatalogStoreRequest(deleteRequest);
    verify(opsCatStoreSupport).getCatalogStoresForRequest(any(), any());
    verify(catalogStoreMock).isAvailable();
    verify(catalogStoreMock).delete(any());
}
Also used : CatalogStore(ddf.catalog.source.CatalogStore) DeleteResponse(ddf.catalog.operation.DeleteResponse) ArrayList(java.util.ArrayList) IngestException(ddf.catalog.source.IngestException) Test(org.junit.Test)

Example 69 with IngestException

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

the class SolrCatalogProviderImpl method create.

@Override
public CreateResponse create(CreateRequest request) throws IngestException {
    nonNull(request);
    List<Metacard> metacards = request.getMetacards();
    List<Metacard> output = new ArrayList<>();
    if (metacards == null) {
        return new CreateResponseImpl(request, null, output);
    }
    for (Metacard metacard : metacards) {
        boolean isSourceIdSet = (metacard.getSourceId() != null && !"".equals(metacard.getSourceId()));
        /*
       * If an ID is not provided, then one is generated so that documents are unique. Solr
       * will not accept documents unless the id is unique.
       */
        if (metacard.getId() == null || metacard.getId().equals("")) {
            if (isSourceIdSet) {
                throw new IngestException("Metacard from a separate distribution must have ID");
            }
            metacard.setAttribute(new AttributeImpl(Metacard.ID, generatePrimaryKey()));
        }
        if (!isSourceIdSet) {
            metacard.setSourceId(getId());
        }
        output.add(metacard);
    }
    long startTime = System.currentTimeMillis();
    try {
        client.add(output, isForcedAutoCommit());
    } catch (SolrServerException | SolrException | IOException | MetacardCreationException e) {
        LOGGER.info("Solr could not ingest metacard(s) during create.", e);
        throw new IngestException("Could not ingest metacard(s).", e);
    }
    LOGGER.debug("Time elapsed to create {} metacards is {} ms", metacards.size(), System.currentTimeMillis() - startTime);
    return new CreateResponseImpl(request, request.getProperties(), output);
}
Also used : MetacardCreationException(ddf.catalog.data.MetacardCreationException) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Metacard(ddf.catalog.data.Metacard) IngestException(ddf.catalog.source.IngestException) SolrException(org.apache.solr.common.SolrException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl)

Example 70 with IngestException

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

the class SolrCatalogProviderImpl method deleteListOfMetacards.

private void deleteListOfMetacards(List<Metacard> deletedMetacards, List<? extends Serializable> identifiers, String attributeName) throws IngestException {
    String fieldName = attributeName + SchemaFields.TEXT_SUFFIX;
    List<Metacard> metacards = getMetacards(identifiers, fieldName);
    deletedMetacards.addAll(metacards);
    try {
        // the assumption is if something was deleted, it should be gone
        // right away, such as expired data, etc.
        // so we force the commit
        client.deleteByIds(fieldName, identifiers, true);
    } catch (SolrServerException | SolrException | IOException e) {
        LOGGER.info("Failed to delete metacards by ID(s).", e);
        throw new IngestException(COULD_NOT_COMPLETE_DELETE_REQUEST_MESSAGE);
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException)

Aggregations

IngestException (ddf.catalog.source.IngestException)70 Metacard (ddf.catalog.data.Metacard)42 ArrayList (java.util.ArrayList)36 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)29 HashMap (java.util.HashMap)25 CreateResponse (ddf.catalog.operation.CreateResponse)21 IOException (java.io.IOException)21 Test (org.junit.Test)19 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)17 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)16 CreateRequest (ddf.catalog.operation.CreateRequest)15 InternalIngestException (ddf.catalog.source.InternalIngestException)15 Serializable (java.io.Serializable)15 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)14 Map (java.util.Map)13 DeleteResponse (ddf.catalog.operation.DeleteResponse)12 UpdateRequest (ddf.catalog.operation.UpdateRequest)12 FederationException (ddf.catalog.federation.FederationException)11 QueryResponse (ddf.catalog.operation.QueryResponse)11 UpdateResponse (ddf.catalog.operation.UpdateResponse)11