本文整理汇总了Java中org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder类的典型用法代码示例。如果您正苦于以下问题:Java ConfigSnapshotHolder类的具体用法?Java ConfigSnapshotHolder怎么用?Java ConfigSnapshotHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigSnapshotHolder类属于org.opendaylight.controller.config.persist.api包,在下文中一共展示了ConfigSnapshotHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadLastConfigs
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
@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;
}
示例2: fromXmlSnapshot
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
private Optional<ConfigSnapshotHolder> fromXmlSnapshot(final File file) {
try {
return Optional.of(loadLastConfig(file));
} catch (final JAXBException e) {
// In case of parse error, issue a warning, ignore and continue
LOG.warn(
"Unable to parse configuration snapshot from {}. "
+ "Initial config from {} will be IGNORED in this run. ",
file, file);
LOG.warn(
"Note that subsequent config files may fail due to this problem. ",
"Xml markup in this file needs to be fixed, for detailed information see enclosed exception.",
e);
}
return Optional.absent();
}
示例3: asHolder
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
private static ConfigSnapshotHolder asHolder(final ConfigSnapshot unmarshalled) {
return new ConfigSnapshotHolder() {
@Override
public String getConfigSnapshot() {
return unmarshalled.getConfigSnapshot();
}
@Override
public SortedSet<String> getCapabilities() {
return unmarshalled.getCapabilities();
}
@Override
public String toString() {
return unmarshalled.toString();
}
};
}
示例4: testEmptyDirectory
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
@Test
public void testEmptyDirectory() throws Exception {
File folder = new File("target/emptyFolder");
folder.mkdir();
tested = instantiatePersisterFromAdapter(folder);
assertEquals(Collections.<ConfigSnapshotHolder>emptyList(), tested.loadLastConfigs());
try {
tested.persistConfig(new ConfigSnapshotHolder() {
@Override
public String getConfigSnapshot() {
throw new RuntimeException();
}
@Override
public SortedSet<String> getCapabilities() {
throw new RuntimeException();
}
});
fail();
} catch (final UnsupportedOperationException e) {
// TODO: empty catch block
}
}
示例5: pushConfigWithConflictingVersionRetries
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
private synchronized boolean pushConfigWithConflictingVersionRetries(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException {
ConflictingVersionException lastException;
Stopwatch stopwatch = Stopwatch.createUnstarted();
do {
//TODO wait untill all expected modules are in yangStoreService, do we even need to with yangStoreService instead on netconfOperationService?
String idForReporting = configSnapshotHolder.toString();
SortedSet<String> expectedCapabilities = checkNotNull(configSnapshotHolder.getCapabilities(),
"Expected capabilities must not be null - %s, check %s", idForReporting,
configSnapshotHolder.getClass().getName());
// wait max time for required capabilities to appear
waitForCapabilities(expectedCapabilities, idForReporting);
try {
if(!stopwatch.isRunning()) {
stopwatch.start();
}
return pushConfig(configSnapshotHolder);
} catch (final ConflictingVersionException e) {
lastException = e;
LOG.info("Conflicting version detected, will retry after timeout");
sleep();
}
} while (stopwatch.elapsed(TimeUnit.MILLISECONDS) < conflictingVersionTimeoutMillis);
throw new IllegalStateException("Max wait for conflicting version stabilization timeout after " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms",
lastException);
}
示例6: loadLastConfigs
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
/**
* @return last non-empty result from input persisters
*/
@Override
public List<ConfigSnapshotHolder> loadLastConfigs() {
// iterate in reverse order
ListIterator<PersisterWithConfiguration> li = persisterWithConfigurations.listIterator(persisterWithConfigurations.size());
while(li.hasPrevious()) {
PersisterWithConfiguration persisterWithConfiguration = li.previous();
List<ConfigSnapshotHolder> configs = null;
try {
configs = persisterWithConfiguration.storage.loadLastConfigs();
} catch (final IOException e) {
throw new RuntimeException("Error while calling loadLastConfig on " + persisterWithConfiguration, e);
}
if (!configs.isEmpty()) {
LOG.debug("Found non empty configs using {}:{}", persisterWithConfiguration, configs);
return configs;
}
}
// no storage had an answer
LOG.debug("No non-empty list of configuration snapshots found");
return Collections.emptyList();
}
示例7: setUp
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Mockito.doNothing().when(mockPersister).persistConfig(any(ConfigSnapshotHolder.class));
doReturn("persister").when(mockPersister).toString();
final PersisterAggregator.PersisterWithConfiguration withCfg = new PersisterAggregator.PersisterWithConfiguration(mockPersister, false);
persisterAggregator = new PersisterAggregator(Lists.newArrayList(withCfg));
doReturn("netconfUnknownNotification").when(unknownNetconfNotif).toString();
doReturn("netconfCommitNotification").when(commitNetconfNotif).toString();
doReturn("config client").when(configRegistryClient).toString();
doReturn("cap").when(cap).getCapabilityUri();
doReturn(facade).when(facadeFactory).createFacade(anyString());
doReturn(Collections.singleton(cap)).when(facadeFactory).getCurrentCapabilities();
doReturn(XmlUtil.readXmlToElement("<snapshot/>")).when(facade)
.getConfiguration(any(Document.class), any(Datastore.class), any(Optional.class));
}
示例8: loadLastConfig
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
@Test
public void loadLastConfig() throws Exception {
List<PersisterWithConfiguration> persisterWithConfigurations = new ArrayList<>();
PersisterWithConfiguration first = new PersisterWithConfiguration(mockPersister("p0"), false);
ConfigSnapshotHolder ignored = mockHolder("ignored");
doReturn(Arrays.asList(ignored)).when(first.getStorage()).loadLastConfigs(); // should be ignored
ConfigSnapshotHolder used = mockHolder("used");
PersisterWithConfiguration second = new PersisterWithConfiguration(mockPersister("p1"), false);
doReturn(Arrays.asList(used)).when(second.getStorage()).loadLastConfigs(); // should be used
PersisterWithConfiguration third = new PersisterWithConfiguration(mockPersister("p2"), false);
doReturn(Arrays.asList()).when(third.getStorage()).loadLastConfigs();
persisterWithConfigurations.add(first);
persisterWithConfigurations.add(second);
persisterWithConfigurations.add(third);
try (PersisterAggregator persisterAggregator = new PersisterAggregator(persisterWithConfigurations)) {
List<ConfigSnapshotHolder> configSnapshotHolderOptional = persisterAggregator.loadLastConfigs();
assertEquals(1, configSnapshotHolderOptional.size());
assertEquals(used, configSnapshotHolderOptional.get(0));
}
}
示例9: loadLastConfigs
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
@Override
public List<ConfigSnapshotHolder> loadLastConfigs() throws IOException {
Preconditions.checkNotNull(storage, "Storage file is null");
if (!storage.exists()) {
return Collections.emptyList();
}
Optional<ConfigSnapshot> lastSnapshot = Config.fromXml(storage).getLastSnapshot();
if (lastSnapshot.isPresent()) {
lastCfgSnapshotCache = lastSnapshot.get();
return Lists.newArrayList(toConfigSnapshot(lastCfgSnapshotCache));
} else {
return Collections.emptyList();
}
}
示例10: toConfigSnapshot
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
public ConfigSnapshotHolder toConfigSnapshot(final ConfigSnapshot configSnapshot) {
return new ConfigSnapshotHolder() {
@Override
public String getConfigSnapshot() {
return configSnapshot.getConfigSnapshot();
}
@Override
public SortedSet<String> getCapabilities() {
return configSnapshot.getCapabilities();
}
@Override
public String toString() {
return configSnapshot.toString();
}
};
}
示例11: testNewFile
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
@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));
}
示例12: testNoProperties2
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void testNoProperties2() throws Exception {
try (XmlFileStorageAdapter storage = new XmlFileStorageAdapter()) {
storage.persistConfig(new ConfigSnapshotHolder() {
@Override
public String getConfigSnapshot() {
return mock(String.class);
}
@Override
public SortedSet<String> getCapabilities() {
return new TreeSet<>();
}
});
}
}
示例13: loadLastConfig
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
public static ConfigSnapshotHolder loadLastConfig(final File file) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(ConfigSnapshot.class);
Unmarshaller um = jaxbContext.createUnmarshaller();
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
try {
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(file));
return asHolder((ConfigSnapshot) um.unmarshal(xsr));
} catch (final XMLStreamException e) {
throw new JAXBException(e);
}
}
示例14: testOneFile
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
@Test
public void testOneFile() throws Exception {
File folder = getFolder("oneFile");
tested = instantiatePersisterFromAdapter(folder, Optional.of("xml"));
LOG.info("Testing : {}", tested);
List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
assertEquals(1, results.size());
ConfigSnapshotHolder result = results.get(0);
assertResult(result, "<config>1</config>", "cap1&rev", "cap2", "capa a");
}
示例15: assertResult
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; //导入依赖的package包/类
private void assertResult(final ConfigSnapshotHolder result,
final String string,
final String... caps) throws SAXException, IOException {
assertXMLEqual(string, result.getConfigSnapshot());
int index = 0;
for (String capFromSnapshot : result.getCapabilities()) {
assertEquals(capFromSnapshot, caps[index++]);
}
}