Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump to 2.1.1 #70

Merged
merged 8 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test_helm_chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:

- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 'latest'
token: ${{ secrets.GITHUB_TOKEN }}

- name: Helm Check Action
uses: hopisaurus/helm-check-action@v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions agrold-javaweb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build stage
FROM maven:3.9-amazoncorretto-8 as build
FROM maven:3.9-amazoncorretto-17 as build
# Shared arguments between build and run stages

ARG AGROLD_NAME=aldp
Expand All @@ -11,7 +11,7 @@ COPY . /build_dir
RUN mvn clean install -Dagrold.name=${AGROLD_NAME}

# Run stage
FROM bitnami/tomcat:8.5
FROM bitnami/tomcat:9.0

ARG GIT_COMMIT=unknown
ARG AGROLD_NAME=aldp
Expand Down
51 changes: 21 additions & 30 deletions agrold-javaweb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@

### Cloner l'appli

- `git clone --branch dev `
-
- `git clone --branch dev`

Vous pourrez voir comment paramétrer votre IDE dans [la section appropriée sur le Notion](https://agrold-wiki.notion.site/Configurer-et-utiliser-son-IDE-pour-les-projets-cbf2dc48224f48009a9c0775a173a6d5)

### Deployer l'appli web

#### Pré requis

- Tomcat 7/8
- Tomcat 7/8/9
- JDK 17
- Maven
- mysql (sera bientôt agnostique ou retiré)
- Docker (optionnel)

#### Paramètres

Le déploiement de l'application se fait premièrement avec des propriétés Java passées à tomcat.

| Name | Description | Valeur par défaut |
| :------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------: |
| `agrold.name` | Nom de l'archive et du contexte (le nom apparait après `agrold.baseurl` , par exemple si on met la valeur à `aldp` on a `https://someurl/agrold`) | `aldp` |
| `agrold.description` | Description affichée dans Tomcat | :x: |
| `agrold.baseurl` | L'URL de base de l'app | `http://localhost:8080/` |
| `agrold.sparql_endpoint` | Url de l'endpoint SPARQL | `http://sparql.southgreen.fr` |
| `agrold.db_connection_url` | Url de la base de données ex: `[host]:[port]/[db]?[opt]` | :x: (requis) |
| `agrold.db_username` | Utilisateur de la base de données | :x: (requis) |
| `agrold.db_password` | Mot de passe de la base de données | :x: (requis) |
| `agrold.rf_link` | Lien vers une instance de RelFinder[Reformed] | `http://rf.southgreen.fr/` |
| Name | Description | Valeur par défaut |
| :------------------------: | :------------------------------------------------------------------------: | :---------------------------: |
| `agrold.name` | Nom de l'archive et du contexte `aldp` on a `https://<un domaine>/agrold`) | `aldp` |
| `agrold.description` | Description affichée dans Tomcat | :x: |
| `agrold.sparql_endpoint` | Url de l'endpoint SPARQL | `http://sparql.southgreen.fr` |
| `agrold.db_connection_url` | Url de la base de données ex: `[host]:[port]/[db]?[opt]` | :x: |
| `agrold.db_username` | Utilisateur de la base de données | :x: |
| `agrold.db_password` | Mot de passe de la base de données | :x: |
| `agrold.rf_link` | Lien vers une instance de RelFinder[Reformed] | `http://rf.southgreen.fr/` |

Pour injecter ces variables dans tomcat, il faut déclarer les sous forme d'argument en ligne de commande sous cette forme `-Dnomdelapropriété=valeur` et les placer dans la variable d'environnement `CATALINA_OPTS`

Expand All @@ -40,26 +41,18 @@ Par exemple:

```bash
# Directement sur l'hôte
export CATALINA_OPTS="-Dagrold.db_connection_url=someurlhere -Dagrold.db_username=usr -Dagrold.db_password=pwd"
export CATALINA_OPTS="-Dagrold.blabla=valeur"
catalina.sh
```

```java
...
String URL = System.getProperty("agrold.db_connection_url");
String usr = System.getProperty("agrold.db_username");
String pwd = System.getProperty("agrold.db_password");
...
```

Si vous lancez tomcat avec systemd le remplissage des variables d'environnement se fait ainsi

```bash
sudo systemctl edit tomcat8 #ou tomcat7
sudo systemctl edit tomcat8 #ou tomcat7/9

# dans l'éditeur
[Service]
Environment="CATALINA_OPTS='-Dagrold.db_connection_url=someurlhere -Dagrold.db_username=usr -Dagrold.db_password=pwd'"
Environment="CATALINA_OPTS='-Dagrold.blabla=valeur'"
```

Pour compiler lancez maven à la racine du projet, Il est possible de passer la propriété `agrold.name` en argument de maven
Expand All @@ -72,24 +65,22 @@ mvn clean install
mvn clean install -Dagrold.name=un_nom # vous accéderez à l'application via https://<votre url>/un_nom
```

````

Si vous utilisez docker:

```bash
cd agrold-javaweb/

# Vous pouvez utiliser le dockerfile
# le mot de passe du manager
docker build . -t <tag> --build-arg TOMCAT_PASSWORD=a --build-arg AGROLD_NAME=agrolddev
# la valeur de agrold.name
docker build . -t <tag> --build-arg AGROLD_NAME=agrolddev

# Ou pull l'image stockée depuis le registre dans l'environnement de développement,
docker login 10.9.2.21:8080 -u <user> -p <password>
docker pull 10.9.2.21:8080

# Lancer le conteneur
docker run -p 8080:8080 -e CATALINA_OPTS="-Dagrold.db_connection_url=someurl -Dagrold.db_username=usr -Dagrold.db_password=pwd -Dagrold.baseurl=http://localhost:8080/ -Dagrold.sparql_endpoint=a" <tag>
````
docker run -p 8080:8080 <tag>
```

> [!NOTE]
> À noter que l'image docker crée prend pour base l'image [bitnami/tomcat](https://hub.docker.com/r/bitnami/tomcat/). Cela veut dire que vous pouvez configurer l'image d'AgroLD comme celle de bitnami sur certain points nottament la configuration de l'utilisateur manager de tomcat.
Expand Down
4 changes: 2 additions & 2 deletions agrold-javaweb/charts/agrold-javaweb/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ annotations:
image: docker.io/bitnami/tomcat:10.1.20-debian-12-r0
licenses: Apache-2.0
apiVersion: v2
appVersion: 2.1.0
appVersion: 2.1.1
dependencies:
- name: common
repository: oci://registry-1.docker.io/bitnamicharts
Expand Down Expand Up @@ -46,4 +46,4 @@ name: agrold
sources:
- https://github.com/bitnami/charts/tree/main/bitnami/tomcat
- https://github.com/SouthGreenPlatform/AgroLD_webapp
version: 2.0.0
version: 2.0.1
4 changes: 2 additions & 2 deletions agrold-javaweb/charts/agrold-javaweb/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Return the proper CATALINA_OPTS value
{{- define "tomcat.catalinaOpts" -}}
{{- $agrold := include "tomcat.flattenIntoSysProperties" .Values.agroldProperties -}}
{{- if .Values.metrics.jmx.enabled -}}
{{- default "" (cat .Values.catalinaOpts .Values.metrics.jmx.catalinaOpts (printf "-Dagrold.baseurl=%q" (ternary (print "https://" .Values.ingress.hostname) (print "http://" .Values.ingress.hostname) .Values.ingress.tls)) $agrold) | trim -}}
{{- default "" (cat .Values.catalinaOpts .Values.metrics.jmx.catalinaOpts $agrold) | trim -}}
{{- else -}}
{{- default "" (cat .Values.catalinaOpts (printf "-Dagrold.baseurl=%q" (ternary (print "https://" .Values.ingress.hostname) (print "http://" .Values.ingress.hostname) .Values.ingress.tls)) $agrold) | trim -}}
{{- default "" (cat .Values.catalinaOpts $agrold) | trim -}}
{{- end -}}
{{- end -}}

Expand Down
4 changes: 1 addition & 3 deletions agrold-javaweb/charts/agrold-javaweb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
##

agroldProperties:
# The property below is set to ingress.hostname, set this value to override it
# baseurl: "http://agrold.org"
db_connection_url: someurl
db_username: user
db_password: password
Expand Down Expand Up @@ -77,7 +75,7 @@ extraDeploy: []
image:
registry: ghcr.io
repository: southgreenplatform/agrold
tag: 2.0.0
tag: 2.1.1
digest: ""
## Specify a imagePullPolicy
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
Expand Down
2 changes: 1 addition & 1 deletion agrold-javaweb/charts/virtuoso/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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: 1.0.0
version: 1.0.1

# 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
Expand Down
4 changes: 2 additions & 2 deletions agrold-javaweb/charts/virtuoso/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ metadata:
name: secrets-{{ $fullName }}
type: Opaque
data:
DAVPassword: {{ .Values.DAVPassword | b64enc | quote }}
DBAPassword: {{ .Values.DBAPassword | b64enc | quote }}
DAVPassword: {{ .Values.DAVPassword | default (randAlphaNum 32) | b64enc | quote }}
DBAPassword: {{ .Values.DBAPassword | default (randAlphaNum 32) | b64enc | quote }}

6 changes: 2 additions & 4 deletions agrold-javaweb/charts/virtuoso/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ initdb:
enabled: true
name: sparql-initdb
kind: ConfigMap
data:
init.sh: |
#!/bin/bash
echo "Ready to go!"
data: {}


persistence:
enabled: true
Expand Down
28 changes: 14 additions & 14 deletions agrold-javaweb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>agrold</groupId>
<artifactId>agrold</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
<packaging>war</packaging>


Expand Down Expand Up @@ -45,17 +45,17 @@
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
<version>2.4.0-b180830.0359</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
<version>4.0.5</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
<version>4.0.5</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
Expand All @@ -70,57 +70,57 @@
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.26</version>
<version>2.42</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.26</version>
<version>2.42</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
<version>2.42</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.26</version>
<version>2.42</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
<version>20240303</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<version>2.10.1</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private MySQLProperties(){
/* prevent usage of constructor bcause it's a static class */
}


// TODO: Change how it is handled, this will be replaced by cookies since it is just for history purposes
/**
*
* @return an ArrayList of String with the lines of the text in the same
Expand All @@ -39,13 +39,9 @@ private MySQLProperties(){
public static List<String> readLoginConfigurations() {
List<String> lines = new ArrayList<>();
try {
String URL = System.getProperty("agrold.db_connection_url");
String usr = System.getProperty("agrold.db_username");
String pwd = System.getProperty("agrold.db_password");

if (URL == null) throw new NullPointerException("Missing system property: agrold.db_connection_url");
if (usr == null) throw new NullPointerException("Missing system property: agrold.db_username");
if (pwd == null) throw new NullPointerException("Missing system property: agrold.db_password");
String URL = System.getProperty("agrold.db_connection_url", "");
String usr = System.getProperty("agrold.db_username", "");
String pwd = System.getProperty("agrold.db_password", "");

lines.add(URL);
lines.add(usr);
Expand Down
21 changes: 11 additions & 10 deletions agrold-javaweb/src/main/java/agrold/webservices/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
Expand Down Expand Up @@ -95,15 +96,15 @@ String inputStream2String(InputStream incomingData){
@GET
// @Consumes(MediaType.APPLICATION_JSON) // for "in body parameters"
@Path("/customizable/{serviceLocalName}")
public Response genericGet(@PathParam("serviceLocalName") String serviceLocalName, @Context UriInfo uriInfo, @Context HttpHeaders headers) throws IOException {
public Response genericGet(@PathParam("serviceLocalName") String serviceLocalName, @Context UriInfo uriInfo, @Context HttpHeaders headers) throws IOException {
List<MediaType> mediaTypes = headers.getAcceptableMediaTypes();
MediaType reponseMediaType = mediaTypes.get(0);
if (reponseMediaType == null) {
return Response.serverError()
.entity("[AgroLD Web Services] - Format Error: The requested resource is not available in the format \"" + mediaTypes.get(0) + "\"")
.build();
}
String content = CustomizableServicesManager.queryCustomizableService(serviceLocalName, uriInfo.getQueryParameters(), "get", reponseMediaType);
String content = CustomizableServicesManager.queryCustomizableService(serviceLocalName, uriInfo.getQueryParameters(), "get", reponseMediaType, headers.HOST);
return buildResponse(content, reponseMediaType.toString());
}

Expand All @@ -122,8 +123,8 @@ public Response genericGet(@PathParam("serviceLocalName") String serviceLocalNam
// generic web service for modifiables ones
@GET
@Path("/webservices")
public Response getAPISpecification() throws IOException {
String content = CustomizableServicesManager.readAPISpecification(Utils.AGROLDAPIJSONURL);
public Response getAPISpecification(@HeaderParam("Host") String host) throws IOException {
String content = CustomizableServicesManager.readAPISpecification(Utils.AGROLDAPIJSONURL, host);
return buildResponse(content, Utils.JSON);
}

Expand All @@ -132,24 +133,24 @@ public Response getAPISpecification() throws IOException {
@DELETE
@Produces(MediaType.TEXT_PLAIN)
@Path("/webservices")
public Response deleteService(@QueryParam("name") String name, @QueryParam("httpMethod") String httpMethod) throws IOException {
String content = CustomizableServicesManager.deleteService(name, httpMethod);
public Response deleteService(@QueryParam("name") String name, @QueryParam("httpMethod") String httpMethod, @HeaderParam("Host") String host) throws IOException {
String content = CustomizableServicesManager.deleteService(name, httpMethod, host);
return buildResponse(content, MediaType.TEXT_PLAIN);
}

@RolesAllowed("ADMIN")
@PUT
@Path("/webservices")
public Response addService(@QueryParam("name") String name, @QueryParam("httpMethod") String httpMethod, InputStream specificationDataStream) throws IOException {
String content = CustomizableServicesManager.addService(name, httpMethod, inputStream2String(specificationDataStream));
public Response addService(@QueryParam("name") String name, @QueryParam("httpMethod") String httpMethod, InputStream specificationDataStream, @HeaderParam("Host") String host) throws IOException {
String content = CustomizableServicesManager.addService(name, httpMethod, inputStream2String(specificationDataStream), host);
return buildResponse(content, MediaType.TEXT_PLAIN);
}

@RolesAllowed("ADMIN")
@POST
@Path("/webservices")
public Response updateService(@QueryParam("name") String name, @QueryParam("httpMethod") String httpMethod, InputStream specificationDataStream) throws IOException {
String content = CustomizableServicesManager.updateService(name, httpMethod, inputStream2String(specificationDataStream));
public Response updateService(@QueryParam("name") String name, @QueryParam("httpMethod") String httpMethod, InputStream specificationDataStream, @HeaderParam("Host") String host) throws IOException {
String content = CustomizableServicesManager.updateService(name, httpMethod, inputStream2String(specificationDataStream), host);
return buildResponse(content, MediaType.TEXT_PLAIN);
}

Expand Down
Loading
Loading