Skip to content

Commit

Permalink
Merge pull request #122 from com-pas/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Dennis Labordus authored Aug 8, 2022
2 parents 4f30f66 + 7b25903 commit 7949e21
Show file tree
Hide file tree
Showing 20 changed files with 8,313 additions and 5,252 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up JDK 1.11
uses: actions/setup-java@v3.4.0
- name: Set up JDK 17
uses: actions/setup-java@v3.4.1
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@v20
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
shell: bash
# Extra the tagname form the git reference, value of GITHUB_REF will be something like refs/tags/<tag_name>.
run: echo "##[set-output name=tagname;]$(echo ${GITHUB_REF##*/})"
- name: Set up JDK 1.11
uses: actions/setup-java@v3.4.0
- name: Set up JDK 17
uses: actions/setup-java@v3.4.1
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@v20
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ jobs:
with:
fetch-depth: 0

- name: Set up JDK 1.11
uses: actions/setup-java@v3.4.0
- name: Set up JDK 17
uses: actions/setup-java@v3.4.1
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
Expand Down
20 changes: 18 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
115 changes: 115 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!--
SPDX-FileCopyrightText: 2022 Alliander N.V.
SPDX-License-Identifier: Apache-2.0
-->

# Development for CoMPAS SCL Auto Alignment

This project uses Java 17 and Quarkus to build and run the application. The project is split into multi modules.
The app module will use Quarkus to expose the services as REST XML Endpoints. The service module contains all
the logic to determine X/Y Coordinates into IEC 61850 XML (using the namespace
http://www.iec.ch/61850/2003/SCLcoordinates). This module uses no Quarkus dependencies, but mainly standard
java dependencies and PowSyBl dependencies to determine coordinates. This way the service module can also be used in
other environment as Java library, for instance a Spring project.

## Building the application

You can use Maven to build the application and see if all tests are working using:

```shell script
./mvnw clean verify
```

This should normally be enough to also run the application, but there were cases that we need to build using:

```shell script
./mvnw clean install
```

This to make the local modules available for the app module to run the application.

## Running the application locally 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
```

### Application depends on a running KeyCloak instance for dev mode

A KeyCloak instance needs to be running on port 8089 by default in dev mode. If a custom KeyCloak instance is used see
[Security](README.md#security) for more details.

There is a preconfigured Demo KeyCloak instance available for CoMPAS in the
[CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment). This repository can be cloned and
used to execute the following commands to create a local Docker Image with the CoMPAS Demo configuration.

```shell
cd <CoMPAS Deployment Repository Directory>/compas/keycloak
docker build -t compas_keycloak .
```

A Docker Image `compas_keycloak` is created that can be started using the following command

```shell
docker run --rm --name compas_keycloak \
-p 8089:8080
-d compas_keycloak:latest
```

There are now 3 users available to be used, `scl-data-editor`, `scl-data-reader`, `scd-reader`. See
[CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment) for more information about the users.

## Testing the application

The application is tested with unit and integration tests, but you can also manually test the application using for
instance Postman. And there is also a way to test this service with the CoMPAS OpenSCD Frontend application.

### Postman

To manually test the application there is a Postman collection in the directory `postman` that can be imported
and used to execute REST XML Calls.

To make the call work we also need to import an environment and authorisation collection. These files can be found
in [CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment) in the directory `postman`
(`auth.collection.json` and `local.environment.json`).

In the authorisation collection there are called for the 3 users known within the Demo KeyCloak instance.
If one of these calls are executed there is a variable `bearer` filled.

Now one of the SCL Auto Alignment calls can be executed, the variable `bearer` is added to the header of the request.
After the call is executed the result should be shown in Postman.

### CoMPAS OpenSCD Frontend application

To test the SCL Auto Alignment with the CoMPAS OpenSCD application just run the application in dev mode, including the
KeyCloak instance. For further instruction how to start the CoMPAS OpenSCD application and use this locally see
the file `DEVELOPMENT.md` in [CoMPAS OpenSCD application](https://github.com/com-pas/compas-open-scd).

## Docker Images

### Creating a Docker image with native executable

The releases created in the repository will create a docker image with a native executable. If you're running a Linux
system it's possible to create and run the executable locally. You can create a Docker image with native executable
using:

```shell script
./mvnw package -Pnative-image
```

You can then execute your native executable with: `./app/target/app-local-SNAPSHOT-runner`

### Creating a Docker image with JVM executable

There is also a profile to create a Docker Image which runs the application using a JVM. You can create a Docker Image
with JVM executable using:

```shell script
./mvnw package -Pjvm-image
```

The JVM Image can also (temporary) be created by the release action if there are problems creating or running the
native executable.
52 changes: 4 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
SPDX-FileCopyrightText: 2021 Alliander N.V.
SPDX-FileCopyrightText: 2022 Alliander N.V.
SPDX-License-Identifier: Apache-2.0
-->
Expand All @@ -10,55 +10,11 @@ SPDX-License-Identifier: Apache-2.0
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5925/badge)](https://bestpractices.coreinfrastructure.org/projects/5925)
[![Slack](https://raw.githubusercontent.com/com-pas/compas-architecture/master/public/LFEnergy-slack.svg)](http://lfenergy.slack.com/)

# compas-scl-auto-alignment
# CoMPAS SCL Auto Alignment

## Running the application in dev mode
## Development

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`.

## Creating a native executable

You can create a native executable using:

```shell script
./mvnw package -Pnative
```

Or, if you don't have GraalVM installed, you can run the native executable build in a container using:

```shell script
./mvnw package -Pnative -Dquarkus.native.container-build=true
```

You can then execute your native executable with: `./app/target/code-with-quarkus-local-SNAPSHOT-runner`

If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.html
.
Information about how to run and develop for this project check [Development](DEVELOPMENT.md).

## Environment variables

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
###
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6

ARG JAVA_PACKAGE=java-11-openjdk-headless
ARG JAVA_PACKAGE=java-17-openjdk-headless
ARG RUN_JAVA_VERSION=1.3.8
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
# Install java and the run-java script
Expand Down
9 changes: 4 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ SPDX-License-Identifier: Apache-2.0

<properties>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

Expand All @@ -26,10 +25,10 @@ SPDX-License-Identifier: Apache-2.0

<compas.core.version>0.9.1</compas.core.version>

<quarkus.platform.version>2.10.1.Final</quarkus.platform.version>
<quarkus.platform.version>2.11.2.Final</quarkus.platform.version>
<slf4j.version>1.7.36</slf4j.version>
<powsybl.sld.version>2.11.0</powsybl.sld.version>
<gson.version>2.9.0</gson.version>
<powsybl.sld.version>2.12.0</powsybl.sld.version>
<gson.version>2.9.1</gson.version>
<openpojo.version>0.9.1</openpojo.version>
</properties>

Expand Down
505 changes: 505 additions & 0 deletions postman/scl-auto-alignment-service.collection.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions postman/scl-auto-alignment-service.collection.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2022 Alliander N.V.

SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ private void createVoltageLevel() {
var busbarIndex = new AtomicInteger(1);
voltageLevel.getBays().stream()
.filter(GenericBay::isBusbar)
.forEach(busbar -> processBusbarNode(busbar, busbarIndex));
.forEach(busbar -> processBusbarNode(busbar, busbarIndex.getAndIncrement()));

// Next process the other bays.
var bayIndex = new AtomicInteger(1);
voltageLevel.getBays().stream()
.filter(bay -> !bay.isBusbar())
.forEach(this::processBayNode);
.forEach(bay -> processBayNode(bay, bayIndex.getAndIncrement()));
}

private void processBusbarNode(GenericBay busbar,
AtomicInteger busbarIndex) {
int busbarIndex) {
busbar.getConnectivityNodes()
.stream().findFirst()
.ifPresent(connectivityNode ->
addNode(connectivityNode.getPathName(),
createBusbarNode(busbar.getFullName(), busbarIndex.getAndIncrement(), 1)));
createBusbarNode(busbar.getFullName(), busbarIndex, 1)));
}

