Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ public void importContainerData(InputStream input,
+ " as the container descriptor (%s) has already been exist.",
getContainerData().getContainerID(),
getContainerFile().getAbsolutePath());
throw new IOException(errorMessage);
throw new StorageContainerException(errorMessage,
CONTAINER_ALREADY_EXISTS);
}
//copy the values from the input stream to the final destination
// directory.
Expand Down Expand Up @@ -496,11 +497,17 @@ public void importContainerData(InputStream input,
KeyValueContainerUtil.parseKVContainerData(containerData, config);

} catch (Exception ex) {
if (ex instanceof StorageContainerException &&
((StorageContainerException) ex).getResult() ==
CONTAINER_ALREADY_EXISTS) {
throw ex;
}
//delete all the temporary data in case of any exception.
try {
FileUtils.deleteDirectory(new File(containerData.getMetadataPath()));
FileUtils.deleteDirectory(new File(containerData.getChunksPath()));
FileUtils.deleteDirectory(getContainerFile());
FileUtils.deleteDirectory(
new File(getContainerData().getContainerPath()));
} catch (Exception deleteex) {
LOG.error(
"Can not cleanup destination directories after a container import"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,33 @@ public void testContainerImportExport() throws Exception {
fail("Container is imported twice. Previous files are overwritten");
} catch (IOException ex) {
//all good
assertTrue(container.getContainerFile().exists());
}

//Import failure should cleanup the container directory
containerData =
new KeyValueContainerData(containerId + 1,
keyValueContainerData.getLayOutVersion(),
keyValueContainerData.getMaxSize(), UUID.randomUUID().toString(),
datanodeId.toString());
container = new KeyValueContainer(containerData, CONF);

containerVolume = volumeChoosingPolicy.chooseVolume(volumeSet
.getVolumesList(), 1);
hddsVolumeDir = containerVolume.getHddsRootDir().toString();
container.populatePathFields(scmId, containerVolume, hddsVolumeDir);
try {
FileInputStream fis = new FileInputStream(folderToExport);
fis.close();
container.importContainerData(fis, packer);
fail("Container import should fail");
} catch (Exception ex) {
assertTrue(ex instanceof IOException);
} finally {
File directory =
new File(container.getContainerData().getContainerPath());
assertFalse(directory.exists());
}
}

/**
Expand Down