From: Marco Platania Date: Tue, 27 Feb 2018 21:32:25 +0000 (-0500) Subject: Add NETCONF/RESTconf APIs to vLB X-Git-Tag: v1.2.0~140 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=0766a3ace2df01e523d65e726fc3f7c0c00b4dc8;hp=33621cb3587792e4d29bcebf5ff02d42ed50c8e2;p=demo.git Add NETCONF/RESTconf APIs to vLB Create a new directory for the vLB Manual Scale out use case (vLBMS). Add NETCONF/RESTconf APIs for configuring the vLB via ONAP. Change-Id: I06c557143d3a6d12159fc3195991cd8d49432348 Issue-ID: INT-432 Signed-off-by: Marco Platania --- diff --git a/.gitignore b/.gitignore index 93fc263e..bd5fd821 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.project /.pydevproject .*.sw? +.DS_Store \ No newline at end of file diff --git a/pom.xml b/pom.xml index dc3d7d2a..1ce01a40 100755 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ vnfs/VESreporting_vLB5.0 vnfs/VESreporting_vFW5.0 vnfs/vCPE/kea-sdnc-notify-mod + vnfs/vLBMS/apis diff --git a/scripts/.DS_Store b/scripts/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/scripts/.DS_Store and /dev/null differ diff --git a/vnfs/VES/.DS_Store b/vnfs/VES/.DS_Store deleted file mode 100644 index 4b31f725..00000000 Binary files a/vnfs/VES/.DS_Store and /dev/null differ diff --git a/vnfs/VES/code/.DS_Store b/vnfs/VES/code/.DS_Store deleted file mode 100644 index a9cc98d2..00000000 Binary files a/vnfs/VES/code/.DS_Store and /dev/null differ diff --git a/vnfs/VES/code/evel_training/.DS_Store b/vnfs/VES/code/evel_training/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/vnfs/VES/code/evel_training/.DS_Store and /dev/null differ diff --git a/vnfs/VES/output/.DS_Store b/vnfs/VES/output/.DS_Store deleted file mode 100644 index e34c8329..00000000 Binary files a/vnfs/VES/output/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/.DS_Store b/vnfs/honeycomb_plugin/.DS_Store deleted file mode 100644 index 102e7ce1..00000000 Binary files a/vnfs/honeycomb_plugin/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/.DS_Store deleted file mode 100644 index 935eda93..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/.DS_Store deleted file mode 100644 index 6816049e..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/.DS_Store deleted file mode 100644 index 7db2c2e3..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/.DS_Store deleted file mode 100644 index 06450486..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/.DS_Store deleted file mode 100644 index 47336c35..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/fd/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/fd/.DS_Store deleted file mode 100644 index 0bb0440d..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/fd/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/fd/honeycomb/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/fd/honeycomb/.DS_Store deleted file mode 100644 index 70a47622..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-distribution/src/main/java/io/fd/honeycomb/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/.DS_Store deleted file mode 100644 index 935eda93..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/src/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/src/.DS_Store deleted file mode 100644 index 6816049e..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/src/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/src/main/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/src/main/.DS_Store deleted file mode 100644 index 45c9ff18..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-api/src/main/.DS_Store and /dev/null differ diff --git a/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-impl/.DS_Store b/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-impl/.DS_Store deleted file mode 100644 index 935eda93..00000000 Binary files a/vnfs/honeycomb_plugin/sample_plugin/sample-plugin-impl/.DS_Store and /dev/null differ diff --git a/vnfs/vFW/.DS_Store b/vnfs/vFW/.DS_Store deleted file mode 100644 index d5659b63..00000000 Binary files a/vnfs/vFW/.DS_Store and /dev/null differ diff --git a/vnfs/vFW/pg_streams/.DS_Store b/vnfs/vFW/pg_streams/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/vnfs/vFW/pg_streams/.DS_Store and /dev/null differ diff --git a/vnfs/vFW/scripts/.DS_Store b/vnfs/vFW/scripts/.DS_Store deleted file mode 100644 index e97f86f1..00000000 Binary files a/vnfs/vFW/scripts/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/DNSClient/.DS_Store b/vnfs/vLB/DNSClient/.DS_Store deleted file mode 100644 index 210fb02d..00000000 Binary files a/vnfs/vLB/DNSClient/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/DNSClient/src/.DS_Store b/vnfs/vLB/DNSClient/src/.DS_Store deleted file mode 100644 index dba6f684..00000000 Binary files a/vnfs/vLB/DNSClient/src/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/DNSClient/src/main/.DS_Store b/vnfs/vLB/DNSClient/src/main/.DS_Store deleted file mode 100644 index 9206bc71..00000000 Binary files a/vnfs/vLB/DNSClient/src/main/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/DNSClient/src/main/java/.DS_Store b/vnfs/vLB/DNSClient/src/main/java/.DS_Store deleted file mode 100644 index 05c35472..00000000 Binary files a/vnfs/vLB/DNSClient/src/main/java/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/DNSManager/.DS_Store b/vnfs/vLB/DNSManager/.DS_Store deleted file mode 100644 index cc896b07..00000000 Binary files a/vnfs/vLB/DNSManager/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/DNSManager/src/.DS_Store b/vnfs/vLB/DNSManager/src/.DS_Store deleted file mode 100644 index 201b6cf3..00000000 Binary files a/vnfs/vLB/DNSManager/src/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/DNSManager/src/main/.DS_Store b/vnfs/vLB/DNSManager/src/main/.DS_Store deleted file mode 100644 index d0f5e852..00000000 Binary files a/vnfs/vLB/DNSManager/src/main/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/DNSManager/src/main/java/.DS_Store b/vnfs/vLB/DNSManager/src/main/java/.DS_Store deleted file mode 100644 index 097132be..00000000 Binary files a/vnfs/vLB/DNSManager/src/main/java/.DS_Store and /dev/null differ diff --git a/vnfs/vLB/dns_streams/.DS_Store b/vnfs/vLB/dns_streams/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/vnfs/vLB/dns_streams/.DS_Store and /dev/null differ diff --git a/vnfs/vLBMS/apis/asciidoc/Readme.adoc b/vnfs/vLBMS/apis/asciidoc/Readme.adoc new file mode 100644 index 00000000..292e5fd6 --- /dev/null +++ b/vnfs/vLBMS/apis/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += vlb-business-vnf-onap-plugin-aggregator + +Overview of vlb-business-vnf-onap-plugin-aggregator \ No newline at end of file diff --git a/vnfs/vLBMS/apis/pom.xml b/vnfs/vLBMS/apis/pom.xml new file mode 100755 index 00000000..5ce6ed0f --- /dev/null +++ b/vnfs/vLBMS/apis/pom.xml @@ -0,0 +1,56 @@ + + + + + demo-aggregator + 1.2.0-SNAPSHOT + org.onap.demo.vnf + ../../../pom.xml + + + org.onap.vnf.vlb + vlb-business-vnf-onap-plugin-aggregator + 1.2.0-SNAPSHOT + vlb-business-vnf-onap-plugin-aggregator + pom + 4.0.0 + + + vlb-business-vnf-onap-plugin-api + vlb-business-vnf-onap-plugin-impl + vlb-vnf-onap-distribution + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.apache.maven.plugins + maven-install-plugin + + true + + + + + diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/asciidoc/Readme.adoc b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/asciidoc/Readme.adoc new file mode 100644 index 00000000..84ed862b --- /dev/null +++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += vlb-business-vnf-onap-plugin-api + +Overview of vlb-business-vnf-onap-plugin-api \ No newline at end of file diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/pom.xml b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/pom.xml new file mode 100644 index 00000000..dd6c5972 --- /dev/null +++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/pom.xml @@ -0,0 +1,75 @@ + + + + + io.fd.honeycomb.common + api-parent + 1.17.07 + + + 4.0.0 + org.onap.vnf.vlb + vlb-business-vnf-onap-plugin-api + vlb-business-vnf-onap-plugin-api + bundle + + + + org.opendaylight.mdsal.model + iana-if-type-2014-05-08 + + + org.opendaylight.mdsal.model + ietf-yang-types-20130715 + + + org.opendaylight.mdsal.model + ietf-interfaces + + + org.opendaylight.mdsal.model + ietf-inet-types-2013-07-15 + + + org.opendaylight.mdsal.model + yang-ext + + + + + + + org.codehaus.mojo + exec-maven-plugin + + + none + + + + true + + + + maven-checkstyle-plugin + + true + + + + + + diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/src/main/yang/vlb-business-vnf-onap-plugin.yang b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/src/main/yang/vlb-business-vnf-onap-plugin.yang new file mode 100644 index 00000000..229ad7a3 --- /dev/null +++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-api/src/main/yang/vlb-business-vnf-onap-plugin.yang @@ -0,0 +1,66 @@ +module vlb-business-vnf-onap-plugin { + + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:vlb-business-vnf-onap-plugin"; + prefix "vlb-business-vnf-onap-plugin"; + + description + "This YANG module defines the generic configuration and + operational data for vlb-business-vnf-onap-plugin in VPP"; + + revision "2016-09-18" { + description "Initial revision of vlb-business-vnf-onap-plugin model"; + } + + container vlb-business-vnf-onap-plugin { + uses vlb-business-vnf-onap-plugin-params; + description "Configuration data of vlb-business-vnf-onap-plugin in Honeycomb"; + + // READ + // curl -u admin:admin http://localhost:8181/restconf/config/vlb-business-vnf-onap-plugin:vlb-business-vnf-onap-plugin + + // WRITE + // curl http://localhost:8181/restconf/operational/vlb-business-vnf-onap-plugin:vlb-business-vnf-onap-plugin + + } + + container vlb-business-vnf-onap-plugin-state { + config false; + uses vlb-business-vnf-onap-plugin-params; + description "Operational data of vlb-business-vnf-onap-plugin persisted in VPP"; + + // READ + // curl -u admin:admin http://localhost:8181/restconf/operational/vlb-business-vnf-onap-plugin:vlb-business-vnf-onap-plugin-state + } + +// grouping vlb-business-vnf-onap-plugin-params { +// list element { +// +// key id; +// leaf id { +// type uint32; +// } +// +// leaf description { +// type string; +// } +// } +// } + + + grouping vlb-business-vnf-onap-plugin-params { + container vdns-instances { + list vdns-instance { + + key ip-addr; + leaf ip-addr { + type string; + } + + leaf is-enabled { + type boolean; + } + } + } + } +} diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/asciidoc/Readme.adoc b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/asciidoc/Readme.adoc new file mode 100644 index 00000000..ab759c7b --- /dev/null +++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += vlb-business-vnf-onap-plugin-impl + +Overview of vlb-business-vnf-onap-plugin-impl \ No newline at end of file diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/pom.xml b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/pom.xml new file mode 100644 index 00000000..7f96b5c6 --- /dev/null +++ b/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/pom.xml @@ -0,0 +1,96 @@ + + + + io.fd.honeycomb.common + impl-parent + 1.17.07 + + + 4.0.0 + org.onap.vnf.vlb + vlb-business-vnf-onap-plugin-impl + vlb-business-vnf-onap-plugin-impl + bundle + + + 1.17.07 + + + + + ${project.groupId} + vlb-business-vnf-onap-plugin-api + ${project.version} + + + + + io.fd.honeycomb + translate-api + ${honeycomb.infra.version} + + + + io.fd.honeycomb + translate-spi + ${honeycomb.infra.version} + + + + io.fd.honeycomb + cfg-init + ${honeycomb.infra.version} + + + + + com.google.inject + guice + + + net.jmob + guice.conf + + + com.google.inject.extensions + guice-multibindings + + + + + + + org.codehaus.mojo + exec-maven-plugin + + + none + + + + true + + + + maven-checkstyle-plugin + + true + + + + + + diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/CrudService.java b/vnfs/vLBMS/apis/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-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. + *

+ * Shared by all the customizers hiding the ugly details of our data management. + * + * TODO update javadoc + */ +public interface CrudService { + + /** + * Perform write of provided data. + */ + void writeData(@Nonnull final InstanceIdentifier identifier, @Nonnull final T data) + throws WriteFailedException; + + + /** + * Perform delete of existing data. + */ + void deleteData(@Nonnull final InstanceIdentifier identifier, @Nonnull final T data) + throws WriteFailedException; + + /** + * Perform update of existing data. + */ + void updateData(@Nonnull final InstanceIdentifier identifier, @Nonnull final T dataOld, + @Nonnull final T dataNew) + throws WriteFailedException; + + /** + * Read data identified by provided identifier. + */ + T readSpecific(@Nonnull final InstanceIdentifier identifier) throws ReadFailedException; + + /** + * Read all nodes of type {@link T}. + */ + List readAll() throws ReadFailedException; +} diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ElementCrudService.java b/vnfs/vLBMS/apis/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-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. + *

+ * No real handling, serves just as an illustration. + * + * TODO update javadoc + */ +final class ElementCrudService implements CrudService { + + private static final Logger LOG = LoggerFactory.getLogger(ElementCrudService.class); + + @Override + public void writeData(@Nonnull final InstanceIdentifier 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 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 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 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 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-impl/src/main/java/org/onap/vnf/vlb/Module.java b/vnfs/vLBMS/apis/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-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>(){}) + .annotatedWith(Names.named(ELEMENT_SERVICE_NAME)) + .to(ElementCrudService.class); + + // creates reader factory binding + // can hold multiple binding for separate yang modules + //final Multibinder 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 writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class); + writerFactoryBinder.addBinding().to(ModuleWriterFactory.class); + } +} diff --git a/vnfs/vLBMS/apis/vlb-business-vnf-onap-plugin-impl/src/main/java/org/onap/vnf/vlb/ModuleConfiguration.java b/vnfs/vLBMS/apis/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-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,
+ * either loaded from property file vlb-business-vnf-onap-plugin.json from classpath. + *

+ * 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-impl/src/main/java/org/onap/vnf/vlb/write/DnsInstanceManager.java b/vnfs/vLBMS/apis/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-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 dnsInstances = new HashMap(); + + /* + * 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-impl/src/main/java/org/onap/vnf/vlb/write/ElementCustomizer.java b/vnfs/vLBMS/apis/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-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 { + + private final CrudService crudService; + private DnsInstanceManager dnsInstanceManager; + private static final Logger LOG = LoggerFactory.getLogger(ElementCustomizer.class); + + public ElementCustomizer(@Nonnull final CrudService crudService) { + this.crudService = crudService; + dnsInstanceManager = new DnsInstanceManager(); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier 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 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 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-impl/src/main/java/org/onap/vnf/vlb/write/ModuleWriterFactory.java b/vnfs/vLBMS/apis/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-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 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 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))); + } +} diff --git a/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/asciidoc/Readme.adoc b/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/asciidoc/Readme.adoc new file mode 100644 index 00000000..0a6c66d4 --- /dev/null +++ b/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += vlb-vnf-onap-distribution + +Overview of vlb-vnf-onap-distribution \ No newline at end of file diff --git a/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/pom.xml b/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/pom.xml new file mode 100644 index 00000000..b70c2594 --- /dev/null +++ b/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/pom.xml @@ -0,0 +1,103 @@ + + + + + io.fd.honeycomb.common + minimal-distribution-parent + 1.17.07 + + + 4.0.0 + org.onap.vnf.vlb + vlb-vnf-onap-distribution + 1.2.0-SNAPSHOT + + + -Xms128m -Xmx128m + io.fd.honeycomb.infra.distro.Main + 1.17.07 + 1.17.07 + + + org.onap.vnf.vlb.Module + + + + + + + maven-compiler-plugin + + + org.codehaus.gmaven + groovy-maven-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.maven.plugins + maven-dependency-plugin + + + maven-assembly-plugin + + + org.apache.maven.plugins + maven-deploy-plugin + + false + + + + org.apache.maven.plugins + maven-install-plugin + + false + + + + org.codehaus.mojo + exec-maven-plugin + + + none + + + + true + + + + maven-checkstyle-plugin + + true + + + + + + + + + org.onap.vnf.vlb + vlb-business-vnf-onap-plugin-impl + ${interfaces.mapping.version} + + + + io.fd.honeycomb + minimal-distribution + ${honeycomb.min.distro.version} + + + +