use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class PersisterAggregatorTest method mockHolder.
private ConfigSnapshotHolder mockHolder(final String name) {
ConfigSnapshotHolder result = mock(ConfigSnapshotHolder.class);
doReturn("mock:" + name).when(result).toString();
return result;
}
use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class PersisterAggregatorTest method loadLastConfig.
@Test
public void loadLastConfig() throws Exception {
List<PersisterWithConfiguration> persisterWithConfigurations = new ArrayList<>();
PersisterWithConfiguration first = new PersisterWithConfiguration(mockPersister("p0"), false);
ConfigSnapshotHolder ignored = mockHolder("ignored");
// should be ignored
doReturn(Arrays.asList(ignored)).when(first.getStorage()).loadLastConfigs();
ConfigSnapshotHolder used = mockHolder("used");
PersisterWithConfiguration second = new PersisterWithConfiguration(mockPersister("p1"), false);
// should be used
doReturn(Arrays.asList(used)).when(second.getStorage()).loadLastConfigs();
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));
}
}
use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class ConfigPusherImpl method internalPushConfigs.
private LinkedHashMap<? extends ConfigSnapshotHolder, Boolean> internalPushConfigs(final List<? extends ConfigSnapshotHolder> configs) throws DocumentedException {
LOG.debug("Last config snapshots to be pushed to netconf: {}", configs);
LinkedHashMap<ConfigSnapshotHolder, Boolean> result = new LinkedHashMap<>();
// start pushing snapshots
for (ConfigSnapshotHolder configSnapshotHolder : configs) {
if (configSnapshotHolder != null) {
LOG.info("Pushing configuration snapshot {}", configSnapshotHolder);
boolean pushResult = false;
try {
pushResult = pushConfigWithConflictingVersionRetries(configSnapshotHolder);
} catch (final ConfigSnapshotFailureException e) {
LOG.error("Failed to apply configuration snapshot: {}. Config snapshot is not semantically correct and will be IGNORED. " + "for detailed information see enclosed exception.", e.getConfigIdForReporting(), e);
throw new IllegalStateException("Failed to apply configuration snapshot " + e.getConfigIdForReporting(), e);
} catch (final Exception e) {
String msg = String.format("Failed to apply configuration snapshot: %s", configSnapshotHolder);
LOG.error(msg, e);
throw new IllegalStateException(msg, e);
}
LOG.info("Successfully pushed configuration snapshot {}", configSnapshotHolder);
result.put(configSnapshotHolder, pushResult);
}
}
LOG.info("All configuration snapshots have been pushed successfully.");
return result;
}
use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class ConfigPersisterActivator method start.
@Override
public void start(final BundleContext context) throws Exception {
LOG.debug("ConfigPersister starting");
this.context = context;
PropertiesProviderBaseImpl propertiesProvider = new PropertiesProviderBaseImpl(context);
final PersisterAggregator persisterAggregator = PersisterAggregator.createFromProperties(propertiesProvider);
autoCloseables.add(persisterAggregator);
final long maxWaitForCapabilitiesMillis = getMaxWaitForCapabilitiesMillis(propertiesProvider);
final List<ConfigSnapshotHolder> configs = persisterAggregator.loadLastConfigs();
final long conflictingVersionTimeoutMillis = getConflictingVersionTimeoutMillis(propertiesProvider);
LOG.debug("Following configs will be pushed: {}", configs);
ServiceTrackerCustomizer<ConfigSubsystemFacadeFactory, ConfigSubsystemFacadeFactory> schemaServiceTrackerCustomizer = new ServiceTrackerCustomizer<ConfigSubsystemFacadeFactory, ConfigSubsystemFacadeFactory>() {
@Override
public ConfigSubsystemFacadeFactory addingService(final ServiceReference<ConfigSubsystemFacadeFactory> reference) {
LOG.debug("Got addingService(SchemaContextProvider) event");
// Yang store service should not be registered multiple times
ConfigSubsystemFacadeFactory configSubsystemFacadeFactory = reference.getBundle().getBundleContext().getService(reference);
startPusherThread(configs, maxWaitForCapabilitiesMillis, configSubsystemFacadeFactory, conflictingVersionTimeoutMillis, persisterAggregator);
return configSubsystemFacadeFactory;
}
@Override
public void modifiedService(final ServiceReference<ConfigSubsystemFacadeFactory> reference, final ConfigSubsystemFacadeFactory service) {
LOG.warn("Config manager facade was modified unexpectedly");
}
@Override
public void removedService(final ServiceReference<ConfigSubsystemFacadeFactory> reference, final ConfigSubsystemFacadeFactory service) {
LOG.warn("Config manager facade was removed unexpectedly");
}
};
ServiceTracker<ConfigSubsystemFacadeFactory, ConfigSubsystemFacadeFactory> schemaContextProviderServiceTracker = new ServiceTracker<>(context, ConfigSubsystemFacadeFactory.class, schemaServiceTrackerCustomizer);
schemaContextProviderServiceTracker.open();
}
use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.
the class DirectoryStorageAdapterTest method testOneFile.
@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");
}
Aggregations