diff options
71 files changed, 4539 insertions, 67 deletions
@@ -1,4 +1,3 @@ ---- project: 'dcaegen2-services' project_creation_date: '2017-05-17' project_category: '' @@ -26,7 +25,7 @@ meetings: server: 'n/a' channel: 'n/a' repeats: 'weekly' - time: '13:00-14:00 UTC (DST), 15:30-16:30 UTC (post DST)' + time: 'Wednesday, 14.30 UTC' repositories: - 'dcaegen2/services' committers: @@ -36,31 +35,11 @@ committers: company: 'ATT' id: 'wrider' timezone: 'America/New_York' - - name: 'Michael Hwang' - email: 'mhwang@research.att.com' - company: 'ATT' - id: 'researchmike' - timezone: 'America/New_York' - name: 'Tony Hansen' email: 'tony@att.com' company: 'ATT' id: 'TonyLHansen' timezone: 'America/New_York' - - name: 'Yan Yang' - email: 'yangyanyj@chinamobile.com' - company: 'ChinaMobile' - id: 'yangyan' - timezone: 'Asia/Shanghai' - - name: 'Xinhui Li' - email: 'lxinhui@vmware.com' - company: 'VMware' - id: 'xinhuili' - timezone: 'Asia/Shanghai' - - name: 'Jack Lucas' - email: 'jflucas@research.att.com' - company: 'ATT' - id: 'jflucas' - timezone: 'America/New_York' - name: 'Piotr Wielebski' email: 'piotr.wielebski@nokia.com' company: 'Nokia' @@ -76,6 +55,11 @@ committers: company: 'EST' id: 'JoeOLeary' timezone: 'Ireland/UTC' + - name: 'Jack Lucas' + email: 'jflucas@research.att.com' + company: 'ATT' + id: 'jackl' + timezone: 'America/New_York' tsc: approval: 'https://lists.onap.org/pipermail/onap-tsc' changes: @@ -94,3 +78,12 @@ tsc: - type: 'Addition' name: 'Joseph O Leary' link: 'https://lists.onap.org/g/onap-tsc/message/5715' + - type: 'Removal' + name: 'Michael Hwang' + link: 'https://lists.onap.org/g/onap-tsc/message/5859' + - type: 'Removal' + name: 'Yan Yang' + link: 'https://lists.onap.org/g/onap-tsc/message/6814' + - type: 'Removal' + name: 'Xinhui Li' + link: 'https://lists.onap.org/g/onap-tsc/message/6814' diff --git a/components/bbs-event-processor/pom.xml b/components/bbs-event-processor/pom.xml index 7d8c43f0..ff98f43c 100644 --- a/components/bbs-event-processor/pom.xml +++ b/components/bbs-event-processor/pom.xml @@ -12,7 +12,7 @@ <groupId>org.onap.dcaegen2.services.components</groupId> <artifactId>bbs-event-processor</artifactId> - <version>2.0.0-SNAPSHOT</version> + <version>2.0.1-SNAPSHOT</version> <name>dcaegen2-services-bbs-event-processor</name> <description>BBS Re-Registration and CPE Authentication Handler</description> diff --git a/components/bbs-event-processor/version.properties b/components/bbs-event-processor/version.properties index 358e99ce..4b2b9f13 100644 --- a/components/bbs-event-processor/version.properties +++ b/components/bbs-event-processor/version.properties @@ -1,6 +1,6 @@ major=2 minor=0 -patch=0 +patch=1 base_version=${major}.${minor}.${patch} release_version=${base_version} snapshot_version=${base_version}-SNAPSHOT diff --git a/components/datalake-handler/admin/Dockerfile b/components/datalake-handler/admin/Dockerfile index 2e6442ae..6237741a 100644 --- a/components/datalake-handler/admin/Dockerfile +++ b/components/datalake-handler/admin/Dockerfile @@ -18,23 +18,15 @@ RUN groupadd -r datalake && useradd -r -g datalake datalake COPY --from=builder /app/dist/* /usr/share/nginx/html/ COPY --from=builder /app/dl-admin-nginx.conf /etc/nginx/conf.d/default.conf COPY --from=builder /app/nginx.conf /etc/nginx/nginx.conf +COPY --from=builder /app/run.sh /tmp RUN chown -R datalake:datalake /etc/nginx RUN chown -R datalake:datalake /var/cache/nginx +RUN chown -R datalake:datalake /tmp/run.sh +RUN chmod 0744 /tmp/run.sh USER datalake -#CMD echo "domain-needed" >> /etc/dnsmasq.conf && \ -# echo "resolv-file=/etc/resolv.conf" >> /etc/dnsmasq.conf && \ -# echo "expand-hosts" >> /etc/dnsmasq.conf && \ -# echo "listen-address=127.0.0.1" >> /etc/dnsmasq.conf && \ -# service dnsmasq restart && \ -# echo set \$upstreamName http://dl-feeder.`grep search /etc/resolv.conf | awk {'print $2'}`:1680/datalake/v1\$1\$is_args\$args\; > /etc/nginx/upstream.conf && \ -# nginx -g "daemon off;" +CMD ["sh", "-c", "/tmp/run.sh"] -CMD echo resolver `grep nameserver /etc/resolv.conf |awk {'print $2'}` valid=10s\; > /etc/nginx/resolver.conf && \ - echo set \$upstreamName http://dl-feeder.`grep search /etc/resolv.conf | awk {'print $2'}`:1680/datalake/v1\$1\$is_args\$args\; > /etc/nginx/upstream.conf && \ - nginx -g "daemon off;" - -#CMD ["sh", "-c", "tail -f /dev/null"] diff --git a/components/datalake-handler/admin/nginx/nginx.conf b/components/datalake-handler/admin/nginx/nginx.conf index 8613dff5..731935d8 100644 --- a/components/datalake-handler/admin/nginx/nginx.conf +++ b/components/datalake-handler/admin/nginx/nginx.conf @@ -1,8 +1,9 @@ -user nginx; +user datalake; worker_processes 1; -error_log /tmp/error.log warn; pid /tmp/nginx.pid; +error_log stderr warn; +#access_log /dev/stdout http; events { @@ -18,7 +19,7 @@ http { '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; - access_log /tmp/access.log main; + access_log /dev/stdout main; sendfile on; #tcp_nopush on; diff --git a/components/datalake-handler/admin/nginx/run.sh b/components/datalake-handler/admin/nginx/run.sh new file mode 100644 index 00000000..b638807f --- /dev/null +++ b/components/datalake-handler/admin/nginx/run.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo resolver `grep nameserver /etc/resolv.conf |awk {'print $2'}` valid=10s\; > /etc/nginx/resolver.conf +echo set \$upstreamName http://dl-feeder.`grep ^search /etc/resolv.conf | awk {'print $2'}`:1680/datalake/v1\$1\$is_args\$args\; > /etc/nginx/upstream.conf +nginx -g "daemon off;" diff --git a/components/datalake-handler/admin/pom.xml b/components/datalake-handler/admin/pom.xml index ff2044d5..2448b082 100644 --- a/components/datalake-handler/admin/pom.xml +++ b/components/datalake-handler/admin/pom.xml @@ -7,7 +7,7 @@ <parent> <groupId>org.onap.dcaegen2.services.components</groupId> <artifactId>datalake-handler</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> diff --git a/components/datalake-handler/collector/pom.xml b/components/datalake-handler/collector/pom.xml index a9dad993..b18efdec 100644 --- a/components/datalake-handler/collector/pom.xml +++ b/components/datalake-handler/collector/pom.xml @@ -7,7 +7,7 @@ <parent> <groupId>org.onap.dcaegen2.services.components</groupId> <artifactId>datalake-handler</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> diff --git a/components/datalake-handler/des/Dockerfile b/components/datalake-handler/des/Dockerfile new file mode 100644 index 00000000..a5d590a3 --- /dev/null +++ b/components/datalake-handler/des/Dockerfile @@ -0,0 +1,50 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2020 China Mobile. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== +FROM openjdk:11-jre-slim + +MAINTAINER Guobiao Mo <guobiaomo@chinamobile.com> + +EXPOSE 1681 + +RUN groupadd -r datalake && useradd -r -g datalake datalake +RUN mkdir /home/datalake/ + +USER datalake + +WORKDIR /home/datalake + +#add the fat jar +COPY target/${JAR_FILE} /home/datalake/ +COPY src/assembly/run.sh /home/datalake/ + +WORKDIR /home/datalake/db_init +ADD src/assembly/init_db/scripts/db_init . +USER root +RUN chmod 0755 ./* +WORKDIR /home/datalake +COPY src/assembly/init_db/scripts/init_db.sql . +COPY src/assembly/init_db/scripts/init_db_data.sql . + +RUN apt update && \ + apt install -y mariadb-client && \ + apt install -y curl + +USER datalake + +CMD ["sh", "run.sh"] + diff --git a/components/datalake-handler/des/README.md b/components/datalake-handler/des/README.md new file mode 100644 index 00000000..9eb70937 --- /dev/null +++ b/components/datalake-handler/des/README.md @@ -0,0 +1 @@ +DataLake Data Exposure Service provides a framework to expose data in BigData databases via REST API with just configurations. diff --git a/components/datalake-handler/des/pom.xml b/components/datalake-handler/des/pom.xml new file mode 100644 index 00000000..c0346ce9 --- /dev/null +++ b/components/datalake-handler/des/pom.xml @@ -0,0 +1,284 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2020 China Mobile. + ================================================================================ + 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. + + SPDX-License-Identifier: Apache-2.0 + ============LICENSE_END========================================================= +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.dcaegen2.services.components</groupId> + <artifactId>datalake-handler</artifactId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> + <artifactId>des</artifactId> + <packaging>jar</packaging> + <name>DataLake Exposure Service</name> + + <properties> + <swagger.version>2.9.2</swagger.version> + <dockerfile-maven.version>1.4.5</dockerfile-maven.version> + <docker.image.path>onap/org.onap.dcaegen2.services.datalake.exposure.service</docker.image.path> + <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format> + </properties> + + <dependencies> + + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + <version>2.0.6</version> + </dependency> + + <dependency> + <groupId>com.facebook.presto</groupId> + <artifactId>presto-jdbc</artifactId> + <version>0.229</version> + </dependency> + + <dependency> + <groupId>org.apache.hadoop</groupId> + <artifactId>hadoop-client</artifactId> + <version>${hadoop.version}</version> + </dependency> + + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + <version>2.4.1</version> + </dependency> + + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20190722</version> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.5.10</version> + </dependency> + + <dependency> + <groupId>org.apache.kafka</groupId> + <artifactId>kafka-clients</artifactId> + <version>2.3.1</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>${springboot.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + <version>${springboot.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + <version>${springboot.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-couchbase</artifactId> + <version>${springboot.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <version>${springboot.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <version>${springboot.version}</version> + </dependency> + + <dependency> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-high-level-client</artifactId> + <version>${elasticsearchjava.version}</version> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.6</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-yaml</artifactId> + <version>${jackson.version}</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-xml</artifactId> + <version>${jackson.version}</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>${jackson.version}</version> + </dependency> + + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.8.2</version> + </dependency> + + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.10</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>io.druid</groupId> + <artifactId>tranquility-core_2.11</artifactId> + <version>0.8.3</version> + </dependency> + + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity-engine-core</artifactId> + <version>2.1</version> + </dependency> + + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + <version>5.3.7.Final</version> + </dependency> + + <!-- jsr303 validation --> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>2.0.1.Final</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + <version>6.1.0.Final</version> + </dependency> + + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-swagger2</artifactId> + <version>${swagger.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-swagger-ui</artifactId> + <version>${swagger.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.mongodb</groupId> + <artifactId>mongo-java-driver</artifactId> + <version>${mongojava.version}</version> + </dependency> + + <dependency> + <groupId>com.couchbase.mock</groupId> + <artifactId>CouchbaseMock</artifactId> + <version>1.5.22</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> + <artifactId>feeder</artifactId> + </dependency> + + </dependencies> + + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>com.spotify</groupId> + <artifactId>dockerfile-maven-plugin</artifactId> + <version>${dockerfile-maven.version}</version> + <configuration> + <!-- <username>docker</username> <password>docker</password> --> + <!-- repository>repo.treescale.com/moguobiao/datalake-feeder-maven</repository --> + <!-- repository>moguobiao/datalake-feeder-maven-spotify</repository --> + <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <!-- <repository>mizunoami123/dl-feeder</repository> --> + <tag>${project.version}</tag> + <dockerfile>Dockerfile</dockerfile> + <!-- useMavenSettingsForAuth>true</useMavenSettingsForAuth --> + <buildArgs> + <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> + </buildArgs> + </configuration> + <!-- <executions> <execution> <id>build-sl-des-image</id> <phase>package</phase> + <goals> <goal>build</goal> </goals> </execution> <execution> <id>tag-and-push-image-latest</id> + <phase>package</phase> <goals> <goal>tag</goal> <goal>push</goal> </goals> + <configuration> <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <tag>latest</tag> <useMavenSettingsForAuth>true</useMavenSettingsForAuth> + </configuration> </execution> <execution> <id>tag-and-push-image-with-version</id> + <phase>package</phase> <goals> <goal>tag</goal> <goal>push</goal> </goals> + <configuration> <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <tag>${project.version}</tag> <useMavenSettingsForAuth>true</useMavenSettingsForAuth> + </configuration> </execution> <execution> <id>tag-and-push-image-with-version-and-date</id> + <phase>package</phase> <goals> <goal>tag</goal> <goal>push</goal> </goals> + <configuration> <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <tag>${project.version}-${maven.build.timestamp}Z</tag> <useMavenSettingsForAuth>true</useMavenSettingsForAuth> + </configuration> </execution> </executions> --> + <dependencies> + <!-- To make this work on JDK 9+ --> + <dependency> + <groupId>javax.activation</groupId> + <artifactId>javax.activation-api</artifactId> + <version>1.2.0</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> diff --git a/components/datalake-handler/des/src/assembly/init_db/scripts/init_db.sql b/components/datalake-handler/des/src/assembly/init_db/scripts/init_db.sql new file mode 100644 index 00000000..e71093aa --- /dev/null +++ b/components/datalake-handler/des/src/assembly/init_db/scripts/init_db.sql @@ -0,0 +1,143 @@ + +/* +* ============LICENSE_START======================================================= +* ONAP : DATALAKE +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ +drop DATABASE datalake; +create database datalake; +use datalake; +CREATE TABLE `topic_name` ( + `id` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `db_type` ( + `id` varchar(255) NOT NULL, + `default_port` int(11) DEFAULT NULL, + `name` varchar(255) NOT NULL, + `tool` bit(1) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `db` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `database_name` varchar(255) DEFAULT NULL, + `enabled` bit(1) NOT NULL, + `encrypt` bit(1) DEFAULT NULL, + `host` varchar(255) DEFAULT NULL, + `login` varchar(255) DEFAULT NULL, + `name` varchar(255) DEFAULT NULL, + `pass` varchar(255) DEFAULT NULL, + `port` int(11) DEFAULT NULL, + `property1` varchar(255) DEFAULT NULL, + `property2` varchar(255) DEFAULT NULL, + `property3` varchar(255) DEFAULT NULL, + `db_type_id` varchar(255) NOT NULL, + `presto_catalog` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `FK3njadtw43ieph7ftt4kxdhcko` (`db_type_id`), + CONSTRAINT `FK3njadtw43ieph7ftt4kxdhcko` FOREIGN KEY (`db_type_id`) REFERENCES `db_type` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `design_type` ( + `id` varchar(255) NOT NULL, + `name` varchar(255) DEFAULT NULL, + `note` varchar(255) DEFAULT NULL, + `db_type_id` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + KEY `FKm8rkv2qkq01gsmeq1c3y4w02x` (`db_type_id`), + CONSTRAINT `FKm8rkv2qkq01gsmeq1c3y4w02x` FOREIGN KEY (`db_type_id`) REFERENCES `db_type` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `design` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `body` text DEFAULT NULL, + `name` varchar(255) DEFAULT NULL, + `note` varchar(255) DEFAULT NULL, + `submitted` bit(1) DEFAULT NULL, + `design_type_id` varchar(255) NOT NULL, + `topic_name_id` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + KEY `FKo43yi6aputq6kwqqu8eqbspm5` (`design_type_id`), + KEY `FKabb8e74230glxpaiai4aqsr34` (`topic_name_id`), + CONSTRAINT `FKabb8e74230glxpaiai4aqsr34` FOREIGN KEY (`topic_name_id`) REFERENCES `topic_name` (`id`), + CONSTRAINT `FKo43yi6aputq6kwqqu8eqbspm5` FOREIGN KEY (`design_type_id`) REFERENCES `design_type` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `kafka` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `broker_list` varchar(255) NOT NULL, + `consumer_count` int(11) DEFAULT 3, + `enabled` bit(1) NOT NULL, + `excluded_topic` varchar(1023) DEFAULT '__consumer_offsets,__transaction_state', + `group` varchar(255) DEFAULT 'datalake', + `included_topic` varchar(255) DEFAULT NULL, + `login` varchar(255) DEFAULT NULL, + `name` varchar(255) NOT NULL, + `pass` varchar(255) DEFAULT NULL, + `secure` bit(1) DEFAULT b'0', + `security_protocol` varchar(255) DEFAULT NULL, + `timeout_sec` int(11) DEFAULT 10, + `zk` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `topic` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `aggregate_array_path` varchar(255) DEFAULT NULL, + `correlate_cleared_message` bit(1) NOT NULL DEFAULT b'0', + `data_format` varchar(255) DEFAULT NULL, + `enabled` bit(1) NOT NULL, + `flatten_array_path` varchar(255) DEFAULT NULL, + `login` varchar(255) DEFAULT NULL, + `message_id_path` varchar(255) DEFAULT NULL, + `pass` varchar(255) DEFAULT NULL, + `save_raw` bit(1) NOT NULL DEFAULT b'0', + `ttl_day` int(11) DEFAULT NULL, + `topic_name_id` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + KEY `FKj3pldlfaokdhqjfva8n3pkjca` (`topic_name_id`), + CONSTRAINT `FKj3pldlfaokdhqjfva8n3pkjca` FOREIGN KEY (`topic_name_id`) REFERENCES `topic_name` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `map_db_design` ( + `design_id` int(11) NOT NULL, + `db_id` int(11) NOT NULL, + PRIMARY KEY (`design_id`,`db_id`), + KEY `FKhpn49r94k05mancjtn301m2p0` (`db_id`), + CONSTRAINT `FKfli240v96cfjbnmjqc0fvvd57` FOREIGN KEY (`design_id`) REFERENCES `design` (`id`), + CONSTRAINT `FKhpn49r94k05mancjtn301m2p0` FOREIGN KEY (`db_id`) REFERENCES `db` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `map_db_topic` ( + `topic_id` int(11) NOT NULL, + `db_id` int(11) NOT NULL, + PRIMARY KEY (`db_id`,`topic_id`), + KEY `FKq1jon185jnrr7dv1dd8214uw0` (`topic_id`), + CONSTRAINT `FKirro29ojp7jmtqx9m1qxwixcc` FOREIGN KEY (`db_id`) REFERENCES `db` (`id`), + CONSTRAINT `FKq1jon185jnrr7dv1dd8214uw0` FOREIGN KEY (`topic_id`) REFERENCES `topic` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `map_kafka_topic` ( + `kafka_id` int(11) NOT NULL, + `topic_id` int(11) NOT NULL, + PRIMARY KEY (`topic_id`,`kafka_id`), + KEY `FKtdrme4h7rxfh04u2i2wqu23g5` (`kafka_id`), + CONSTRAINT `FK5q7jdxy54au5rcrhwa4a5igqi` FOREIGN KEY (`topic_id`) REFERENCES `topic` (`id`), + CONSTRAINT `FKtdrme4h7rxfh04u2i2wqu23g5` FOREIGN KEY (`kafka_id`) REFERENCES `kafka` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `data_exposure` ( + `id` varchar(255) NOT NULL, + `note` varchar(255) DEFAULT NULL, + `sql_template` varchar(10000) NOT NULL, + `db_id` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `FKf5ps4jxauwawk4ac86t5t6xev` (`db_id`), + CONSTRAINT `FKf5ps4jxauwawk4ac86t5t6xev` FOREIGN KEY (`db_id`) REFERENCES `db` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/components/datalake-handler/des/src/assembly/init_db/scripts/init_db_data.sql b/components/datalake-handler/des/src/assembly/init_db/scripts/init_db_data.sql new file mode 100644 index 00000000..234351fb --- /dev/null +++ b/components/datalake-handler/des/src/assembly/init_db/scripts/init_db_data.sql @@ -0,0 +1,95 @@ + +/* +* ============LICENSE_START======================================================= +* ONAP : DATALAKE +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ +INSERT INTO datalake.kafka( + id + ,name + ,consumer_count + ,enabled + ,`group` + ,broker_list + ,included_topic + ,login + ,pass + ,secure + ,security_protocol + ,timeout_sec + ,zk +) VALUES ( + 1 + ,'main Kafka cluster' -- name - IN varchar(255) + ,3 -- consumer_count - IN int(11) + ,1 -- enabled - IN bit(1) + ,'dlgroup' -- group - IN varchar(255) + ,'message-router-kafka:9092' -- host_port - IN varchar(255) + ,'' -- included_topic - IN varchar(255) + ,'admin' -- login - IN varchar(255) + ,'admin-secret' -- pass - IN varchar(255) + ,0 -- secure - IN bit(1) + ,'SASL_PLAINTEXT' -- security_protocol - IN varchar(255) + ,10 -- timeout_sec - IN int(11) + ,'message-router-zookeeper:2181' -- zk - IN varchar(255) +); +insert into db_type (`id`, `name`, tool) values ('CB', 'Couchbase', false); +insert into db_type (`id`, `name`, tool) values ('ES', 'Elasticsearch', false); +insert into db_type (`id`, `name`, tool,`default_port`) values ('MONGO', 'MongoDB', false, 27017); +insert into db_type (`id`, `name`, tool) values ('DRUID', 'Druid', false); +insert into db_type (`id`, `name`, tool) values ('HDFS', 'HDFS', false); +insert into db_type (`id`, `name`, tool) values ('KIBANA', 'Kibana', true); +insert into db_type (`id`, `name`, tool) values ('SUPERSET', 'Apache Superset', true); +insert into db (id, db_type_id, enabled, encrypt, `name`,`host`,`login`,`pass`,`database_name`) values (1, 'CB', true, true, 'Couchbase 1','dl-couchbase','dl','dl1234','datalake'); +insert into db (id, db_type_id, enabled, encrypt, `name`,`host`) values (2, 'ES', true, true, 'Elasticsearch','dl-es'); +insert into db (id, db_type_id, enabled, encrypt, `name`,`host`,`port`,`database_name`,`presto_catalog`) values (3, 'MONGO', true, true, 'MongoDB 1','dl-mongodb',27017,'datalake','mongodb'); +insert into db (id, db_type_id, enabled, encrypt, `name`,`host`) values (4, 'DRUID', true, true, 'Druid','dl-druid'); +insert into db (id, db_type_id, enabled, encrypt, `name`,`host`,`login`) values (5, 'HDFS', true, true, 'Hadoop Cluster','dl-hdfs','dl'); +insert into db (id, db_type_id, enabled, encrypt, `name`,`host`) values (6, 'KIBANA', true, false, 'Kibana demo','dl-es'); +insert into db (id, db_type_id, enabled, encrypt, `name`,`host`) values (7, 'SUPERSET', true, false, 'Superset demo','dl-druid'); +insert into topic_name (id) values ('_DL_DEFAULT_'); +insert into topic_name (id) values ('unauthenticated.SEC_FAULT_OUTPUT'); +insert into topic_name (id) values ('unauthenticated.VES_MEASUREMENT_OUTPUT'); +insert into topic_name (id) values ('EPC'); +insert into topic_name (id) values ('HW'); +-- in production, default enabled should be off +insert into `topic`(id, `topic_name_id`,`enabled`,`save_raw`,`ttl_day`,`data_format`) values (1, '_DL_DEFAULT_',1,0,3650,'JSON'); +insert into `topic`(id, `topic_name_id`,correlate_cleared_message,`enabled`, message_id_path,`data_format`) +values (2, 'unauthenticated.SEC_FAULT_OUTPUT',1,1,'/event/commonEventHeader/eventName,/event/commonEventHeader/reportingEntityName,/event/faultFields/specificProblem,/event/commonEventHeader/eventId','JSON'); +insert into `topic`(id, `topic_name_id`,`enabled`, aggregate_array_path,flatten_array_path,`data_format`) +values (3, 'unauthenticated.VES_MEASUREMENT_OUTPUT',1, +'/event/measurementsForVfScalingFields/memoryUsageArray,/event/measurementsForVfScalingFields/diskUsageArray,/event/measurementsForVfScalingFields/cpuUsageArray,/event/measurementsForVfScalingFields/vNicPerformanceArray', +'/event/measurementsForVfScalingFields/astriMeasurement/astriDPMeasurementArray/astriInterface', +'JSON'); +insert into `topic`(id, `topic_name_id`,`enabled`, flatten_array_path,`data_format`) +values (4, 'EPC',1, '/event/measurementsForVfScalingFields/astriMeasurement/astriDPMeasurementArray/astriInterface', 'JSON'); +insert into `topic`(id, `topic_name_id`,`enabled`, aggregate_array_path,`data_format`) +values (5, 'HW',1, +'/event/measurementsForVfScalingFields/memoryUsageArray,/event/measurementsForVfScalingFields/diskUsageArray,/event/measurementsForVfScalingFields/cpuUsageArray,/event/measurementsForVfScalingFields/vNicPerformanceArray', +'JSON'); +insert into `map_db_topic`(`db_id`,`topic_id`) select db.id, topic.id from db_type, db, topic where db.db_type_id=db_type.id and db_type.tool=0; +insert into `map_kafka_topic`(`kafka_id`,`topic_id`) select kafka.id, topic.id from kafka, topic; +insert into design_type (id, `name`, `db_type_id`) values ('KIBANA_DB', 'Kibana Dashboard', 'KIBANA'); +insert into design_type (id, `name`, `db_type_id`) values ('KIBANA_SEARCH', 'Kibana Search', 'KIBANA'); +insert into design_type (id, `name`, `db_type_id`) values ('KIBANA_VISUAL', 'Kibana Visualization', 'KIBANA'); +insert into design_type (id, `name`, `db_type_id`) values ('ES_MAPPING', 'Elasticsearch Field Mapping Template', 'ES'); +insert into design_type (id, `name`, `db_type_id`) values ('DRUID_KAFKA_SPEC', 'Druid Kafka Indexing Service Supervisor Spec', 'DRUID'); +insert into design (id, `name`,topic_name_id, `submitted`,`body`, design_type_id) values (1, 'Kibana Dashboard on EPC test1', 'EPC', 0, 'body here', 'KIBANA_DB'); +insert into map_db_design (`design_id`,`db_id` ) values (1, 6); +insert into `data_exposure`(`id`,`note`,`sql_template`,`db_id`) values ('totalBandwidth','KPI bandwidth history','select from_unixtime(commonEventHeader.lastEpochMicrosec/1000) as timeStamp, sum(measurementFields.additionalFields."UPF.N3IncPkt._Dnn"+measurementFields.additionalFields."UPF.N3OgPkt._Dnn") as bandwidth from upf where commonEventHeader.sourceId = ''${id}'' and ( from_unixtime(commonEventHeader.lastEpochMicrosec/1000) between from_iso8601_timestamp( ''${timeStamp}'') - interval ''${hour}'' hour and from_iso8601_timestamp( ''${timeStamp}'') ) group by commonEventHeader.lastEpochMicrosec order by commonEventHeader.lastEpochMicrosec desc ',3); +insert into `data_exposure`(`id`,`note`,`sql_template`,`db_id`) values ('totalTraffic','KPI sum over history','select commonEventHeader.sourceId as id, sum(measurementFields.additionalFields."UPF.N3IncPkt._Dnn"+measurementFields.additionalFields."UPF.N3OgPkt._Dnn") as totalTraffic from upf where commonEventHeader.sourceId = ''${id}'' and from_unixtime(commonEventHeader.lastEpochMicrosec/1000) <= from_iso8601_timestamp( ''${timeStamp}'') ',3); +insert into `data_exposure`(`id`,`note`,`sql_template`,`db_id`) values ('userNumber','KPI',' select from_unixtime(commonEventHeader.lastEpochMicrosec/1000) as timeStamp, sum(measurementFields.additionalFields."AMF.RegSub._NS") as userNumber from amf where commonEventHeader.sourceId = ''${id}'' and ( from_unixtime(commonEventHeader.lastEpochMicrosec/1000) between from_iso8601_timestamp( ''${timeStamp}'') - interval ''${hour}'' hour and from_iso8601_timestamp( ''${timeStamp}'') ) group by commonEventHeader.lastEpochMicrosec, commonEventHeader.sourceId order by commonEventHeader.lastEpochMicrosec desc ',3); diff --git a/components/datalake-handler/des/src/assembly/run.sh b/components/datalake-handler/des/src/assembly/run.sh new file mode 100644 index 00000000..363daf6e --- /dev/null +++ b/components/datalake-handler/des/src/assembly/run.sh @@ -0,0 +1,35 @@ +# ============LICENSE_START=================================================== +# Copyright (C) 2020 China Mobile. +# ============================================================================ +# 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END===================================================== +#!/bin/sh + +echo "start init db ..." + +/bin/run-parts /home/datalake/db_init + +echo "finish init db" + +cmd=`find . -regex '\./feeder-[0-9]+\.[0-9]+\.[0-9]+[-SNAPSHOT]+\.jar'` +cmd1=`find . -regex '\./feeder-[0-9]+\.[0-9]+\.[0-9]+\.jar'` +if [ -n "$cmd" ]; then + java -jar $cmd +elif [ -n "$cmd1" ]; then + java -jar $cmd1 +else + echo "STRING is empty" + sleep 10000 +fi diff --git a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/DesApplication.java b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/DesApplication.java new file mode 100644 index 00000000..afb0fef9 --- /dev/null +++ b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/DesApplication.java @@ -0,0 +1,43 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : Data Extraction Service +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ + +package org.onap.datalake.des; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * Entry point of the Data Extraction Service application + * + * @author Kai Lu + * + */ + +@SpringBootApplication +@EnableSwagger2 +public class DesApplication { + + public static void main(String[] args) { + SpringApplication.run(DesApplication.class, args); + } + +} diff --git a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/SwaggerConfig.java b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/SwaggerConfig.java new file mode 100644 index 00000000..79022e50 --- /dev/null +++ b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/SwaggerConfig.java @@ -0,0 +1,67 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : Data Extraction Service +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ + +package org.onap.datalake.des; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * For Swagger integration + * + * @author Kai Lu + * + */ + +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + + /** + * produceApi. + * + * @return Docket Docket + * + */ + @Bean + public Docket produceApi() { + return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() + .apis(RequestHandlerSelectors.basePackage("org.onap.datalake.des")).paths(PathSelectors.any()).build(); + } + + /** + * Api description. + * + * @return ApiInfo api Info + * + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder().title("DataLake Rest APIs") + .description("This page lists all the rest apis for DataLake.").version("1.0.0-SNAPSHOT").build(); + } +} diff --git a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/controller/DataExposureController.java b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/controller/DataExposureController.java new file mode 100644 index 00000000..e71ba6b0 --- /dev/null +++ b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/controller/DataExposureController.java @@ -0,0 +1,280 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : Data Extraction Service +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ + +package org.onap.datalake.des.controller; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.text.StringSubstitutor; +import org.onap.datalake.des.domain.DataExposure; +import org.onap.datalake.des.dto.DataExposureConfig; +import org.onap.datalake.des.repository.DataExposureRepository; +import org.onap.datalake.des.service.DataExposureService; +import org.onap.datalake.feeder.controller.domain.PostReturnBody; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + +/** + * Data Exposure WS. + * + * @author Kai Lu + * + */ +@RestController +@RequestMapping(value = "/exposure", produces = { MediaType.APPLICATION_JSON_VALUE }) +@Api(value = "/exposure", consumes = "application/json", produces = "application/json") +public class DataExposureController { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + @Autowired + private DataExposureService dataExposureService; + @Autowired + private DataExposureRepository dataExposureRepository; + + /** + * serve API. + * + * @param serviceId serviceId + * @param requestMap requestMap + * @param bindingResult bindingResult + * @param response response + * @return message that application is started + * @throws IOException + * @throws SQLException + * + */ + @PostMapping("/{serviceId}") + @ResponseBody + @ApiOperation(value = "Datalake Data Exposure Service.") + public HashMap<String, Object> serve(@PathVariable String serviceId, @RequestBody Map<String, String> requestMap, + BindingResult bindingResult, HttpServletResponse response) throws IOException, SQLException { + log.info("Going to start Datalake Data Exposure Service ... requestMap=" + requestMap); + HashMap<String, Object> ret = new HashMap<>(); + ret.put("request", requestMap); + DataExposure dataExposure = dataExposureService.getDataExposure(serviceId); + String sqlTemplate = dataExposure.getSqlTemplate(); + StringSubstitutor sub = new StringSubstitutor(requestMap); + String query = sub.replace(sqlTemplate); + log.info("Going to start Datalake Data Exposure Service ... query=" + query); + // https://prestodb.io/docs/current/installation/jdbc.html + String url = String.format("jdbc:presto://dl-presto:8080/%s/%s", dataExposure.getDb().getPrestoCatalog(), + dataExposure.getDb().getDatabase()); + Properties properties = new Properties(); + properties.setProperty("user", "test"); + // properties.setProperty("password", "secret"); + // properties.setProperty("SSL", "true"); + Connection connection = DriverManager.getConnection(url, properties); + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery(query); + ResultSetMetaData meta = rs.getMetaData(); + int columnCount = meta.getColumnCount(); + ArrayList<HashMap<String, Object>> result = new ArrayList<>(); + int count = 0; + while (rs.next()) { + HashMap<String, Object> entry = new HashMap<>(); + for (int i = 1; i <= columnCount; i++) { + String label = meta.getColumnLabel(i); + Object value = rs.getObject(i); + entry.put(label, value); + log.info(label + "\t" + value); + } + result.add(entry); + count++; + } + ret.put("result", result); + ret.put("result_count", count); + return ret; + } + + /** + * queryAllDataExposure API. + * + * @return data exposure config list + * + */ + @GetMapping("") + @ResponseBody + @ApiOperation(value = "Datalake Data Exposure list") + public List<DataExposureConfig> queryAllDataExposure() { + return dataExposureService.queryAllDataExposure(); + } + + /** + * query API. + * + * @param id id + * @param response HttpServletResponse + * @return DataExposureConfig + * @throws IOException + * + */ + @GetMapping("/{id}") + @ResponseBody + @ApiOperation(value = "Get Detail of DataExposure") + public DataExposureConfig queryAllDataExposure(@PathVariable String id, HttpServletResponse response) + throws IOException { + log.info("Get Detail of DataExposure Starting....."); + DataExposure oldDataExposure = dataExposureService.getDataExposureById(id); + if (oldDataExposure == null) { + sendError(response, 400, "DataExposure not found, ID: " + id); + return null; + } else { + log.info("ResponseBody......" + oldDataExposure.getDataExposureConfig()); + return oldDataExposure.getDataExposureConfig(); + } + } + + /** + * delete Kfaka API. + * + * @param id id + * @param response HttpServletResponse + * @throws IOException + * + */ + @DeleteMapping("/{id}") + @ResponseBody + @ApiOperation(value = "delete a dataExposure.") + public void deleteKafka(@PathVariable String id, HttpServletResponse response) throws IOException { + DataExposure oldDataExposure = dataExposureService.getDataExposureById(id); + if (oldDataExposure == null) { + sendError(response, 400, "DataExposure not found, ID: " + id); + } else { + dataExposureRepository.delete(oldDataExposure); + response.setStatus(204); + } + } + + /** + * Create a DataExposure. + * + * @param dataExposureConfig dataExposureConfig + * @param result BindingResult + * @param response HttpServletResponse + * @return DataExposureConfig + * @throws IOException + * + */ + @PostMapping("") + @ResponseBody + @ApiOperation(value = "Create a DataExposure.") + public PostReturnBody<DataExposureConfig> createDataExposure(@RequestBody DataExposureConfig dataExposureConfig, + BindingResult result, HttpServletResponse response) throws IOException { + if (result.hasErrors()) { + sendError(response, 400, "Error parsing DataExposureConfig : " + result.toString()); + return null; + } + DataExposure oldDataExposure = dataExposureService.getDataExposureById(dataExposureConfig.getId()); + if (oldDataExposure != null) { + sendError(response, 400, "DataExposure is exist " + dataExposureConfig.getId()); + return null; + } else { + DataExposure dataExposure = null; + try { + dataExposure = dataExposureService.fillDataExposureConfiguration(dataExposureConfig); + } catch (Exception e) { + log.debug("FillDataExposureConfiguration failed", e.getMessage()); + sendError(response, 400, "Error FillDataExposureConfiguration: " + e.getMessage()); + return null; + } + dataExposureRepository.save(dataExposure); + log.info("Kafka save successed"); + return mkPostReturnBody(200, dataExposure); + } + } + + /** + * Update a DataExposure. + * + * @param dataExposureConfig dataExposureConfig + * @param result BindingResult + * @param id id + * @param response HttpServletResponse + * @return DataExposureConfig + * @throws IOException + * + */ + @PutMapping("/{id}") + @ResponseBody + @ApiOperation(value = "Update a DataExposure.") + public PostReturnBody<DataExposureConfig> updateDataExposure(@RequestBody DataExposureConfig dataExposureConfig, + BindingResult result, @PathVariable String id, HttpServletResponse response) throws IOException { + if (result.hasErrors()) { + sendError(response, 400, "Error parsing DataExposureConfig : " + result.toString()); + return null; + } + DataExposure oldDataExposure = dataExposureService.getDataExposureById(id); + if (oldDataExposure == null) { + sendError(response, 400, "DataExposure not found: " + id); + return null; + } else { + try { + dataExposureService.fillDataExposureConfiguration(dataExposureConfig, oldDataExposure); + } catch (Exception e) { + log.debug("FillDataExposureConfiguration failed", e.getMessage()); + sendError(response, 400, "Error FillDataExposureConfiguration: " + e.getMessage()); + return null; + } + dataExposureRepository.save(oldDataExposure); + log.info("DataExposure update successed"); + return mkPostReturnBody(200, oldDataExposure); + } + } + + private PostReturnBody<DataExposureConfig> mkPostReturnBody(int statusCode, DataExposure dataExposure) { + PostReturnBody<DataExposureConfig> retBody = new PostReturnBody<>(); + retBody.setStatusCode(statusCode); + retBody.setReturnBody(dataExposure.getDataExposureConfig()); + return retBody; + } + + private void sendError(HttpServletResponse response, int sc, String msg) throws IOException { + log.info(msg); + response.sendError(sc, msg); + } +} diff --git a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/domain/DataExposure.java b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/domain/DataExposure.java new file mode 100644 index 00000000..c1347022 --- /dev/null +++ b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/domain/DataExposure.java @@ -0,0 +1,76 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : Data Extraction Service +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ + +package org.onap.datalake.des.domain; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import lombok.Getter; +import lombok.Setter; +import javax.persistence.*; + +import org.onap.datalake.des.dto.DataExposureConfig; +import org.onap.datalake.feeder.domain.Db; + +/** + * Domain class representing DataExposure + * + * @author Kai Lu + */ +@Getter +@Setter +@Entity +@Table(name = "data_exposure") +public class DataExposure { + + @Id + @Column(name = "`id`") + private String id; + @Column(name = "`sql_template`", nullable = false) + private String sqlTemplate; + @Column(name = "`note`") + private String note; + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "db_id", nullable = false) + @JsonBackReference + private Db db; + + public DataExposure() { + } + + public DataExposure(String id, String sqlTemplate) { + this.id = id; + this.sqlTemplate = sqlTemplate; + } + + /** + * getDataExposureConfig. + * + * @return data exposure config + * + */ + public DataExposureConfig getDataExposureConfig() { + DataExposureConfig dataExposureConfig = new DataExposureConfig(); + dataExposureConfig.setId(getId()); + dataExposureConfig.setSqlTemplate(getSqlTemplate()); + dataExposureConfig.setNote(getNote()); + dataExposureConfig.setDbId(getDb().getId()); + return dataExposureConfig; + } +} diff --git a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/dto/DataExposureConfig.java b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/dto/DataExposureConfig.java new file mode 100644 index 00000000..86124f77 --- /dev/null +++ b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/dto/DataExposureConfig.java @@ -0,0 +1,36 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : Data Extraction Service +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ + +package org.onap.datalake.des.dto; +import lombok.Getter; +import lombok.Setter; +/** + * SON request body for DataExposure manipulation. + * + * @author Kai Lu + */ +@Getter +@Setter +public class DataExposureConfig { + private String id; + private String note; + private String sqlTemplate; + private Integer dbId; +} diff --git a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/repository/DataExposureRepository.java b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/repository/DataExposureRepository.java new file mode 100644 index 00000000..b77e5d29 --- /dev/null +++ b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/repository/DataExposureRepository.java @@ -0,0 +1,36 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : Data Extraction Service +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ + +package org.onap.datalake.des.repository; + +import org.onap.datalake.des.domain.DataExposure; +import org.springframework.data.repository.CrudRepository; + +/** + * + * DataExposure Repository + * + * @author Kai Lu + * + */ + +public interface DataExposureRepository extends CrudRepository<DataExposure, String> { + +} diff --git a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java new file mode 100644 index 00000000..c7d642b5 --- /dev/null +++ b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java @@ -0,0 +1,131 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : Data Extraction Service +* ================================================================================ +* Copyright 2020 China Mobile +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ + +package org.onap.datalake.des.service; + +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.onap.datalake.des.domain.DataExposure; +import org.onap.datalake.des.dto.DataExposureConfig; +import org.onap.datalake.des.repository.DataExposureRepository; +import org.onap.datalake.feeder.domain.Db; +import org.onap.datalake.feeder.repository.DbRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Service for DataExposure + * + * @author Kai Lu + * + */ +@Service +public class DataExposureService { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + @Autowired + private DataExposureRepository dataExposureRepository; + @Autowired + private DbRepository dbRepository; + + /** + * getDataExposure. + * + * @param serviceId serviceId + * + * @return DataExposure + * + */ + public DataExposure getDataExposure(String serviceId) { + Optional<DataExposure> ret = dataExposureRepository.findById(serviceId); + return ret.isPresent() ? ret.get() : null; + } + + public List<DataExposureConfig> queryAllDataExposure() { + List<DataExposure> dataExposureList = null; + List<DataExposureConfig> dataExposureConfigList = new ArrayList<>(); + dataExposureList = (List<DataExposure>) dataExposureRepository.findAll(); + if (!dataExposureList.isEmpty()) { + log.info("DataExposureList is not null"); + for (DataExposure dataExposure : dataExposureList) { + dataExposureConfigList.add(dataExposure.getDataExposureConfig()); + } + } + return dataExposureConfigList; + } + + /** + * getDataExposureById. + * + * @param id id + * + * @return data exposure + * + */ + public DataExposure getDataExposureById(String id) { + Optional<DataExposure> ret = dataExposureRepository.findById(id); + return ret.isPresent() ? ret.get() : null; + } + + /** + * fillDataExposureConfiguration. + * + * @param dataExposureConfig DataExposureConfig + * + * @return data exposure + * + */ + public DataExposure fillDataExposureConfiguration(DataExposureConfig dataExposureConfig) { + DataExposure dataExposure = new DataExposure(); + fillDataExposure(dataExposureConfig, dataExposure); + return dataExposure; + } + + /** + * fillDataExposureConfiguration. + * + * @param dataExposureConfig DataExposureConfig + * @param dataExposure DataExposure + * + * @return data exposure + * + */ + public void fillDataExposureConfiguration(DataExposureConfig dataExposureConfig, DataExposure dataExposure) { + fillDataExposure(dataExposureConfig, dataExposure); + } + + private void fillDataExposure(DataExposureConfig dataExposureConfig, DataExposure dataExposure) + throws IllegalArgumentException { + dataExposure.setId(dataExposureConfig.getId()); + dataExposure.setNote(dataExposureConfig.getNote()); + dataExposure.setSqlTemplate(dataExposureConfig.getSqlTemplate()); + if (dataExposureConfig.getDbId() == null) + throw new IllegalArgumentException("Can not find db_id in db, db_id: " + dataExposureConfig.getDbId()); + Optional<Db> dbOptional = dbRepository.findById(dataExposureConfig.getDbId()); + if (!dbOptional.isPresent()) + throw new IllegalArgumentException("db_id is null " + dataExposureConfig.getDbId()); + dataExposure.setDb(dbOptional.get()); + } +} diff --git a/components/datalake-handler/des/src/main/resources/application.properties b/components/datalake-handler/des/src/main/resources/application.properties new file mode 100644 index 00000000..c0997e78 --- /dev/null +++ b/components/datalake-handler/des/src/main/resources/application.properties @@ -0,0 +1,73 @@ +#####################App general +server.port = 16810 +server.servlet.context-path = /datalake/v1 + +#tolerate inconsistency when system crash, see PullThread.run() +async=true + +#SSL global flag, if enabled, still need to check each individual DB SSL flag +enableSSL=false + +#names for extra fields that DL adds to each record +timestampLabel=datalake_ts_ +rawDataLabel=datalake_text_ + +defaultTopicName=_DL_DEFAULT_ + +#####################Spring connection to MariaDB for ORM +#spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=none +spring.jpa.show-sql=false + +#spring.datasource.driver-class-name=com.mysql.jdbc.Driver +spring.datasource.url=jdbc:mariadb://mariadb-galera:3306/datalake?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8 +spring.datasource.username=dl +spring.datasource.password=dl1234 + + +#####################DMaaP +dmaapZookeeperHostPort=message-router-zookeeper:2181 +dmaapKafkaHostPort=message-router-kafka:9092 +dmaapKafkaGroup=dlgroup44 +#dmaapKafkaLogin=admin +#dmaapKafkaPass=admin-secret +#dmaapKafkaSecurityProtocol=SASL_PLAINTEXT + +#in second +dmaapKafkaTimeout=10 +dmaapKafkaExclude[0]=__consumer_offsets +dmaapKafkaExclude[1]=__transaction_state +#dmaapKafkaExclude[2]=msgrtr.apinode.metrics.dmaap +#check for new topics , in millisecond +dmaapCheckNewTopicInterval=10000 + +kafkaConsumerCount=3 + +#####################Elasticsearch +elasticsearchType=doc + +#####################HDFS +hdfsBufferSize=4096 +#how often we flush stall updates, in millisecond +hdfsFlushInterval=30000 +hdfsBatchSize=500 + +#####################Logging +logging.level.org.springframework.web=ERROR +logging.level.com.att.nsa.apiClient.http=ERROR +logging.level.org.onap.datalake=DEBUG + +#####################Verison +datalakeVersion=0.0.1 + +#####################KibanaDashboardImportApi +kibanaDashboardImportApi=/api/kibana/dashboards/import?exclude=index-pattern + +#####################KibanaPort +kibanaPort=5601 + +#####################Elasticsearch Template API +esTemplateMappingApi=/_template/ + +#####################Elasticsearch port +esPort=9200 diff --git a/components/datalake-handler/des/src/main/resources/logback.xml b/components/datalake-handler/des/src/main/resources/logback.xml new file mode 100644 index 00000000..436f4f03 --- /dev/null +++ b/components/datalake-handler/des/src/main/resources/logback.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> +<!-- https://logback.qos.ch/manual/layouts.html --> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <layout class="ch.qos.logback.classic.PatternLayout"> + <Pattern> + %date |%-5level| [%20.20thread] %-40(%logger:%line) - %msg%n%ex{full} + </Pattern> + </layout> + </appender> + + <logger name="org.onap.datalake" level="debug" + additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <root level="error"> + <appender-ref ref="STDOUT" /> + </root> +</configuration>
\ No newline at end of file diff --git a/components/datalake-handler/des/src/main/resources/swagger.json b/components/datalake-handler/des/src/main/resources/swagger.json new file mode 100644 index 00000000..017f04f8 --- /dev/null +++ b/components/datalake-handler/des/src/main/resources/swagger.json @@ -0,0 +1,67 @@ +{ + "swagger": "2.0", + "info": { + "description": "This page lists all the rest apis for DataLake.", + "version": "1.2.0-SNAPSHOT", + "title": "DataLake Exposure Service Rest APIs" + }, + "host": "r-node-1:31157/datalake/v1/", + "basePath": "/", + "tags": [{ + "name": "des-controller", + "description": "DES Controller" + }], + "paths": { + "/exposure/{serviceId}": { + "post": { + "tags": ["des-controller"], + "summary": "Datalake Data Exposure Service.", + "operationId": "serveUsingPOST", + "consumes": ["application/json"], + "produces": ["application/json"], + "parameters": [{ + "in": "body", + "name": "requestMap", + "description": "requestMap", + "required": true, + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, { + "name": "serviceId", + "in": "path", + "description": "serviceId", + "required": true, + "type": "string" + }], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + }, + "201": { + "description": "Created" + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + }, + "404": { + "description": "Not Found" + } + }, + "deprecated": false + } + } + } +}
\ No newline at end of file diff --git a/components/datalake-handler/feeder/Dockerfile b/components/datalake-handler/feeder/Dockerfile index b34834be..1a853986 100644 --- a/components/datalake-handler/feeder/Dockerfile +++ b/components/datalake-handler/feeder/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:8-jre-slim +FROM openjdk:11-jre-slim MAINTAINER Guobiao Mo <guobiaomo@chinamobile.com> diff --git a/components/datalake-handler/feeder/pom.xml b/components/datalake-handler/feeder/pom.xml index 5954b378..468ac674 100644 --- a/components/datalake-handler/feeder/pom.xml +++ b/components/datalake-handler/feeder/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.onap.dcaegen2.services.components</groupId> <artifactId>datalake-handler</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> diff --git a/components/datalake-handler/feeder/src/assembly/run.sh b/components/datalake-handler/feeder/src/assembly/run.sh index be401f8a..01e339af 100644 --- a/components/datalake-handler/feeder/src/assembly/run.sh +++ b/components/datalake-handler/feeder/src/assembly/run.sh @@ -12,7 +12,4 @@ if [ -n "$cmd" ]; then java -jar $cmd elif [ -n "$cmd1" ]; then java -jar $cmd1 -else - echo "STRING is empty" - sleep 10000 fi diff --git a/components/datalake-handler/pom.xml b/components/datalake-handler/pom.xml index fc4922ca..bf709828 100644 --- a/components/datalake-handler/pom.xml +++ b/components/datalake-handler/pom.xml @@ -12,7 +12,7 @@ <groupId>org.onap.dcaegen2.services.components</groupId> <artifactId>datalake-handler</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <packaging>pom</packaging> <name>dcaegen2-service-datalake-handler</name> @@ -26,7 +26,7 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <java.version>1.8</java.version> + <java.version>11</java.version> <mongojava.version>3.10.1</mongojava.version> <springboot.version>2.1.0.RELEASE</springboot.version> diff --git a/components/pm-subscription-handler/Dockerfile b/components/pm-subscription-handler/Dockerfile index 566b2ab9..a30c3484 100644 --- a/components/pm-subscription-handler/Dockerfile +++ b/components/pm-subscription-handler/Dockerfile @@ -1,5 +1,6 @@ # ============LICENSE_START=================================================== # Copyright (C) 2020 Nordix Foundation. +# Copyright 2020 Deutsche Telekom. 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. @@ -16,28 +17,27 @@ # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END===================================================== -FROM python:3.7-slim-buster +FROM python:3.8.2-alpine3.11 MAINTAINER lego@est.tech -ENV PMSHUSER=pmsh \ - APPDIR="/opt/app/pmsh" \ - # set PATH & PYTHONPATH vars - PATH=/usr/local/lib/python3.7/bin:$PATH:$APPDIR/bin \ - PYTHONPATH=/usr/local/lib/python3.7/site-packages:./mod:./:$PYTHONPATH:$APPDIR/bin \ +ARG user=onap +ARG group=onap + +WORKDIR /app + +# set PATH & PYTHONPATH vars +ENV PATH=/usr/local/lib/python3.8/bin:$PATH:./bin \ + PYTHONPATH=/usr/local/lib/python3.8/site-packages:./mod:./:$PYTHONPATH:./bin \ REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \ LOGS_PATH="/var/log/ONAP/dcaegen2/services/pmsh" \ LOGGER_CONFIG=/opt/app/pmsh/log_config.yaml -WORKDIR $APPDIR - # add non root user & group -RUN addgroup --system $PMSHUSER && adduser --ingroup $PMSHUSER --system $PMSHUSER && \ +RUN addgroup --system $user && adduser --ingroup $user --system $user && \ # create and chown the LOGS_PATH - apt-get update && \ - apt-get install -y --no-install-recommends vim-tiny && \ - apt-get clean && rm -rf /var/lib/apt/lists/* && \ + apk add build-base libffi-dev postgresql-dev && \ mkdir -p $LOGS_PATH && \ - chown -R $PMSHUSER:$PMSHUSER $LOGS_PATH + chown -R $user:$group $LOGS_PATH COPY setup.py ./ COPY requirements.txt ./ @@ -49,11 +49,8 @@ RUN pip install --upgrade pip && \ pip install -r requirements.txt && \ pip install -e . && \ # change own & perms on entrypoint - chown -R $PMSHUSER:$PMSHUSER $APPDIR && \ - chmod 500 $APPDIR/bin/*.py - -# set to non root user -USER $PMSHUSER + chown -R $user:$group . && \ + chmod 500 ./bin/*.py # run the app ENTRYPOINT ["python", "./bin/pmsh_service_main.py"]
\ No newline at end of file diff --git a/components/pm-subscription-handler/tox.ini b/components/pm-subscription-handler/tox.ini index 5ba25d5b..1136f5a3 100644 --- a/components/pm-subscription-handler/tox.ini +++ b/components/pm-subscription-handler/tox.ini @@ -17,7 +17,7 @@ # ============LICENSE_END========================================================= [tox] -envlist = py36,py37,flake8 +envlist = py36,py37,flake8,py38 skip_missing_interpreters = true [testenv] diff --git a/components/slice-analysis-ms/.checkstyle b/components/slice-analysis-ms/.checkstyle new file mode 100644 index 00000000..97b553d8 --- /dev/null +++ b/components/slice-analysis-ms/.checkstyle @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false"> + <local-check-config name="maven-checkstyle-plugin onap-license" location="jar:file:/home/reshma/.m2/repository/org/onap/oparent/checkstyle/2.0.0/checkstyle-2.0.0.jar!/onap-checkstyle/check-license.xml" type="remote" description="maven-checkstyle-plugin configuration onap-license"> + <property name="checkstyle.header.file" value="/home/reshma/eclipse-workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/slice-analysis-ms/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-onap-license.txt"/> + <property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/> + </local-check-config> + <local-check-config name="maven-checkstyle-plugin onap-java-style" location="jar:file:/home/reshma/.m2/repository/org/onap/oparent/checkstyle/2.0.0/checkstyle-2.0.0.jar!/onap-checkstyle/onap-java-style.xml" type="remote" description="maven-checkstyle-plugin configuration onap-java-style"> + <property name="checkstyle.header.file" value="/home/reshma/eclipse-workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/slice-analysis-ms/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-onap-java-style.txt"/> + <property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/> + </local-check-config> + <fileset name="java-sources-onap-license" enabled="true" check-config-name="maven-checkstyle-plugin onap-license" local="true"> + <file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/test/java/.*\/.*\.java" include-pattern="true"/> + </fileset> + <fileset name="java-sources-onap-java-style" enabled="true" check-config-name="maven-checkstyle-plugin onap-java-style" local="true"> + <file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/test/java/.*\/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/main/resources/.*\.properties" include-pattern="true"/> + <file-match-pattern match-pattern="^src/test/resources/.*\.properties" include-pattern="true"/> + </fileset> +</fileset-config> diff --git a/components/slice-analysis-ms/.gitignore b/components/slice-analysis-ms/.gitignore new file mode 100644 index 00000000..a325eaff --- /dev/null +++ b/components/slice-analysis-ms/.gitignore @@ -0,0 +1,35 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +.mvn/ +**/src/main/**/target/ +**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ +/bin/ diff --git a/components/slice-analysis-ms/LICENSE.txt b/components/slice-analysis-ms/LICENSE.txt new file mode 100644 index 00000000..b91e6533 --- /dev/null +++ b/components/slice-analysis-ms/LICENSE.txt @@ -0,0 +1,36 @@ +/* +* ============LICENSE_START========================================== +* =================================================================== +* Copyright (c) 2020 WIPRO Intellectual Property. All rights reserved. +* =================================================================== +* +* Unless otherwise specified, all software contained herein is licensed +* under the Apache License, Version 2.0 (the "License"); +* you may not use this software 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. +* +* +* +* Unless otherwise specified, all documentation contained herein is licensed +* under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +* you may not use this documentation except in compliance with the License. +* You may obtain a copy of the License at +* +* https://creativecommons.org/licenses/by/4.0/ +* +* Unless required by applicable law or agreed to in writing, documentation +* 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. +* +* ============LICENSE_END============================================ +*/ diff --git a/components/slice-analysis-ms/README.md b/components/slice-analysis-ms/README.md new file mode 100644 index 00000000..c268789f --- /dev/null +++ b/components/slice-analysis-ms/README.md @@ -0,0 +1,39 @@ +SLICE-ANALYSIS-MS + +### Build Instructions + +This project is organized as a mvn project and is a sub-project of dcaegen2/services (inside components directory). The build generate a jar and package into docker container. + +``` +git clone https://gerrit.onap.org/r/dcaegen2/services +To build slice-analysis-ms run `mvn clean install` from **components/slice-analysis-ms** directory +To build docker image run `mvn clean install docker:build` +``` + + +### Environment variables in Docker Container + + +Variables coming from deployment system: + +- APP_NAME - slice-analysis-ms application name that will be registered with consul +- CONSUL_PROTOCOL - Consul protocol by default set to **https**, if it is need to change it then that can be set to different value +- CONSUL_HOST - used with conjunction with CBSPOLLTIMER, should be a host address (without port! e.g my-ip-or-host) where Consul service lies +- CBS_PROTOCOL - Config Binding Service protocol by default set to **https**, if it is need to change it then that can be set to different value +- CONFIG_BINDING_SERVICE - used with conjunction with CBSPOLLTIMER, should be a name of CBS as it is registered in Consul +- HOSTNAME - used with conjunction with CBSPOLLTIMER, should be a name of slice-analysis-ms application as it is registered in CBS catalog + + +### Deployment + + +### Standalone deployment +Slice analysis ms can be deployed standalone using docker-compose. + +Navigate to src/main/docker directory. docker-compose.yaml can be found there. + +To install : + docker-compose up + +To uninstall : + docker-compose down diff --git a/components/slice-analysis-ms/pom.xml b/components/slice-analysis-ms/pom.xml new file mode 100644 index 00000000..f8eb7fa6 --- /dev/null +++ b/components/slice-analysis-ms/pom.xml @@ -0,0 +1,321 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.oparent</groupId> + <artifactId>oparent</artifactId> + <version>2.0.0</version> + </parent> + + <groupId>org.onap.dcaegen2.services.components</groupId> + <artifactId>slice-analysis-ms</artifactId> + <version>1.0.0-SNAPSHOT</version> + <name>dcaegen2-services-slice-analysis-ms</name> + <description>Network slice PM analyser</description> + <packaging>jar</packaging> + + <properties> + <java.version>11</java.version> + <sdk.version>1.1.4</sdk.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> + <docker.image.name>onap/${project.groupId}.${project.artifactId}</docker.image.name> + <!-- NEXUS RELATED SETTINGS --> + <nexusproxy>https://nexus.onap.org</nexusproxy> + <snapshots.path>content/repositories/snapshots/</snapshots.path> + <releases.path>content/repositories/releases/</releases.path> + <site.path>content/sites/site/org/onap/dcaegen2/services/${project.artifactId}/${project.version}</site.path> + <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format> + <sonar.coverage.jacoco.xmlReportPaths> + ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml + </sonar.coverage.jacoco.xmlReportPaths> + + </properties> + + <dependencies> + <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-util --> + <dependency> + <groupId>org.apache.tomcat</groupId> + <artifactId>tomcat-util</artifactId> + <version>9.0.37</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-autoconfigure</artifactId> + <version>2.3.1.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-webmvc</artifactId> + <version>5.2.7.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>5.2.7.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>5.2.7.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + <version>5.2.7.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>5.2.7.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-tx</artifactId> + <version>5.2.7.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework.data</groupId> + <artifactId>spring-data-commons</artifactId> + <version>2.2.0.RELEASE</version> + </dependency> + <!-- cbs client --> + <dependency> + <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> + <artifactId>cbs-client</artifactId> + <version>${sdk.version}</version> + </dependency> + + <dependency> + <groupId>org.onap.dcaegen2.services.sdk.security.crypt</groupId> + <artifactId>crypt-password</artifactId> + <version>${sdk.version}</version> + </dependency> + <dependency> + <!-- Import dependency management from Spring Boot --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-dependencies</artifactId> + <version>2.1.3.RELEASE</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>com.att.nsa</groupId> + <artifactId>cambriaClient</artifactId> + <version>0.0.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + <version>2.11.0</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>2.11.0</version> + </dependency> + <!-- https://mvnrepository.com/artifact/javax.json/javax.json-api --> + <dependency> + <groupId>javax.json</groupId> + <artifactId>javax.json-api</artifactId> + <version>1.1.2</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>2.1.3.RELEASE</version> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>42.2.5</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + <version>2.1.3.RELEASE</version> + </dependency> + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.0-api</artifactId> + <version>1.0.1.Final</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <version>2.1.3.RELEASE</version> + <scope>test</scope> + <!-- exclusions> <exclusion> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> + </exclusion> </exclusions --> + </dependency> + <!-- https://mvnrepository.com/artifact/org.mockito/mockito-core --> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>2.21.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 --> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito2</artifactId> + <version>2.0.2</version> + <exclusions> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4 --> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.functionaljava</groupId> + <artifactId>functionaljava</artifactId> + <version>3.0</version> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.5.7</version> + </dependency> + + <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils --> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.9.4</version> + </dependency> + <!-- mvnrepository.com/artifact/org.eclipse.jetty/jetty-server --> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>9.4.17.v20190418</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.webjars/bootstrap --> + <dependency> + <groupId>org.webjars</groupId> + <artifactId>bootstrap</artifactId> + <version>4.3.1</version> + </dependency> + <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api --> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>2.3.0</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.javassist/javassist --> + <dependency> + <groupId>org.javassist</groupId> + <artifactId>javassist</artifactId> + <version>3.24.1-GA</version> + </dependency> + <dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-core</artifactId> + <version>9.0.36</version> + </dependency> + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>2.3.1.RELEASE</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>com.spotify</groupId> + <artifactId>docker-maven-plugin</artifactId> + <configuration> + <serverId>${onap.nexus.dockerregistry.daily}</serverId> + + <imageName>${onap.nexus.dockerregistry.daily}/${docker.image.name}</imageName> + <imageTags> + <imageTag>${project.version}-${maven.build.timestamp}Z</imageTag> + <imageTag>${project.version}</imageTag> + <imageTag>latest</imageTag> + </imageTags> + <baseImage>openjdk:11.0.6-jre-slim</baseImage> + <user>sliceanalysis</user> + <resources> + <resource> + <targetPath>/bin</targetPath> + <directory>${project.build.directory}</directory> + <include>${project.artifactId}-${project.version}.jar</include> + </resource> + </resources> + <runs> + <!-- Maven is loosing file permissions during artifacts copy --> + <run>adduser --disabled-password sliceanalysis </run> + <run>mv /bin/*.jar /bin/application.jar</run> + <run>chmod -R 777 /bin</run> + </runs> + <exposes> + <expose>8080</expose> + </exposes> + <entryPoint>java -jar /bin/application.jar</entryPoint> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/components/slice-analysis-ms/src/main/docker/config/dmaap/MsgRtrApi.properties b/components/slice-analysis-ms/src/main/docker/config/dmaap/MsgRtrApi.properties new file mode 100755 index 00000000..61f3f033 --- /dev/null +++ b/components/slice-analysis-ms/src/main/docker/config/dmaap/MsgRtrApi.properties @@ -0,0 +1,171 @@ +# LICENSE_START======================================================= +# org.onap.dmaap +# ================================================================================ +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2020 Wipro Limited. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# +############################################################################### +############################################################################### +## +## Cambria API Server config +## +## - Default values are shown as commented settings. +## + +############################################################################### +## +## HTTP service +## +## - 3904 is standard as of 7/29/14. +# +## Zookeeper Connection +## +## Both Cambria and Kafka make use of Zookeeper. +## +#config.zk.servers=172.18.1.1 +config.zk.servers=zookeeper:2181 +#config.zk.root=/fe3c/cambria/config + + +############################################################################### +## +## Kafka Connection +## +## Items below are passed through to Kafka's producer and consumer +## configurations (after removing "kafka.") +## if you want to change request.required.acks it can take this one value +#kafka.metadata.broker.list=localhost:9092,localhost:9093 +kafka.metadata.broker.list=kafka:9092 +##kafka.request.required.acks=-1 +#kafka.client.zookeeper=${config.zk.servers} +consumer.timeout.ms=100 +zookeeper.connection.timeout.ms=6000 +zookeeper.session.timeout.ms=20000 +zookeeper.sync.time.ms=2000 +auto.commit.interval.ms=1000 +fetch.message.max.bytes =1000000 +auto.commit.enable=false + +#(backoff*retries > zksessiontimeout) +kafka.rebalance.backoff.ms=10000 +kafka.rebalance.max.retries=6 + + +############################################################################### +## +## Secured Config +## +## Some data stored in the config system is sensitive -- API keys and secrets, +## for example. to protect it, we use an encryption layer for this section +## of the config. +## +## The key is a base64 encode AES key. This must be created/configured for +## each installation. +#cambria.secureConfig.key= +## +## The initialization vector is a 16 byte value specific to the secured store. +## This must be created/configured for each installation. +#cambria.secureConfig.iv= + +## Southfield Sandbox +cambria.secureConfig.key=b/7ouTn9FfEw2PQwL0ov/Q== +cambria.secureConfig.iv=wR9xP5k5vbz/xD0LmtqQLw== +authentication.adminSecret=fe3cCompound +#cambria.secureConfig.key[pc569h]=YT3XPyxEmKCTLI2NK+Sjbw== +#cambria.secureConfig.iv[pc569h]=rMm2jhR3yVnU+u2V9Ugu3Q== + + +############################################################################### +## +## Consumer Caching +## +## Kafka expects live connections from the consumer to the broker, which +## obviously doesn't work over connectionless HTTP requests. The Cambria +## server proxies HTTP requests into Kafka consumer sessions that are kept +## around for later re-use. Not doing so is costly for setup per request, +## which would substantially impact a high volume consumer's performance. +## +## This complicates Cambria server failover, because we often need server +## A to close its connection before server B brings up the replacement. +## + +## The consumer cache is normally enabled. +#cambria.consumer.cache.enabled=true + +## Cached consumers are cleaned up after a period of disuse. The server inspects +## consumers every sweepFreqSeconds and will clean up any connections that are +## dormant for touchFreqMs. +#cambria.consumer.cache.sweepFreqSeconds=15 +cambria.consumer.cache.touchFreqMs=120000 +##stickforallconsumerrequests=false +## The cache is managed through ZK. The default value for the ZK connection +## string is the same as config.zk.servers. +#cambria.consumer.cache.zkConnect=${config.zk.servers} + +## +## Shared cache information is associated with this node's name. The default +## name is the hostname plus the HTTP service port this host runs on. (The +## hostname is determined via InetAddress.getLocalHost ().getCanonicalHostName(), +## which is not always adequate.) You can set this value explicitly here. +## +#cambria.api.node.identifier=<use-something-unique-to-this-instance> + +#cambria.rateLimit.maxEmptyPollsPerMinute=30 +#cambria.rateLimitActual.delay.ms=10 + +############################################################################### +## +## Metrics Reporting +## +## This server can report its metrics periodically on a topic. +## +#metrics.send.cambria.enabled=true +#metrics.send.cambria.topic=cambria.apinode.metrics #msgrtr.apinode.metrics.dmaap +#metrics.send.cambria.sendEverySeconds=60 + +cambria.consumer.cache.zkBasePath=/fe3c/cambria/consumerCache +consumer.timeout=17 +default.partitions=3 +default.replicas=3 +############################################################################## +#100mb +maxcontentlength=10000 + + +############################################################################## +#AAF Properties +msgRtr.namespace.aaf=org.onap.dmaap.mr.topic +msgRtr.topicfactory.aaf=org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic: +enforced.topic.name.AAF=org.onap +forceAAF=false +transidUEBtopicreqd=false +defaultNSforUEB=org.onap.dmaap.mr +############################################################################## +#Mirror Maker Agent +msgRtr.mirrormakeradmin.aaf=com.onap.dmaap.mr.dev.mirrormaker|*|admin +msgRtr.mirrormakeruser.aaf=com.onap.dmaap.mr.dev.mirrormaker|*|user +msgRtr.mirrormakeruser.aaf.create=com.onap.dmaap.mr.dev.topicFactory|:com.onap.dmaap.mr.dev.topic: +msgRtr.mirrormaker.timeout=15000 +msgRtr.mirrormaker.topic=com.onap.dmaap.mr.prod.mm.agent +msgRtr.mirrormaker.consumergroup=mmagentserver +msgRtr.mirrormaker.consumerid=1 + +kafka.max.poll.interval.ms=300000 +kafka.heartbeat.interval.ms=60000 +kafka.session.timeout.ms=240000 +kafka.max.poll.records=1000 + diff --git a/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json b/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json new file mode 100644 index 00000000..21a82344 --- /dev/null +++ b/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json @@ -0,0 +1,59 @@ +{ + "config": { + "streams_subscribes": { + "performance_management_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.VES_MEASUREMENT_OUTPUT", + "client_role": "sliceanalysis-subscriber", + "location": "onap", + "client_id": "sdnr-sliceanalysis-1" + }, + "aaf_username": null + }, + "dcae_cl_response_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_RSP", + "client_role": "sliceanalysis-subscriber", + "location": "onap", + "client_id": "sdnr-sliceanalysis-1" + }, + "aaf_username": null + } + }, + "streams_publishes": { + "CL_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.DCAE_CL_OUTPUT", + "client_role": "sliceanalysis-subscriber", + "location": "onap", + "client_id": "sdnr-sliceanalysis-1" + }, + "aaf_username": null + } + }, + "postgres.password": "postgres", + "postgres.username": "sliceanalysisms_admin", + "postgres.host": "postgres", + "postgres.port": "5432", + "sliceanalysisms.dmaap.server": [ + "dmaap" + ], + "cbsPollingInterval": 60, + "sliceanalysisms.cg": "sliceanalysisms-cg", + "sliceanalysisms.pollingInterval": 20, + "sliceanalysisms.cid": "sliceanalysisms-cid", + "sliceanalysisms.configDb.service": "http://sdnc.onap:8181", + "service_calls": { + "policy-req": [] + } + }, + "policies": { + + } +} diff --git a/components/slice-analysis-ms/src/main/docker/docker-compose.yaml b/components/slice-analysis-ms/src/main/docker/docker-compose.yaml new file mode 100644 index 00000000..0f503948 --- /dev/null +++ b/components/slice-analysis-ms/src/main/docker/docker-compose.yaml @@ -0,0 +1,91 @@ +# ============LICENSE_START======================================================= +# slice-analysis-ms +# ================================================================================ +# Copyright (C) 2020 Wipro Limited. +# ============================================================================== +# 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. +# ============LICENSE_END========================================================= + +version: '2.4' +networks: + slice-analysis-ms-default: + driver: bridge + driver_opts: + com.docker.network.driver.mtu: 1400 +services: + zookeeper: + image: wurstmeister/zookeeper + ports: + - "2181:2181" + networks: + - slice-analysis-ms-default + kafka: + image: wurstmeister/kafka + ports: + - "9092:9092" + environment: + KAFKA_ADVERTISED_HOST_NAME: "kafka" + KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true' + KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181" + KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka:9092" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + depends_on: + - zookeeper + networks: + - slice-analysis-ms-default + dmaap: + image: nexus3.onap.org:10001/onap/dmaap/dmaap-mr:1.1.8 + ports: + - "3904:3904" + - "3905:3905" + volumes: + - ./config/dmaap/MsgRtrApi.properties:/appl/dmaapMR1/bundleconfig/etc/appprops/MsgRtrApi.properties + depends_on: + - zookeeper + - kafka + networks: + - slice-analysis-ms-default + postgres: + image: 'postgres:12-alpine' + container_name: slice-analysis-ms-postgres + hostname: postgres + environment: + - POSTGRES_USER=sliceanalysisms_admin + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=sliceanalysisms + ports: + - 5432 + healthcheck: + test: ["CMD", "nc", "-z", "localhost", "5432"] + interval: 30s + timeout: 10s + retries: 5 + networks: + - slice-analysis-ms-default + sliceanalysisms: + image: "nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.components.slice-analysis-ms:latest" + container_name: sliceanalysisms + hostname: sliceanalysisms + environment: + - STANDALONE=true + - CONFIG_FILE=/etc/config_all.json + ports: + - "8080:8080" + volumes: + - ./config/sliceanalysisms/config_all.json:/etc/config_all.json + depends_on: + - postgres + networks: + - slice-analysis-ms-default + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java new file mode 100644 index 00000000..f522e008 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java @@ -0,0 +1,139 @@ + +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.lang.reflect.Type; +import java.time.Duration; +import java.util.Map; + +import javax.sql.DataSource; + +import org.onap.slice.analysis.ms.beans.ConfigPolicy; +import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.controller.ConfigFetchFromCbs; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * + * Entry point for the slice analysis service application + * + */ +@EnableScheduling +@SpringBootApplication +public class Application { + + private static Logger log = LoggerFactory.getLogger(Application.class); + + /** + * Main method where initial configuration and context is set + * @param args + */ + public static void main(String[] args) { + getConfig(); + log.info("Starting spring boot application"); + SpringApplication.run(Application.class, args); + } + + private static void getConfig() { + + Boolean standalone = Boolean.parseBoolean(System.getenv("STANDALONE")); + + if (standalone) { + log.info("Running in standalone mode"); + + String configFile = System.getenv("CONFIG_FILE"); + String configAllJson = readFromFile(configFile); + + JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class); + + JsonObject config = configAll.getAsJsonObject("config"); + + Configuration.getInstance().updateConfigurationFromJsonObject(config); + + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + Type mapType = new TypeToken<Map<String, Object>>() { + }.getType(); + if (configAll.getAsJsonObject("policies") != null) { + JsonObject policyJson = configAll.getAsJsonObject("policies").getAsJsonArray("items").get(0) + .getAsJsonObject().getAsJsonObject("config"); + Map<String, Object> policy = new Gson().fromJson(policyJson, mapType); + configPolicy.setConfig(policy); + log.info("Config policy {}", configPolicy); + } + return; + } + + ConfigFetchFromCbs configFetchFromCbs = new ConfigFetchFromCbs(Duration.ofSeconds(60)); + Thread configFetchThread = new Thread(configFetchFromCbs); + configFetchThread.start(); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + log.debug("InterruptedException : {}", e); + Thread.currentThread().interrupt(); + } + log.info("after 10s sleep"); + } + + /** + * DataSource bean. + */ + @Bean + public DataSource dataSource() { + Configuration configuration = Configuration.getInstance(); + + String url = "jdbc:postgresql://" + configuration.getPgHost() + ":" + configuration.getPgPort() + "/sliceanalysisms"; + + return DataSourceBuilder.create().url(url).username(configuration.getPgUsername()) + .password(configuration.getPgPassword()).build(); + } + + private static String readFromFile(String file) { + String content = ""; + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + } catch (Exception e) { + content = null; + } + return content; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/ConfigPolicy.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/ConfigPolicy.java new file mode 100644 index 00000000..d4cd53b8 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/ConfigPolicy.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.beans; + +import java.util.Map; + +/** + * + * Model class for configuration policy + * + */ + +public class ConfigPolicy { + + private static ConfigPolicy instance = null; + private Map<String, Object> config; + + protected ConfigPolicy() { + + } + + /** + * Get instance of class. + */ + public static ConfigPolicy getInstance() { + if (instance == null) { + instance = new ConfigPolicy(); + } + return instance; + } + + /** + * Get config param of ConfigPolicy + */ + public Map<String, Object> getConfig() { + return config; + } + + /** + * set config param of ConfigPolicy + */ + public void setConfig(Map<String, Object> config) { + this.config = config; + } + + /** + * Return ConfigPolicy instance as String + */ + @Override + public String toString() { + return "ConfigPolicy [config=" + config + "]"; + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/Configuration.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/Configuration.java new file mode 100644 index 00000000..c7072343 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/Configuration.java @@ -0,0 +1,242 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.beans; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Model class for the application Configuration + */ +public class Configuration { + private static Logger log = LoggerFactory.getLogger(Configuration.class); + + private static Configuration instance = null; + private String pgHost; + private int pgPort; + private String pgUsername; + private String pgPassword; + private List<String> dmaapServers; + private String configDbService; + private String cg; + private String cid; + private int pollingInterval; + private int pollingTimeout; + private String aafUsername; + private String aafPassword; + private Map<String, Object> streamsSubscribes; + private Map<String, Object> streamsPublishes; + + /** + * Check if topic is secure. + */ + public boolean isSecured() { + return (aafUsername != null); + + } + + public String getAafUsername() { + return aafUsername; + } + + public void setAafUsername(String aafUsername) { + this.aafUsername = aafUsername; + } + + public String getAafPassword() { + return aafPassword; + } + + public void setAafPassword(String aafPassword) { + this.aafPassword = aafPassword; + } + + public Map<String, Object> getStreamsSubscribes() { + return streamsSubscribes; + } + + public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { + this.streamsSubscribes = streamsSubscribes; + } + + public Map<String, Object> getStreamsPublishes() { + return streamsPublishes; + } + + public void setStreamsPublishes(Map<String, Object> streamsPublishes) { + this.streamsPublishes = streamsPublishes; + } + + protected Configuration() { + + } + + /** + * Get instance of class. + */ + public static Configuration getInstance() { + if (instance == null) { + instance = new Configuration(); + } + return instance; + } + + public String getCg() { + return cg; + } + + public void setCg(String cg) { + this.cg = cg; + } + + public String getCid() { + return cid; + } + + public void setCid(String cid) { + this.cid = cid; + } + + public int getPollingInterval() { + return pollingInterval; + } + + public void setPollingInterval(int pollingInterval) { + this.pollingInterval = pollingInterval; + } + + public int getPollingTimeout() { + return pollingTimeout; + } + + public void setPollingTimeout(int pollingTimeout) { + this.pollingTimeout = pollingTimeout; + } + + public String getPgHost() { + return pgHost; + } + + public void setPgHost(String pgHost) { + this.pgHost = pgHost; + } + + public int getPgPort() { + return pgPort; + } + + public void setPgPort(int pgPort) { + this.pgPort = pgPort; + } + + public String getPgUsername() { + return pgUsername; + } + + public void setPgUsername(String pgUsername) { + this.pgUsername = pgUsername; + } + + public String getPgPassword() { + return pgPassword; + } + + public void setPgPassword(String pgPassword) { + this.pgPassword = pgPassword; + } + + public List<String> getDmaapServers() { + return dmaapServers; + } + + public void setDmaapServers(List<String> dmaapServers) { + this.dmaapServers = dmaapServers; + } + + public String getConfigDbService() { + return configDbService; + } + + public void setConfigDbService(String configDbService) { + this.configDbService = configDbService; + } + + + + @Override + public String toString() { + return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword=" + + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService + ", cg=" + cg + + ", cid=" + cid + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword + ", streamsSubscribes=" + + streamsSubscribes + ", streamsPublishes=" + streamsPublishes + "]"; + } + + /** + * updates application configuration. + */ + public void updateConfigurationFromJsonObject(JsonObject jsonObject) { + + log.info("Updating configuration from CBS"); + + Type mapType = new TypeToken<Map<String, Object>>() { + }.getType(); + + JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); + streamsSubscribes = new Gson().fromJson(subscribes, mapType); + + JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); + streamsPublishes = new Gson().fromJson(publishes, mapType); + + pgPort = jsonObject.get("postgres.port").getAsInt(); + pollingInterval = jsonObject.get("sliceanalysisms.pollingInterval").getAsInt(); + pgPassword = jsonObject.get("postgres.password").getAsString(); + pgUsername = jsonObject.get("postgres.username").getAsString(); + pgHost = jsonObject.get("postgres.host").getAsString(); + + JsonArray servers = jsonObject.getAsJsonArray("sliceanalysisms.dmaap.server"); + Type listType = new TypeToken<List<String>>() { + }.getType(); + dmaapServers = new Gson().fromJson(servers, listType); + + cg = jsonObject.get("sliceanalysisms.cg").getAsString(); + cid = jsonObject.get("sliceanalysisms.cid").getAsString(); + configDbService = jsonObject.get("sliceanalysisms.configDb.service").getAsString(); + + pollingTimeout = jsonObject.get("sliceanalysisms.pollingInterval").getAsInt(); + + log.info("configuration from CBS {}", this); + + } + + + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java new file mode 100644 index 00000000..e8e4e11b --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.controller; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import java.lang.reflect.Type; +import java.time.Duration; +import java.util.Map; + +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFactory; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; +import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import org.onap.slice.analysis.ms.beans.ConfigPolicy; +import org.onap.slice.analysis.ms.beans.Configuration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import reactor.core.Disposable; + +/** + * This class provides method to fetch application Configuration + * from CBS + */ +public class ConfigFetchFromCbs implements Runnable { + + private static Logger log = LoggerFactory.getLogger(ConfigFetchFromCbs.class); + + private Duration interval; + + public ConfigFetchFromCbs() { + + } + + public ConfigFetchFromCbs(Duration interval) { + this.interval = interval; + } + + /** + * Gets app config from CBS. + */ + private Disposable getAppConfig() { + + // Generate RequestID and InvocationID which will be used when logging and in + // HTTP requests + log.info("getAppconfig start .."); + RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + // Read necessary properties from the environment + final EnvProperties env = EnvProperties.fromEnvironment(); + log.debug("environments {}", env); + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + + // Polling properties + final Duration initialDelay = Duration.ofSeconds(5); + final Duration period = interval; + + // Create the client and use it to get the configuration + final CbsRequest request = CbsRequests.getAll(diagnosticContext); + return CbsClientFactory.createCbsClient(env) + .flatMapMany(cbsClient -> cbsClient.updates(request, initialDelay, period)).subscribe(jsonObject -> { + log.info("configuration and policy from CBS {}", jsonObject); + JsonObject config = jsonObject.getAsJsonObject("config"); + Duration newPeriod = Duration.ofSeconds(config.get("cbsPollingInterval").getAsInt()); + if (!newPeriod.equals(period)) { + interval = newPeriod; + synchronized (this) { + this.notifyAll(); + } + + } + Configuration.getInstance().updateConfigurationFromJsonObject(config); + + Type mapType = new TypeToken<Map<String, Object>>() { + }.getType(); + if (jsonObject.getAsJsonObject("policies") != null) { + JsonObject policyJson = jsonObject.getAsJsonObject("policies").getAsJsonArray("items").get(0) + .getAsJsonObject().getAsJsonObject("config"); + Map<String, Object> policy = new Gson().fromJson(policyJson, mapType); + configPolicy.setConfig(policy); + log.info("Config policy {}", configPolicy); + } + }, throwable -> log.warn("Ooops", throwable)); + } + + + + @Override + public void run() { + Boolean done = false; + while (!done) { + try { + Disposable disp = getAppConfig(); + synchronized (this) { + this.wait(); + } + log.info("Polling interval changed"); + disp.dispose(); + } catch (Exception e) { + done = true; + } + } + } + +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/HealthCheck.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/HealthCheck.java new file mode 100644 index 00000000..854bdf4f --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/HealthCheck.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * This Controller provides the slice-analysis-ms + * application's health + */ +@RestController +public class HealthCheck { + @RequestMapping(value = "/healthcheck", method = RequestMethod.GET) + public ResponseEntity<HttpStatus> healthCheck() { + return new ResponseEntity<>(HttpStatus.OK); + } +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotifications.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotifications.java new file mode 100644 index 00000000..2fa06d9f --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotifications.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.data.beans; + +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.CreationTimestamp; + +/** + * Entity for PERFORMANCE_NOTIFICATIONS table + */ +@Entity +@Table(name = "PERFORMANCE_NOTIFICATIONS") +public class PerformanceNotifications { + + @Id + @Column(name = "notification", columnDefinition = "text") + private String notification; + + @CreationTimestamp + @Column(name = "created_at", columnDefinition = "timestamp") + private Timestamp createdAt; + + /** + * default constructor + */ + public PerformanceNotifications() { + + } + + /** + * Constructs PerformanceNotifications instance + * @param notification + * @param createdAt + */ + public PerformanceNotifications(String notification, Timestamp createdAt) { + this.notification = notification; + this.createdAt = createdAt; + } + + public String getNotification() { + return notification; + } + + public void setNotification(String notification) { + this.notification = notification; + } + + public Timestamp getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Timestamp createdAt) { + this.createdAt = createdAt; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/data/repository/PerformanceNotificationsRepository.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/data/repository/PerformanceNotificationsRepository.java new file mode 100644 index 00000000..55338c9e --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/data/repository/PerformanceNotificationsRepository.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.data.repository; + +import org.onap.slice.analysis.ms.data.beans.PerformanceNotifications; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +/** + * This interface provides methods to perform CRUD operations + * on performance_notifications table + */ +@Repository +public interface PerformanceNotificationsRepository extends CrudRepository<PerformanceNotifications, String> { + + /** + * read performanceNotifications from db + * @return + */ + @Query(nativeQuery = true, value = "DELETE FROM performance_notifications " + + "WHERE notification = ( SELECT notification FROM performance_notifications ORDER BY " + + "created_at FOR UPDATE SKIP LOCKED LIMIT 1 ) RETURNING notification;") + public String getPerformanceNotificationFromQueue(); + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java new file mode 100644 index 00000000..6e0ea401 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import com.att.nsa.cambria.client.CambriaConsumer; + +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.annotation.PostConstruct; + +import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.utils.DmaapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * This class initializes and starts the dmaap client + * to listen on application required dmaap events + */ +@Component +public class DmaapClient { + + private Configuration configuration; + private static Logger log = LoggerFactory.getLogger(DmaapClient.class); + + private DmaapUtils dmaapUtils; + + /** + * init dmaap client. + */ + @PostConstruct + public void initClient() { + log.debug("initializing client"); + dmaapUtils = new DmaapUtils(); + configuration = Configuration.getInstance(); + if (log.isDebugEnabled()) { + log.debug(configuration.toString()); + } + + startClient(); + } + + /** + * start dmaap client. + */ + @SuppressWarnings("unchecked") + public synchronized void startClient() { + + Map<String, Object> streamSubscribes = Configuration.getInstance().getStreamsSubscribes(); + + String pmTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes + .get("performance_management_topic")).get("dmaap_info")).get("topic_url"); + String[] pmTopicSplit = pmTopicUrl.split("\\/"); + String pmTopic = pmTopicSplit[pmTopicSplit.length - 1]; + log.debug("pm topic : {}", pmTopic); + String policyResponseTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes + .get("dcae_cl_response_topic")).get("dmaap_info")).get("topic_url"); + String[] policyResponseTopicUrlSplit = policyResponseTopicUrl.split("\\/"); + String policyResponseTopic = policyResponseTopicUrlSplit[policyResponseTopicUrlSplit.length - 1]; + log.debug("policyResponse Topic : {}", policyResponseTopic); + CambriaConsumer pmNotifCambriaConsumer = null; + CambriaConsumer policyResponseCambriaConsumer = null; + + pmNotifCambriaConsumer = dmaapUtils.buildConsumer(configuration, pmTopic); + policyResponseCambriaConsumer = dmaapUtils.buildConsumer(configuration, policyResponseTopic); + + ScheduledExecutorService executorPool; + + // create notification consumers for PM + NotificationConsumer pmNotificationConsumer = new NotificationConsumer(pmNotifCambriaConsumer, + new PmNotificationCallback()); + // start pm notification consumer threads + executorPool = Executors.newScheduledThreadPool(10); + executorPool.scheduleAtFixedRate(pmNotificationConsumer, 0, configuration.getPollingInterval(), + TimeUnit.SECONDS); + + // create notification consumers for Policy + NotificationConsumer policyNotificationConsumer = new NotificationConsumer(policyResponseCambriaConsumer, + new PolicyNotificationCallback()); + // start policy notification consumer threads + executorPool = Executors.newScheduledThreadPool(10); + executorPool.scheduleAtFixedRate(policyNotificationConsumer, 0, configuration.getPollingInterval(), + TimeUnit.SECONDS); + + + + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java new file mode 100644 index 00000000..5c1f496b --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import javax.annotation.PostConstruct; + +import org.springframework.stereotype.Component; + +/** + * This class indicates whether new pm notification + * is set for the slice-analysis-ms + */ +@Component +public class NewPmNotification { + + private Boolean newNotif; + + /** + * Initialize new pm Notification flag + */ + @PostConstruct + public void init() { + newNotif = false; + } + + public Boolean getNewNotif() { + return newNotif; + } + + public void setNewNotif(Boolean newNotif) { + this.newNotif = newNotif; + } + + public NewPmNotification(Boolean newNotif) { + super(); + this.newNotif = newNotif; + } + + /** + * Default constructor + */ + public NewPmNotification() { + + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java new file mode 100644 index 00000000..427b4048 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +public abstract class NotificationCallback { + + public abstract void activateCallBack(String msg); + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumer.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumer.java new file mode 100644 index 00000000..b605264c --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumer.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import com.att.nsa.cambria.client.CambriaConsumer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Consume Notifications from DMAAP events + */ +public class NotificationConsumer implements Runnable { + + private static Logger log = LoggerFactory.getLogger(NotificationConsumer.class); + private CambriaConsumer cambriaConsumer; + private NotificationCallback notificationCallback; + + /** + * Parameterized Constructor. + */ + public NotificationConsumer(CambriaConsumer cambriaConsumer, NotificationCallback notificationCallback) { + super(); + this.cambriaConsumer = cambriaConsumer; + this.notificationCallback = notificationCallback; + } + + /** + * starts fetching msgs from dmaap events + */ + @Override + public void run() { + try { + Iterable<String> msgs = cambriaConsumer.fetch(); + for (String msg : msgs) { + log.debug(msg); + notificationCallback.activateCallBack(msg); + } + } catch (Exception e) { + log.debug("exception when fetching msgs from dmaap", e); + } + + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationProducer.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationProducer.java new file mode 100644 index 00000000..03e1c238 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationProducer.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; + +import java.io.IOException; + +/** + * Produces Notification on DMAAP events + */ +public class NotificationProducer { + + private CambriaBatchingPublisher cambriaBatchingPublisher; + + + /** + * Parameterized constructor. + */ + public NotificationProducer(CambriaBatchingPublisher cambriaBatchingPublisher) { + super(); + this.cambriaBatchingPublisher = cambriaBatchingPublisher; + } + + /** + * sends notification to dmaap. + */ + public int sendNotification(String msg) throws IOException { + + return cambriaBatchingPublisher.send("", msg); + + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java new file mode 100644 index 00000000..17e50aca --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import org.onap.slice.analysis.ms.data.beans.PerformanceNotifications; +import org.onap.slice.analysis.ms.data.repository.PerformanceNotificationsRepository; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Handles Notification on dmaap for Performance events + */ +public class PmNotificationCallback extends NotificationCallback { + + private static Logger log = LoggerFactory.getLogger(PmNotificationCallback.class); + + @Override + public void activateCallBack(String msg) { + handleNotification(msg); + } + + /** + * Parse Performance dmaap notification and save to DB + * @param msg + */ + private void handleNotification(String msg) { + + PerformanceNotificationsRepository performanceNotificationsRepository = BeanUtil + .getBean(PerformanceNotificationsRepository.class); + PerformanceNotifications performanceNotification = new PerformanceNotifications(); + performanceNotification.setNotification(msg); + log.info("Performance notification {}", performanceNotification); + NewPmNotification newNotification = BeanUtil.getBean(NewPmNotification.class); + performanceNotificationsRepository.save(performanceNotification); + newNotification.setNewNotif(true); + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java new file mode 100644 index 00000000..81ca9ef1 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import java.io.IOException; +import java.util.Map; + +import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.utils.DmaapUtils; + +/** + * Client class to handle Policy interactions + */ +public class PolicyDmaapClient { + + private DmaapUtils dmaapUtils; + + private Configuration configuration; + + public PolicyDmaapClient(DmaapUtils dmaapUtils, Configuration configuration) { + this.dmaapUtils = dmaapUtils; + this.configuration = configuration; + } + + /** + * Method stub for sending notification to policy. + */ + @SuppressWarnings("unchecked") + public boolean sendNotificationToPolicy(String msg) { + Map<String, Object> streamsPublishes = configuration.getStreamsPublishes(); + String policyTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamsPublishes.get("CL_topic")) + .get("dmaap_info")).get("topic_url"); + String[] policyTopicSplit = policyTopicUrl.split("\\/"); + String policyTopic = policyTopicSplit[policyTopicSplit.length - 1]; + CambriaBatchingPublisher cambriaBatchingPublisher; + try { + + cambriaBatchingPublisher = dmaapUtils.buildPublisher(configuration, policyTopic); + + NotificationProducer notificationProducer = new NotificationProducer(cambriaBatchingPublisher); + notificationProducer.sendNotification(msg); + } catch (IOException e) { + return false; + } + return true; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java new file mode 100644 index 00000000..57aadd18 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import org.slf4j.Logger; + +/** + * Handles Notification on dmaap for Policy events + */ +public class PolicyNotificationCallback extends NotificationCallback { + + private static final Logger log = org.slf4j.LoggerFactory.getLogger(PolicyNotificationCallback.class); + + /** + * Trigger on Notification from policy component + */ + @Override + public void activateCallBack(String msg) { + handlePolicyNotification(msg); + } + + /** + * Parse and take actions on reception of Notification from Policy + * @param msg + */ + private void handlePolicyNotification(String msg) { + log.info("Message received from policy: " +msg); + //TBD - actions to perform on reception of notification from policy + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/BeanUtil.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/BeanUtil.java new file mode 100644 index 00000000..5f4006c9 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/BeanUtil.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.utils; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Service; + +/** + * This class is used to get/set bean references + */ +@Service +public class BeanUtil implements ApplicationContextAware { + private static ApplicationContext context; + + /** + * set ApplicationContext + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + context = applicationContext; + } + + /** + * Get bean class + * @param <T> + * @param beanClass + * @return + */ + public static <T> T getBean(Class<T> beanClass) { + return context.getBean(beanClass); + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/DmaapUtils.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/DmaapUtils.java new file mode 100644 index 00000000..0952f754 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/DmaapUtils.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.utils; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaClient; +import com.att.nsa.cambria.client.CambriaClientBuilders; +import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder; +import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder; +import com.att.nsa.cambria.client.CambriaClientBuilders.TopicManagerBuilder; +import com.att.nsa.cambria.client.CambriaConsumer; +import com.att.nsa.cambria.client.CambriaTopicManager; + +import java.net.MalformedURLException; +import java.security.GeneralSecurityException; + +import org.onap.slice.analysis.ms.beans.Configuration; + +/** + * Utility class to perform actions related to Dmaap + */ +public class DmaapUtils { + + /** + * Build publisher. + */ + public CambriaBatchingPublisher buildPublisher(Configuration config, String topic) { + try { + return builder(config, topic).build(); + } catch (MalformedURLException | GeneralSecurityException e) { + return null; + + } + } + + /** + * Build consumer. + */ + public CambriaConsumer buildConsumer(Configuration config, String topic) { + + try { + return builderConsumer(config, topic).build(); + } catch (MalformedURLException | GeneralSecurityException e) { + return null; + } + + } + + private static PublisherBuilder builder(Configuration config, String topic) { + if (config.isSecured()) { + return authenticatedBuilder(config, topic); + } else { + return unAuthenticatedBuilder(config, topic); + } + } + + private static PublisherBuilder authenticatedBuilder(Configuration config, String topic) { + return unAuthenticatedBuilder(config, topic).usingHttps().authenticatedByHttp(config.getAafUsername(), + config.getAafPassword()); + } + + private static PublisherBuilder unAuthenticatedBuilder(Configuration config, String topic) { + return new CambriaClientBuilders.PublisherBuilder().usingHosts(config.getDmaapServers()).onTopic(topic) + .logSendFailuresAfter(5); + } + + private static ConsumerBuilder builderConsumer(Configuration config, String topic) { + if (config.isSecured()) { + return authenticatedConsumerBuilder(config, topic); + } else { + return unAuthenticatedConsumerBuilder(config, topic); + } + } + + private static ConsumerBuilder unAuthenticatedConsumerBuilder(Configuration config, String topic) { + return new CambriaClientBuilders.ConsumerBuilder().usingHosts(config.getDmaapServers()).onTopic(topic) + .knownAs(config.getCg(), config.getCid()).withSocketTimeout(config.getPollingTimeout() * 1000); + } + + private static ConsumerBuilder authenticatedConsumerBuilder(Configuration config, String topic) { + return unAuthenticatedConsumerBuilder(config, topic).usingHttps().authenticatedByHttp(config.getAafUsername(), + config.getAafPassword()); + } + + /** + * Build cambriaClient. + */ + public CambriaTopicManager cambriaCLientBuilder(Configuration configuration) { + if (configuration.isSecured()) { + return authenticatedCambriaCLientBuilder(configuration); + } else { + return unAuthenticatedCambriaCLientBuilder(configuration); + + } + } + + private static CambriaTopicManager authenticatedCambriaCLientBuilder(Configuration config) { + try { + return buildCambriaClient(new TopicManagerBuilder().usingHosts(config.getDmaapServers()) + .authenticatedByHttp(config.getAafUsername(), config.getAafPassword())); + } catch (MalformedURLException | GeneralSecurityException e) { + return null; + } + } + + private static CambriaTopicManager unAuthenticatedCambriaCLientBuilder(Configuration config) { + try { + return buildCambriaClient(new TopicManagerBuilder().usingHosts(config.getDmaapServers())); + } catch (MalformedURLException | GeneralSecurityException e) { + return null; + + } + } + + @SuppressWarnings("unchecked") + private static <T extends CambriaClient> T buildCambriaClient( + CambriaClientBuilders.AbstractAuthenticatedManagerBuilder<? extends CambriaClient> client) + throws MalformedURLException, GeneralSecurityException { + return (T) client.build(); + } + +} diff --git a/components/slice-analysis-ms/src/main/resources/application.properties b/components/slice-analysis-ms/src/main/resources/application.properties new file mode 100644 index 00000000..a82e68e7 --- /dev/null +++ b/components/slice-analysis-ms/src/main/resources/application.properties @@ -0,0 +1,35 @@ +############################################################################### +# ============LICENSE_START======================================================= +# slice-analysis-ms +# ================================================================================ +# Copyright (C) 2020 Wipro Limited. +# ============================================================================== +# 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. +# ============LICENSE_END========================================================= +# +############################################################################### + + +spring.datasource.initialization-mode=always + +spring.datasource.initialize=true + +spring.datasource.schema=classpath:/schema.sql + +spring.datasource.continue-on-error=true + +spring.jpa.hibernate.ddl-auto=validate + +spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false + +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect diff --git a/components/slice-analysis-ms/src/main/resources/logback.xml b/components/slice-analysis-ms/src/main/resources/logback.xml new file mode 100644 index 00000000..8d79c4ee --- /dev/null +++ b/components/slice-analysis-ms/src/main/resources/logback.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + --> + <configuration> + + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <layout class="ch.qos.logback.classic.PatternLayout"> + <Pattern> + %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + </Pattern> + </layout> + </appender> + + <root level="info"> + <appender-ref ref="CONSOLE"/> + </root> + +</configuration> diff --git a/components/slice-analysis-ms/src/main/resources/schema.sql b/components/slice-analysis-ms/src/main/resources/schema.sql new file mode 100644 index 00000000..468e5e3e --- /dev/null +++ b/components/slice-analysis-ms/src/main/resources/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE PERFORMANCE_NOTIFICATIONS( + notification TEXT PRIMARY KEY NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/ApplicationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/ApplicationTest.java new file mode 100644 index 00000000..38c2bacc --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/ApplicationTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ApplicationTest.class) +public class ApplicationTest { + + @Test + public void contextLoads() { + + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java new file mode 100644 index 00000000..66f97d96 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + + +package org.onap.slice.analysis.ms.beans; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + + +public class ConfigPolicyTest { + + @Test + public void configPolicyTest() { + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + Map<String, Object> config = new HashMap<String, Object>(); + config.put("policyName", "pcims_policy"); + configPolicy.setConfig(config); + assertEquals(config, configPolicy.getConfig()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java new file mode 100644 index 00000000..a3487773 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + + +package org.onap.slice.analysis.ms.beans; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; + + +public class ConfigurationTest { + Configuration configuration = Configuration.getInstance(); + + @Test + public void configurationTest() { + + List<String> list = new ArrayList<String>(); + list.add("server"); + Map<String, Object> subscribes = new HashMap<>(); + + configuration.setStreamsSubscribes(subscribes); + configuration.setStreamsPublishes(subscribes); + configuration.setDmaapServers(list); + configuration.setCg("cg"); + configuration.setCid("cid"); + configuration.setAafPassword("password"); + configuration.setAafUsername("user"); + configuration.setPgHost("pg"); + configuration.setPgPort(5432); + configuration.setPgPassword("password"); + configuration.setPgUsername("user"); + configuration.setPollingInterval(30); + configuration.setPollingTimeout(100); + configuration.setConfigDbService("sdnrService"); + + assertEquals("cg", configuration.getCg()); + assertEquals("cid", configuration.getCid()); + assertEquals("user", configuration.getAafUsername()); + assertEquals("password", configuration.getAafPassword()); + assertEquals("user", configuration.getPgUsername()); + assertEquals("password", configuration.getPgPassword()); + assertEquals("pg", configuration.getPgHost()); + assertEquals(5432, configuration.getPgPort()); + assertEquals(30, configuration.getPollingInterval()); + assertEquals(100, configuration.getPollingTimeout()); + assertEquals("sdnrService", configuration.getConfigDbService()); + assertEquals(list, configuration.getDmaapServers()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotificationsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotificationsTest.java new file mode 100644 index 00000000..e8654003 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotificationsTest.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.data.beans; + +import static org.junit.Assert.*; + +import java.sql.Timestamp; + +import org.junit.Test; + +public class PerformanceNotificationsTest { + + private Timestamp createdAt; + + @Test + public void test() { + + PerformanceNotifications performanceNotifications = new PerformanceNotifications(); + performanceNotifications.setNotification("notification"); + performanceNotifications.setCreatedAt(createdAt); + assertEquals("notification", performanceNotifications.getNotification()); + assertEquals(createdAt, performanceNotifications.getCreatedAt()); } + +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java new file mode 100644 index 00000000..f2420b02 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + + +package org.onap.slice.analysis.ms.dmaap; + +import static org.mockito.Mockito.when; + +import com.att.nsa.cambria.client.CambriaTopicManager; +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.slice.analysis.ms.beans.Configuration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = DmaapClientTest.class) +public class DmaapClientTest { + + @Mock + private CambriaTopicManager topicManager; + + + @InjectMocks + DmaapClient client; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void getAllTopicsTest() { + Set<String> topics = new HashSet<String>(); + topics.add("topic1"); + topics.add("topic2"); + Configuration configuration = Configuration.getInstance(); + List<String> list = new ArrayList<String>(); + list.add("server"); + configuration.setDmaapServers(list); + configuration.setCg("cg"); + configuration.setCid("cid"); + configuration.setPollingInterval(30); + configuration.setPollingTimeout(100); + configuration.setConfigDbService("sdnrService"); + + try { + when(topicManager.getTopics()).thenReturn(topics); + + client=Mockito.mock(DmaapClient.class); + client.initClient(); + Mockito.verify(client).initClient(); + // Mockito.verifycreateAndConfigureTopics(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void startClientTest() { + try { + Configuration configuration = Configuration.getInstance(); + String configAllJson = readFromFile("src/test/resources/config_all.json"); + + JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class); + + JsonObject config = configAll.getAsJsonObject("config"); + + configuration.updateConfigurationFromJsonObject(config); + DmaapClient client= new DmaapClient(); + client.initClient(); + //Mockito.verify(client).startClient(); + // Mockito.verifycreateAndConfigureTopics(); + + } catch ( Exception e) { + e.printStackTrace(); + } + } + + private static String readFromFile(String file) { + String content = ""; + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + } catch (Exception e) { + content = null; + } + return content; + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NewPmNotificationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NewPmNotificationTest.java new file mode 100644 index 00000000..7c11d03a --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NewPmNotificationTest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class NewPmNotificationTest { + + @Test + public void testNewPmNotif() { + NewPmNotification newPmNotif1 = new NewPmNotification(true); + NewPmNotification newPmNotif2 = new NewPmNotification(); + newPmNotif2.setNewNotif(true); + assertTrue(newPmNotif2.getNewNotif()); + newPmNotif2.init(); + assertEquals(false, newPmNotif2.getNewNotif()); + assertTrue(newPmNotif1.getNewNotif()); + + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java new file mode 100644 index 00000000..f4b64397 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.att.nsa.cambria.client.CambriaConsumer; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = NotificationConsumerTest.class) +public class NotificationConsumerTest { + + @Mock + CambriaConsumer cambriaConsumer; + + @Mock + NotificationCallback notificationCallback; + + @InjectMocks + NotificationConsumer notificationConsumer; + + @Test + public void testNotificationConsumer() { + try { + List<String> notifications = new ArrayList<>(); + notifications.add("notification1"); + when(cambriaConsumer.fetch()).thenReturn(notifications); + Mockito.doNothing().when(notificationCallback).activateCallBack(Mockito.anyString()); + notificationConsumer.run(); + + }catch(Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationProducerTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationProducerTest.java new file mode 100644 index 00000000..9dc51412 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationProducerTest.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + + +package org.onap.slice.analysis.ms.dmaap; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; + +import java.io.IOException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = NotificationProducerTest.class) +public class NotificationProducerTest { + + @Mock + CambriaBatchingPublisher cambriaBatchingPublisher; + + @InjectMocks + NotificationProducer notificationProducer; + + @Test + public void notificationProducerTest() { + + try { + + when(cambriaBatchingPublisher.send(Mockito.anyString(), Mockito.anyString())).thenReturn(0); + int result = notificationProducer.sendNotification("msg"); + assertEquals(0, result); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallbackTest.java new file mode 100644 index 00000000..8b47ba58 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallbackTest.java @@ -0,0 +1,59 @@ + +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.dmaap; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.onap.slice.analysis.ms.data.repository.PerformanceNotificationsRepository; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ BeanUtil.class }) +@SpringBootTest(classes = PmNotificationCallbackTest.class) +public class PmNotificationCallbackTest { + + @Mock + PerformanceNotificationsRepository performanceNotificationsRepository; + + @Mock + NewPmNotification newPmNotif; + + @Test + public void testActivateCallBack() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(PerformanceNotificationsRepository.class)).thenReturn(performanceNotificationsRepository); + PowerMockito.when(BeanUtil.getBean(NewPmNotification.class)).thenReturn(newPmNotif); + PmNotificationCallback pmNotificationCallback = new PmNotificationCallback(); + pmNotificationCallback.activateCallBack("pmNotification"); + } + +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java new file mode 100644 index 00000000..a458d33c --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + + +package org.onap.slice.analysis.ms.dmaap; + +import static org.junit.Assert.*; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaConsumer; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.utils.DmaapUtils; +import org.springframework.boot.test.context.SpringBootTest; + +@RunWith(MockitoJUnitRunner.class) +@SpringBootTest(classes = PolicyDmaapClient.class) +public class PolicyDmaapClientTest { + + @Mock + Configuration configurationMock; + + @Mock + DmaapUtils dmaapUtilsMock; + + @InjectMocks + PolicyDmaapClient policyDmaapClient; + + @Mock + CambriaConsumer policyResponseCambriaConsumerMock; + + @Mock + CambriaBatchingPublisher cambriaBatchingPublisherMock; + + @Mock + NotificationProducer notificationProducerMock; + + @Before + public void setup() { + policyDmaapClient = new PolicyDmaapClient(dmaapUtilsMock, configurationMock); + } + + @Test + public void sendNotificationToPolicyTest() { + Map<String, Object> streamsPublishes = new HashMap<>(); + Map<String, String> topics = new HashMap<>(); + Map<String, Object> dmaapInfo = new HashMap<>(); + topics.put("topic_url", "https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_OUTPUT"); + dmaapInfo.put("dmaap_info", topics); + streamsPublishes.put("CL_topic", dmaapInfo); + Mockito.when(configurationMock.getStreamsPublishes()).thenReturn(streamsPublishes); + Mockito.when(dmaapUtilsMock.buildPublisher(configurationMock, "DCAE_CL_OUTPUT")).thenReturn(cambriaBatchingPublisherMock); + try { + Mockito.when(cambriaBatchingPublisherMock.send("", "hello")).thenReturn(0); + } catch (IOException e) { + e.printStackTrace(); + } + assertTrue(policyDmaapClient.sendNotificationToPolicy("hello")); + + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallbackTest.java new file mode 100644 index 00000000..6793a167 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallbackTest.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.dmaap; + +import org.junit.Test; + +public class PolicyNotificationCallbackTest { + + @Test + public void testPolicyActivateCallback() { + + PolicyNotificationCallback policyNotificationCallback = new PolicyNotificationCallback(); + policyNotificationCallback.activateCallBack("newPolicyNotificationMsg"); + } + +} diff --git a/components/slice-analysis-ms/src/test/resources/config_all.json b/components/slice-analysis-ms/src/test/resources/config_all.json new file mode 100644 index 00000000..21a82344 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/config_all.json @@ -0,0 +1,59 @@ +{ + "config": { + "streams_subscribes": { + "performance_management_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.VES_MEASUREMENT_OUTPUT", + "client_role": "sliceanalysis-subscriber", + "location": "onap", + "client_id": "sdnr-sliceanalysis-1" + }, + "aaf_username": null + }, + "dcae_cl_response_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_RSP", + "client_role": "sliceanalysis-subscriber", + "location": "onap", + "client_id": "sdnr-sliceanalysis-1" + }, + "aaf_username": null + } + }, + "streams_publishes": { + "CL_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.DCAE_CL_OUTPUT", + "client_role": "sliceanalysis-subscriber", + "location": "onap", + "client_id": "sdnr-sliceanalysis-1" + }, + "aaf_username": null + } + }, + "postgres.password": "postgres", + "postgres.username": "sliceanalysisms_admin", + "postgres.host": "postgres", + "postgres.port": "5432", + "sliceanalysisms.dmaap.server": [ + "dmaap" + ], + "cbsPollingInterval": 60, + "sliceanalysisms.cg": "sliceanalysisms-cg", + "sliceanalysisms.pollingInterval": 20, + "sliceanalysisms.cid": "sliceanalysisms-cid", + "sliceanalysisms.configDb.service": "http://sdnc.onap:8181", + "service_calls": { + "policy-req": [] + } + }, + "policies": { + + } +} diff --git a/components/slice-analysis-ms/version.properties b/components/slice-analysis-ms/version.properties new file mode 100644 index 00000000..7bbc2fb0 --- /dev/null +++ b/components/slice-analysis-ms/version.properties @@ -0,0 +1,26 @@ +############################################################################### +# ============LICENSE_START======================================================= +# slice-analysis-ms +# ================================================================================ +# Copyright (C) 2020 Wipro Limited. +# ============================================================================== +# 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. +# ============LICENSE_END========================================================= +# +############################################################################### +major=1 +minor=0 +patch=0 +base_version=${major}.${minor}.${patch} +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT |