import com.google.common.util.concurrent.Futures;
import com.google.inject.Inject;
import com.google.inject.name.Named;
-import io.fd.honeycomb.translate.read.ReaderFactory;
-import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
-import io.fd.honeycomb.translate.util.read.BindingBrokerReader;
-import io.fd.honeycomb.transportpce.device.DeviceConfiguration;
+
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+
import org.opendaylight.controller.config.util.capability.Capability;
import org.opendaylight.controller.config.util.capability.YangModuleCapability;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDeviceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.StreamsBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfStateBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import io.fd.honeycomb.translate.read.ReaderFactory;
+import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
+import io.fd.honeycomb.translate.util.read.BindingBrokerReader;
+import io.fd.honeycomb.transportpce.device.configuration.DeviceConfiguration;
+import io.fd.honeycomb.transportpce.device.configuration.NetconfConfiguration;
+
/**
* @author Martial COULIBALY ( martial.coulibaly@gfi.com ) on behalf of Orange
*/
public final class DeviceReaderFactory implements ReaderFactory {
private static final Logger LOG = LoggerFactory.getLogger(DeviceReaderFactory.class);
- public static final InstanceIdentifier<OrgOpenroadmDevice> DEVICE_CONTAINER_ID =
- InstanceIdentifier.create(OrgOpenroadmDevice.class);
+ public static final InstanceIdentifier<OrgOpenroadmDevice> DEVICE_CONTAINER_ID = InstanceIdentifier
+ .create(OrgOpenroadmDevice.class);
private static final String YANG_MODELS = "yang";
@Inject
@Inject
private DeviceConfiguration deviceConfiguration;
+ @Inject
+ private NetconfConfiguration netconfConfiguration;
@Override
public void init(final ModifiableReaderRegistryBuilder registry) {
- registry.add(new BindingBrokerReader<>(DEVICE_CONTAINER_ID, dataBroker,LogicalDatastoreType.OPERATIONAL,
+ registry.add(new BindingBrokerReader<>(DEVICE_CONTAINER_ID, dataBroker, LogicalDatastoreType.OPERATIONAL,
OrgOpenroadmDeviceBuilder.class));
- if(writeXMLDataToOper()) {
+ if (writeXMLDataToOper()) {
writeNetconfState();
+ writeNetconfStream();
loadConfigData();
}
}
/**
- * Write xml data from {@link DeviceConfiguration}
- * to operational data.
+ * Write xml data from {@link DeviceConfiguration} to operational data.
*
*/
public boolean writeXMLDataToOper() {
Boolean res = false;
LOG.info("writting xml file data to oper datastore");
OrgOpenroadmDevice device = this.deviceConfiguration.getDataDevice();
- if (device !=null) {
+ if (device != null) {
String deviceId = device.getInfo().getNodeId();
LOG.info("Getting device info from xml file for device '{}'", deviceId);
- OrgOpenroadmDeviceBuilder result = new OrgOpenroadmDeviceBuilder(device);
+ OrgOpenroadmDeviceBuilder result = new OrgOpenroadmDeviceBuilder(device);
InstanceIdentifier<OrgOpenroadmDevice> iid = InstanceIdentifier.create(OrgOpenroadmDevice.class);
WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
- if (writeTx != null ) {
+ if (writeTx != null) {
LOG.info("WriteTransaction is ok, copy device info to oper datastore");
writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, result.build());
Future<Void> future = writeTx.submit();
}
/**
- * Load data to config
- * device datastore.
+ * Load data to config device datastore.
*
*/
public boolean loadConfigData() {
String xml = this.deviceConfiguration.getConfigDevice();
LOG.info("device info gets from xml file !");
if (xml != null) {
- OrgOpenroadmDevice result = this.deviceConfiguration.getDeviceFromXML(xml);
+ OrgOpenroadmDevice result = this.deviceConfiguration.getDeviceFromXML(xml);
if (result != null) {
LOG.info("OrgOpenroadmDevice info gets : {}", result.getInfo().getNodeId());
WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
- if (writeTx != null ) {
+ if (writeTx != null) {
LOG.info("WriteTransaction is ok, copy device info to config datastore");
writeTx.put(LogicalDatastoreType.CONFIGURATION, DEVICE_CONTAINER_ID, result);
Future<Void> future = writeTx.submit();
try {
Futures.getChecked(future, ExecutionException.class);
LOG.info("device writed to config datastore");
- } catch (ExecutionException e) {
- LOG.error("Failed to write device to config datastore");
- }
+ } catch (ExecutionException e) {
+ LOG.error("Failed to write device to config datastore");
+ }
} else {
LOG.error("WriteTransaction object is null");
}
}
/**
- * Write xml data from {@link DeviceConfiguration}
- * to operational data.
+ * write {@link Streams} data to operational device datastore.
+ *
+ * @return result {@link Boolean}
+ */
+ public boolean writeNetconfStream() {
+ Boolean result = false;
+ LOG.info("writting netconf stream to oper datastore");
+ Streams streams = this.netconfConfiguration.getNetconfStreamsData();
+ if (streams != null) {
+ LOG.info("Netconf Data gets from xml file is present");
+ InstanceIdentifier<Streams> iid = InstanceIdentifier.create(Netconf.class).child(Streams.class);
+ Streams netconfStreams = new StreamsBuilder(streams).build();
+ WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
+ if (writeTx != null) {
+ LOG.info("WriteTransaction is ok");
+ writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, netconfStreams);
+ Future<Void> future = writeTx.submit();
+ try {
+ Futures.getChecked(future, ExecutionException.class);
+ LOG.info("netconf stream writed to oper datastore");
+ result = true;
+ } catch (ExecutionException e) {
+ LOG.error("Failed to write netconf stream to oper datastore");
+ }
+ } else {
+ LOG.error("WriteTransaction object is null");
+ }
+ } else {
+ LOG.error("Netconf data gets from xml file is null !");
+ }
+ return result;
+ }
+
+ /**
+ * Write {@link NetconfState} data to operational device datastore.
*
+ * @return result {@link Boolean}
*/
public boolean writeNetconfState() {
Boolean res = false;
List<Schema> schemaList = new ArrayList<Schema>();
List<Location> locationList = new ArrayList<Location>();
Location location = new Location(Enumeration.NETCONF);
- locationList.add(location );
+ locationList.add(location);
Schema schematobuild = null;
for (final Schema schema : monitor.getSchemas().getSchema()) {
- schematobuild = new SchemaBuilder()
- .setIdentifier(schema.getIdentifier())
- .setNamespace(schema.getNamespace())
- .setVersion(schema.getVersion())
- .setFormat(Yang.class)
- .setLocation(locationList)
- .build();
+ schematobuild = new SchemaBuilder().setIdentifier(schema.getIdentifier())
+ .setNamespace(schema.getNamespace()).setVersion(schema.getVersion()).setFormat(Yang.class)
+ .setLocation(locationList).build();
schemaList.add(schematobuild);
}
- Schemas schemas = new SchemasBuilder()
- .setSchema(schemaList)
- .build();
- NetconfState netconfState = new NetconfStateBuilder()
- .setSchemas(schemas)
- .build();
- if (netconfState !=null) {
+ Schemas schemas = new SchemasBuilder().setSchema(schemaList).build();
+ NetconfState netconfState = new NetconfStateBuilder().setSchemas(schemas).build();
+ if (netconfState != null) {
InstanceIdentifier<NetconfState> iid = InstanceIdentifier.create(NetconfState.class);
WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
- if (writeTx != null ) {
+ if (writeTx != null) {
LOG.info("WriteTransaction is ok, copy device info to oper datastore");
writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, netconfState);
Future<Void> future = writeTx.submit();
consumer.registerSchemaSourceListener(TextToASTTransformer.create(consumer, consumer));
consumer.registerSchemaSourceListener(new SchemaSourceListener() {
@Override
- public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {}
+ public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {
+ }
@Override
public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> potentialSchemaSources) {
}
@Override
- public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {}
+ public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {
+ }
});
LOG.info("Loading models from directory.");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
File models = new File(classLoader.getResource(YANG_MODELS).getFile());
if (models.exists() && models.isDirectory()) {
LOG.info("folder '{}' exists !", models.getAbsolutePath());
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(
- consumer, YangTextSchemaSource.class, models);
- consumer.registerSchemaSourceListener(cache);
+ final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(consumer,
+ YangTextSchemaSource.class, models);
+ consumer.registerSchemaSourceListener(cache);
} else {
LOG.warn("folder '{}' not exists !", models.getAbsolutePath());
LOG.info("Custom module loading skipped.");
}
SchemaContext schemaContext;
try {
- //necessary for creating mdsal data stores and operations
+ // necessary for creating mdsal data stores and operations
schemaContext = consumer.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT)
- .createSchemaContext(loadedSources).get();
+ .createSchemaContext(loadedSources).get();
} catch (final InterruptedException | ExecutionException e) {
throw new RuntimeException("Cannot parse schema context", e);
}
}
private static void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities,
- final Module module) {
+ final Module module) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- //to convert Date to String, use format method of SimpleDateFormat class.
+ // to convert Date to String, use format method of SimpleDateFormat class.
String revision = dateFormat.format(module.getRevision());
- final SourceIdentifier moduleSourceIdentifier = RevisionSourceIdentifier.create(module.getName(),
- revision);
+ final SourceIdentifier moduleSourceIdentifier = RevisionSourceIdentifier.create(module.getName(), revision);
try {
final String moduleContent = new String(
- consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class).get().read());
+ consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class).get().read());
capabilities.add(new YangModuleCapability(module, moduleContent));
- //IOException would be thrown in creating SchemaContext already
+ // IOException would be thrown in creating SchemaContext already
} catch (ExecutionException | InterruptedException | IOException e) {
LOG.warn("Cannot retrieve schema source for module {} from schema repository",
moduleSourceIdentifier.toString(), e);
}
-}
+ }
}