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);
}
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations