use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class FileStorageAdapterTest method testNewFile.
@Test
public void testNewFile() throws Exception {
PropertiesProviderTest pp = new PropertiesProviderTest();
pp.addProperty("fileStorage", NON_EXISTENT_DIRECTORY + NON_EXISTENT_FILE);
pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
storage.instantiate(pp);
final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {
@Override
public String getConfigSnapshot() {
return createConfig();
}
@Override
public SortedSet<String> getCapabilities() {
return createCaps();
}
};
storage.persistConfig(holder);
storage.persistConfig(holder);
assertEquals(storage.toString().replace("\\", "/"), "XmlFileStorageAdapter [storage=" + NON_EXISTENT_DIRECTORY + NON_EXISTENT_FILE + "]");
delete(new File(NON_EXISTENT_DIRECTORY));
}
use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class FileStorageAdapterTest method testNoLastConfig.
@Test
public void testNoLastConfig() throws Exception {
File file = Files.createTempFile("testFilePersist", ".txt").toFile();
file.deleteOnExit();
if (!file.exists()) {
return;
}
try (XmlFileStorageAdapter storage = new XmlFileStorageAdapter()) {
storage.setFileStorage(file);
List<ConfigSnapshotHolder> elementOptional = storage.loadLastConfigs();
assertThat(elementOptional.size(), is(0));
}
}
use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class FileStorageAdapterTest method testNoFeaturesStored.
@Test
public void testNoFeaturesStored() throws Exception {
PropertiesProviderTest pp = new PropertiesProviderTest();
pp.addProperty("fileStorage", file.getPath());
pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
storage.instantiate(pp);
com.google.common.io.Files.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<persisted-snapshots>\n" + " <snapshots>\n" + " <snapshot>\n" + " <required-capabilities>\n" + " <capability>cap12</capability>\n" + " </required-capabilities>\n" + " <configuration>\n" + " <config>1</config>\n" + " </configuration>\n" + " </snapshot>\n" + " </snapshots>\n" + "</persisted-snapshots>", file, StandardCharsets.UTF_8);
List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
assertEquals(1, lastConf.size());
ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
assertXMLEqual("<config>1</config>", configSnapshotHolder.getConfigSnapshot());
assertTrue(storage.getPersistedFeatures().isEmpty());
}
use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class FileStorageAdapterTest method testFileAdapterOneBackup.
@Test
public void testFileAdapterOneBackup() throws Exception {
PropertiesProviderTest pp = new PropertiesProviderTest();
pp.addProperty("fileStorage", file.getPath());
pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
storage.instantiate(pp);
final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {
@Override
public String getConfigSnapshot() {
return createConfig();
}
@Override
public SortedSet<String> getCapabilities() {
return createCaps();
}
};
storage.persistConfig(holder);
storage.persistConfig(holder);
assertEquals(29, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size());
List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
assertEquals(1, lastConf.size());
ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
assertXMLEqual("<config>2</config>", configSnapshotHolder.getConfigSnapshot());
}
use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class XmlDirectoryPersister method loadLastConfigs.
@Override
public List<ConfigSnapshotHolder> loadLastConfigs() throws IOException {
File[] filesArray = extensionsFilter.isPresent() ? storage.listFiles(extensionsFilter.get()) : storage.listFiles();
if (filesArray == null || filesArray.length == 0) {
return Collections.emptyList();
}
List<File> sortedFiles = new ArrayList<>(Arrays.asList(filesArray));
Collections.sort(sortedFiles);
// combine all found files
LOG.debug("Reading files in following order: {}", sortedFiles);
List<ConfigSnapshotHolder> result = new ArrayList<>();
for (File file : sortedFiles) {
LOG.trace("Adding file '{}' to combined result", file);
Optional<ConfigSnapshotHolder> configSnapshotHolderOptional = fromXmlSnapshot(file);
// Ignore non valid snapshot
if (!configSnapshotHolderOptional.isPresent()) {
continue;
}
result.add(configSnapshotHolderOptional.get());
}
return result;
}
Aggregations