Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' into in_memory_analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbagu committed Jul 25, 2017
2 parents 91c126a + a819f70 commit 4832f9d
Show file tree
Hide file tree
Showing 55 changed files with 783 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ package eu.itesla_project.action.dsl
import eu.itesla_project.action.dsl.ast.ExpressionNode
import eu.itesla_project.action.dsl.spi.DslTaskExtension
import eu.itesla_project.contingency.BranchContingency
import eu.itesla_project.contingency.BusbarSectionContingency
import eu.itesla_project.contingency.ContingencyImpl
import eu.itesla_project.contingency.GeneratorContingency
import eu.itesla_project.contingency.tasks.ModificationTask
import eu.itesla_project.iidm.network.BusbarSection
import eu.itesla_project.iidm.network.Generator
import eu.itesla_project.iidm.network.Identifiable
import eu.itesla_project.iidm.network.Line
Expand Down Expand Up @@ -129,6 +131,8 @@ class ActionDslLoader extends DslLoader {
elements.add(new BranchContingency(equipment))
} else if (identifiable instanceof Generator) {
elements.add(new GeneratorContingency(equipment))
} else if (identifiable instanceof BusbarSection) {
elements.add(new BusbarSectionContingency(equipment))
} else {
throw new ActionDslException("Equipment type " + identifiable.getClass().name + " not supported in contingencies")
}
Expand Down
23 changes: 19 additions & 4 deletions afs/afs-core/src/main/java/eu/itesla_project/afs/core/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*/
package eu.itesla_project.afs.core;

import eu.itesla_project.afs.storage.AppFileSystemStorage;
import eu.itesla_project.commons.util.ServiceLoaderCache;
import eu.itesla_project.computation.ComputationManager;
import eu.itesla_project.computation.local.LocalComputationManager;
import eu.itesla_project.iidm.import_.ImportersLoader;
import eu.itesla_project.iidm.import_.ImportersServiceLoader;

import java.util.*;
import java.util.stream.Collectors;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -101,7 +103,7 @@ public Set<Class<? extends ProjectFile>> getProjectFileClasses() {
return projectFileClasses;
}

