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

Integrate RiseClipse as Validator in CoMPAS SCL Validator #21

Merged
merged 24 commits into from
Mar 3, 2022
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
6 changes: 2 additions & 4 deletions .github/workflows/build-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
Expand All @@ -48,9 +50,5 @@ jobs:
with:
output_file: custom_maven_settings.xml
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
- name: Build Native with Maven
if: ${{ github.event_name == 'pull_request' }}
run: ./mvnw -s custom_maven_settings.xml -B -Pnative clean verify
- name: Build with Maven
if: ${{ github.event_name == 'push' }}
run: ./mvnw -s custom_maven_settings.xml -B clean verify
4 changes: 3 additions & 1 deletion .github/workflows/release-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
Expand Down Expand Up @@ -57,6 +59,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy with Maven to GitHub Packages and Docker Hub
run: ./mvnw -B -s custom_maven_settings.xml -Prelease,native clean deploy
run: ./mvnw -B -s custom_maven_settings.xml -Prelease clean deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'true'

- name: Set up JDK 1.11
uses: actions/setup-java@v3
Expand Down
24 changes: 24 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: 2022 Alliander N.V.
#
# SPDX-License-Identifier: Apache-2.0

#
# Remark: the option to ignore 'untracked' files is needed, because the submodules don't contain a file '.gitignore'.
# This cause the target directories to be untracked.
#
[submodule "riseclipse/riseclipse-developer"]
path = riseclipse/riseclipse-developer
url = git@github.com:riseclipse/riseclipse-developer.git
ignore = dirty
[submodule "riseclipse/riseclipse-main"]
path = riseclipse/riseclipse-main
url = git@github.com:riseclipse/riseclipse-main.git
ignore = dirty
[submodule "riseclipse/riseclipse-metamodel-scl2003"]
path = riseclipse/riseclipse-metamodel-scl2003
url = git@github.com:riseclipse/riseclipse-metamodel-scl2003.git
ignore = dirty
[submodule "riseclipse/riseclipse-ocl-constraints-scl2003"]
path = riseclipse/riseclipse-ocl-constraints-scl2003
url = git@github.com:riseclipse/riseclipse-ocl-constraints-scl2003.git
ignore = dirty
82 changes: 82 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!--
SPDX-FileCopyrightText: 2022 Alliander N.V.

SPDX-License-Identifier: Apache-2.0
-->

# Development

## Git

If the project is already cloned and a submodule is added use the following commands, first `git submodule init` and
next `git submodule update`.

