From bea93ab328b82836f0c54ad995cb9ea5467a3fa9 Mon Sep 17 00:00:00 2001 From: Hossein Rimaz Date: Mon, 2 Oct 2023 15:17:55 +0200 Subject: [PATCH 1/4] Fix submodelElements loss after calling $metamodel endpoint See issue #85 --- .../InMemorySubmodelRepository.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/InMemorySubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/InMemorySubmodelRepository.java index cb9159460..747735cba 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/InMemorySubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/InMemorySubmodelRepository.java @@ -34,6 +34,10 @@ import java.util.TreeMap; import java.util.stream.Collectors; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonSerializer; import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; @@ -220,8 +224,18 @@ public SubmodelValueOnly getSubmodelByIdValueOnly(String submodelId) { @Override public Submodel getSubmodelByIdMetadata(String submodelId) { Submodel submodel = getSubmodel(submodelId); - submodel.setSubmodelElements(null); - return submodel; + try { + String submodelAsJSON = new JsonSerializer().write(submodel); + Submodel submodelDeepCopy = new JsonDeserializer().readReferable(submodelAsJSON, Submodel.class); + submodelDeepCopy.setSubmodelElements(null); + return submodelDeepCopy; + } catch (DeserializationException e) { + e.printStackTrace(); + throw new RuntimeException("Unable to deserialize the Submodel"); + } catch (SerializationException e) { + e.printStackTrace(); + throw new RuntimeException("Unable to serialize the Submodel"); + } } @Override From 692b1839a7049ab69c82cb9baf928c04b355efae Mon Sep 17 00:00:00 2001 From: Hossein Rimaz Date: Wed, 4 Oct 2023 10:23:38 +0200 Subject: [PATCH 2/4] Improve exception handling --- .../submodelrepository/InMemorySubmodelRepository.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/InMemorySubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/InMemorySubmodelRepository.java index 747735cba..e22bbc98e 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/InMemorySubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/InMemorySubmodelRepository.java @@ -230,11 +230,9 @@ public Submodel getSubmodelByIdMetadata(String submodelId) { submodelDeepCopy.setSubmodelElements(null); return submodelDeepCopy; } catch (DeserializationException e) { - e.printStackTrace(); - throw new RuntimeException("Unable to deserialize the Submodel"); + throw new RuntimeException("Unable to deserialize the Submodel", e); } catch (SerializationException e) { - e.printStackTrace(); - throw new RuntimeException("Unable to serialize the Submodel"); + throw new RuntimeException("Unable to serialize the Submodel", e); } } From 7cae0e0caf2bd412aab4543856295434f21bed47 Mon Sep 17 00:00:00 2001 From: Hossein Rimaz Date: Thu, 5 Oct 2023 14:43:00 +0200 Subject: [PATCH 3/4] Add healthcheck in dockerfiles --- .../basyx.aasenvironment.component/Dockerfile | 3 ++- basyx.aasrepository/basyx.aasrepository.component/Dockerfile | 3 ++- .../basyx.conceptdescriptionrepository.component/Dockerfile | 3 ++- .../basyx.submodelrepository.component/Dockerfile | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile b/basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile index 6273bf177..d36367a6a 100644 --- a/basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile +++ b/basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile @@ -1,4 +1,4 @@ -FROM amazoncorretto:11 +FROM eclipse-temurin:17-jdk USER nobody WORKDIR /application ARG JAR_FILE=target/*-exec.jar @@ -6,4 +6,5 @@ COPY ${JAR_FILE} basyxExecutable.jar COPY src/main/resources/application.properties application.properties ARG PORT=8081 EXPOSE ${PORT} +HEALTHCHECK --interval=30s --timeout=12s --start-period=30s CMD curl --fail http://localhost:8081/shells || exit 1 ENTRYPOINT ["java","-jar","basyxExecutable.jar"] \ No newline at end of file diff --git a/basyx.aasrepository/basyx.aasrepository.component/Dockerfile b/basyx.aasrepository/basyx.aasrepository.component/Dockerfile index 6f239ba9b..6ba8b1c66 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/Dockerfile +++ b/basyx.aasrepository/basyx.aasrepository.component/Dockerfile @@ -1,4 +1,4 @@ -FROM amazoncorretto:11 +FROM eclipse-temurin:17-jdk USER nobody WORKDIR /application ARG JAR_FILE=target/*-exec.jar @@ -6,4 +6,5 @@ COPY ${JAR_FILE} basyxExecutable.jar COPY src/main/resources/application.properties application.properties ARG PORT=8081 EXPOSE ${PORT} +HEALTHCHECK --interval=30s --timeout=12s --start-period=30s CMD curl --fail http://localhost:8081/shells || exit 1 ENTRYPOINT ["java","-jar","basyxExecutable.jar"] diff --git a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component/Dockerfile b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component/Dockerfile index 6f239ba9b..a132a1484 100644 --- a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component/Dockerfile +++ b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component/Dockerfile @@ -1,4 +1,4 @@ -FROM amazoncorretto:11 +FROM eclipse-temurin:17-jdk USER nobody WORKDIR /application ARG JAR_FILE=target/*-exec.jar @@ -6,4 +6,5 @@ COPY ${JAR_FILE} basyxExecutable.jar COPY src/main/resources/application.properties application.properties ARG PORT=8081 EXPOSE ${PORT} +HEALTHCHECK --interval=30s --timeout=12s --start-period=30s CMD curl --fail http://localhost:8081/submodels || exit 1 ENTRYPOINT ["java","-jar","basyxExecutable.jar"] diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/Dockerfile b/basyx.submodelrepository/basyx.submodelrepository.component/Dockerfile index 6f239ba9b..bacb1fb45 100644 --- a/basyx.submodelrepository/basyx.submodelrepository.component/Dockerfile +++ b/basyx.submodelrepository/basyx.submodelrepository.component/Dockerfile @@ -1,4 +1,4 @@ -FROM amazoncorretto:11 +FROM eclipse-temurin:17-jdk USER nobody WORKDIR /application ARG JAR_FILE=target/*-exec.jar @@ -6,4 +6,6 @@ COPY ${JAR_FILE} basyxExecutable.jar COPY src/main/resources/application.properties application.properties ARG PORT=8081 EXPOSE ${PORT} +HEALTHCHECK --interval=30s --timeout=12s --start-period=30s CMD curl --fail http://localhost:8081/concept-descriptions || exit 1 + ENTRYPOINT ["java","-jar","basyxExecutable.jar"] From 9681fbd374260df539c5952307a0db45d5ae7a3c Mon Sep 17 00:00:00 2001 From: Hossein Rimaz Date: Thu, 5 Oct 2023 14:45:56 +0200 Subject: [PATCH 4/4] Revert base jdk image --- basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile | 2 +- basyx.aasrepository/basyx.aasrepository.component/Dockerfile | 2 +- .../basyx.conceptdescriptionrepository.component/Dockerfile | 2 +- .../basyx.submodelrepository.component/Dockerfile | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile b/basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile index d36367a6a..ee4535a3c 100644 --- a/basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile +++ b/basyx.aasenvironment/basyx.aasenvironment.component/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17-jdk +FROM amazoncorretto:11 USER nobody WORKDIR /application ARG JAR_FILE=target/*-exec.jar diff --git a/basyx.aasrepository/basyx.aasrepository.component/Dockerfile b/basyx.aasrepository/basyx.aasrepository.component/Dockerfile index 6ba8b1c66..6e2fe1b03 100644 --- a/basyx.aasrepository/basyx.aasrepository.component/Dockerfile +++ b/basyx.aasrepository/basyx.aasrepository.component/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17-jdk +FROM amazoncorretto:11 USER nobody WORKDIR /application ARG JAR_FILE=target/*-exec.jar diff --git a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component/Dockerfile b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component/Dockerfile index a132a1484..641d2d753 100644 --- a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component/Dockerfile +++ b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17-jdk +FROM amazoncorretto:11 USER nobody WORKDIR /application ARG JAR_FILE=target/*-exec.jar diff --git a/basyx.submodelrepository/basyx.submodelrepository.component/Dockerfile b/basyx.submodelrepository/basyx.submodelrepository.component/Dockerfile index bacb1fb45..65369658d 100644 --- a/basyx.submodelrepository/basyx.submodelrepository.component/Dockerfile +++ b/basyx.submodelrepository/basyx.submodelrepository.component/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17-jdk +FROM amazoncorretto:11 USER nobody WORKDIR /application ARG JAR_FILE=target/*-exec.jar @@ -7,5 +7,4 @@ COPY src/main/resources/application.properties application.properties ARG PORT=8081 EXPOSE ${PORT} HEALTHCHECK --interval=30s --timeout=12s --start-period=30s CMD curl --fail http://localhost:8081/concept-descriptions || exit 1 - ENTRYPOINT ["java","-jar","basyxExecutable.jar"]