diff --git a/difference-nbi/.gitignore b/difference-nbi/.gitignore new file mode 100644 index 0000000..153c933 --- /dev/null +++ b/difference-nbi/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### 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/ + +### VS Code ### +.vscode/ diff --git a/difference-nbi/.mvn/wrapper/MavenWrapperDownloader.java b/difference-nbi/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000..72308aa --- /dev/null +++ b/difference-nbi/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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 + + https://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. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/difference-nbi/.mvn/wrapper/maven-wrapper.jar b/difference-nbi/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..01e6799 Binary files /dev/null and b/difference-nbi/.mvn/wrapper/maven-wrapper.jar differ diff --git a/difference-nbi/.mvn/wrapper/maven-wrapper.properties b/difference-nbi/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..cd0d451 --- /dev/null +++ b/difference-nbi/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/difference-nbi/pom.xml b/difference-nbi/pom.xml new file mode 100644 index 0000000..a23e98f --- /dev/null +++ b/difference-nbi/pom.xml @@ -0,0 +1,419 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + cloud.difference + difference-nbi + 0.0.1-SNAPSHOT + nbi + Demo project for Spring Boot + + + + 1.8 + 2.9.8 + + + + + org.springframework.boot + + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-devtools + true + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + + + org.glassfish.jersey.containers + jersey-container-servlet + 2.27 + + + org.glassfish.jersey.core + jersey-server + 2.27 + + + org.glassfish.jersey.core + jersey-client + 2.27 + + + org.glassfish.jersey.media + jersey-media-multipart + 2.27 + + + + org.glassfish.jersey.media + jersey-media-json-jackson + 2.27 + + + + org.glassfish.jersey.ext + jersey-spring3 + 2.23 + + + + spring-context + org.springframework + + + spring-core + org.springframework + + + spring-web + org.springframework + + + spring-beans + org.springframework + + + + + + + + com.fasterxml.jackson.core + jackson-core + ${jackson-2-version} + + + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson-2-version} + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-2-version} + + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-smile + ${jackson-2-version} + + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + ${jackson-2-version} + + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + ${jackson-2-version} + + + com.owlike + genson + 1.1 + + + + + org.springframework.boot + spring-boot-starter-websocket + + + + + org.webjars + sockjs-client + 1.0.2 + + + org.webjars + stomp-websocket + 2.3.3 + + + org.webjars + bootstrap + 3.3.7 + + + org.webjars + jquery + 3.1.0 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + docker + + + + io.fabric8 + docker-maven-plugin + 0.28.0 + + true + 1.23 + + + ${project.artifactId} + ${project.artifactId} + + try + ${project.basedir}/target/docker-stage + + ${docker.snapshot.tag} + ${docker.latest.tag} + + + + + + + + generate-images + + build + + + + push-images + deploy + + build + push + + + + + + com.github.kongchen + swagger-maven-plugin + 3.1.7 + + + + + api + + /nbi + + Difference NBI + ${project.version} + http://difference.cloud + + + + basicAuth + basic + + + ${swagger.directory} + + + + + + compile + + generate + + + + + + maven-resources-plugin + 2.6 + + + copy-dockerfile + + copy-resources + + package + + ${project.basedir}/target/docker-stage + + + src/main/docker + + DockerFile + + true + + + + + + copy-properties + + copy-resources + + package + + ${project.basedir}/target/docker-stage/config + + + config + + *.properties + *.xml + *.spec + + false + + + + + + copy-properties-dynamic-conf-directory + + copy-resources + + package + + ${project.basedir}/target/docker-stage/config/dynamic/conf + + + config/dynamic/conf + + *.xml + + false + + + + + + copy-properties-dynamic-routes-directory + + copy-resources + + package + + ${project.basedir}/target/docker-stage/config/dynamic/routes + + + config/dynamic/routes + + *.route + + false + + + + + + copy-properties-rules-directory + + copy-resources + + package + + ${project.basedir}/target/docker-stage/config/rules + + + config/rules + + *.drl + + false + + + + + + copy-script + + copy-resources + + package + + ${project.basedir}/target/docker-stage/ + + + src/main/docker + + *.sh + + false + + + + + + copy-jar + + copy-resources + + package + + ${project.basedir}/target/docker-stage/ + + + target + + *.jar + + false + + + + + + + + + + + diff --git a/difference-nbi/src/main/docker/DockerFile b/difference-nbi/src/main/docker/DockerFile new file mode 100644 index 0000000..d5cf10f --- /dev/null +++ b/difference-nbi/src/main/docker/DockerFile @@ -0,0 +1,19 @@ +FROM anapsix/alpine-java:jre8 + +ARG MICROSERVICE_HOME=/opt/app/ + +# Build up the deployment folder structure +RUN mkdir -p $MICROSERVICE_HOME +RUN mkdir -p $MICROSERVICE_HOME/config/ +RUN mkdir -p $MICROSERVICE_HOME/lib/ +RUN mkdir -p $MICROSERVICE_HOME/bin/ + +ADD difference-nbi-0.0.1-SNAPSHOT.jar $MICROSERVICE_HOME/lib/ +ADD startService.sh $MICROSERVICE_HOME/bin/ +COPY config/ $MICROSERVICE_HOME/config/ + +#RUN chmod 755 $MICROSERVICE_HOME/config/* +RUN chmod 755 $MICROSERVICE_HOME/lib/* +RUN chmod 755 $MICROSERVICE_HOME/bin/* + +CMD ["/opt/app/bin/startService.sh"] \ No newline at end of file diff --git a/difference-nbi/src/main/docker/startService.sh b/difference-nbi/src/main/docker/startService.sh new file mode 100644 index 0000000..9d10f65 --- /dev/null +++ b/difference-nbi/src/main/docker/startService.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +cd /opt/app +#-Dlogging.config=config/logback.xml +if [ -z "${java_runtime_arguments}" ]; then +java -Xms128m -Xmx512m -jar /opt/app/lib/difference-nbi-0.0.1-SNAPSHOT.jar +else +java $java_runtime_arguments -jar /opt/app/lib/difference-nbi-0.0.1-SNAPSHOT.jar +fi diff --git a/difference-nbi/src/main/java/cloud/difference/nbi/Api.java b/difference-nbi/src/main/java/cloud/difference/nbi/Api.java new file mode 100644 index 0000000..98a46e3 --- /dev/null +++ b/difference-nbi/src/main/java/cloud/difference/nbi/Api.java @@ -0,0 +1,22 @@ +package cloud.difference.nbi; + + +public class Api { + + private long id; + private String content; + + public Api(long id, String content) { + this.id = id; + this.content = content; + } + + public long getId() { + return id; + } + + public String getContent() { + return content; + } +} + diff --git a/difference-nbi/src/main/java/cloud/difference/nbi/ApiController.java b/difference-nbi/src/main/java/cloud/difference/nbi/ApiController.java new file mode 100644 index 0000000..c278b1b --- /dev/null +++ b/difference-nbi/src/main/java/cloud/difference/nbi/ApiController.java @@ -0,0 +1,126 @@ +package cloud.difference.nbi; + +import java.util.concurrent.atomic.AtomicLong; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/api") +// http://localhost:8080/nbi/api +public class ApiController { + + private final AtomicLong counter = new AtomicLong(); + private static final CharSequence pass = "PASS"; + private static final CharSequence fail = "FAIL"; + + @RequestMapping(method=RequestMethod.GET) + public @ResponseBody Api process(@RequestParam(value="action", required=true, defaultValue="undefined") String action) { + String message = "pass"; + // external call + //message = externalAPICall(action); + Api api = new Api(counter.incrementAndGet(), message); + return api; + } + +/* private String externalAPICall(String action) { + String content = null; + JAXRSClient client = new JAXRSClient(); + + + // todo + // get https://{{aai_ip}}:8443/aai/v8/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vFW/service-instances/ + // {"service-instance": [ { "service-instance-id": "cd2eb659-2463-461b-9c3b-3bf03619c167", + switch(action) { + case "sec": + content = client.run(false, Configuration.get(Configuration.DC, "coll-ip"), "3904", "events/unauthenticated.SEC_MEASUREMENT_OUTPUT/group3/sub1?timeout=9000", null, null, null); + break; + case "tca": + content = client.run(false, Configuration.get(Configuration.DC, "coll-ip"), "3904", "events/unauthenticated.TCA_EVENT_OUTPUT/group3/sub1?timeout=9000", null, null, null); + break; + case "customer-read": + // will get a 4000 on customers/customer but not customers at demo init state + content = client.run(true, Configuration.get(Configuration.DC, "aai-ip"), "8443", "aai/v8/business/customers/customer", "AAI", "AAI", "AAI"); + //content = client.run(true, Configuration.get(Configuration.DC, "aai-ip"), "8443", "aai/v8/service-design-and-creation/models", "AAI", "AAI", "AAI"); + break; + case "init-config": // 1 demo.sh or rest + ExternalProcessEndpoint ep_ic = new ExternalProcessEndpoint(); + content = verifyScript(ep_ic.runExternal("demo.sh","init")); + break; + case "service-deploy-read": // 2 vid + // check endpoints + content = "service-deploy-read-return"; + break; + case "service-creation-read": // 2 vid + // check endpoints + + // https://{{aai_ip}}:8443/aai/v8/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vFW/service-instances/ + // { "service-instance": [ { "service-instance-id": "9f801217-8cbd-4419-af06-640801422563", "service-instance-name": "DemoInstance", + break; + case "vnf-creation-read": // 3 vid + // check endpoints + ExternalProcessEndpoint ep_vcr = new ExternalProcessEndpoint(); + content = ep_vcr.runExternalAbsolute("/Users/michaelobrien/wse_onap/onap/extract.sh"); + System.out.println(content); + // https://{{aai_ip}}:8443/aai/v8/network/generic-vnfs + //{ "generic-vnf": [ { + // "vnf-id": "6e81b7e3-3a93-4b6f-8790-be65580a12ce", + // "vnf-name": "DemoVNF", + // "vnf-type": "fwservice/vsp 1", + // "service-id": "0a3bb60f-2cf0-4982-a819-853cb088e916", + + + break; + case "vfm-preload": // 4 demo.sh + ExternalProcessEndpoint ep_mp = new ExternalProcessEndpoint(); + content = verifyScript(ep_mp.runExternal("demo.sh","preload", "DemoVNF", "DemoModule")); + // verify http://{{sdnc_ip}}:8282/restconf/config/VNF-API:preload-vnfs + // network on + //"vnf-parameter-name": "ecomp_private_net_id", + // "vnf-parameter-value": "oam_ecomp_d037" + // ips 0= 1= 2= + //"vnf-parameter-name": "vfw_private_ip_2", + //"vnf-parameter-value": "10.1.0.11" + + + + break; + case "vfm-creation-read": // 5 vid or rest + // check endpoints + break; + case "closed-loop": // 6 demo.sh or rest + ExternalProcessEndpoint ep_cl = new ExternalProcessEndpoint(); + content = verifyScript(ep_cl.runExternal("demo.sh","appc", "DemoModule")); + break; + case "ping": // ping -c 1 + break; + case "dc-read": + break; + case "dc-switch": + content = Configuration.switchDC(); + break; + } + + + return content; + } + + private String verifyScript(String content) { + // assume failure + String passed = "fail"; + // check for FAIL + if(content.contains(pass)) { + System.out.println("passed"); + passed = "pass"; + } + if(content.contains(fail)) { + System.out.println("failed"); + passed = "fail"; + } + return passed; + } +*/ +} diff --git a/difference-nbi/src/main/java/cloud/difference/nbi/NbiApplication.java b/difference-nbi/src/main/java/cloud/difference/nbi/NbiApplication.java new file mode 100644 index 0000000..e83d94f --- /dev/null +++ b/difference-nbi/src/main/java/cloud/difference/nbi/NbiApplication.java @@ -0,0 +1,13 @@ +package cloud.difference.nbi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class NbiApplication { + + public static void main(String[] args) { + SpringApplication.run(NbiApplication.class, args); + } + +} diff --git a/difference-nbi/src/main/resources/application.properties b/difference-nbi/src/main/resources/application.properties new file mode 100644 index 0000000..29148fe --- /dev/null +++ b/difference-nbi/src/main/resources/application.properties @@ -0,0 +1 @@ +server.servlet.context-path=/nbi diff --git a/difference-nbi/src/test/java/cloud/difference/nbi/NbiApplicationTests.java b/difference-nbi/src/test/java/cloud/difference/nbi/NbiApplicationTests.java new file mode 100644 index 0000000..5cc868e --- /dev/null +++ b/difference-nbi/src/test/java/cloud/difference/nbi/NbiApplicationTests.java @@ -0,0 +1,17 @@ +package cloud.difference.nbi; + +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 +public class NbiApplicationTests { + + @Test + // fix jpa db context later + public void contextLoads() { + } + +}