use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class ReplicateCommandTest method testFailedtoIngestHalf.
@Test
public void testFailedtoIngestHalf() throws Exception {
when(catalogFramework.create(isA(CreateRequest.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
CreateRequest request = (CreateRequest) args[0];
when(mockCreateResponse.getCreatedMetacards()).thenReturn(request.getMetacards().subList(0, request.getMetacards().size() / 2));
return mockCreateResponse;
});
replicateCommand.isUseTemporal = false;
replicateCommand.sourceId = "sourceId1";
replicateCommand.temporalProperty = Metacard.EFFECTIVE;
replicateCommand.executeWithSubject();
verifyReplicate(HITS, Metacard.EFFECTIVE);
verifyConsoleOutput((int) Math.floor(HITS / 2) + " record(s) replicated; " + (int) (HITS - Math.floor(HITS / 2)) + " record(s) failed;");
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class CreateOperations method create.
public CreateResponse create(CreateStorageRequest streamCreateRequest, List<String> fanoutTagBlacklist) throws IngestException, SourceUnavailableException {
Map<String, Metacard> metacardMap = new HashMap<>();
List<ContentItem> contentItems = new ArrayList<>(streamCreateRequest.getContentItems().size());
HashMap<String, Map<String, Path>> tmpContentPaths = new HashMap<>();
CreateResponse createResponse = null;
CreateStorageRequest createStorageRequest = null;
CreateStorageResponse createStorageResponse;
streamCreateRequest = opsStorageSupport.prepareStorageRequest(streamCreateRequest, streamCreateRequest::getContentItems);
// Operation populates the metacardMap, contentItems, and tmpContentPaths
opsMetacardSupport.generateMetacardAndContentItems(streamCreateRequest.getContentItems(), metacardMap, contentItems, tmpContentPaths);
if (blockCreateMetacards(metacardMap.values(), fanoutTagBlacklist)) {
String message = "Fanout proxy does not support create operations with blacklisted metacard tag";
LOGGER.debug("{}. Tags blacklist: {}", message, fanoutTagBlacklist);
throw new IngestException(message);
}
streamCreateRequest.getProperties().put(CONTENT_PATHS, tmpContentPaths);
injectAttributes(metacardMap);
setDefaultValues(metacardMap);
streamCreateRequest = applyAttributeOverrides(streamCreateRequest, metacardMap);
try {
if (!contentItems.isEmpty()) {
createStorageRequest = new CreateStorageRequestImpl(contentItems, streamCreateRequest.getId(), streamCreateRequest.getProperties());
createStorageRequest = processPreCreateStoragePlugins(createStorageRequest);
try {
createStorageResponse = sourceOperations.getStorage().create(createStorageRequest);
createStorageResponse.getProperties().put(CONTENT_PATHS, tmpContentPaths);
} catch (StorageException e) {
throw new IngestException("Could not store content items.", e);
}
createStorageResponse = processPostCreateStoragePlugins(createStorageResponse);
populateMetacardMap(metacardMap, createStorageResponse);
}
CreateRequest createRequest = new CreateRequestImpl(new ArrayList<>(metacardMap.values()), Optional.ofNullable(createStorageRequest).map(StorageRequest::getProperties).orElseGet(HashMap::new));
createResponse = doCreate(createRequest);
} catch (IOException | RuntimeException e) {
if (createStorageRequest != null) {
try {
sourceOperations.getStorage().rollback(createStorageRequest);
} catch (StorageException e1) {
LOGGER.info("Unable to remove temporary content for id: {}", createStorageRequest.getId(), e1);
}
}
throw new IngestException("Unable to store products for request: " + streamCreateRequest.getId(), e);
} finally {
opsStorageSupport.commitAndCleanup(createStorageRequest, tmpContentPaths);
}
createResponse = doPostIngest(createResponse);
return createResponse;
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderUnavailableCreate.
// End testing CatalogFramework
// Test negative use-cases (expected errors)
/**
* Tests that the framework properly throws a catalog exception when the local provider is not
* available for create.
*
* @throws SourceUnavailableException
*/
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableCreate() throws SourceUnavailableException {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
CatalogFramework framework = createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
CreateRequest create = new CreateRequestImpl(metacards);
// expected to throw exception due to catalog provider being unavailable
try {
framework.create(create);
} catch (IngestException e) {
fail();
}
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnCreate.
@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnCreate() throws IngestException {
MockEventProcessor eventAdmin = new MockEventProcessor();
// use exception provider instead of memory
MockExceptionProvider provider = new MockExceptionProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, null);
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
CreateRequest create = new CreateRequestImpl((Metacard) null);
try {
framework.create(create);
} catch (SourceUnavailableException e) {
fail();
}
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class FanoutCatalogFrameworkTest method testBlacklistedTagCreateRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagCreateRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
CreateRequest request = new CreateRequestImpl(metacard);
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
framework.create(request);
}
Aggregations