Search in sources :

Example 1 with ConfigURLProvider

use of org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader.ConfigURLProvider in project controller by opendaylight.

the class DataStoreAppConfigMetadata method createDefaultInstance.

private DataObject createDefaultInstance() {
    try {
        ConfigURLProvider inputStreamProvider = appConfigFileName -> {
            File appConfigFile = new File(DEFAULT_APP_CONFIG_FILE_PATH, appConfigFileName);
            LOG.debug("{}: parsePossibleDefaultAppConfigXMLFile looking for file {}", logName(), appConfigFile.getAbsolutePath());
            if (!appConfigFile.exists()) {
                return Optional.absent();
            }
            LOG.debug("{}: Found file {}", logName(), appConfigFile.getAbsolutePath());
            return Optional.of(appConfigFile.toURI().toURL());
        };
        DataStoreAppConfigDefaultXMLReader<?> reader = new DataStoreAppConfigDefaultXMLReader<>(logName(), defaultAppConfigFileName, getOSGiService(DOMSchemaService.class), bindingSerializer, bindingContext, inputStreamProvider);
        return reader.createDefaultInstance((schemaContext, dataSchema) -> {
            // Fallback if file cannot be read, try XML from Config
            NormalizedNode<?, ?> dataNode = parsePossibleDefaultAppConfigElement(schemaContext, dataSchema);
            if (dataNode == null) {
                // or, as last resort, defaults from the model
                return bindingContext.newDefaultNode(dataSchema);
            } else {
                return dataNode;
            }
        });
    } catch (final ConfigXMLReaderException | IOException | SAXException | XMLStreamException | ParserConfigurationException | URISyntaxException e) {
        if (e.getCause() == null) {
            setFailureMessage(e.getMessage());
        } else {
            setFailure(e.getMessage(), e);
        }
        return null;
    }
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ClusteredDataTreeChangeListener(org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ExtendedBlueprintContainer(org.apache.aries.blueprint.services.ExtendedBlueprintContainer) Optional(com.google.common.base.Optional) XMLStreamException(javax.xml.stream.XMLStreamException) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) Logger(org.slf4j.Logger) Collection(java.util.Collection) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) IOException(java.io.IOException) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Objects(java.util.Objects) ModificationType(org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType) Futures(com.google.common.util.concurrent.Futures) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) SAXException(org.xml.sax.SAXException) DataTreeModification(org.opendaylight.controller.md.sal.binding.api.DataTreeModification) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ConfigURLProvider(org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader.ConfigURLProvider) ConfigURLProvider(org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader.ConfigURLProvider) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) XMLStreamException(javax.xml.stream.XMLStreamException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService)

Aggregations

Optional (com.google.common.base.Optional)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 File (java.io.File)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ExtendedBlueprintContainer (org.apache.aries.blueprint.services.ExtendedBlueprintContainer)1 ConfigURLProvider (org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader.ConfigURLProvider)1 ClusteredDataTreeChangeListener (org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1 DataObjectModification (org.opendaylight.controller.md.sal.binding.api.DataObjectModification)1