Search in sources :

Example 1 with ConfigSubsystemFacade

use of org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade in project controller by opendaylight.

the class BlueprintContainerRestartServiceImpl method restartConfigModules.

private void restartConfigModules(final BundleContext bundleContext, final List<Entry<String, ModuleIdentifier>> configModules) {
    if (configModules.isEmpty()) {
        return;
    }
    ServiceReference<ConfigSubsystemFacadeFactory> configFacadeFactoryRef = bundleContext.getServiceReference(ConfigSubsystemFacadeFactory.class);
    if (configFacadeFactoryRef == null) {
        LOG.debug("ConfigSubsystemFacadeFactory service reference not found");
        return;
    }
    ConfigSubsystemFacadeFactory configFacadeFactory = bundleContext.getService(configFacadeFactoryRef);
    if (configFacadeFactory == null) {
        LOG.debug("ConfigSubsystemFacadeFactory service not found");
        return;
    }
    try (ConfigSubsystemFacade configFacade = configFacadeFactory.createFacade("BlueprintContainerRestartService")) {
        restartConfigModules(configModules, configFacade);
    } catch (ParserConfigurationException | DocumentedException | ValidationException | ConflictingVersionException e) {
        LOG.error("Error restarting config modules", e);
    } finally {
        bundleContext.ungetService(configFacadeFactoryRef);
    }
}
Also used : ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) ValidationException(org.opendaylight.controller.config.api.ValidationException) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) ConfigSubsystemFacade(org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigSubsystemFacadeFactory(org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory)

Example 2 with ConfigSubsystemFacade

use of org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade in project controller by opendaylight.

the class ConfigPusherImpl method pushConfig.

private synchronized boolean pushConfig(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException, ConflictingVersionException {
    Element xmlToBePersisted;
    try {
        xmlToBePersisted = XmlUtil.readXmlToElement(configSnapshotHolder.getConfigSnapshot());
    } catch (SAXException | IOException e) {
        throw new IllegalStateException("Cannot parse " + configSnapshotHolder, e);
    }
    LOG.trace("Pushing last configuration to config mapping: {}", configSnapshotHolder);
    Stopwatch stopwatch = Stopwatch.createStarted();
    final ConfigSubsystemFacade currentFacade = this.facade.createFacade("config-push");
    try {
        ConfigExecution configExecution = createConfigExecution(xmlToBePersisted, currentFacade);
        executeWithMissingModuleFactoryRetries(currentFacade, configExecution);
    } catch (ValidationException | DocumentedException | ModuleFactoryNotFoundException e) {
        LOG.trace("Validation for config: {} failed", configSnapshotHolder, e);
        throw new ConfigSnapshotFailureException(configSnapshotHolder.toString(), "edit", e);
    }
    try {
        currentFacade.commitSilentTransaction();
    } catch (ValidationException | DocumentedException e) {
        throw new ConfigSnapshotFailureException(configSnapshotHolder.toString(), "commit", e);
    }
    LOG.trace("Last configuration loaded successfully");
    LOG.trace("Total time spent {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
    return true;
}
Also used : ValidationException(org.opendaylight.controller.config.api.ValidationException) ConfigExecution(org.opendaylight.controller.config.facade.xml.ConfigExecution) Element(org.w3c.dom.Element) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) ConfigSubsystemFacade(org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException) SAXException(org.xml.sax.SAXException) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException)

Aggregations

ValidationException (org.opendaylight.controller.config.api.ValidationException)2 ConfigSubsystemFacade (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade)2 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)1 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)1 ConfigExecution (org.opendaylight.controller.config.facade.xml.ConfigExecution)1 ConfigSubsystemFacadeFactory (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1