public FileExtension getFileExtension(Class<? extends File> fileClass) {
FileExtension getFileExtension(Class<? extends File> fileClass) {
Objects.requireNonNull(fileClass);
FileExtension extension = fileExtensions.get(fileClass);
if (extension == null) {
Expand All @@ -110,7 +112,7 @@ public FileExtension getFileExtension(Class<? extends File> fileClass) {
return extension;
}

public FileExtension getFileExtensionByPseudoClass(String filePseudoClass) {
FileExtension getFileExtensionByPseudoClass(String filePseudoClass) {
Objects.requireNonNull(filePseudoClass);
FileExtension extension = fileExtensionsByPseudoClass.get(filePseudoClass);
if (extension == null) {
Expand All @@ -119,7 +121,7 @@ public FileExtension getFileExtensionByPseudoClass(String filePseudoClass) {
return extension;
}

public ProjectFileExtension getProjectFileExtension(Class<?> projectFileOrProjectFileBuilderClass) {
ProjectFileExtension getProjectFileExtension(Class<?> projectFileOrProjectFileBuilderClass) {
Objects.requireNonNull(projectFileOrProjectFileBuilderClass);
ProjectFileExtension extension = projectFileExtensions.get(projectFileOrProjectFileBuilderClass);
if (extension == null) {
Expand All @@ -129,7 +131,7 @@ public ProjectFileExtension getProjectFileExtension(Class<?> projectFileOrProjec
return extension;
}

public ProjectFileExtension getProjectFileExtensionByPseudoClass(String projectFilePseudoClass) {
ProjectFileExtension getProjectFileExtensionByPseudoClass(String projectFilePseudoClass) {
Objects.requireNonNull(projectFilePseudoClass);
ProjectFileExtension extension = projectFileExtensionsByPseudoClass.get(projectFilePseudoClass);
if (extension == null) {
Expand All @@ -147,6 +149,19 @@ public ComputationManager getComputationManager() {
return computationManager;
}

public List<String> getRemotelyAccessibleFileSystemNames() {
return fileSystems.entrySet().stream()
.map(Map.Entry::getValue)
.filter(AppFileSystem::isRemotelyAccessible)
.map(AppFileSystem::getName)
.collect(Collectors.toList());
}

public AppFileSystemStorage getRemotelyAccessibleStorage(String fileSystemName) {
AppFileSystem afs = fileSystems.get(fileSystemName);
return afs != null ? afs.getStorage() : null;
}

@Override
public void close() throws Exception {
getFileSystems().forEach(AppFileSystem::close);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,30 @@ public class AppFileSystem implements AutoCloseable {

private final String name;

private final boolean remotelyAccessible;

private final AppFileSystemStorage storage;

private AppData data;

public AppFileSystem(String name, AppFileSystemStorage storage) {
public AppFileSystem(String name, boolean remotelyAccessible, AppFileSystemStorage storage) {
this.name = Objects.requireNonNull(name);
this.remotelyAccessible = remotelyAccessible;
this.storage = Objects.requireNonNull(storage);
}

public String getName() {
return name;
}

public boolean isRemotelyAccessible() {
return remotelyAccessible;
}

AppFileSystemStorage getStorage() {
return storage;
}

public Folder getRootFolder() {
return new Folder(storage.getRootNode(), storage, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public Project getProject() {
return new Project(projectId, storage, fileSystem);
}

public void moveTo(ProjectFolder folder) {
Objects.requireNonNull(folder);
storage.setParentNode(id, folder.id);
}

public void delete() {
storage.deleteNode(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void setup() throws IOException {
ImportersLoader importersLoader = new ImportersLoaderList(getImporters(), Collections.emptyList());
ComputationManager computationManager = Mockito.mock(ComputationManager.class);
storage = createStorage();
afs = new AppFileSystem("mem", storage);
afs = new AppFileSystem("mem", false, storage);
ad = new AppData(computationManager,
importersLoader,
Collections.singletonList(computationManager1 -> Collections.singletonList(afs)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
package eu.itesla_project.afs.core;

import com.google.common.collect.ImmutableList;
import eu.itesla_project.afs.mapdb.storage.MapDbAppFileSystemStorage;
import eu.itesla_project.afs.storage.AppFileSystemStorage;
import eu.itesla_project.afs.storage.NodeId;
import eu.itesla_project.afs.mapdb.storage.MapDbAppFileSystemStorage;
import eu.itesla_project.computation.ComputationManager;
import eu.itesla_project.iidm.import_.ImportersLoader;
import eu.itesla_project.iidm.import_.ImportersLoaderList;
Expand All @@ -29,6 +29,69 @@
*/
public class AfsBaseTest {

private static class FooFile extends ProjectFile {

private FooFile(NodeId id, AppFileSystemStorage storage, NodeId projectId, AppFileSystem fileSystem) {
super(id, storage, projectId, fileSystem);
}

@Override
public FileIcon getIcon() {
return new FileIcon("?", new byte[]{});
}
}

private static class FooFileBuilder implements ProjectFileBuilder<FooFile> {

private final NodeId folderId;

private final AppFileSystemStorage storage;

private final NodeId projectId;

private final AppFileSystem fileSystem;

private FooFileBuilder(NodeId folderId, AppFileSystemStorage storage, NodeId projectId, AppFileSystem fileSystem) {
this.folderId = folderId;
this.storage = storage;
this.projectId = projectId;
this.fileSystem = fileSystem;
}

@Override
public FooFile build() {
NodeId id = storage.createNode(folderId, "foo", "foo");
return new FooFile(id, storage, projectId, fileSystem);
}
}

private static class FooFileExtension implements ProjectFileExtension {
@Override
public Class<? extends ProjectFile> getProjectFileClass() {
return FooFile.class;
}

@Override
public String getProjectFilePseudoClass() {
return "foo";
}

@Override
public Class<? extends ProjectFileBuilder<? extends ProjectFile>> getProjectFileBuilderClass() {
return FooFileBuilder.class;
}

@Override
public FooFile createProjectFile(NodeId id, AppFileSystemStorage storage, NodeId projectId, AppFileSystem fileSystem) {
return new FooFile(id, storage, projectId, fileSystem);
}

@Override
public FooFileBuilder createProjectFileBuilder(NodeId folderId, AppFileSystemStorage storage, NodeId projectId, AppFileSystem fileSystem) {
return new FooFileBuilder(folderId, storage, projectId, fileSystem);
}
}

private AppFileSystemStorage storage;

private AppFileSystem afs;
Expand All @@ -46,9 +109,9 @@ public void setup() throws IOException {

ImportersLoader importersLoader = new ImportersLoaderList(Collections.emptyList(), Collections.emptyList());
ComputationManager computationManager = Mockito.mock(ComputationManager.class);
afs = new AppFileSystem("mem", storage);
afs = new AppFileSystem("mem", true, storage);
ad = new AppData(computationManager, importersLoader, Collections.singletonList(computationManager1 -> Collections.singletonList(afs)),
Collections.emptyList(), Collections.emptyList());
Collections.emptyList(), Collections.singletonList(new FooFileExtension()));
}

@After
Expand All @@ -57,11 +120,13 @@ public void tearDown() throws Exception {
}

@Test
public void test() throws IOException {
public void baseTest() throws IOException {
assertSame(afs, ad.getFileSystem("mem"));
assertNull(ad.getFileSystem("???"));
assertEquals(Collections.singletonList("mem"), ad.getRemotelyAccessibleFileSystemNames());
assertNotNull(ad.getRemotelyAccessibleStorage("mem"));
assertEquals("mem", afs.getName());
assertTrue(ad.getProjectFileClasses().isEmpty()); // no plugin
assertEquals(1, ad.getProjectFileClasses().size());
Folder root = afs.getRootFolder();
assertNotNull(root);
Folder dir1 = (Folder) root.getChild("dir1");
Expand Down Expand Up @@ -119,4 +184,20 @@ public void test() throws IOException {
assertEquals("dir6", project1.getRootFolder().getChild("dir5/dir6").getName());
}

@Test
public void moveToTest() throws IOException {
Project project = afs.getRootFolder().createProject("test", "");
ProjectFolder test1 = project.getRootFolder().createFolder("test1");
ProjectFolder test2 = project.getRootFolder().createFolder("test2");
FooFile file = test1.fileBuilder(FooFileBuilder.class)
.build();
assertEquals(test1.getId(), file.getFolder().getId());
assertEquals(1, test1.getChildren().size());
assertTrue(test2.getChildren().isEmpty());
file.moveTo(test2);
assertEquals(test2.getId(), file.getFolder().getId());
assertTrue(test1.getChildren().isEmpty());
assertEquals(1, test2.getChildren().size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public AppFileSystemToolTest() {
@Override
protected AppData createAppData() {
AppFileSystemStorage storage = MapDbAppFileSystemStorage.createHeap("mem");
AppFileSystem afs = new AppFileSystem("mem", storage);
AppFileSystem afs = new AppFileSystem("mem", false, storage);
AppData appData = new AppData(computationManager, importersLoader, Collections.singletonList(computationManager1 -> Collections.singletonList(afs)),
Collections.emptyList(), Collections.emptyList());
afs.getRootFolder().createProject("test_project1", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class LocalAppFileSystem extends AppFileSystem {
public LocalAppFileSystem(LocalAppFileSystemConfig config, ComputationManager computationManager, ImportConfig importConfig,
ImportersLoader importersLoader) {
super(config.getDriveName(),
new LocalAppFileSystemStorage(config.getRootDir(), config.getDriveName(), computationManager, importConfig, importersLoader));
config.isRemotelyAccessible(),
new LocalAppFileSystemStorage(config.getRootDir(), config.getDriveName(), computationManager, importConfig, importersLoader));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package eu.itesla_project.afs.local;

import eu.itesla_project.afs.core.AfsException;
import eu.itesla_project.afs.storage.AbstractAppFileSystemConfig;
import eu.itesla_project.commons.config.ModuleConfig;
import eu.itesla_project.commons.config.PlatformConfig;

Expand All @@ -19,9 +20,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class LocalAppFileSystemConfig {

private String driveName;
public class LocalAppFileSystemConfig extends AbstractAppFileSystemConfig<LocalAppFileSystemConfig> {

private Path rootDir;

Expand All @@ -33,17 +32,21 @@ public static List<LocalAppFileSystemConfig> load(PlatformConfig platformConfig)
List<LocalAppFileSystemConfig> configs = new ArrayList<>();
ModuleConfig moduleConfig = platformConfig.getModuleConfigIfExists("local-app-file-system");
if (moduleConfig != null) {
if (moduleConfig.hasProperty("drive-name") && moduleConfig.hasProperty("root-dir")) {
if (moduleConfig.hasProperty("drive-name")
&& moduleConfig.hasProperty("root-dir")) {
String driveName = moduleConfig.getStringProperty("drive-name");
boolean remotelyAccessible = moduleConfig.getBooleanProperty("remotely-accessible", DEFAULT_REMOTELY_ACCESSIBLE);
Path rootDir = moduleConfig.getPathProperty("root-dir");
configs.add(new LocalAppFileSystemConfig(driveName, rootDir));
configs.add(new LocalAppFileSystemConfig(driveName, remotelyAccessible, rootDir));
}
int maxAdditionalDriveCount = moduleConfig.getIntProperty("max-additional-drive-count", 0);
for (int i = 0; i < maxAdditionalDriveCount; i++) {
if (moduleConfig.hasProperty("drive-name-" + i) && moduleConfig.hasProperty("root-dir-" + i)) {
if (moduleConfig.hasProperty("drive-name-" + i)
&& moduleConfig.hasProperty("root-dir-" + i)) {
String driveName = moduleConfig.getStringProperty("drive-name-" + i);
boolean remotelyAccessible = moduleConfig.getBooleanProperty("remotely-accessible-" + i, DEFAULT_REMOTELY_ACCESSIBLE);
Path rootDir = moduleConfig.getPathProperty("root-dir-" + i);
configs.add(new LocalAppFileSystemConfig(driveName, rootDir));
configs.add(new LocalAppFileSystemConfig(driveName, remotelyAccessible, rootDir));
}
}
}
Expand All @@ -58,20 +61,11 @@ private static Path checkRootDir(Path rootDir) {
return rootDir;
}

public LocalAppFileSystemConfig(String driveName, Path rootDir) {
this.driveName = Objects.requireNonNull(driveName);
public LocalAppFileSystemConfig(String driveName, boolean remotelyAccessible, Path rootDir) {
super(driveName, remotelyAccessible);
this.rootDir = checkRootDir(rootDir).toAbsolutePath();
}

public String getDriveName() {
return driveName;
}

public LocalAppFileSystemConfig setDriveName(String driveName) {
this.driveName = Objects.requireNonNull(driveName);
return this;
}

public Path getRootDir() {
return rootDir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public NodeId getParentNode(NodeId nodeId) {
return path.equals(rootDir) ? null : new PathNodeId(path.getParent());
}

@Override
public void setParentNode(NodeId nodeId, NodeId newParentNodeId) {
throw new AssertionError();
}

@Override
public boolean isWritable(NodeId nodeId) {
return false;
Expand Down

0 comments on commit 4832f9d

Please sign in to comment.