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

[WIP] Mixed storage and local data storage #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions afs-core/src/main/java/com/powsybl/afs/AppFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class AppFileSystem implements AutoCloseable {

private final boolean remotelyAccessible;

private final AppStorage storage;
protected final AppStorage storage;

private final Supplier<NodeInfo> rootNodeInfo;

Expand Down Expand Up @@ -232,7 +232,7 @@ public AppData getData() {
return data;
}

void setData(AppData data) {
protected void setData(AppData data) {
this.data = Objects.requireNonNull(data);
}

Expand Down
5 changes: 5 additions & 0 deletions afs-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<artifactId>powsybl-afs-local</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-afs-mixed</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-afs-mapdb</artifactId>
Expand Down
37 changes: 37 additions & 0 deletions afs-mixed/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>powsybl-afs</artifactId>
<groupId>com.powsybl</groupId>
<version>3.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>powsybl-afs-mixed</artifactId>
<dependencies>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-afs-core</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2020, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.afs.mixed;

import com.powsybl.afs.AppFileSystem;
import com.powsybl.afs.mixed.storage.LocalDataAppStorage;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
public class LocalDataAppFileSystem extends AppFileSystem {

LocalDataAppFileSystem(LocalDataAppFileSystemConfig config) {
super(config.getDriveName(), config.isRemotelyAccessible(), new LocalDataAppStorage(config));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright (c) 2020, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.afs.mixed;

import com.powsybl.afs.AfsException;
import com.powsybl.afs.storage.AbstractAppFileSystemConfig;
import com.powsybl.commons.config.ModuleConfig;
import com.powsybl.commons.config.PlatformConfig;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
public class LocalDataAppFileSystemConfig extends AbstractAppFileSystemConfig<LocalDataAppFileSystemConfig> {

private static final String DRIVE_NAME = "drive-name";
private static final String ROOT_DIR = "root-dir";

private Path rootDir;

public static List<LocalDataAppFileSystemConfig> load() {
return load(PlatformConfig.defaultConfig());
}

private static void load(ModuleConfig moduleConfig, int num, List<LocalDataAppFileSystemConfig> configs) {
StringBuilder driveNameTag = new StringBuilder(DRIVE_NAME);
StringBuilder rootDirTag = new StringBuilder(ROOT_DIR);
driveNameTag.append("-").append(num);
rootDirTag.append("-").append(num);
if (moduleConfig.hasProperty(driveNameTag.toString())
&& moduleConfig.hasProperty(rootDirTag.toString())) {
String driveName = moduleConfig.getStringProperty(driveNameTag.toString());
Path rootDir = moduleConfig.getPathProperty(rootDirTag.toString());
configs.add(new LocalDataAppFileSystemConfig(driveName, rootDir));
}
}

private static void load(ModuleConfig moduleConfig, List<LocalDataAppFileSystemConfig> configs) {
if (moduleConfig.hasProperty(DRIVE_NAME)
&& moduleConfig.hasProperty(ROOT_DIR)) {
String driveName = moduleConfig.getStringProperty(DRIVE_NAME);
Path rootDir = moduleConfig.getPathProperty(ROOT_DIR);
configs.add(new LocalDataAppFileSystemConfig(driveName, rootDir));
}
}

public static List<LocalDataAppFileSystemConfig> load(PlatformConfig platformConfig) {
return platformConfig.getOptionalModuleConfig("local-data-app-file-system")
.map(moduleConfig -> {
List<LocalDataAppFileSystemConfig> configs = new ArrayList<>();
load(moduleConfig, configs);
int maxAdditionalDriveCount = moduleConfig.getIntProperty("max-additional-drive-count", 0);
for (int i = 0; i < maxAdditionalDriveCount; i++) {
load(moduleConfig, i, configs);
}
return configs;
})
.orElseGet(() -> {
List<LocalDataAppFileSystemConfig> configs = new ArrayList<>();
for (Path rootDir : FileSystems.getDefault().getRootDirectories()) {
if (Files.isDirectory(rootDir)) {
configs.add(new LocalDataAppFileSystemConfig(rootDir.toString(), rootDir));
}
}
return configs;
});

}

private static Path checkRootDir(Path rootDir) {
Objects.requireNonNull(rootDir);
if (!Files.isDirectory(rootDir)) {
throw new AfsException("Root path " + rootDir + " is not a directory");
}
return rootDir;
}

public LocalDataAppFileSystemConfig(String driveName, Path rootDir) {
super(driveName, false);
this.rootDir = checkRootDir(rootDir).toAbsolutePath();
}

public Path getRootDir() {
return rootDir;
}

public LocalDataAppFileSystemConfig setRootDir(Path rootDir) {
this.rootDir = checkRootDir(rootDir);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2020, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.afs.mixed;

import com.google.auto.service.AutoService;
import com.powsybl.afs.AppFileSystem;
import com.powsybl.afs.AppFileSystemProvider;
import com.powsybl.afs.AppFileSystemProviderContext;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
@AutoService(AppFileSystemProvider.class)
public class LocalDataAppFileSystemProvider implements AppFileSystemProvider {

private final List<LocalDataAppFileSystemConfig> configs;

public LocalDataAppFileSystemProvider() {
this(LocalDataAppFileSystemConfig.load());
}

public LocalDataAppFileSystemProvider(List<LocalDataAppFileSystemConfig> configs) {
this.configs = Objects.requireNonNull(configs);
}

@Override
public List<AppFileSystem> getFileSystems(AppFileSystemProviderContext context) {
return configs.stream().map(LocalDataAppFileSystem::new).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2020, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.afs.mixed;

import com.powsybl.afs.AppData;
import com.powsybl.afs.AppFileSystem;
import com.powsybl.afs.mixed.storage.MixedAppStorage;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
public class MixedAppFileSystem extends AppFileSystem {

MixedAppFileSystem(MixedAppFileSystemConfig config) {
super(config.getDriveName(), config.isRemotelyAccessible(), new MixedAppStorage(config));
}

@Override
protected void setData(AppData data) {
super.setData(data);
((MixedAppStorage) storage).setAppData(data);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2020, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.afs.mixed;

import com.powsybl.afs.storage.AbstractAppFileSystemConfig;
import com.powsybl.commons.config.PlatformConfig;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
public class MixedAppFileSystemConfig extends AbstractAppFileSystemConfig<MixedAppFileSystemConfig> {

private final String nodeStorageDriveName;
private final String dataStorageDriveName;

static List<MixedAppFileSystemConfig> load() {
return load(PlatformConfig.defaultConfig());
}

static List<MixedAppFileSystemConfig> load(PlatformConfig config) {
return config.getOptionalModuleConfig("mixed-app-file-system").map(moduleConfig -> {
List<MixedAppFileSystemConfig> configs = new ArrayList<>();
final String driveName = moduleConfig.getStringProperty("drive-name");
final String nodeStorage = moduleConfig.getStringProperty("node-storage");
final String dataStorage = moduleConfig.getStringProperty("data-storage");
// TODO remote access
final MixedAppFileSystemConfig c = new MixedAppFileSystemConfig(driveName, true, nodeStorage, dataStorage);
configs.add(c);
return configs;
}).orElse(Collections.emptyList());
}

public MixedAppFileSystemConfig(String driveName, boolean remotelyAccessible, String nodeStorageDriveName, String dataStorageDriveName) {
super(driveName, remotelyAccessible);
this.nodeStorageDriveName = Objects.requireNonNull(nodeStorageDriveName);
this.dataStorageDriveName = Objects.requireNonNull(dataStorageDriveName);
}

public String getNodeStorageDriveName() {
return nodeStorageDriveName;
}

public String getDataStorageDriveName() {
return dataStorageDriveName;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2020, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.afs.mixed;

import com.google.auto.service.AutoService;
import com.powsybl.afs.AppFileSystem;
import com.powsybl.afs.AppFileSystemProvider;
import com.powsybl.afs.AppFileSystemProviderContext;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
*/
@AutoService(AppFileSystemProvider.class)
public class MixedAppFileSystemProvider implements AppFileSystemProvider {

private final List<MixedAppFileSystemConfig> configs;

public MixedAppFileSystemProvider() {
this(MixedAppFileSystemConfig.load());
}

public MixedAppFileSystemProvider(List<MixedAppFileSystemConfig> configs) {
this.configs = Objects.requireNonNull(configs);
}

@Override
public List<AppFileSystem> getFileSystems(AppFileSystemProviderContext context) {
return configs.stream().map(MixedAppFileSystem::new).collect(Collectors.toList());
}
}
Loading