aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main')
-rw-r--r--vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/CrudService.java64
-rw-r--r--vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ElementCrudService.java114
-rw-r--r--vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/Module.java66
-rw-r--r--vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ModuleConfiguration.java46
-rw-r--r--vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/DnsInstanceManager.java142
-rw-r--r--vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/ElementCustomizer.java73
-rw-r--r--vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/ModuleWriterFactory.java54
7 files changed, 559 insertions, 0 deletions
diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/CrudService.java b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/CrudService.java
new file mode 100644
index 00000000..1e7be67b
--- /dev/null
+++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/CrudService.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnf.vlb;
+
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Example of an aggregated access interface.
+ * <p/>
+ * Shared by all the customizers hiding the ugly details of our data management.
+ *
+ * TODO update javadoc
+ */
+public interface CrudService<T extends DataObject> {
+
+ /**
+ * Perform write of provided data.
+ */
+ void writeData(@Nonnull final InstanceIdentifier<T> identifier, @Nonnull final T data)
+ throws WriteFailedException;
+
+
+ /**
+ * Perform delete of existing data.
+ */
+ void deleteData(@Nonnull final InstanceIdentifier<T> identifier, @Nonnull final T data)
+ throws WriteFailedException;
+
+ /**
+ * Perform update of existing data.
+ */
+ void updateData(@Nonnull final InstanceIdentifier<T> identifier, @Nonnull final T dataOld,
+ @Nonnull final T dataNew)
+ throws WriteFailedException;
+
+ /**
+ * Read data identified by provided identifier.
+ */
+ T readSpecific(@Nonnull final InstanceIdentifier<T> identifier) throws ReadFailedException;
+
+ /**
+ * Read all nodes of type {@link T}.
+ */
+ List<T> readAll() throws ReadFailedException;
+}
diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ElementCrudService.java b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ElementCrudService.java
new file mode 100644
index 00000000..d17c6c18
--- /dev/null
+++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ElementCrudService.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnf.vlb;
+
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.Collections;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.VlbBusinessVnfOnapPluginState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.VdnsInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstanceKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Simple example of class handling Crud operations for plugin.
+ * <p/>
+ * No real handling, serves just as an illustration.
+ *
+ * TODO update javadoc
+ */
+final class ElementCrudService implements CrudService<VdnsInstance> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ElementCrudService.class);
+
+ @Override
+ public void writeData(@Nonnull final InstanceIdentifier<VdnsInstance> identifier, @Nonnull final VdnsInstance data)
+ throws WriteFailedException {
+ if (data != null) {
+
+ // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
+ // relationships such as to which parent these data are related to
+
+ // Performs any logic needed for persisting such data
+ LOG.info("Writing path[{}] / data [{}]", identifier, data);
+ } else {
+ throw new WriteFailedException.CreateFailedException(identifier, data,
+ new NullPointerException("Provided data are null"));
+ }
+ }
+
+ @Override
+ public void deleteData(@Nonnull final InstanceIdentifier<VdnsInstance> identifier, @Nonnull final VdnsInstance data)
+ throws WriteFailedException {
+ if (data != null) {
+
+ // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
+ // relationships such as to which parent these data are related to
+
+ // Performs any logic needed for persisting such data
+ LOG.info("Removing path[{}] / data [{}]", identifier, data);
+ } else {
+ throw new WriteFailedException.DeleteFailedException(identifier,
+ new NullPointerException("Provided data are null"));
+ }
+ }
+
+ @Override
+ public void updateData(@Nonnull final InstanceIdentifier<VdnsInstance> identifier, @Nonnull final VdnsInstance dataOld,
+ @Nonnull final VdnsInstance dataNew) throws WriteFailedException {
+ if (dataOld != null && dataNew != null) {
+
+ // identifier.firstKeyOf(SomeClassUpperInHierarchy.class) can be used to identify
+ // relationships such as to which parent these data are related to
+
+ // Performs any logic needed for persisting such data
+ LOG.info("Update path[{}] from [{}] to [{}]", identifier, dataOld, dataNew);
+ } else {
+ throw new WriteFailedException.DeleteFailedException(identifier,
+ new NullPointerException("Provided data are null"));
+ }
+ }
+
+ @Override
+ public VdnsInstance readSpecific(@Nonnull final InstanceIdentifier<VdnsInstance> identifier) throws ReadFailedException {
+
+ // read key specified in path identifier
+ final VdnsInstanceKey key = identifier.firstKeyOf(VdnsInstance.class);
+
+ // load data by this key
+ // *Key class will always contain key of entity, in this case long value
+
+ return new VdnsInstanceBuilder()
+ .setIpAddr(key.getIpAddr())
+ .setKey(key)
+ .setIsEnabled(true)
+ .build();
+ }
+
+ @Override
+ public List<VdnsInstance> readAll() throws ReadFailedException {
+ // read all data under parent node,in this case {@link ModuleState}
+ return Collections.singletonList(
+ readSpecific(InstanceIdentifier.create(VlbBusinessVnfOnapPluginState.class).child(VdnsInstances.class).child(VdnsInstance.class, new VdnsInstanceKey(""))));
+ }
+}
diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/Module.java b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/Module.java
new file mode 100644
index 00000000..37506d1e
--- /dev/null
+++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/Module.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnf.vlb;
+
+import static org.onap.vnf.vlb.ModuleConfiguration.ELEMENT_SERVICE_NAME;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.TypeLiteral;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
+//import org.onap.vnf.vlb.read.ModuleStateReaderFactory;
+import org.onap.vnf.vlb.write.ModuleWriterFactory;
+import io.fd.honeycomb.data.init.DataTreeInitializer;
+import io.fd.honeycomb.translate.read.ReaderFactory;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import net.jmob.guice.conf.core.ConfigurationModule;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstance;
+
+/**
+ * Module class instantiating vlb-business-vnf-onap-plugin plugin components.
+ */
+public final class Module extends AbstractModule {
+
+ // TODO This initiates all the plugin components, but it still needs to be registered/wired into an integration
+ // module producing runnable distributions. There is one such distribution in honeycomb project:
+ // vpp-integration/minimal-distribution
+ // In order to integrate this plugin with the distribution:
+ // 1. Add a dependency on this maven module to the the distribution's pom.xml
+ // 2. Add an instance of this module into the distribution in its Main class
+
+ @Override
+ protected void configure() {
+ // requests injection of properties
+ install(ConfigurationModule.create());
+ requestInjection(ModuleConfiguration.class);
+
+ // creates binding for interface implementation by name
+ bind(new TypeLiteral<CrudService<VdnsInstance>>(){})
+ .annotatedWith(Names.named(ELEMENT_SERVICE_NAME))
+ .to(ElementCrudService.class);
+
+ // creates reader factory binding
+ // can hold multiple binding for separate yang modules
+ //final Multibinder<ReaderFactory> readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
+ //readerFactoryBinder.addBinding().to(ModuleStateReaderFactory.class);
+
+ // create writer factory binding
+ // can hold multiple binding for separate yang modules
+ final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
+ writerFactoryBinder.addBinding().to(ModuleWriterFactory.class);
+ }
+}
diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ModuleConfiguration.java b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ModuleConfiguration.java
new file mode 100644
index 00000000..c2a429ab
--- /dev/null
+++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ModuleConfiguration.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnf.vlb;
+
+import net.jmob.guice.conf.core.BindConfig;
+import net.jmob.guice.conf.core.InjectConfig;
+import net.jmob.guice.conf.core.Syntax;
+
+/**
+ * Class containing static configuration for vlb-business-vnf-onap-plugin module,<br>
+ * either loaded from property file vlb-business-vnf-onap-plugin.json from classpath.
+ * <p/>
+ * Further documentation for the configuration injection can be found at:
+ * https://github.com/yyvess/gconf
+ */
+@BindConfig(value = "vlb-business-vnf-onap-plugin", syntax = Syntax.JSON)
+public final class ModuleConfiguration {
+
+ // TODO change the sample property to real plugin configuration
+ // If there is no such configuration, remove this, vlb-business-vnf-onap-plugin.json resource and its wiring from Module class
+
+ /**
+ * Sample property that's injected from external json configuration file.
+ */
+ @InjectConfig("sample-prop")
+ public String sampleProp;
+
+ /**
+ * Constant name used to identify vlb-business-vnf-onap-plugin plugin specific components during dependency injection.
+ */
+ public static final String ELEMENT_SERVICE_NAME = "element-service";
+}
diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/DnsInstanceManager.java b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/DnsInstanceManager.java
new file mode 100644
index 00000000..dc3e9248
--- /dev/null
+++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/DnsInstanceManager.java
@@ -0,0 +1,142 @@
+
+/*************************************************************************//**
+ *
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+
+package org.onap.vnf.vlb.write;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * Class that maintains a map of all the active vDNS instances.
+ * A vDNS instance is represented by its IP address and a flag
+ * that represents its status, i.e. enabled or disabled.
+ *
+ * Clients can update the vDNS map via NETCONF or RESTconf.
+ * Operations are translated by the Honeycomb agent into a JSON
+ * object that is persisted on disk (see Honeycomb distribution
+ * configuration for more information). The ElementCustomizer
+ * class then updates this map. Each operation results in a vLB
+ * setup change, e.g. GRE tunnels that connect the vLB to the
+ * vDNS instances are created or deleted, depending on the kind
+ * of operation that is invoked. Only vDNS instances for which
+ * the isEnabled flag is true are currently served by the vLB.
+ *
+ * The vLB setup and configuration is executed via shell scripts.
+ *
+ */
+
+public class DnsInstanceManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DnsInstanceManager.class);
+ private Map<String, Boolean> dnsInstances = new HashMap<String, Boolean>();
+
+ /*
+ * Add a new DNS instance to the map and create a GRE tunnel
+ * towards that instance if isEnabled is set to true.
+ */
+ void addDnsInstance(String ipAddr, Boolean isEnabled) {
+ // Call updateDnsInstance in case the DNS instance already exists.
+ // This is somewhat redundant because Honeycomb already runs this check.
+ if(dnsInstances.containsKey(ipAddr)) {
+ updateDnsInstance(ipAddr, isEnabled);
+ return;
+ }
+
+ dnsInstances.put(ipAddr, isEnabled);
+ LOG.debug("DNS instance " + ipAddr + " with status isEnabled=" + isEnabled + " has been added.");
+
+ // Create a GRE tunnel towards the new DNS instance if isEnabled is true.
+ if(isEnabled) {
+ addGreTunnel(ipAddr);
+ }
+ }
+
+ /*
+ * Update an existing DNS instance and create or remove a GRE
+ * tunnel based on the current value of the isEnabled flag.
+ */
+ void updateDnsInstance(String ipAddr, Boolean isEnabled) {
+ // This is somewhat redundant because Honeycomb already runs this check.
+ if(dnsInstances.get(ipAddr) == isEnabled) {
+ LOG.debug("DNS instance " + ipAddr + " with status isEnabled=" + isEnabled + " already exists. No update is necessary.");
+ return;
+ }
+
+ dnsInstances.put(ipAddr, isEnabled);
+ LOG.debug("DNS instance " + ipAddr + " has been updated with status isEnabled=" + isEnabled + ".");
+
+ if(isEnabled) {
+ addGreTunnel(ipAddr);
+ }
+ else {
+ deleteGreTunnel(ipAddr);
+ }
+ }
+
+ /*
+ * Delete an existing DNS instance from the map and remove the
+ * GRE tunnel if isEnabled was set to true.
+ */
+ void deleteDnsInstance(String ipAddr) {
+ // This is somewhat redundant because Honeycomb already runs this check.
+ if(!dnsInstances.containsKey(ipAddr)) {
+ LOG.debug("DNS instance " + ipAddr + " doesn't exist.");
+ return;
+ }
+
+ // Remove a GRE tunnel towards this DNS instance if it exists.
+ if(dnsInstances.get(ipAddr)) {
+ deleteGreTunnel(ipAddr);
+ }
+
+ dnsInstances.remove(ipAddr);
+ }
+
+ /*
+ * Auxiliary function that calls a shell script to create a GRE tunnel towards a new vDNS instance.
+ */
+ private void addGreTunnel(String ipAddr) {
+ String script = new String("bash /opt/add_dns.sh " + ipAddr);
+ try {
+ Runtime.getRuntime().exec(script);
+ LOG.debug("New GRE tunnel towards DNS instance " + ipAddr + " created.");
+ } catch (IOException e) {
+ LOG.error("add_dns.sh returned an error.");
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * Auxiliary function that calls a shell script to delete a GRE tunnel towards a vDNS instance.
+ */
+ private void deleteGreTunnel(String ipAddr) {
+ String script = new String("bash /opt/remove_dns.sh " + ipAddr);
+ try {
+ Runtime.getRuntime().exec(script);
+ LOG.debug("GRE tunnel towards DNS instance " + ipAddr + " removed.");
+ } catch (IOException e) {
+ LOG.error("remove_dns.sh returned an error.");
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/ElementCustomizer.java b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/ElementCustomizer.java
new file mode 100644
index 00000000..d8da0b5b
--- /dev/null
+++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/ElementCustomizer.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnf.vlb.write;
+
+import org.onap.vnf.vlb.CrudService;
+import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstanceKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Writer for {@link Element} list node from our YANG model.
+ */
+public final class ElementCustomizer implements ListWriterCustomizer<VdnsInstance, VdnsInstanceKey> {
+
+ private final CrudService<VdnsInstance> crudService;
+ private DnsInstanceManager dnsInstanceManager;
+ private static final Logger LOG = LoggerFactory.getLogger(ElementCustomizer.class);
+
+ public ElementCustomizer(@Nonnull final CrudService<VdnsInstance> crudService) {
+ this.crudService = crudService;
+ dnsInstanceManager = new DnsInstanceManager();
+ }
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<VdnsInstance> id, @Nonnull final VdnsInstance dataAfter,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ //perform write of data,or throw exception
+ //invoked by PUT operation,if provided data doesn't exist in Config data
+ crudService.writeData(id, dataAfter);
+ dnsInstanceManager.addDnsInstance(dataAfter.getIpAddr(), dataAfter.isIsEnabled());
+ }
+
+ @Override
+ public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<VdnsInstance> id,
+ @Nonnull final VdnsInstance dataBefore,
+ @Nonnull final VdnsInstance dataAfter, @Nonnull final WriteContext writeContext)
+ throws WriteFailedException {
+ //perform update of data,or throw exception
+ //invoked by PUT operation,if provided data does exist in Config data
+ crudService.updateData(id, dataBefore, dataAfter);
+ dnsInstanceManager.updateDnsInstance(dataAfter.getIpAddr(), dataAfter.isIsEnabled());
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<VdnsInstance> id,
+ @Nonnull final VdnsInstance dataBefore,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ //perform delete of data,or throw exception
+ //invoked by DELETE operation
+ crudService.deleteData(id, dataBefore);
+ dnsInstanceManager.deleteDnsInstance(dataBefore.getIpAddr());
+ }
+}
diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/ModuleWriterFactory.java b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/ModuleWriterFactory.java
new file mode 100644
index 00000000..8be4bb10
--- /dev/null
+++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/write/ModuleWriterFactory.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vnf.vlb.write;
+
+import static org.onap.vnf.vlb.ModuleConfiguration.ELEMENT_SERVICE_NAME;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import org.onap.vnf.vlb.CrudService;
+import io.fd.honeycomb.translate.impl.write.GenericWriter;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.VlbBusinessVnfOnapPlugin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.VdnsInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vlb.business.vnf.onap.plugin.rev160918.vlb.business.vnf.onap.plugin.params.vdns.instances.VdnsInstance;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Factory producing writers for vlb-business-vnf-onap-plugin plugin's data.
+ */
+public final class ModuleWriterFactory implements WriterFactory {
+
+ private static final InstanceIdentifier<VlbBusinessVnfOnapPlugin> ROOT_CONTAINER_ID = InstanceIdentifier.create(VlbBusinessVnfOnapPlugin.class);
+
+ /**
+ * Injected crud service to be passed to customizers instantiated in this factory.
+ */
+ @Inject
+ @Named(ELEMENT_SERVICE_NAME)
+ private CrudService<VdnsInstance> crudService;
+
+ @Override
+ public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
+
+ //adds writer for child node
+ //no need to add writers for empty nodes
+ registry.add(new GenericWriter<>(ROOT_CONTAINER_ID.child(VdnsInstances.class).child(VdnsInstance.class), new ElementCustomizer(crudService)));
+ }
+}