More about Git Submodules can be found [here](https://git-scm.com/book/en/v2/Git-Tools-Submodules).

**Remark**: The URLs to the submodules are configured in the file `.gitmodules`, but these are using the SSH URLs. There
is a way described [here](https://git-scm.com/book/en/v2/Git-Tools-Submodules) that the URL can be overwritten locally
with an HTTPS URL of the GIT Repository. Because of the subdirectory where the submodules are in, this doesn't work
exactly that way. Use the following commands to update the URLs locally to HTTPS.

```
git config submodule.riseclipse/riseclipse-developer.url https://github.com/riseclipse/riseclipse-developer.git
git config submodule.riseclipse/riseclipse-main.url https://github.com/riseclipse/riseclipse-main.git
git config submodule.riseclipse/riseclipse-metamodel-scl2003.url https://github.com/riseclipse/riseclipse-metamodel-scl2003.git
git config submodule.riseclipse/riseclipse-ocl-constraints-scl2003.url https://github.com/riseclipse/riseclipse-ocl-constraints-scl2003.git

git submodule init
git submodule update
```

## IntelliJ

Importing the project is a bit harder for the SCL Validator then normal. It's caused because of the submodules that are
needed from RiseClipse. These projects are Eclipse projects using Eclipse Tycho to build and Eclipse project structure.

A way to make everything work in IntelliJ is importing the project in the following way.

- First step is to just import everything like it are Maven projects;
- Next step is to re-import the RiseClipse Submodule as Eclipse;
- In IntelliJ select "File" -> "New" -> "Module from Existing Sources...";
- Select one of the RiseClipse Submodules, for instance "riseclipse-metamodel-scl2003";
- Next select "Eclipse" by "Import module from External Model";
- Follow the rest of the wizard, only to remember to select all subprojects that are available in the directory;

Now the module should be correctly imported in IntelliJ to be used. Check the Module Settings of one of the subprojects
to check if the directory "src" is a Java Source Directory, for instance the module
"riseclipse/riseclipse-metamodel-scl2003/fr.centralesupelec.edf.riseclipse.iec61850.scl.utilities".

## Eclipse

Example about how to use Eclipse OCL was found
[here](https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FPivotStandalone.html).

## Running the application in dev mode

You can run your application in dev mode that enables live coding using:

```shell script
./mvnw package io.quarkus:quarkus-maven-plugin::dev
```

> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.

## Packaging and running the application

The application can be packaged using:

```shell script
./mvnw package
```

It produces the `quarkus-run.jar` file in the `app/target/quarkus-app/` directory. Be aware that it’s not an _über-jar_
as the dependencies are copied into the `app/target/quarkus-app/lib/` directory.

If you want to build an _über-jar_, execute the following command:

```shell script
./mvnw package -Dquarkus.package.type=uber-jar
```

The application is now runnable using `java -jar app/target/quarkus-app/quarkus-run.jar`.

39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,38 @@ SPDX-License-Identifier: Apache-2.0

Service to validate SCL Files.

## Development

For the RiseClipse implementation of the validator parts of the RiseClipse project are being used. Currently, these
parts aren't distributed to any Maven Repository, so the Git Repositories need to be included. This is done using Git
Submodules.

To clone the project or update the project this means that the Git commands are sometimes a little different. To clone
the project use the following command `git clone --recurse-submodules git@github.com:com-pas/compas-scl-validator.git`.
This will also clone the submodules.

Tip: The URL to the submodules are configured in the file `.gitmodules`, but these are using the SSH URL. There is a way
described in the URL above that the URL can be overwritten locally with an HTTPS URL of the GIT Repository.

Check the [Development](DEVELOPMENT.md) page for more detail information how to work with this repository, because of
the mixture with RiseClipse.

## Common Environment variables

Below environment variable(s) can be used to configure which claims and information are used to fill the UserInfo
response.
Below environment variable(s) can be used to configure the validator.

| Environment variable | Java Property | Description | Example |
| -------------------------------- | ------------------------------- | ----------------------------------------------------------- | ---------------- |
| USERINFO_NAME_CLAIMNAME | compas.userinfo.name.claimname | The Name of the user logged in. | name |
| USERINFO_WHO_CLAIMNAME | compas.userinfo.who.claimname | The Name of the user used in the Who History. | name |
| USERINFO_SESSION_WARNING | compas.userinfo.session.warning | Number of minutes a Session Warning can be displayed. | 20 |
| USERINFO_SESSION_EXPIRES | compas.userinfo.session.expires | Number of minutes a Session Expires to display in Frontend. | 30 |
| Environment variable | Java Property | Description | Example |
|---------------------------------------|---------------------------------------|---------------------------------------------------|-----------|
| COMPAS_VALIDATOR_OCL_CUSTOM_DIRECTORY | compas.validator.ocl.custom.directory | Reference to a directory to load custom OCL Files | /data/ocl |

## Security

To use most of the endpoints the users needs to be authenticated using JWT in the authorization header. There are 4
environment variables that can be set in the container to configure the validation/processing of the JWT.

| Environment variable | Java Property | Description | Example |
| -------------------------------- | -------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------- |
| JWT_VERIFY_KEY | smallrye.jwt.verify.key.location | Location of certificates to verify the JWT. | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs |
| JWT_VERIFY_ISSUER | mp.jwt.verify.issuer | The issuer of the JWT. | http://localhost:8089/auth/realms/compas |
| JWT_VERIFY_CLIENT_ID | mp.jwt.verify.audiences | The Client ID that should be in the "aud" claim. | scl-validator |
| JWT_GROUPS_PATH | smallrye.jwt.path.groups | The JSON Path where to find the roles of the user. | resource_access/scl-validator/roles |
| Environment variable | Java Property | Description | Example |
|----------------------|----------------------------------|----------------------------------------------------|------------------------------------------------------------------------|
| JWT_VERIFY_KEY | smallrye.jwt.verify.key.location | Location of certificates to verify the JWT. | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs |
| JWT_VERIFY_ISSUER | mp.jwt.verify.issuer | The issuer of the JWT. | http://localhost:8089/auth/realms/compas |
| JWT_VERIFY_CLIENT_ID | mp.jwt.verify.audiences | The Client ID that should be in the "aud" claim. | scl-validator |
| JWT_GROUPS_PATH | smallrye.jwt.path.groups | The JSON Path where to find the roles of the user. | resource_access/scl-validator/roles |
30 changes: 25 additions & 5 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ SPDX-License-Identifier: Apache-2.0
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.scl.validator</groupId>
<artifactId>validator-riseclipse</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -112,6 +118,11 @@ SPDX-License-Identifier: Apache-2.0
<artifactId>quarkus-jacoco</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.openpojo</groupId>
<artifactId>openpojo</artifactId>
Expand Down Expand Up @@ -156,8 +167,13 @@ SPDX-License-Identifier: Apache-2.0

<properties>
<quarkus.package.type>native</quarkus.package.type>
<quarkus.native.container-build>true</quarkus.native.container-build> <!-- Allows for creating a Linux executable without GraalVM being installed -->
<quarkus.container-image.build>true</quarkus.container-image.build> <!-- Also make a Docker Image, so the native test will be executed against the container -->
<!-- Allows for creating a Linux executable without GraalVM being installed -->
<quarkus.native.container-build>true</quarkus.native.container-build>
<!-- Also make a Docker Image, so the native test will be executed against the container -->
<quarkus.container-image.build>true</quarkus.container-image.build>
<quarkus.native.additional-build-args>
--allow-incomplete-classpath
</quarkus.native.additional-build-args>
</properties>

<build>
Expand All @@ -174,8 +190,12 @@ SPDX-License-Identifier: Apache-2.0
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
<java.util.logging.manager>
org.jboss.logmanager.LogManager
</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
Expand All @@ -201,8 +221,8 @@ SPDX-License-Identifier: Apache-2.0
<id>release</id>

<properties>
<!-- Properties only used for publishing a native docker image (default to Docker Hub) -->
<quarkus.container-image.build>true</quarkus.container-image.build>
<!-- Properties only used for publishing a native docker image (default to Docker Hub) -->
<quarkus.container-image.push>true</quarkus.container-image.push>
<quarkus.container-image.additional-tags>latest</quarkus.container-image.additional-tags>
</properties>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ COPY --chown=1001 target/quarkus-app/*.jar /deployments/
COPY --chown=1001 target/quarkus-app/app/ /deployments/app/
COPY --chown=1001 target/quarkus-app/quarkus/ /deployments/quarkus/

RUN mkdir -p /data/ocl \
&& mkdir -p /data/temp \
&& chown -R 1001 /data \
&& chmod -R "g+rwX" /data
VOLUME /data/ocl

EXPOSE 8080
USER 1001

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ RUN chown 1001 /work \
&& chown 1001:root /work
COPY --chown=1001:root target/*-runner /work/application

RUN mkdir -p /data/ocl \
&& mkdir -p /data/temp \
&& chown -R 1001 /data \
&& chmod -R "g+rwX" /data
VOLUME /data/ocl

EXPOSE 8080
USER 1001

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package org.lfenergy.compas.scl.validator.rest;

import org.lfenergy.compas.core.commons.ElementConverter;
import org.lfenergy.compas.scl.validator.collector.CompasOclFileCollector;
import org.lfenergy.compas.scl.validator.collector.OclFileCollector;
import org.lfenergy.compas.scl.validator.impl.SclRiseClipseValidator;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
Expand All @@ -17,4 +20,17 @@ public class CompasSclValidatorConfiguration {
public ElementConverter createElementConverter() {
return new ElementConverter();
}

@Produces
@ApplicationScoped
public OclFileCollector createOclFileCollector(ValidatorProperties properties) {
return new CompasOclFileCollector(properties.oclCustomDirectory());
}

@Produces
@ApplicationScoped
public SclRiseClipseValidator createSclRiseClipseValidator(OclFileCollector oclFileCollector,
ValidatorProperties properties) {
return new SclRiseClipseValidator(oclFileCollector, properties.tempDirectory());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2021 Alliander N.V.
//
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.validator.rest;

import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithName;

import java.nio.file.Path;

@ConfigMapping(prefix = "compas.validator")
public interface ValidatorProperties {
@WithName("ocl.custom.directory")
String oclCustomDirectory();

@WithName("temp.directory")
Path tempDirectory();
}
18 changes: 6 additions & 12 deletions app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#
# SPDX-License-Identifier: Apache-2.0

compas.userinfo.who.claimname = ${USERINFO_WHO_CLAIMNAME:name}
compas.validator.ocl.custom.directory = /data/ocl
compas.validator.temp.directory = /data/temp

quarkus.http.cors = false
quarkus.http.root-path = /compas-scl-validator/
Expand All @@ -11,18 +12,11 @@ quarkus.http.limits.max-body-size = 150M
quarkus.log.level = INFO
quarkus.log.category."org.lfenergy.compas.scl.validator".level = INFO

# Add scanning these dependencies for scanning, also used by native compilation.
quarkus.index-dependency.scl2007b4.group-id=org.lfenergy.compas.core
quarkus.index-dependency.scl2007b4.artifact-id=commons

quarkus.index-dependency.jaxb-api.group-id=org.jboss.spec.javax.xml.bind
quarkus.index-dependency.jaxb-api.artifact-id=jboss-jaxb-api_2.3_spec

# Settings needed for native compilation of the project.
quarkus.native.resources.includes=ConvergenceLibrary/*.*,*.css

# Dev Profile overrides.
%dev.quarkus.http.port = 9092
%dev.compas.validator.ocl.custom.directory = ./src/test/data/ocl
%dev.compas.validator.temp.directory = ./target/data/temp

%dev.quarkus.http.port = 9093
%dev.quarkus.http.cors = true

%dev.quarkus.log.level = DEBUG
Expand Down
Loading