use of ddf.catalog.content.StorageException in project ddf by codice.
the class ExportCommand method doDelete.
private void doDelete(List<ExportItem> exportedItems, List<ExportItem> exportedContentItems) {
Instant start;
console.println("Starting delete");
start = Instant.now();
for (ExportItem exportedContentItem : exportedContentItems) {
try {
DeleteStorageRequestImpl deleteRequest = new DeleteStorageRequestImpl(Collections.singletonList(new IdAndUriMetacard(exportedContentItem.getId(), exportedContentItem.getResourceUri())), exportedContentItem.getId(), Collections.emptyMap());
storageProvider.delete(deleteRequest);
storageProvider.commit(deleteRequest);
} catch (StorageException e) {
printErrorMessage("Could not delete content for metacard: " + exportedContentItem.toString());
}
}
for (ExportItem exported : exportedItems) {
try {
catalogProvider.delete(new DeleteRequestImpl(exported.getId()));
} catch (IngestException e) {
printErrorMessage("Could not delete metacard: " + exported.toString());
}
}
// delete items from cache
try {
getCacheProxy().removeById(exportedItems.stream().map(ExportItem::getId).collect(Collectors.toList()).toArray(new String[exportedItems.size()]));
} catch (Exception e) {
LOGGER.warn("Could not delete all exported items from cache (Results will eventually expire)", e);
}
console.println("Metacards and Content deleted in: " + getFormattedDuration(start));
console.println("Number of metacards deleted: " + exportedItems.size());
console.println("Number of content deleted: " + exportedContentItems.size());
}
use of ddf.catalog.content.StorageException in project ddf by codice.
the class IngestCommand method submitToStorageProvider.
private void submitToStorageProvider(List<Metacard> metacardList) {
metacardList.stream().filter(metacard -> metacardFileMapping.containsKey(metacard.getId())).map(metacard -> {
List<File> fileList = metacardFileMapping.get(metacard.getId());
List<ContentItem> contentItemList = new ArrayList<>();
ContentItem contentItem;
for (File file : fileList) {
ByteSource byteSource = com.google.common.io.Files.asByteSource(file);
String fileName = file.getName().split("-")[1];
String fragment = null;
if (!file.getPath().contains(CONTENT + File.separator + metacard.getId())) {
fragment = StringUtils.substringBetween(file.getPath(), CONTENT + File.separator, File.separator + metacard.getId());
}
contentItem = new ContentItemImpl(metacard.getId(), fragment, byteSource, metacard.getContentTypeName(), fileName, file.length(), metacard);
contentItemList.add(contentItem);
}
return new CreateStorageRequestImpl(contentItemList, metacard.getId(), new HashMap<>());
}).forEach(createStorageRequest -> {
try {
storageProvider.create(createStorageRequest);
storageProvider.commit(createStorageRequest);
} catch (StorageException e) {
LOGGER.debug("Unable to create content for {}", createStorageRequest.getId(), e);
try {
storageProvider.rollback(createStorageRequest);
} catch (StorageException e1) {
LOGGER.debug("Unable to perform rollback on temporary content for {} ", createStorageRequest.getId(), e1);
}
}
});
}
use of ddf.catalog.content.StorageException in project ddf by codice.
the class FileSystemStorageProvider method commitUpdates.
private void commitUpdates(StorageRequest request) throws StorageException {
try {
for (String contentUri : updateMap.get(request.getId())) {
Path contentIdDir = getTempContentItemDir(request.getId(), new URI(contentUri));
Path target = getContentItemDir(new URI(contentUri));
try {
if (Files.exists(contentIdDir)) {
if (Files.exists(target)) {
List<Path> files = listPaths(target);
for (Path file : files) {
if (!Files.isDirectory(file)) {
Files.deleteIfExists(file);
}
}
}
Files.createDirectories(target.getParent());
Files.move(contentIdDir, target, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
LOGGER.debug("Unable to move files by simple rename, resorting to copy. This will impact performance.", e);
try {
Path createdTarget = Files.createDirectories(target);
List<Path> files = listPaths(contentIdDir);
Files.copy(files.get(0), Paths.get(createdTarget.toAbsolutePath().toString(), files.get(0).getFileName().toString()));
} catch (IOException e1) {
throw new StorageException("Unable to commit changes for request: " + request.getId(), e1);
}
}
}
} catch (URISyntaxException e) {
throw new StorageException(e);
} finally {
rollback(request);
}
}
use of ddf.catalog.content.StorageException in project ddf by codice.
the class FileSystemStorageProviderTest method testDeleteWithSimilarIds.
@Test
public void testDeleteWithSimilarIds() throws Exception {
CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
String id = createResponse.getCreatedContentItems().get(0).getId();
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
String badId = id.substring(0, 6) + uuid.substring(6, uuid.length() - 1);
boolean hadError = false;
try {
CreateStorageResponse badCreateResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, badId, "");
} catch (AssertionError e) {
// bad id is not a valid ID
hadError = true;
} finally {
if (!hadError) {
fail("Create succeeded when it should not have! " + badId + "Should not be valid!");
}
hadError = false;
}
DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(createResponse.getCreatedContentItems().stream().map(ContentItem::getMetacard).collect(Collectors.toList()), null);
when(deleteRequest.getMetacards().get(0).getId()).thenReturn(id);
DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
List<ContentItem> items = deleteResponse.getDeletedContentItems();
ContentItem item = items.get(0);
LOGGER.debug("Item retrieved: {}", item);
assertEquals(id, item.getId());
assertThat(item.getFilename(), is(""));
provider.commit(deleteRequest);
try {
assertReadRequest(createResponse.getCreatedContentItems().get(0).getUri(), NITF_MIME_TYPE);
} catch (StorageException e) {
// The item was deleted so it shouldn't have found it
hadError = true;
} finally {
if (!hadError) {
fail("read succeeded when it should not have! ");
}
}
}
use of ddf.catalog.content.StorageException in project ddf by codice.
the class DeleteOperations method performLocalDelete.
private DeleteResponse performLocalDelete(DeleteRequest deleteRequest, DeleteStorageRequest deleteStorageRequest) throws IngestException {
if (!Requests.isLocal(deleteRequest)) {
return null;
}
try {
sourceOperations.getStorage().delete(deleteStorageRequest);
} catch (StorageException e) {
LOGGER.info("Unable to delete stored content items. Not removing stored metacards", e);
throw new InternalIngestException("Unable to delete stored content items. Not removing stored metacards.", e);
}
DeleteResponse deleteResponse = sourceOperations.getCatalog().delete(deleteRequest);
deleteResponse = injectAttributes(deleteResponse);
try {
historian.version(deleteResponse);
} catch (SourceUnavailableException e) {
LOGGER.debug("Could not version deleted item!", e);
throw new IngestException("Could not version deleted Item!");
}
return deleteResponse;
}
Aggregations