Search in sources :

Example 1 with ConfigSnapshotHolder

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;
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder)

Example 2 with ConfigSnapshotHolder

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));
    }
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PersisterWithConfiguration(org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with ConfigSnapshotHolder

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;
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) IOException(java.io.IOException) ValidationException(org.opendaylight.controller.config.api.ValidationException) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException) SAXException(org.xml.sax.SAXException) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ConfigSnapshotHolder

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();
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) ConfigSubsystemFacadeFactory(org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory) PersisterAggregator(org.opendaylight.controller.config.persist.impl.PersisterAggregator) ServiceReference(org.osgi.framework.ServiceReference)

Example 5 with ConfigSnapshotHolder

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");
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) File(java.io.File) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Aggregations

ConfigSnapshotHolder (org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder)17 Test (org.junit.Test)13 PropertiesProviderTest (org.opendaylight.controller.config.persist.test.PropertiesProviderTest)12 File (java.io.File)8 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 SortedSet (java.util.SortedSet)1 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)1 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)1 ValidationException (org.opendaylight.controller.config.api.ValidationException)1 ConfigSubsystemFacadeFactory (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory)1 PersisterAggregator (org.opendaylight.controller.config.persist.impl.PersisterAggregator)1 PersisterWithConfiguration (org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration)1 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1 SAXException (org.xml.sax.SAXException)1