Search in sources :

Example 1 with DocumentedException

use of org.opendaylight.controller.config.util.xml.DocumentedException 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 DocumentedException

use of org.opendaylight.controller.config.util.xml.DocumentedException in project controller by opendaylight.

the class InstanceRuntimeRpc method resolveConfiguration.

private void resolveConfiguration(final Map<String, AttributeConfigElement> mappedConfig) {
    // TODO make field, resolvingStrategies can be instantiated only once
    Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> resolvingStrategies = new ObjectResolver(null).prepareResolving(yangToAttrConfig, enumResolver);
    // TODO make constructor for object resolver without service tracker
    for (Entry<String, AttributeConfigElement> configDefEntry : mappedConfig.entrySet()) {
        try {
            AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy = resolvingStrategies.get(configDefEntry.getKey());
            configDefEntry.getValue().resolveValue(attributeResolvingStrategy, configDefEntry.getKey());
            configDefEntry.getValue().setJmxName(yangToAttrConfig.get(configDefEntry.getKey()).getUpperCaseCammelCase());
        } catch (final DocumentedException e) {
            throw new IllegalStateException("Unable to resolve value " + configDefEntry.getValue() + " to attribute " + configDefEntry.getKey(), e);
        }
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) AttributeResolvingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.resolving.AttributeResolvingStrategy) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) ObjectResolver(org.opendaylight.controller.config.facade.xml.mapping.attributes.resolving.ObjectResolver)

Example 3 with DocumentedException

use of org.opendaylight.controller.config.util.xml.DocumentedException 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 DocumentedException

use of org.opendaylight.controller.config.util.xml.DocumentedException 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)

Example 5 with DocumentedException

use of org.opendaylight.controller.config.util.xml.DocumentedException in project controller by opendaylight.

the class Config method fromXmlModulesResolved.

// TODO refactor, replace string representing namespace with namespace class
// TODO refactor, replace Map->Multimap with e.g. ConfigElementResolved
// class
public Map<String, Multimap<String, ModuleElementResolved>> fromXmlModulesResolved(final XmlElement xml, final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) throws DocumentedException {
    Optional<XmlElement> modulesElement = getModulesElement(xml);
    List<XmlElement> moduleElements = getModulesElementList(modulesElement);
    Map<String, Multimap<String, ModuleElementResolved>> retVal = Maps.newHashMap();
    ResolvingStrategy<ModuleElementResolved> resolvingStrategy = (moduleMapping, moduleElement, serviceTracker1, instanceName, moduleNamespace, defaultStrategy) -> moduleMapping.fromXml(moduleElement, serviceTracker1, instanceName, moduleNamespace, defaultStrategy, identityMap, enumResolver);
    for (XmlElement moduleElement : moduleElements) {
        resolveModule(retVal, serviceTracker, moduleElement, defaultEditStrategyType, resolvingStrategy);
    }
    return retVal;
}
Also used : XmlUtil(org.opendaylight.controller.config.util.xml.XmlUtil) Multimap(com.google.common.collect.Multimap) EditStrategyType(org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Optional(com.google.common.base.Optional) Document(org.w3c.dom.Document) Map(java.util.Map) EnumResolver(org.opendaylight.controller.config.facade.xml.osgi.EnumResolver) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) Collection(java.util.Collection) Set(java.util.Set) ObjectName(javax.management.ObjectName) Maps(com.google.common.collect.Maps) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Revision(org.opendaylight.yangtools.yang.common.Revision) Element(org.w3c.dom.Element) Entry(java.util.Map.Entry) Preconditions(com.google.common.base.Preconditions) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ObjectNameUtil(org.opendaylight.controller.config.api.jmx.ObjectNameUtil) Collections(java.util.Collections) XmlMappingConstants(org.opendaylight.controller.config.util.xml.XmlMappingConstants) Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Aggregations

DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)9 Map (java.util.Map)3 ObjectName (javax.management.ObjectName)3 ValidationException (org.opendaylight.controller.config.api.ValidationException)3 AttributeConfigElement (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement)3 XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)3 Element (org.w3c.dom.Element)3 Optional (com.google.common.base.Optional)2 Preconditions (com.google.common.base.Preconditions)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 HashMultimap (com.google.common.collect.HashMultimap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Multimap (com.google.common.collect.Multimap)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2