/powsybl-network-store

Persistent implementation of PowSyBl network based on Spring Boot

Primary LanguageJavaMozilla Public License 2.0MPL-2.0

PowSyBl Network Store

Actions Status Coverage Status MPL-2.0 License Join the community on Spectrum Slack

PowSyBl (Power System Blocks) is an open source framework written in Java, that makes it easy to write complex software for power systems’ simulations and analysis. Its modular approach allows developers to extend or customize its features.

PowSyBl is part of the LF Energy Foundation, a project of The Linux Foundation that supports open source innovation projects within the energy and electricity sectors.

PowSyBl Logo

Read more at https://www.powsybl.org !

This project and everyone participating in it is governed by the PowSyBl Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to powsybl-tsc@lists.lfenergy.org.

PowSyBl vs PowSyBl Network Store

PowSyBl Network Store is an alternative implementation of PowSyBl Core Network API that persists in a Cassandra database.

Getting started

Build

cd powsybl-network-store
mvn clean install

Cassandra install

cd $HOME
wget http://archive.apache.org/dist/cassandra/3.11.4/apache-cassandra-3.11.4-bin.tar.gz
tar xvfz apache-cassandra-3.11.4-bin.tar.gz
cd apache-cassandra-3.11.4
bin/cassandra
bin/cqlsh

Create keyspace:

CREATE KEYSPACE IF NOT EXISTS iidm WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

Copy paste network-store-server/src/main/resources/iidm.cql in the cql shell to create the iidm keyspace and all necessary tables.

Start network store server

In an other shell:

cd powsybl-network-store/network-store-server/target/
java -jar powsybl-network-store-server-1.0.0-SNAPSHOT-exec.jar

Spring boot server should start and connect to Cassandra database (localhost hardcoded...)

Import a network in the database

In your preferred IDE, create a project with following dependencies:

<dependency>
    <groupId>com.powsybl</groupId>
    <artifactId>powsybl-network-store-client</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>com.powsybl</groupId>
    <artifactId>powsybl-iidm-test</artifactId>
    <version>3.0.0</version>
</dependency>

Run the Java code to import in IIDM store a programmatic test node/breaker network:

public static void main(String[] args) throws Exception {
    String baseUrl = "http://localhost:8080/";
    try (NetworkStoreService service = new NetworkStoreService(baseUrl, PreloadingStrategy.NONE)) {
    	Network network = NetworkTest1Factory.create(service.getNetworkFactory());
    }
}

Import a network from a file in the database

public static void main(String[] args) throws Exception {
    String baseUrl = "http://localhost:8080/";
    try (NetworkStoreService service = new NetworkStoreService(baseUrl, PreloadingStrategy.NONE)) {
        Network network = service.importNetwork(Paths.get("/tmp/network1.xiidm"));
    }
}

List voltage levels from a stored network

public static void main(String[] args) throws Exception {
    String baseUrl = "http://localhost:8080/";
    try (NetworkStoreService service = new NetworkStoreService(baseUrl, PreloadingStrategy.COLLECTION)) {
        Network network = service.getNetwork("network1");
        for (VoltageLevel vl : network.getVoltageLevels()) {
            System.out.println(vl.getId());
        }
   }
}

Injection network store service in a Spring controller

@RestController
@RequestMapping(value = "/test")
@ComponentScan(basePackageClasses = {NetworkStoreService.class})
public class TestController {

    @Autowired
    private NetworkStoreService service;

    @RequestMapping(method = GET, produces = APPLICATION_JSON_VALUE)
    public List<String> getSubstations(String networkId) {
        Network network = service.getNetwork(networkId, PreloadingStrategy.COLLECTION);
        return network.getSubstationStream().map(Identifiable::getId).collect(Collectors.toList());
    }
}

Network store service could be configured using application.yml like this:

network-store-server:
    base-uri: http://localhost:8080/
    preloading-strategy: COLLECTION

List of available variables:

Variable Description Optional Default vallue
network-store-server.base-uri URL of the network store server Yes http://network-store-server/
network-store-server.preloading-strategy Preloading strategy Yes NONE

Run integration tests

To run the integration tests, a cassandra distribution is downloaded automatically once for all the projects at the first execution for your user. It is stored in $HOME/.embedded-cassandra . For this first execution, you need http internet access, and if you are a on a restricted network requiring a proxy, you need to set the proxy details. In addition to the standard java system properties -DproxyHost, -DproxyPort, we use -DproxyUser and -DproxyPassword for authenticated proxies. In IDEs, set them in the tests system properties (usually in the "Edit run configuration" menu). For maven CLI, either set them in MAVEN_OPTS or directly on the command line:

$ export MAVEN_OPTS="-DproxyHost=proxy.com -DproxyPort=8080 -DproxyUser=user -DproxyPassword=XXXX"
$ mvn verify

OR

$ mvn verify -DproxyHost=proxy.com -DproxyPort=8080 -DproxyUser=user -DproxyPassword=XXXX