public BusNode createBusbarNode(String id, int busbarIndex, int sectionIndex) {
Expand All @@ -64,9 +65,10 @@ public BusNode createBusbarNode(String id, int busbarIndex, int sectionIndex) {
return busNode;
}

private void processBayNode(GenericBay bay) {
private void processBayNode(GenericBay bay, int bayIndex) {
bay.getConnectivityNodes().forEach(this::createConnectivityNode);
bay.getConductingEquipments().forEach(this::processConductingEquipment);
bay.getConductingEquipments().forEach(conductingEquipment ->
processConductingEquipment(conductingEquipment, bayIndex));
}

private void createConnectivityNode(GenericConnectivityNode connectivityNode) {
Expand Down Expand Up @@ -94,36 +96,39 @@ private Optional<GenericPowerTransformer> getPowerTransformer(String pathName) {
return Optional.empty();
}

private void processConductingEquipment(GenericConductingEquipment conductingEquipment) {
private void processConductingEquipment(GenericConductingEquipment conductingEquipment, int order) {
var terminals = conductingEquipment.getTerminals();
var fullName = conductingEquipment.getFullName();
var node = createSwitchNode(fullName);
var node = createSwitchNode(fullName, order);

if (!terminals.isEmpty()) {
Node node1 = terminalToNode(terminals.get(0));
Node node2 = null;
var termNb = terminals.size();
if (termNb == 1) {
node2 = createLoad(fullName + "/Grounded");
} else if (termNb == 2) {
node2 = terminalToNode(terminals.get(1));
}
var node1 = terminalToNode(terminals.get(0), order);
connectNode(node, node1);
connectNode(node, node2);

if (terminals.size() == 2) {
var node2 = terminalToNode(terminals.get(1), order);
connectNode(node, node2);
} else {
var node2 = createLoad(fullName + "/Grounded", order);
connectNode(node, node2);
}
}
}

private Node terminalToNode(GenericTerminal terminal) {
private Node terminalToNode(GenericTerminal terminal, int order) {
var pathName = terminal.getConnectivityNode();
if (pathName != null) {
return getNodeByPath(pathName);
}
return createLoad(terminal.getCNodeName());
return createLoad(terminal.getCNodeName(), order);
}

private SwitchNode createSwitchNode(String id) {
return NodeFactory.createSwitchNode(getGraph(), id, id, SwitchNode.SwitchKind.BREAKER.name(),
private SwitchNode createSwitchNode(String id, int order) {
var switchNode = NodeFactory.createSwitchNode(getGraph(), id, id, SwitchNode.SwitchKind.BREAKER.name(),
false, SwitchNode.SwitchKind.BREAKER, false);
switchNode.setOrder(order);
switchNode.setDirection(Direction.TOP);
return switchNode;
}

private void connectNode(Node node1, Node node2) {
Expand All @@ -134,9 +139,9 @@ private FictitiousNode createFictitiousNode(String id) {
return NodeFactory.createFictitiousNode(getGraph(), id, id, id, ComponentTypeName.LINE);
}

private FeederNode createLoad(String id) {
private FeederNode createLoad(String id, int order) {
FeederNode fn = NodeFactory.createLoad(getGraph(), id, id);
commonFeederSetting(fn, id, 0, null);
commonFeederSetting(fn, id, order, Direction.TOP);
return fn;
}

Expand Down
Loading

0 comments on commit 7949e21

Please sign in to comment.