use of org.opendaylight.yangtools.yang.binding.DataObject in project openflowplugin by opendaylight.
the class WakeupOnNode method onDataTreeChanged.
@Override
public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Table>> modifications) {
Short requiredTableId = 0;
for (DataTreeModification modification : modifications) {
if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) {
DataObject table = modification.getRootNode().getDataAfter();
if (table instanceof Table) {
Table tableSure = (Table) table;
LOG.trace("table: {}", table);
if (requiredTableId.equals(tableSure.getId())) {
InstanceIdentifier<Table> tablePath = modification.getRootPath().getRootIdentifier();
learningSwitchHandler.onSwitchAppeared(tablePath);
}
}
}
}
}
use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.
the class DataStoreAppConfigDefaultXMLReader method createDefaultInstance.
@SuppressWarnings("unchecked")
public T createDefaultInstance(final FallbackConfigProvider fallback) throws ConfigXMLReaderException, URISyntaxException, ParserConfigurationException, XMLStreamException, SAXException, IOException {
YangInstanceIdentifier yangPath = bindingSerializer.toYangInstanceIdentifier(bindingContext.appConfigPath);
LOG.debug("{}: Creating app config instance from path {}, Qname: {}", logName, yangPath, bindingContext.bindingQName);
checkNotNull(schemaService, "%s: Could not obtain the SchemaService OSGi service", logName);
SchemaContext schemaContext = schemaService.getGlobalContext();
Module module = schemaContext.findModule(bindingContext.bindingQName.getModule()).orElse(null);
checkNotNull(module, "%s: Could not obtain the module schema for namespace %s, revision %s", logName, bindingContext.bindingQName.getNamespace(), bindingContext.bindingQName.getRevision());
DataSchemaNode dataSchema = module.getDataChildByName(bindingContext.bindingQName);
checkNotNull(dataSchema, "%s: Could not obtain the schema for %s", logName, bindingContext.bindingQName);
checkCondition(bindingContext.schemaType.isAssignableFrom(dataSchema.getClass()), "%s: Expected schema type %s for %s but actual type is %s", logName, bindingContext.schemaType, bindingContext.bindingQName, dataSchema.getClass());
NormalizedNode<?, ?> dataNode = parsePossibleDefaultAppConfigXMLFile(schemaContext, dataSchema);
if (dataNode == null) {
dataNode = fallback.get(schemaService.getGlobalContext(), dataSchema);
}
DataObject appConfig = bindingSerializer.fromNormalizedNode(yangPath, dataNode).getValue();
// This shouldn't happen but need to handle it in case...
checkNotNull(appConfig, "%s: Could not create instance for app config binding %s", logName, bindingContext.appConfigBindingClass);
return (T) appConfig;
}
use of org.opendaylight.yangtools.yang.binding.DataObject 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;
}
}
use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.
the class DataStoreAppConfigMetadata method setInitialAppConfig.
private boolean setInitialAppConfig(final Optional<DataObject> possibleAppConfig) {
boolean result = readingInitialAppConfig.compareAndSet(true, false);
if (result) {
DataObject localAppConfig;
if (possibleAppConfig.isPresent()) {
localAppConfig = possibleAppConfig.get();
} else {
// No app config data is present so create an empty instance via the bindingSerializer service.
// This will also return default values for leafs that haven't been explicitly set.
localAppConfig = createDefaultInstance();
}
LOG.debug("{}: Setting currentAppConfig instance: {}", logName(), localAppConfig);
// Now publish the app config instance to the volatile field and notify the callback to let the
// container know our dependency is now satisfied.
currentAppConfig = localAppConfig;
setSatisfied();
}
return result;
}
use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.
the class DataStoreAppConfigMetadata method readInitialAppConfig.
private void readInitialAppConfig(final DataBroker dataBroker) {
final ReadOnlyTransaction readOnlyTx = dataBroker.newReadOnlyTransaction();
ListenableFuture<Optional<DataObject>> future = readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, bindingContext.appConfigPath);
Futures.addCallback(future, new FutureCallback<Optional<DataObject>>() {
@Override
public void onSuccess(final Optional<DataObject> possibleAppConfig) {
LOG.debug("{}: Read of app config {} succeeded: {}", logName(), bindingContext.appConfigBindingClass.getName(), possibleAppConfig);
readOnlyTx.close();
setInitialAppConfig(possibleAppConfig);
}
@Override
public void onFailure(final Throwable failure) {
readOnlyTx.close();
// We may have gotten the app config via the data tree change listener so only retry if not.
if (readingInitialAppConfig.get()) {
LOG.warn("{}: Read of app config {} failed - retrying", logName(), bindingContext.appConfigBindingClass.getName(), failure);
readInitialAppConfig(dataBroker);
}
}
}, MoreExecutors.directExecutor());
}
Aggregations