From ea8647cb043a7be2668d568f34207df8af056acd Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Tue, 6 Feb 2024 08:28:53 +0100 Subject: [PATCH 1/4] docs: extended local/INSTALL.md --- local/INSTALL.md | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/local/INSTALL.md b/local/INSTALL.md index 2c265ebb..ca3239cc 100644 --- a/local/INSTALL.md +++ b/local/INSTALL.md @@ -1,32 +1,54 @@ -# Initial Setup +# Creating a local testing and development setup via Docker + +## Additional information for Windows users + +If you want to use the local setup on a Windows machine, it seems advisable to use the Windows subsystem for Linux (WSL). +An installation guide can be found [here](https://learn.microsoft.com/en-us/windows/wsl/install). + +Also see this [additional information about using Docker in combination with WSL2](https://docs.docker.com/desktop/wsl/) + +## Initial Setup In case you had any previous installations of this project on your machine, it is advisable to remove them via the script -(see below in the Notes on debugging section). +(see below in the Notes on debugging section). Run the following script to generate the necessary keys. It will also create an .env file in the ./local folder. -Make sure to have `openssl` and `jq` installed in your shell. +Make sure to have `openssl` and `jq` installed in your shell. openssl is pre-installed on most operating systems. jq can be +installed via the usual installation repositories, see [here](https://jqlang.github.io/jq/download/) ```shell cd local sh generate-keys.sh ``` -# Build +## Build If you are doing a fresh install and everytime you edited the code of the PURIS frontend or backend you have to create a new build of docker images for the PURIS frontend/backend. +For creating a docker image of the frontend, navigate your shell to the frontend folder and run + +``` +docker build -t puris-frontend:dev . +``` + +For creating a docker image of the backend, navigate your shell to the backend folder and run + +``` +docker build -t puris-backend:dev . +``` + Please see the INSTALL.md documents in the [frontend](../frontend/INSTALL.md) and [backend](../backend/INSTALL.md) The default image tag is 'dev'. Remember to also adjust the tag in the docker-compose.yaml if you want to use different tags. -# Start -First start the infrastructure: +## Start +First start the infrastructure by navigating your shell to the local folder and running ```shell docker compose -f docker-compose-infrastructure.yaml up ``` -After the MIW container has finished booting, use this script to initialise two wallets for customer and supplier: +After the MIW container has finished booting, use this script (also in the local folder) to initialise two wallets for customer and supplier: ```shell -sh ./init-wallets.sh +sh init-wallets.sh ``` Then start the PURIS demonstrator containers via: ```shell From 2ff142cfbd3f71269afbbe48b3d2cdc0b222df78 Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Tue, 6 Feb 2024 08:51:47 +0100 Subject: [PATCH 2/4] docs: added re-build infos --- local/INSTALL.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/local/INSTALL.md b/local/INSTALL.md index ca3239cc..4228351e 100644 --- a/local/INSTALL.md +++ b/local/INSTALL.md @@ -56,6 +56,24 @@ docker compose up ``` Wait for the startup and visit http://localhost:3000/ for the customer's frontend or http://localhost:3001/ for the supplier side. +Whenever you have edited the source code in the frontend or backend and you want to test these changes, we recommend that you +stop all the containers, which are not part of the infrastructure, by deleting the volumes, i.e. run + +``` +docker compose down -v +``` + +Then, build a new docker image for the respective component (frontend and/or backend) as described above and then restart via + +```shell +docker compose up +``` + +In general, it is not necessary to restart the infrastructure, if you had to rebuild frontend or backend. +However, in rare cases there may be issues with the MIW. If this +happens, you should use the cleanup script as mentioned in the debugging section below and then repeat the above-mentioned +steps beginning with the Initial Setup section. + ## Notes on debugging ### Vault & Certs From 6274bf07b6e3db06d53dea7b04a8b165152dd04c Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Tue, 6 Feb 2024 08:57:01 +0100 Subject: [PATCH 3/4] chore: more distinctive pg container name --- local/docker-compose-infrastructure.yaml | 2 +- local/miw/infrastructure.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/local/docker-compose-infrastructure.yaml b/local/docker-compose-infrastructure.yaml index c1fb7376..5c32f92b 100644 --- a/local/docker-compose-infrastructure.yaml +++ b/local/docker-compose-infrastructure.yaml @@ -33,7 +33,7 @@ services: postgres: image: postgres:15.4-alpine - container_name: postgres + container_name: postgres-miw environment: POSTGRES_DB: edc POSTGRES_USER: ${PG_USER} diff --git a/local/miw/infrastructure.properties b/local/miw/infrastructure.properties index cef54260..be43806d 100644 --- a/local/miw/infrastructure.properties +++ b/local/miw/infrastructure.properties @@ -21,7 +21,7 @@ AUTH_SERVER_URL=http://keycloak:8080 APPLICATION_PORT=80 MANAGEMENT_PORT=8090 APPLICATION_ENVIRONMENT=dev -DB_HOST=postgres +DB_HOST=postgres-miw DB_PORT=5432 USE_SSL=false DB_USER=${PG_USER} From 75ccfa546a0eaee434a3c81d06c74eda9aff4098 Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Tue, 6 Feb 2024 14:00:34 +0100 Subject: [PATCH 4/4] fix: initial commit --- .../controller/ItemStockRequestApiController.java | 4 ++-- .../logic/service/ItemStockRequestApiService.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/controller/ItemStockRequestApiController.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/controller/ItemStockRequestApiController.java index a0e3355a..43369d3a 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/controller/ItemStockRequestApiController.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/controller/ItemStockRequestApiController.java @@ -84,9 +84,9 @@ public ResponseEntity postMapping(@RequestBody ItemSt return ResponseEntity.status(422).body(new RequestReactionMessageDto(requestMessageDto.getHeader().getMessageId())); } switch (requestMessageDto.getContent().getDirection()) { - case INBOUND -> - executorService.submit(() -> itemStockRequestApiService.handleRequestFromCustomer(requestMessageDto, createdRequestMessage)); case OUTBOUND -> + executorService.submit(() -> itemStockRequestApiService.handleRequestFromCustomer(requestMessageDto, createdRequestMessage)); + case INBOUND -> executorService.submit(() -> itemStockRequestApiService.handleRequestFromSupplier(requestMessageDto, createdRequestMessage)); default -> { log.warn("Missing direction in request \n" + requestMessageDto); diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ItemStockRequestApiService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ItemStockRequestApiService.java index 4c504350..7bf61264 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ItemStockRequestApiService.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ItemStockRequestApiService.java @@ -79,10 +79,10 @@ public class ItemStockRequestApiService { public void handleRequestFromCustomer(ItemStockRequestMessageDto requestMessageDto, ItemStockRequestMessage requestMessage) { var requestMessageHeader = requestMessageDto.getHeader(); Partner customerPartner = partnerService.findByBpnl(requestMessageHeader.getSenderBpn()); - if (customerPartner == null || requestMessageDto.getContent().getDirection() != DirectionCharacteristic.INBOUND) { + if (customerPartner == null || requestMessageDto.getContent().getDirection() != DirectionCharacteristic.OUTBOUND) { requestMessage.setState(DT_RequestStateEnum.Error); itemStockRequestMessageService.update(requestMessage); - if(requestMessageDto.getContent().getDirection() != DirectionCharacteristic.INBOUND){ + if(requestMessageDto.getContent().getDirection() != DirectionCharacteristic.OUTBOUND){ log.error("Wrong direction in request from customer \n" + requestMessageDto); } if(customerPartner == null) { @@ -140,10 +140,10 @@ public void handleRequestFromCustomer(ItemStockRequestMessageDto requestMessageD public void handleRequestFromSupplier(ItemStockRequestMessageDto requestMessageDto, ItemStockRequestMessage requestMessage) { var requestMessageHeader = requestMessageDto.getHeader(); Partner supplierPartner = partnerService.findByBpnl(requestMessageHeader.getSenderBpn()); - if (supplierPartner == null || requestMessageDto.getContent().getDirection() != DirectionCharacteristic.OUTBOUND) { + if (supplierPartner == null || requestMessageDto.getContent().getDirection() != DirectionCharacteristic.INBOUND) { requestMessage.setState(DT_RequestStateEnum.Error); itemStockRequestMessageService.update(requestMessage); - if(requestMessageDto.getContent().getDirection() != DirectionCharacteristic.OUTBOUND){ + if(requestMessageDto.getContent().getDirection() != DirectionCharacteristic.INBOUND){ log.error("Wrong direction in request from customer \n" + requestMessageDto); } if(supplierPartner == null) { @@ -242,7 +242,7 @@ private void sendResponse(Partner partner, ItemStockResponseDto responseDto, Ite */ public void doRequestForMaterialItemStocks(Partner supplierPartner, Material... materials) { ItemStockRequestMessage itemStockRequestMessage = getItemStockRequestMessage(supplierPartner); - itemStockRequestMessage.setDirection(DirectionCharacteristic.INBOUND); + itemStockRequestMessage.setDirection(DirectionCharacteristic.OUTBOUND); for (var material : materials) { ItemStockRequestMessage.Request request = new ItemStockRequestMessage.Request(); request.setMaterialGlobalAssetId(material.getMaterialNumberCx()); @@ -262,7 +262,7 @@ public void doRequestForMaterialItemStocks(Partner supplierPartner, Material... */ public void doRequestForProductItemStocks(Partner customerPartner, Material... materials) { ItemStockRequestMessage itemStockRequestMessage = getItemStockRequestMessage(customerPartner); - itemStockRequestMessage.setDirection(DirectionCharacteristic.OUTBOUND); + itemStockRequestMessage.setDirection(DirectionCharacteristic.INBOUND); for (var material : materials) { ItemStockRequestMessage.Request request = new ItemStockRequestMessage.Request(); request.setMaterialGlobalAssetId(material.getMaterialNumberCx());