From dafdbe531634823882261f2ce8c9cf334b579b52 Mon Sep 17 00:00:00 2001 From: ambrishest Date: Fri, 1 Mar 2024 13:05:16 +0000 Subject: [PATCH] Hello World SME Invoker Service Issue-ID: NONRTRIC-965 Change-Id: Icc998cc3d456ca894eb86b44779c7798c2df1fd4 Signed-off-by: ambrishest --- .../hello-world-sme-invoker}/.gitignore | 0 sample-services/hello-world-sme-invoker/Dockerfile | 47 +++++ sample-services/hello-world-sme-invoker/README.md | 37 ++++ sample-services/hello-world-sme-invoker/build.sh | 96 +++++++++ .../hello-world-sme-invoker/container-tag.yaml | 25 +++ .../hello-world-sme-invoker/docker-compose.yml | 29 +++ .../hello-world-sme-invoker-build-start.sh | 35 ++++ .../hello-world-sme-invoker}/.helmignore | 0 .../hello-world-sme-invoker/Chart.yaml | 44 +++++ .../templates/deployment.yaml | 48 +++++ .../hello-world-sme-invoker/templates/service.yaml | 25 +-- .../hello-world-sme-invoker/values.yaml | 34 ++++ sample-services/hello-world-sme-invoker/pom.xml | 72 +++++++ .../sample/HelloWorldSmeInvokerApplication.java | 39 ++++ .../sample/exception/CapifAccessException.java | 28 +++ .../sample/exception/GlobalExceptionHandler.java | 39 ++++ .../rest/HelloWorldSmeInvokerController.java | 203 +++++++++++++++++++ .../nonrtric/sample/rest/response/ApiResponse.java | 215 +++++++++++++++++++++ sample-services/hello-world/.gitignore | 38 ++++ .../hello-world}/Dockerfile | 0 .../hello-world}/README.md | 16 +- .../hello-world}/build.sh | 2 +- .../hello-world}/container-tag.yaml | 0 .../hello-world}/docker-compose.yml | 2 +- .../hello-world/hello-world-build-start.sh | 4 +- .../hello-world/hello-world-chart/.helmignore | 23 +++ .../hello-world}/hello-world-chart/Chart.yaml | 0 .../hello-world-chart/templates/deployment.yaml | 0 .../hello-world-chart/templates/service.yaml | 1 - .../hello-world}/hello-world-chart/values.yaml | 4 +- .../hello-world}/pom.xml | 2 +- .../nonrtric/sample/HelloWorldApplication.java | 4 +- .../nonrtric/sample/rest/HelloWorldController.java | 0 .../sample/rest/HelloWorldControllerTest.java | 0 .../hello-world-chart/templates/_helpers.tpl | 62 ------ 35 files changed, 1082 insertions(+), 92 deletions(-) rename {test/servicestub => sample-services/hello-world-sme-invoker}/.gitignore (100%) create mode 100644 sample-services/hello-world-sme-invoker/Dockerfile create mode 100644 sample-services/hello-world-sme-invoker/README.md create mode 100644 sample-services/hello-world-sme-invoker/build.sh create mode 100644 sample-services/hello-world-sme-invoker/container-tag.yaml create mode 100644 sample-services/hello-world-sme-invoker/docker-compose.yml create mode 100644 sample-services/hello-world-sme-invoker/hello-world-sme-invoker-build-start.sh rename {test/servicestub/hello-world-chart => sample-services/hello-world-sme-invoker/hello-world-sme-invoker}/.helmignore (100%) create mode 100644 sample-services/hello-world-sme-invoker/hello-world-sme-invoker/Chart.yaml create mode 100644 sample-services/hello-world-sme-invoker/hello-world-sme-invoker/templates/deployment.yaml rename test/servicestub/hello-world-chart/templates/tests/test-connection.yaml => sample-services/hello-world-sme-invoker/hello-world-sme-invoker/templates/service.yaml (65%) create mode 100644 sample-services/hello-world-sme-invoker/hello-world-sme-invoker/values.yaml create mode 100644 sample-services/hello-world-sme-invoker/pom.xml create mode 100644 sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/HelloWorldSmeInvokerApplication.java create mode 100644 sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/CapifAccessException.java create mode 100644 sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/GlobalExceptionHandler.java create mode 100644 sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldSmeInvokerController.java create mode 100644 sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/rest/response/ApiResponse.java create mode 100644 sample-services/hello-world/.gitignore rename {test/servicestub => sample-services/hello-world}/Dockerfile (100%) rename {test/servicestub => sample-services/hello-world}/README.md (59%) rename {test/servicestub => sample-services/hello-world}/build.sh (98%) rename {test/servicestub => sample-services/hello-world}/container-tag.yaml (100%) rename {test/servicestub => sample-services/hello-world}/docker-compose.yml (93%) rename test/servicestub/service-stub-build-start.sh => sample-services/hello-world/hello-world-build-start.sh (94%) create mode 100644 sample-services/hello-world/hello-world-chart/.helmignore rename {test/servicestub => sample-services/hello-world}/hello-world-chart/Chart.yaml (100%) rename {test/servicestub => sample-services/hello-world}/hello-world-chart/templates/deployment.yaml (100%) rename {test/servicestub => sample-services/hello-world}/hello-world-chart/templates/service.yaml (98%) rename {test/servicestub => sample-services/hello-world}/hello-world-chart/values.yaml (91%) rename {test/servicestub => sample-services/hello-world}/pom.xml (95%) rename test/servicestub/src/main/java/org/oransc/nonrtric/sample/ServiceStubApplication.java => sample-services/hello-world/src/main/java/org/oransc/nonrtric/sample/HelloWorldApplication.java (88%) rename {test/servicestub => sample-services/hello-world}/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldController.java (100%) rename {test/servicestub => sample-services/hello-world}/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java (100%) delete mode 100644 test/servicestub/hello-world-chart/templates/_helpers.tpl diff --git a/test/servicestub/.gitignore b/sample-services/hello-world-sme-invoker/.gitignore similarity index 100% rename from test/servicestub/.gitignore rename to sample-services/hello-world-sme-invoker/.gitignore diff --git a/sample-services/hello-world-sme-invoker/Dockerfile b/sample-services/hello-world-sme-invoker/Dockerfile new file mode 100644 index 00000000..4885a483 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/Dockerfile @@ -0,0 +1,47 @@ +#================================================================================== +# Copyright (C) 2024: OpenInfra Foundation Europe +# +# 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. +# +# This source code is part of the near-RT RIC (RAN Intelligent Controller) +# platform project (RICP). +#================================================================================== + + +# Use Maven image with OpenJDK 17 for the build stage +FROM maven:3.8.5-openjdk-17 AS maven_build + +# Copy Maven project files +COPY pom.xml /tmp/ +COPY src /tmp/src/ + +# Set working directory +WORKDIR /tmp/ + +# Build the Maven project +RUN mvn package + +# Use a separate image with OpenJDK 17 for the runtime stage +FROM openjdk:17-jdk-slim + +# Expose port 8080 +EXPOSE 8080 + +# Set the working directory +WORKDIR /app + +# Copy the JAR file from the maven_build stage to the runtime stage +COPY --from=maven_build /tmp/target/hello-world-sme-invoker-0.1.0.jar /app/hello-world-sme-invoker-0.1.0.jar + +# Command to run the application +CMD ["java", "-jar", "hello-world-sme-invoker-0.1.0.jar"] diff --git a/sample-services/hello-world-sme-invoker/README.md b/sample-services/hello-world-sme-invoker/README.md new file mode 100644 index 00000000..95822a71 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/README.md @@ -0,0 +1,37 @@ +# Hello World Sme Invoker Service + +This repository contains a Spring Boot application serving few Hello World SME endpoints. +The application can be built and run using the provided script - ``hello-world-sme-invoker-build-start.sh``. + +## Prerequisites + +- Docker installed on your machine. + +## Building and Running the Application +Run the script: + +```bash + ./hello-world-sme-invoker-build-start.sh +``` + +The script will build a Docker image and run a container with the Hello World SME service. After the container starts, +wait for a few seconds to ensure the Spring Boot application is fully initialized. Next, it will make an HTTP request to the +Hello World SME endpoint and display the response: + +```bash + response=$(curl -s http://localhost:8080/helloworld/v1/sme) + echo "Response from the Hello World SME endpoint:" + echo "$response" +``` + +To stop and remove the Docker container: + +```bash + docker stop hello-world-sme-invoker + docker rm hello-world-sme-invoker +``` + +## Additional Information + +- The Hello World SME endpoint is available at http://localhost:8080/helloworld/v1/sme. + diff --git a/sample-services/hello-world-sme-invoker/build.sh b/sample-services/hello-world-sme-invoker/build.sh new file mode 100644 index 00000000..7dc17866 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/build.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2024: OpenInfra Foundation Europe. +# ======================================================================== +# 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================================================= +# + +# Build image from Dockerfile with/without custom image tag +# Optionally push to external image repo + +print_usage() { + echo "Usage: build.sh no-push| []" + exit 1 +} + +if [ $# -ne 1 ] && [ $# -ne 2 ]; then + print_usage +fi + +IMAGE_NAME="nonrtric-sample-helloworld-sme-invoker" +IMAGE_TAG="latest" +REPO="" +if [ $1 == "no-push" ]; then + echo "Only local image build" +else + REPO=$1 + echo "Attempt to push built image to: "$REPO +fi + +shift +while [ $# -ne 0 ]; do + if [ $1 == "--tag" ]; then + shift + if [ -z "$1" ]; then + print_usage + fi + IMAGE_TAG=$1 + echo "Setting image tag to: "$IMAGE_TAG + shift + else + echo "Unknown parameter: $1" + print_usage + fi +done + +IMAGE=$IMAGE_NAME:$IMAGE_TAG + +export DOCKER_DEFAULT_PLATFORM=linux/amd64 +CURRENT_PLATFORM=$(docker system info --format '{{.OSType}}/{{.Architecture}}') +if [ $CURRENT_PLATFORM != $DOCKER_DEFAULT_PLATFORM ]; then + echo "Image may not work on the current platform: $CURRENT_PLATFORM, only platform $DOCKER_DEFAULT_PLATFORM supported" +fi + +echo "Building image $IMAGE" +docker build -t $IMAGE_NAME:$IMAGE_TAG . +if [ $? -ne 0 ]; then + echo "BUILD FAILED" + exit 1 +fi +echo "BUILD OK" + +if [ "$REPO" != "" ]; then + echo "Tagging image" + NEW_IMAGE=$REPO/$IMAGE_NAME:$IMAGE_TAG + docker tag $IMAGE $NEW_IMAGE + if [ $? -ne 0 ]; then + echo "RE-TAGGING FAILED" + exit 1 + fi + echo "RE-TAG OK" + + echo "Pushing image $NEW_IMAGE" + docker push $NEW_IMAGE + if [ $? -ne 0 ]; then + echo "PUSHED FAILED" + echo " Perhaps not logged into docker-hub repo $REPO?" + exit 1 + fi + IMAGE=$NEW_IMAGE + echo "PUSH OK" +fi + +echo "IMAGE OK: $IMAGE" +echo "DONE" diff --git a/sample-services/hello-world-sme-invoker/container-tag.yaml b/sample-services/hello-world-sme-invoker/container-tag.yaml new file mode 100644 index 00000000..77dc89e9 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/container-tag.yaml @@ -0,0 +1,25 @@ +# - +# ========================LICENSE_START================================= +# O-RAN-SC +# %% +# Copyright (C) 2024: OpenInfra Foundation Europe. +# %% +# 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=================================== +# + +# The Jenkins job requires a tag to build the Docker image. +# By default this file is in the docker build directory, +# but the location can configured in the JJB template. +--- +tag: 0.1.0 diff --git a/sample-services/hello-world-sme-invoker/docker-compose.yml b/sample-services/hello-world-sme-invoker/docker-compose.yml new file mode 100644 index 00000000..eaaef185 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/docker-compose.yml @@ -0,0 +1,29 @@ +# - +# ========================LICENSE_START================================= +# O-RAN-SC +# %% +# Copyright (C) 2024: OpenInfra Foundation Europe +# %% +# 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: "3.0" + +services: + hello-world-sme-invoker: + build: + context: ../../sample-services/hello-world-sme-invoker + dockerfile: Dockerfile + ports: + - 8080:8080 \ No newline at end of file diff --git a/sample-services/hello-world-sme-invoker/hello-world-sme-invoker-build-start.sh b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker-build-start.sh new file mode 100644 index 00000000..e4a2edec --- /dev/null +++ b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker-build-start.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# - +# ========================LICENSE_START================================= +# O-RAN-SC +# %% +# Copyright (C) 2024: OpenInfra Foundation Europe. +# %% +# 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=================================== +# + +NAME="hello-world-sme-invoker" +IMAGE_NAME="nonrtric-sample-helloworld-sme-invoker" + +docker build -t $IMAGE_NAME:latest . + +docker run --rm -d -p 8080:8080 --name $NAME $IMAGE_NAME + +sleep 10 + +echo "Make an HTTP request to the Hello World Sme Invoker endpoint and display the response" +response=$(curl -s http://localhost:8080/helloworld/v1/sme) +echo "Response from the /helloworld/v1/sme endpoint: " +echo "$response" diff --git a/test/servicestub/hello-world-chart/.helmignore b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/.helmignore similarity index 100% rename from test/servicestub/hello-world-chart/.helmignore rename to sample-services/hello-world-sme-invoker/hello-world-sme-invoker/.helmignore diff --git a/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/Chart.yaml b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/Chart.yaml new file mode 100644 index 00000000..3eee3d6b --- /dev/null +++ b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/Chart.yaml @@ -0,0 +1,44 @@ +# - +# ========================LICENSE_START================================= +# O-RAN-SC +# %% +# Copyright (C) 2024: OpenInfra Foundation Europe +# %% +# 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=================================== +# + +apiVersion: v2 +name: hello-world-sme-invoker +description: A Helm chart for NONRTRIC Hello World SME Invoker + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "0.1.0" diff --git a/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/templates/deployment.yaml b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/templates/deployment.yaml new file mode 100644 index 00000000..9a31fba1 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/templates/deployment.yaml @@ -0,0 +1,48 @@ +# - +# ========================LICENSE_START================================= +# O-RAN-SC +# %% +# Copyright (C) 2024: OpenInfra Foundation Europe +# %% +# 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=================================== +# + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "hello-world-sme-invoker.fullname" . }} + labels: + {{- include "hello-world-sme-invoker.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "hello-world-sme-invoker.selectorLabels" . | nindent 8 }} + template: + metadata: + labels: + {{- include "hello-world-sme-invoker.selectorLabels" . | nindent 12 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + env: + - name: RAPP_INSTANCE_ID + value: "{{ .Values.environment.RAPP_INSTANCE_ID }}" + - name: SME_DISCOVERY_ENDPOINT + value: "{{ .Values.environment.SME_DISCOVERY_ENDPOINT }}" + ports: + - name: http + containerPort: {{ .Values.service.port }} + diff --git a/test/servicestub/hello-world-chart/templates/tests/test-connection.yaml b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/templates/service.yaml similarity index 65% rename from test/servicestub/hello-world-chart/templates/tests/test-connection.yaml rename to sample-services/hello-world-sme-invoker/hello-world-sme-invoker/templates/service.yaml index a8b1698f..9d214953 100644 --- a/test/servicestub/hello-world-chart/templates/tests/test-connection.yaml +++ b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/templates/service.yaml @@ -2,7 +2,7 @@ # ========================LICENSE_START================================= # O-RAN-SC # %% -# Copyright (C) 2023: OpenInfra Foundation Europe +# Copyright (C) 2024: OpenInfra Foundation Europe # %% # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,17 +19,18 @@ # apiVersion: v1 -kind: Pod +kind: Service metadata: - name: "{{ include "hello-world-chart.fullname" . }}-test-connection" + name: {{ include "hello-world-sme-invoker.fullname" . }} labels: - {{- include "hello-world-chart.labels" . | nindent 4 }} - annotations: - "helm.sh/hook": test + {{- include "hello-world-sme-invoker.labels" . | nindent 4 }} spec: - containers: - - name: wget - image: busybox - command: ['wget'] - args: ['{{ include "hello-world-chart.fullname" . }}:{{ .Values.service.port }}'] - restartPolicy: Never + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "hello-world-sme-invoker.selectorLabels" . | nindent 4 }} + diff --git a/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/values.yaml b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/values.yaml new file mode 100644 index 00000000..39aeeb5f --- /dev/null +++ b/sample-services/hello-world-sme-invoker/hello-world-sme-invoker/values.yaml @@ -0,0 +1,34 @@ +# - +# ========================LICENSE_START================================= +# O-RAN-SC +# %% +# Copyright (C) 2024: OpenInfra Foundation Europe +# %% +# 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=================================== +# + +image: + repository: nexus3.o-ran-sc.org:10003/nonrtric-sample-helloworld-sme-invoker + tag: latest + +service: + name: hello-world-sme-invoker + type: ClusterIP + port: 8080 + +environment: + APP_ID: Invoker_Rapp_Id + SME_DISCOVERY_ENDPOINT: capifcore.nonrtric.svc.cluster.local:8090/service-apis/v1/allServiceAPIs + + diff --git a/sample-services/hello-world-sme-invoker/pom.xml b/sample-services/hello-world-sme-invoker/pom.xml new file mode 100644 index 00000000..07c46c2b --- /dev/null +++ b/sample-services/hello-world-sme-invoker/pom.xml @@ -0,0 +1,72 @@ + + + + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.2.3 + + + org.o-ran-sc.nonrtric.plt + hello-world-sme-invoker + 0.1.0 + + + 17 + 17 + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.mockito + mockito-core + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/HelloWorldSmeInvokerApplication.java b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/HelloWorldSmeInvokerApplication.java new file mode 100644 index 00000000..0a384f42 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/HelloWorldSmeInvokerApplication.java @@ -0,0 +1,39 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2024 OpenInfra Foundation Europe. + * %% + * 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.oransc.nonrtric.sample; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + +@SpringBootApplication(scanBasePackages = "org.oransc.nonrtric.sample") +public class HelloWorldSmeInvokerApplication { + public static void main(String[] args) { + SpringApplication.run(HelloWorldSmeInvokerApplication.class, args); + } + + @Bean + public RestTemplate restTemplate(RestTemplateBuilder builder) { + return builder.build(); + } +} diff --git a/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/CapifAccessException.java b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/CapifAccessException.java new file mode 100644 index 00000000..b4c2940c --- /dev/null +++ b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/CapifAccessException.java @@ -0,0 +1,28 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2024 OpenInfra Foundation Europe. + * %% + * 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.oransc.nonrtric.sample.exception; + +public class CapifAccessException extends RuntimeException { + public CapifAccessException(String message) { + super(message); + } +} + diff --git a/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/GlobalExceptionHandler.java b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..414adf05 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/GlobalExceptionHandler.java @@ -0,0 +1,39 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2024 OpenInfra Foundation Europe. + * %% + * 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.oransc.nonrtric.sample.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(CapifAccessException.class) + public ResponseEntity handleCapifAccessException(CapifAccessException ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .contentType(MediaType.TEXT_PLAIN) + .body(ex.getMessage()); + } +} + diff --git a/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldSmeInvokerController.java b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldSmeInvokerController.java new file mode 100644 index 00000000..57820927 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldSmeInvokerController.java @@ -0,0 +1,203 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2024 OpenInfra Foundation Europe. + * %% + * 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.oransc.nonrtric.sample.rest; + +import jakarta.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; +import org.oransc.nonrtric.sample.exception.CapifAccessException; +import org.oransc.nonrtric.sample.rest.response.ApiResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@RestController +public class HelloWorldSmeInvokerController { + + private final RestTemplate restTemplate; + private static final Logger logger = LoggerFactory.getLogger(HelloWorldSmeInvokerController.class); + + public HelloWorldSmeInvokerController(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + @RequestMapping("/helloworld/v1/sme") + public String helloWorld(HttpServletRequest request) { + String path = logRequestPath(request); + return "Hello from " + path; + } + + @RequestMapping("/helloworld/sme/invoker/v1/apiset") + public ResponseEntity helloWorldSmeInvoker(HttpServletRequest request) { + String path = logRequestPath(request); + String capifUrl = createCapifUrl(); + try { + ApiResponse apiResponse = restTemplate.getForObject(capifUrl, ApiResponse.class); + return ResponseEntity.ok(apiResponse); + } catch (IllegalArgumentException e) { + throw new CapifAccessException("Error accessing the URL :- "+capifUrl); + } catch (Exception e) { + throw new CapifAccessException("Unexpected error"); + } + } + + @RequestMapping("/helloworld/sme/invoker/v1") + public ResponseEntity accessHelloWorldByInvoker(HttpServletRequest request) { + String path = logRequestPath(request); + String capifUrl = createCapifUrl(); + String baseUrl = ""; + ApiResponse apiResponse = new ApiResponse(); + try { + apiResponse = restTemplate.getForObject(capifUrl, ApiResponse.class); + baseUrl = getBaseUrl(apiResponse); + } catch (IllegalArgumentException e) { + throw new CapifAccessException("Error accessing the URL :- "+capifUrl); + } catch (Exception e) { + throw new CapifAccessException("Unexpected error"); + } + + String helloWorldEndpoint = ""; + List apiSetEndpoints = getApiSetEndpoints(apiResponse, baseUrl); + if(apiSetEndpoints != null && !apiSetEndpoints.isEmpty()){ + helloWorldEndpoint = apiSetEndpoints.get(0); + } + + try { + String responseHelloWorld = restTemplate.getForObject(helloWorldEndpoint, String.class); + logger.info("Response :- ", responseHelloWorld); + return ResponseEntity.ok(responseHelloWorld); + } catch (IllegalArgumentException e) { + throw new CapifAccessException("Error accessing the URL :- "+helloWorldEndpoint); + } catch (Exception e) { + throw new CapifAccessException("Unexpected error"); + } + } + + private String logRequestPath(HttpServletRequest request) { + String path = request.getRequestURI(); + logger.info("Received request for path: {}", path); + return path; + } + + private String createCapifUrl() { + String appId = System.getenv("APP_ID"); + if (appId != null) { + logger.info("APP_ID: " + appId); + } else { + logger.info("APP_ID environment variable is not set. "); + appId = "Invoker_App_1"; + logger.info("APP_ID default value :- " + appId); + } + + String smeDiscoveryEndpoint = System.getenv("SME_DISCOVERY_ENDPOINT"); + if (smeDiscoveryEndpoint != null) { + logger.info("SME_DISCOVERY_ENDPOINT: " + smeDiscoveryEndpoint); + } else { + logger.info("SME_DISCOVERY_ENDPOINT environment variable is not set."); + smeDiscoveryEndpoint = "capifcore.nonrtric.svc.cluster.local:8090/service-apis/v1/allServiceAPIs"; + logger.info("SME_DISCOVERY_ENDPOINT default value :- " + smeDiscoveryEndpoint); + } + + String invokerId = "api_invoker_id_Invoker_App_1"; + if (appId != null) { + invokerId = "api_invoker_id_" + appId; + } + logger.info("invokerId: " + invokerId); + + String capifUrl = + "http://capifcore.nonrtric.svc.cluster.local:8090/service-apis/v1/allServiceAPIs" + "?api-invoker-id=" + + invokerId; + if (smeDiscoveryEndpoint != null) { + capifUrl = smeDiscoveryEndpoint + "?api-invoker-id=" + invokerId; + } + logger.info("capifUrl: " + capifUrl); + + return capifUrl; + } + + private static String getBaseUrl(ApiResponse apiResponse) { + if (apiResponse != null && + apiResponse.getServiceAPIDescriptions() != null && + !apiResponse.getServiceAPIDescriptions().isEmpty()) { + + ApiResponse.ServiceAPIDescription serviceAPIDescription = apiResponse.getServiceAPIDescriptions().get(0); + + if (serviceAPIDescription.getAefProfiles() != null && + !serviceAPIDescription.getAefProfiles().isEmpty()) { + + ApiResponse.AefProfile aefProfile = serviceAPIDescription.getAefProfiles().get(0); + + if (aefProfile.getInterfaceDescriptions() != null && + !aefProfile.getInterfaceDescriptions().isEmpty()) { + ApiResponse.InterfaceDescription interfaceDescription = aefProfile.getInterfaceDescriptions().get(0); + return "http://" + interfaceDescription.getIpv4Addr() + ":" + interfaceDescription.getPort(); + } + } + } + return ""; + } + + private static List getApiSetEndpoints(ApiResponse apiResponse, String baseUrl){ + + String helloWorldEndpoint = ""; + List apiSetEndpoints = new ArrayList<>(5); + + if (apiResponse != null && + apiResponse.getServiceAPIDescriptions() != null && + !apiResponse.getServiceAPIDescriptions().isEmpty()) { + + ApiResponse.ServiceAPIDescription serviceAPIDescription = apiResponse.getServiceAPIDescriptions().get(0); + + if (serviceAPIDescription.getAefProfiles() != null && + !serviceAPIDescription.getAefProfiles().isEmpty()) { + + ApiResponse.AefProfile aefProfile = serviceAPIDescription.getAefProfiles().get(0); + + if (aefProfile.getInterfaceDescriptions() != null && + !aefProfile.getInterfaceDescriptions().isEmpty()) { + + ApiResponse.InterfaceDescription interfaceDescription = aefProfile.getInterfaceDescriptions().get(0); + + if (aefProfile.getVersions() != null && + !aefProfile.getVersions().isEmpty()) { + + ApiResponse.ApiVersion apiVersion = aefProfile.getVersions().get(0); + + if (apiVersion.getResources() != null && + !apiVersion.getResources().isEmpty()) { + + for(ApiResponse.Resource resource : apiVersion.getResources()) { + helloWorldEndpoint = baseUrl + resource.getUri(); + logger.info("Complete URL for resource " + helloWorldEndpoint); + apiSetEndpoints.add(helloWorldEndpoint); + } + } + } + } + } + } + return apiSetEndpoints; + } + +} diff --git a/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/rest/response/ApiResponse.java b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/rest/response/ApiResponse.java new file mode 100644 index 00000000..f7dbde84 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/rest/response/ApiResponse.java @@ -0,0 +1,215 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2024 OpenInfra Foundation Europe. + * %% + * 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.oransc.nonrtric.sample.rest.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +public class ApiResponse { + + @JsonProperty("serviceAPIDescriptions") + private List serviceAPIDescriptions; + + public List getServiceAPIDescriptions() { + return serviceAPIDescriptions; + } + + public void setServiceAPIDescriptions(List serviceAPIDescriptions) { + this.serviceAPIDescriptions = serviceAPIDescriptions; + } + + public static class ServiceAPIDescription { + @JsonProperty("apiName") + private String apiName; + + @JsonProperty("apiId") + private String apiId; + + @JsonProperty("description") + private String description; + + @JsonProperty("aefProfiles") + private List aefProfiles; + + public String getApiName() { + return apiName; + } + + public void setApiName(String apiName) { + this.apiName = apiName; + } + + public String getApiId() { + return apiId; + } + + public void setApiId(String apiId) { + this.apiId = apiId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getAefProfiles() { + return aefProfiles; + } + + public void setAefProfiles(List aefProfiles) { + this.aefProfiles = aefProfiles; + } + } + + public static class AefProfile { + private String aefId; + private String domainName; + private List versions; + private String protocol; + private List interfaceDescriptions; + + public String getAefId() { + return aefId; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public void setAefId(String aefId) { + this.aefId = aefId; + } + + public List getVersions() { + return versions; + } + + public void setVersions(List versions) { + this.versions = versions; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public List getInterfaceDescriptions() { + return interfaceDescriptions; + } + + public void setInterfaceDescriptions( + List interfaceDescriptions) { + this.interfaceDescriptions = interfaceDescriptions; + } + } + + public static class ApiVersion { + private String apiVersion; + private List resources; + + public String getApiVersion() { + return apiVersion; + } + + public void setApiVersion(String apiVersion) { + this.apiVersion = apiVersion; + } + + public List getResources() { + return resources; + } + + public void setResources(List resources) { + this.resources = resources; + } + } + + public static class Resource { + private String resourceName; + private String commType; + private String uri; + private List operations; + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getCommType() { + return commType; + } + + public void setCommType(String commType) { + this.commType = commType; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public List getOperations() { + return operations; + } + + public void setOperations(List operations) { + this.operations = operations; + } + } + + public static class InterfaceDescription { + private String ipv4Addr; + private int port; + + public String getIpv4Addr() { + return ipv4Addr; + } + + public void setIpv4Addr(String ipv4Addr) { + this.ipv4Addr = ipv4Addr; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + } +} + diff --git a/sample-services/hello-world/.gitignore b/sample-services/hello-world/.gitignore new file mode 100644 index 00000000..5ff6309b --- /dev/null +++ b/sample-services/hello-world/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/test/servicestub/Dockerfile b/sample-services/hello-world/Dockerfile similarity index 100% rename from test/servicestub/Dockerfile rename to sample-services/hello-world/Dockerfile diff --git a/test/servicestub/README.md b/sample-services/hello-world/README.md similarity index 59% rename from test/servicestub/README.md rename to sample-services/hello-world/README.md index b4aa791b..1dd8abce 100644 --- a/test/servicestub/README.md +++ b/sample-services/hello-world/README.md @@ -1,7 +1,7 @@ -# Hello World Service Stub +# Hello World Service This repository contains a Spring Boot application serving a Hello World endpoint. The application can be built and -run using the provided script - ``service-stub-build-start.sh``. +run using the provided script - ``hello-world-build-start.sh``. ## Prerequisites @@ -11,7 +11,7 @@ run using the provided script - ``service-stub-build-start.sh``. Run the script: ```bash - ./service-stub-build-start.sh + ./hello-world-build-start.sh ``` The script will build a Docker image and run a container with the Hello World service. After the container starts, @@ -19,19 +19,19 @@ wait for a few seconds to ensure the Spring Boot application is fully initialize Hello World endpoint and display the response: ```bash - response=$(curl -s http://localhost:8080/helloworld/v1/sme) - echo "Response from the Hello World SME endpoint:" + response=$(curl -s http://localhost:8080/helloworld/v1) + echo "Response from the Hello World endpoint:" echo "$response" ``` To stop and remove the Docker container: ```bash - docker stop service-stub-hello-world-test - docker rm service-stub-hello-world-test + docker stop hello-world + docker rm hello-world ``` ## Additional Information -- The Hello World SME endpoint is available at http://localhost:8080/helloworld/v1/sme. +- The Hello World endpoint is available at http://localhost:8080/helloworld/v1. diff --git a/test/servicestub/build.sh b/sample-services/hello-world/build.sh similarity index 98% rename from test/servicestub/build.sh rename to sample-services/hello-world/build.sh index bb0ff80a..5d1ad297 100644 --- a/test/servicestub/build.sh +++ b/sample-services/hello-world/build.sh @@ -29,7 +29,7 @@ if [ $# -ne 1 ] && [ $# -ne 2 ]; then print_usage fi -IMAGE_NAME="nonrtric-hello-world" +IMAGE_NAME="nonrtric-sample-helloworld" IMAGE_TAG="latest" REPO="" if [ $1 == "no-push" ]; then diff --git a/test/servicestub/container-tag.yaml b/sample-services/hello-world/container-tag.yaml similarity index 100% rename from test/servicestub/container-tag.yaml rename to sample-services/hello-world/container-tag.yaml diff --git a/test/servicestub/docker-compose.yml b/sample-services/hello-world/docker-compose.yml similarity index 93% rename from test/servicestub/docker-compose.yml rename to sample-services/hello-world/docker-compose.yml index b137ec16..4c2ac673 100644 --- a/test/servicestub/docker-compose.yml +++ b/sample-services/hello-world/docker-compose.yml @@ -23,7 +23,7 @@ version: "3.0" services: hello-world: build: - context: ./ + context: ../../sample-services/hello-world dockerfile: Dockerfile ports: - 8080:8080 \ No newline at end of file diff --git a/test/servicestub/service-stub-build-start.sh b/sample-services/hello-world/hello-world-build-start.sh similarity index 94% rename from test/servicestub/service-stub-build-start.sh rename to sample-services/hello-world/hello-world-build-start.sh index de641674..50014314 100644 --- a/test/servicestub/service-stub-build-start.sh +++ b/sample-services/hello-world/hello-world-build-start.sh @@ -20,8 +20,8 @@ # ========================LICENSE_END=================================== # -NAME="service-stub-hello-world-test" -IMAGE_NAME="nonrtric-hello-world" +NAME="hello-world" +IMAGE_NAME="nonrtric-sample-helloworld" docker build -t $IMAGE_NAME:latest . diff --git a/sample-services/hello-world/hello-world-chart/.helmignore b/sample-services/hello-world/hello-world-chart/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/sample-services/hello-world/hello-world-chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/test/servicestub/hello-world-chart/Chart.yaml b/sample-services/hello-world/hello-world-chart/Chart.yaml similarity index 100% rename from test/servicestub/hello-world-chart/Chart.yaml rename to sample-services/hello-world/hello-world-chart/Chart.yaml diff --git a/test/servicestub/hello-world-chart/templates/deployment.yaml b/sample-services/hello-world/hello-world-chart/templates/deployment.yaml similarity index 100% rename from test/servicestub/hello-world-chart/templates/deployment.yaml rename to sample-services/hello-world/hello-world-chart/templates/deployment.yaml diff --git a/test/servicestub/hello-world-chart/templates/service.yaml b/sample-services/hello-world/hello-world-chart/templates/service.yaml similarity index 98% rename from test/servicestub/hello-world-chart/templates/service.yaml rename to sample-services/hello-world/hello-world-chart/templates/service.yaml index fdd91440..d5b9f5d4 100644 --- a/test/servicestub/hello-world-chart/templates/service.yaml +++ b/sample-services/hello-world/hello-world-chart/templates/service.yaml @@ -31,7 +31,6 @@ spec: targetPort: http protocol: TCP name: http - nodePort: 30951 selector: {{- include "hello-world-chart.selectorLabels" . | nindent 4 }} diff --git a/test/servicestub/hello-world-chart/values.yaml b/sample-services/hello-world/hello-world-chart/values.yaml similarity index 91% rename from test/servicestub/hello-world-chart/values.yaml rename to sample-services/hello-world/hello-world-chart/values.yaml index 8856b1cb..fe54e8f8 100644 --- a/test/servicestub/hello-world-chart/values.yaml +++ b/sample-services/hello-world/hello-world-chart/values.yaml @@ -19,11 +19,11 @@ # image: - repository: nonrtric-hello-world + repository: nexus3.o-ran-sc.org:10003/nonrtric-sample-helloworld tag: latest service: name: hello-world - type: NodePort + type: ClusterIP port: 8080 diff --git a/test/servicestub/pom.xml b/sample-services/hello-world/pom.xml similarity index 95% rename from test/servicestub/pom.xml rename to sample-services/hello-world/pom.xml index e46ae58d..35848cd6 100644 --- a/test/servicestub/pom.xml +++ b/sample-services/hello-world/pom.xml @@ -28,7 +28,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.1 + 3.2.3 org.o-ran-sc.nonrtric.plt diff --git a/test/servicestub/src/main/java/org/oransc/nonrtric/sample/ServiceStubApplication.java b/sample-services/hello-world/src/main/java/org/oransc/nonrtric/sample/HelloWorldApplication.java similarity index 88% rename from test/servicestub/src/main/java/org/oransc/nonrtric/sample/ServiceStubApplication.java rename to sample-services/hello-world/src/main/java/org/oransc/nonrtric/sample/HelloWorldApplication.java index a28bec2f..d75a5aca 100644 --- a/test/servicestub/src/main/java/org/oransc/nonrtric/sample/ServiceStubApplication.java +++ b/sample-services/hello-world/src/main/java/org/oransc/nonrtric/sample/HelloWorldApplication.java @@ -24,8 +24,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages = "org.oransc.nonrtric.sample") -public class ServiceStubApplication { +public class HelloWorldApplication { public static void main(String[] args) { - SpringApplication.run(ServiceStubApplication.class, args); + SpringApplication.run(HelloWorldApplication.class, args); } } diff --git a/test/servicestub/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldController.java b/sample-services/hello-world/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldController.java similarity index 100% rename from test/servicestub/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldController.java rename to sample-services/hello-world/src/main/java/org/oransc/nonrtric/sample/rest/HelloWorldController.java diff --git a/test/servicestub/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java b/sample-services/hello-world/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java similarity index 100% rename from test/servicestub/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java rename to sample-services/hello-world/src/test/java/org/oransc/nonrtric/sample/rest/HelloWorldControllerTest.java diff --git a/test/servicestub/hello-world-chart/templates/_helpers.tpl b/test/servicestub/hello-world-chart/templates/_helpers.tpl deleted file mode 100644 index 5759827d..00000000 --- a/test/servicestub/hello-world-chart/templates/_helpers.tpl +++ /dev/null @@ -1,62 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "hello-world-chart.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "hello-world-chart.fullname" -}} -{{- if .Values.fullnameOverride }} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} -{{- end }} -{{- end }} -{{- end }} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "hello-world-chart.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "hello-world-chart.labels" -}} -helm.sh/chart: {{ include "hello-world-chart.chart" . }} -{{ include "hello-world-chart.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "hello-world-chart.selectorLabels" -}} -app.kubernetes.io/name: {{ include "hello-world-chart.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "hello-world-chart.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "hello-world-chart.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} -- 2.16.6