X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=tests%2Fhoneynode%2Fhoneynode-plugin-impl%2Fsrc%2Fmain%2Fjava%2Fio%2Ffd%2Fhoneycomb%2Ftransportpce%2Fdevice%2Fread%2FDeviceReaderFactory.java;h=94d473a160b06173c7d887238bb8754eb699e029;hb=069d87382e19639aa51646aa3e6be835bee9bf4a;hp=c16a1a8b339331c8760f378b850fa782b51e0234;hpb=1ec3d13e31cefd39f86bfc7f77b2fedd20f45a1e;p=transportpce.git diff --git a/tests/honeynode/honeynode-plugin-impl/src/main/java/io/fd/honeycomb/transportpce/device/read/DeviceReaderFactory.java b/tests/honeynode/honeynode-plugin-impl/src/main/java/io/fd/honeycomb/transportpce/device/read/DeviceReaderFactory.java index c16a1a8b3..94d473a16 100644 --- a/tests/honeynode/honeynode-plugin-impl/src/main/java/io/fd/honeycomb/transportpce/device/read/DeviceReaderFactory.java +++ b/tests/honeynode/honeynode-plugin-impl/src/main/java/io/fd/honeycomb/transportpce/device/read/DeviceReaderFactory.java @@ -19,10 +19,7 @@ import com.google.common.collect.Sets; 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; @@ -32,6 +29,7 @@ import java.util.List; 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; @@ -39,6 +37,9 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; 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; @@ -64,14 +65,20 @@ import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer; 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 DEVICE_CONTAINER_ID = - InstanceIdentifier.create(OrgOpenroadmDevice.class); + public static final InstanceIdentifier DEVICE_CONTAINER_ID = InstanceIdentifier + .create(OrgOpenroadmDevice.class); private static final String YANG_MODELS = "yang"; @Inject @@ -81,33 +88,35 @@ public final class DeviceReaderFactory implements ReaderFactory { @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 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 future = writeTx.submit(); @@ -128,8 +137,7 @@ public final class DeviceReaderFactory implements ReaderFactory { } /** - * Load data to config - * device datastore. + * Load data to config device datastore. * */ public boolean loadConfigData() { @@ -138,20 +146,20 @@ public final class DeviceReaderFactory implements ReaderFactory { 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 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"); } @@ -165,9 +173,43 @@ public final class DeviceReaderFactory implements ReaderFactory { } /** - * 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 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 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; @@ -179,28 +221,20 @@ public final class DeviceReaderFactory implements ReaderFactory { List schemaList = new ArrayList(); List locationList = new ArrayList(); 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 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 future = writeTx.submit(); @@ -225,7 +259,8 @@ public final class DeviceReaderFactory implements ReaderFactory { 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> potentialSchemaSources) { @@ -235,25 +270,26 @@ public final class DeviceReaderFactory implements ReaderFactory { } @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 cache = new FilesystemSchemaSourceCache<>( - consumer, YangTextSchemaSource.class, models); - consumer.registerSchemaSourceListener(cache); + final FilesystemSchemaSourceCache 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); } @@ -270,21 +306,20 @@ public final class DeviceReaderFactory implements ReaderFactory { } private static void addModuleCapability(final SharedSchemaRepository consumer, final Set 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); } -} + } }