Uweheuerbackend: Difference between revisions

From Wiki RB4
 
(42 intermediate revisions by the same user not shown)
Line 5: Line 5:
==Architecture and Implementation==
==Architecture and Implementation==
===Environment Variables===
===Environment Variables===
* see 1. sheet 'Backend Environment Variables'
Environment variables are used to set [[SpringBoot#Application_Properties|application properties]] of this Spring Boot application:
* on a local Windows development laptop they are set as user specific environment variables (see <code>SetLocalEnv.bat</code>).
* for running from Ecplise they are set in run configuration
 
* see [[Uweheuerbackend#Documentation|Documentation]] 1. sheet 'Backend Environment Variables'


==ToDo==
==ToDo==
Line 16: Line 20:
** http://localhost:8080/backend/admin/updateSoftware
** http://localhost:8080/backend/admin/updateSoftware
** http://localhost:8080/backend/admin/getBuildTimestamp
** http://localhost:8080/backend/admin/getBuildTimestamp
** http://localhost:8080/backend/admin/showStartup
* Backend REST
* Backend REST
** http://localhost:8080/backend/menus/
** http://localhost:8080/backend/menus/
** http://localhost:8080/backend/menus/954eacd0-2e97-4e4a-b103-8ebcbfc77e0f
* Actuator
* Actuator
** http://localhost:8080/backend/actuator // list all endpoints
** http://localhost:8080/backend/actuator // list all endpoints
Line 31: Line 37:


===Local Docker===
===Local Docker===
* http://localhost:8080/backend/menus/
* Backend
* http://localhost:8080/backend/actuator/health
** http://localhost:8080/backend/menus/
* http://localhost:8080/backend/actuator/env
** http://localhost:8080/backend/actuator/health
* http://localhost:8080/backend/admin/import
** http://localhost:8080/backend/actuator/env
* Frontend http://localhost/
** Admin
* PHPMyAdmin http://localhost:8081/
*** http://localhost:8080/backend/admin/import
*** http://localhost:8080/backend/admin/showStartup
* Frontend http://localhost:80/
* PHPMyAdmin http://localhost:8081/ (see <code>.phpmyadmin.env</code>)


===Raspberry Docker via IP===
===Raspberry Docker via IP===
* Frontend http://192.168.178.72/fwdtest/
* Frontend http://192.168.178.72/fwdtest/
* Backend Admin
* Backend  
** Admin Backend Import http://192.168.178.72:8080/backend/admin/import
** Admin
** Admin Backend Version http://192.168.178.72:8080/backend/admin/getBuildTimestamp
*** Admin Backend Import http://192.168.178.72:8080/backend/admin/import
* Backend REST
*** Admin Backend Version http://192.168.178.72:8080/backend/admin/getBuildTimestamp
** http://192.168.178.72:8080/backend/menus/
*** Update Software http://192.168.178.72:8080/backend/admin/updateSoftware
* Actuator
*** Show Startup http://192.168.178.72:8080/backend/admin/showStartup
** http://192.168.178.72:8080/backend/actuator // list all endpoints
** REST
** http://192.168.178.72:8080/backend/actuator/health
*** http://192.168.178.72:8080/backend/menus/
** http://192.168.178.72:8080/backend/actuator/env
** Host Interface
** http://192.168.178.72:8080/backend/actuator/info
*** http://192.168.178.72:8091/rest/update_uweheuer
** http://192.168.178.72:8080/backend/actuator/httptrace
*** http://192.168.178.72:8091/actuator/health
** Actuator
*** http://192.168.178.72:8080/backend/actuator // list all endpoints
*** http://192.168.178.72:8080/backend/actuator/health
*** http://192.168.178.72:8080/backend/actuator/env
*** http://192.168.178.72:8080/backend/actuator/info
*** http://192.168.178.72:8080/backend/actuator/httptrace
* PHPMyAdmin http://192.168.178.72:8081/
* PHPMyAdmin http://192.168.178.72:8081/
* Portainer https://192.168.178.72:9443/ (use in Edge)
* Portainer https://192.168.178.72:9443/ (use in Edge)
Line 60: Line 75:
*** https://uweheuer.spdns.de/fwdtest/backend/admin/getBuildTimestamp
*** https://uweheuer.spdns.de/fwdtest/backend/admin/getBuildTimestamp
*** https://uweheuer.spdns.de/fwdtest/backend/admin/import
*** https://uweheuer.spdns.de/fwdtest/backend/admin/import
*** *** https://uweheuer.spdns.de/fwdtest/backend/admin/updateSoftware
*** https://uweheuer.spdns.de/fwdtest/backend/admin/updateSoftware
*** https://uweheuer.spdns.de/fwdtest/backend/admin/showStartup
** Backend REST
** Backend REST
*** https://uweheuer.spdns.de/fwdtest/backend/menus/
*** https://uweheuer.spdns.de/fwdtest/backend/menus/
Line 87: Line 103:
  uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace $ git clone https://github.com/UweHeuer/uweheuer-backend.git
  uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace $ git clone https://github.com/UweHeuer/uweheuer-backend.git
  uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace $ gh repo clone UweHeuer/uweheuer-frontend
  uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace $ gh repo clone UweHeuer/uweheuer-frontend
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace $ git clone https://github.com/UweHeuer/hostinterface.git


==Build==
==Build==
Line 104: Line 121:
* jar-file
* jar-file
  uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/uweheuer-backend $ mvn -DskipTests package
  uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/uweheuer-backend $ mvn -DskipTests package
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/hostinterface $ mvn -DskipTests package


===Docker===
===Docker===
* build image on all computers
* build image on all computers
  <PROJECT_PATH> docker build --tag uweheuerbackend .
  <PROJECT_PATH> docker build --tag uweheuerbackend .
==Test==
===Local from Command Line===
C:\Uwes\SoftwareProjects\eclipse-workspace\uweheuer-backend>mvn test
===Local from Eclipse===
[[File:Screenshot 2023-10-30 154825.png|400px]]


==Run==
==Run==


===Local from Command Line===
===Local from Command Line===
  C:\Uwes\SoftwareProjects\eclipse-workspace\uweheuer-backend>mvn spring-boot:run -Dspring-boot.run.arguments="--spring.datasource.password=mHalloo0@1m --spring.datasource.username=root --uweheuer.bookmarks.import.dbuser=root --uweheuer.bookmarks.import.dbpwd=mHalloo0@1m --uweheuer.bookmarks.parole=jakobthimo123456"
Uses the local environment variables (see [[Uweheuerbackend#Environment_Variables|here]])
# run MySQL
# start backend from command line
  C:\Uwes\SoftwareProjects\eclipse-workspace\uweheuer-backend>mvn spring-boot:run  
Additional settings could be set via adding <code>-Dspring-boot.run.arguments="--spring.datasource.password=xyz" </code>


===Local from Eclipse===
===Local from Eclipse===
* run MySQL
# run MySQL
* create Eclipse Run Configuration (picture outdated) [[File:SpringBootRunConfiguration1.png|400px]] [[File:SpringBootRunConfiguration2.png|400px]]
# use Eclipse Run Configuration (picture outdated) [[File:SpringBootRunConfiguration1.png|400px]] [[File:SpringBootRunConfiguration2.png|400px]]
** this creates a file <code>UweHeuerBackend Run SpringBoot Run Configuration.launch</code> in C:\Uwes\SoftwareProjects\eclipse-workspace\.metadata\.plugins\org.eclipse.debug.core\.launches\
## this creates a file <code>UweHeuerBackend Run SpringBoot Run Configuration.launch</code> in C:\Uwes\SoftwareProjects\eclipse-workspace\.metadata\.plugins\org.eclipse.debug.core\.launches\
*** if eclipse error occurs and run configuration is empty see [https://stackoverflow.com/questions/65720335/how-to-fix-eclipse-ide-run-configuration-problem-occurred-dialog here]. Add the two missing lines with value of project name 'uweheuer-backend'.
### if eclipse error occurs and run configuration is empty see [https://stackoverflow.com/questions/65720335/how-to-fix-eclipse-ide-run-configuration-problem-occurred-dialog here]. Add the two missing lines with value of project name 'uweheuer-backend'.
 
===Raspberry Hostinterface===
export UWEHEUER_HOSTINTERFACE_UPDATESOFTWARE_SCRIPT=/home/uwe/SoftwareProjects/eclipse-workspace/uweheuer-backend/BuildAndRunRaspberry.sh
nohup mvn spring-boot:run & // check by ps -e


===Docker Compose===
===Docker Compose===
* run all containers
* configuration see <code>docker-compose.yml</code> and <code>.compose.env</code>
 
====Local Windows Laptop====
# start Docker Desktop
# run all containers
C:\Uwes\SoftwareProjects\eclipse-workspace\uweheuer-backend>docker compose --env-file .compose.env up -d
* log files go to
CONTAINER_LOGS_FOLDER=C:/Uwes/ContainerLogs/uweheuerbackend (see .compose.env)
* database goes to
MYSQL_DB_FOLDER=C:/Uwes/MySQLContainerData/uweheuerbackend  (see .compose.env)
 
====Raspberry====
  uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/uweheuer-backend $ docker compose --env-file .compose.env up -d // using an local env file, run in background
  uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/uweheuer-backend $ docker compose --env-file .compose.env up -d // using an local env file, run in background
* stop all containers
* stop all containers
Line 154: Line 198:
* uses [https://logback.qos.ch/manual/layouts.html Logback]
* uses [https://logback.qos.ch/manual/layouts.html Logback]
* see <code>/src/main/resource/log-back-spring.xml</code>
* see <code>/src/main/resource/log-back-spring.xml</code>
** log files go to <code>./logs/</code> directory
** log files go to <code>/logs/</code> directory, which is in case of Docker mapped [[Uweheuerbackend#Docker_Compose|Docker Compose Configuration]]
** pattern
** pattern
*** %C{0} // print out without package name
*** %C{0} // print out without package name
*** %M // print out method name
*** %M // print out method name
* in a Docker environment <code>/logs/</code> is mapped via <code>.compose.env</code> to a local machine directory
* in a Docker environment <code>/logs/</code> is mapped via <code>.compose.env</code> to a local machine directory

Latest revision as of 21:32, 20 November 2023

Documentation[edit]

  1. https://miro.com/app/board/uXjVPuAgvI0=/
  2. C:\Uwes\owncloud\documents\Software_Development\MyDevelopments\uweheuer.drawio

Architecture and Implementation[edit]

Environment Variables[edit]

Environment variables are used to set application properties of this Spring Boot application:

  • on a local Windows development laptop they are set as user specific environment variables (see SetLocalEnv.bat).
  • for running from Ecplise they are set in run configuration

ToDo[edit]

APIs[edit]

Local Dev[edit]

Local Docker[edit]

Raspberry Docker via IP[edit]

Raspberry Docker via uweheuer.spdns.de[edit]

By Windows Powershell[edit]

curl.exe -X POST localhost:8080/menus -H “Content-type:application/json” -d '{ \"name\": \"test by curl\" }'

By Linux Command Shell[edit]

curl https://uweheuer.spdns.de/fwdtest/backend/admin/import

Installation[edit]

Raspberry[edit]

  • Git installation
  • Maven installation
  • Java installation
  • Login via gh auth login
  • Clone repositories
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace $ git clone https://github.com/UweHeuer/uweheuer-backend.git
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace $ gh repo clone UweHeuer/uweheuer-frontend
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace $ git clone https://github.com/UweHeuer/hostinterface.git

Build[edit]

  • build by Maven
  • setup on computer see here
  • steering of target environments by profiles in pom.xml:
    • local_dev (default)
    • heroku

Development Laptop[edit]

  • jar-file
C:\Uwes\SoftwareProjects\eclipse-workspace\uweheuer-backend>mvn -DskipTests package

Raspberry[edit]

  • get updates from repository
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/uweheuer-backend $ git pull
  • jar-file
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/uweheuer-backend $ mvn -DskipTests package
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/hostinterface $ mvn -DskipTests package

Docker[edit]

  • build image on all computers
<PROJECT_PATH> docker build --tag uweheuerbackend .

Test[edit]

Local from Command Line[edit]

C:\Uwes\SoftwareProjects\eclipse-workspace\uweheuer-backend>mvn test

Local from Eclipse[edit]

Run[edit]

Local from Command Line[edit]

Uses the local environment variables (see here)

  1. run MySQL
  2. start backend from command line
C:\Uwes\SoftwareProjects\eclipse-workspace\uweheuer-backend>mvn spring-boot:run 

Additional settings could be set via adding -Dspring-boot.run.arguments="--spring.datasource.password=xyz"

Local from Eclipse[edit]

  1. run MySQL
  2. use Eclipse Run Configuration (picture outdated)
    1. this creates a file UweHeuerBackend Run SpringBoot Run Configuration.launch in C:\Uwes\SoftwareProjects\eclipse-workspace\.metadata\.plugins\org.eclipse.debug.core\.launches\
      1. if eclipse error occurs and run configuration is empty see here. Add the two missing lines with value of project name 'uweheuer-backend'.

Raspberry Hostinterface[edit]

export UWEHEUER_HOSTINTERFACE_UPDATESOFTWARE_SCRIPT=/home/uwe/SoftwareProjects/eclipse-workspace/uweheuer-backend/BuildAndRunRaspberry.sh
nohup mvn spring-boot:run & // check by ps -e

Docker Compose[edit]

  • configuration see docker-compose.yml and .compose.env

Local Windows Laptop[edit]

  1. start Docker Desktop
  2. run all containers
C:\Uwes\SoftwareProjects\eclipse-workspace\uweheuer-backend>docker compose --env-file .compose.env up -d
  • log files go to
CONTAINER_LOGS_FOLDER=C:/Uwes/ContainerLogs/uweheuerbackend (see .compose.env)
  • database goes to
MYSQL_DB_FOLDER=C:/Uwes/MySQLContainerData/uweheuerbackend  (see .compose.env)

Raspberry[edit]

uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/uweheuer-backend $ docker compose --env-file .compose.env up -d // using an local env file, run in background
  • stop all containers
uwe@raspberrypi4:~/SoftwareProjects/eclipse-workspace/uweheuer-backend $ docker compose --env-file .compose.env down

Implementation[edit]

Spring Boot Standard Diagnosis Actuator[edit]

  • adding Spring Boot Actuator by adding to pom.xml:
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  • adding to application.properties all endpoints
management.endpoints.web.exposure.include=*
  • add class ActuatorHttpExchangesConfiguration for HTTP request logging

Calling Host from Backend Container[edit]

  • add to pom.xml
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
  • implement using WebClient

Set Build Timestamp[edit]

  • see pom.xml below spring-boot-maven-plugin and
  • AdminController.java BuildProperties attribute

Logging[edit]

  • uses Logback
  • see /src/main/resource/log-back-spring.xml
    • log files go to /logs/ directory, which is in case of Docker mapped Docker Compose Configuration
    • pattern
      • %C{0} // print out without package name
      • %M // print out method name
  • in a Docker environment /logs/ is mapped via .compose.env to a local machine directory