Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • simonrose/naming-backend
  • anderslindh1/naming-backend
  • andersharrisson/naming-backend
3 results
Show changes
Commits on Source (83)
Showing
with 146 additions and 19 deletions
......@@ -3,6 +3,7 @@ target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.env
### STS ###
.apt_generated
......@@ -32,5 +33,8 @@ build/
### VS Code ###
.vscode/
### Eclipse ###
.settings/org.eclipse.jdt.core.prefs
### Docker ###
docker-compose-local*
variables:
CONTAINER_BRANCH_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
CONTAINER_BRANCH_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
stages:
- compile
......@@ -85,3 +85,26 @@ docker-release:
- docker push $CI_REGISTRY_IMAGE:latest
only:
- main
.deploy:
stage: deploy
image: registry.esss.lu.se/ics-docker/awxkit
tags:
- docker
script:
- >
awx job_templates launch ${AWX_JOB_TEMPLATE}
--extra_vars "naming_container_image_tag: $CI_COMMIT_REF_SLUG"
--monitor
dependencies: []
only:
- branches@ics-software/naming-backend
when: manual
deploy-test-02:
extends: .deploy
variables:
AWX_JOB_TEMPLATE: deploy-naming-test-02
environment:
name: test-02
url: https://naming-test-02.cslab.esss.lu.se
......@@ -7,4 +7,4 @@ FROM openjdk:17
# deployment unit
COPY target/naming-backend-*.jar /naming/naming-backend.jar
CMD ["java", "-jar", "/naming/naming-backend.jar", "--spring.config.name=application-docker"]
CMD ["java", "-jar", "/naming/naming-backend.jar", "--spring.config.name=application"]
# naming-backend
# Naming
The purpose of Naming is to handle Naming of ESS wide physical and logical devices according to ESS Naming Convention.
## Naming backend
Naming backend is a web application implemented as a REST style web service backed by a relational database. The web service is implemented as a Spring Boot application and the database is available as PostgreSQL.
Background and motivation, application and database design, and more, is available through content in docs folder.
### Environment
Tools
* Java 17 (openjdk)
* Maven 3.8+ (e.g. 3.8.5)
* PostgreSQL (9.6 client lib)
* Docker (docker, docker-compose)
* Git
Dependencies
* postgresql
* springdoc
* springframework
* testcontainers
### Set up development environment and test
#### Checkout and build
* ```git clone https://gitlab.esss.lu.se/ics-software/naming-backend.git```
* ```cd directory```
* ```mvn clean install```
#### Start application (with database)
Either
* start the application and database
* ```docker-compose up --build```
or
* make sure database available as in ```src/main/resources/application.properties```
* start the application
* ```java -jar target/naming-backend-*.jar```
Then
* browse to ```http://localhost:8080/swagger-ui.html```
#### Integration tests with Docker containers
See ```src/test/java``` and packages
* ```org.openepics.names.docker```
* ```org.openepics.names.docker.complex```
JUnit tests start a docker container for the application (Naming backend) and another docker container for the database (Postgresql) through ```docker-compose-integrationtest.yml```.
```
@Container
public static final DockerComposeContainer<?> ENVIRONMENT =
new DockerComposeContainer<>(new File("docker-compose-integrationtest.yml"))
.waitingFor(ITUtil.NAMING, Wait.forLogMessage(".*Started NamingApplication.*", 1));
```
Thereafter a number of http requests (GET) and curl commands (POST, PUT, PATCH, DELETE) are run towards the application to test behavior (CRUD - create, read, update, delete) and replies are received and checked if content is as expected.
#### Note
* Pre-populated database to be available if data to be available at start of application. Otherwise database may be populated through ```curl``` at command line or Swagger UI.
* See ```src/main/resources``` and sub folders for database scripts.
* If no prior database is available, see integration tests for examples on how to populate database. E.g. tests may be debugged and database content may be examined at any debug point. It's possible to backup database at such debug point and later restore it outside test. In such way, database may be set to state of choice.
#### Recommentation
* Have local docker-compose file for database alone if there is need to backup or restore database.
......@@ -8,6 +8,8 @@ services:
build: ./
ports:
- "8080:8083"
environment:
keycloak.enabled: "false"
depends_on:
postgres:
condition: service_healthy
......
File added
File added
File added
File added
......@@ -718,6 +718,35 @@ BEGIN
END;
$$;
CREATE OR REPLACE FUNCTION public.get_instance_index(convention_name text)
RETURNS text
LANGUAGE plpgsql
AS
$$
DECLARE
len int;
pos int;
mnemonic_path text;
nbr_delimiters int;
BEGIN
pos = strpos(convention_name, ':');
IF pos > 0 THEN
mnemonic_path = substr(convention_name, pos+1);
nbr_delimiters = array_length(string_to_array(mnemonic_path, '-'), 1) - 1;
IF nbr_delimiters = 2 then
mnemonic_path = reverse(mnemonic_path);
len = length(mnemonic_path);
pos = strpos(mnemonic_path, '-');
mnemonic_path = reverse(mnemonic_path);
RETURN substr(mnemonic_path, len - pos + 2);
ELSE
RETURN null;
END IF;
END IF;
RETURN null;
END;
$$;
CREATE OR REPLACE FUNCTION get_mnemonic_path_system(system_uuid text)
RETURNS text
LANGUAGE plpgsql
......@@ -725,15 +754,10 @@ AS
$$
DECLARE
system_mnemonic text;
systemgroup_uuid text;
systemgroup_mnemonic text;
BEGIN
select parent_uuid, mnemonic into systemgroup_uuid, system_mnemonic from "system" where uuid = system_uuid and latest = true;
select mnemonic into systemgroup_mnemonic from systemgroup where uuid = systemgroup_uuid and latest = true;
select mnemonic into system_mnemonic from "system" where uuid = system_uuid and latest = true;
if systemgroup_mnemonic is not null and system_mnemonic is not null then
return concat(systemgroup_mnemonic, '-', system_mnemonic);
elsif system_mnemonic is not null then
if system_mnemonic is not null then
return system_mnemonic;
else
return null;
......@@ -750,19 +774,12 @@ DECLARE
subsystem_mnemonic text;
system_uuid text;
system_mnemonic text;
systemgroup_uuid text;
systemgroup_mnemonic text;
BEGIN
select parent_uuid, mnemonic into system_uuid, subsystem_mnemonic from subsystem where uuid = subsystem_uuid and latest = true;
select parent_uuid, mnemonic into systemgroup_uuid, system_mnemonic from "system" where uuid = system_uuid and latest = true;
select mnemonic into systemgroup_mnemonic from systemgroup where uuid = systemgroup_uuid and latest = true;
select mnemonic into system_mnemonic from "system" where uuid = system_uuid and latest = true;
if systemgroup_mnemonic is not null and system_mnemonic is not null and subsystem_mnemonic is not null then
return concat(systemgroup_mnemonic, '-', system_mnemonic, '-', subsystem_mnemonic);
elsif system_mnemonic is not null and subsystem_mnemonic is not null then
if system_mnemonic is not null and subsystem_mnemonic is not null then
return concat(system_mnemonic, '-', subsystem_mnemonic);
elsif subsystem_mnemonic is not null then
return subsystem_mnemonic;
else
return null;
end if;
......
Developer documentation
Purpose to help understand application, database and in between.
Created on Ubuntu 18.04 LTS with LibreOffice (6.0.7.3)(Draw, Writer), GNOME Screenshot, Krita (4.3.0).
Document ".odt" exported to ".pdf".
File added