-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...c/main/java/eu/itesla_project/histodb/client/impl/util/CacheOnlyHistoDbClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) 2016, 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 eu.itesla_project.histodb.client.impl.util; | ||
|
||
import eu.itesla_project.histodb.client.impl.HistoDbCacheImpl; | ||
import eu.itesla_project.histodb.client.impl.HistoDbClientImpl; | ||
import eu.itesla_project.modules.histo.HistoDbClient; | ||
import eu.itesla_project.modules.histo.HistoDbClientFactory; | ||
import eu.itesla_project.histodb.client.impl.HistoDbConfig; | ||
|
||
/** | ||
* | ||
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com> | ||
*/ | ||
public class CacheOnlyHistoDbClientFactory implements HistoDbClientFactory { | ||
|
||
@Override | ||
public HistoDbClient create(boolean cache) { | ||
return new HistoDbClientImpl(HistoDbConfig.load(), new DummyHistoDbHttpClient(new HistoDbCacheImpl())); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...ient/src/main/java/eu/itesla_project/histodb/client/impl/util/DummyHistoDbHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2016, 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 eu.itesla_project.histodb.client.impl.util; | ||
|
||
import eu.itesla_project.histodb.client.impl.HistoDbHttpClient; | ||
import eu.itesla_project.histodb.client.impl.HistoDbUrl; | ||
import eu.itesla_project.modules.histo.cache.HistoDbCache; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Objects; | ||
|
||
/** | ||
* In the case of an MPI workflow we only want to work with cached data, so | ||
* we use a dummy http client that throws an exception in case of data not | ||
* in the cache. | ||
* | ||
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com> | ||
*/ | ||
class DummyHistoDbHttpClient implements HistoDbHttpClient { | ||
|
||
private final HistoDbCache cache; | ||
|
||
DummyHistoDbHttpClient(HistoDbCache cache) { | ||
Objects.requireNonNull(cache); | ||
this.cache = cache; | ||
} | ||
|
||
@Override | ||
public HistoDbCache getCache() { | ||
return cache; | ||
} | ||
|
||
private InputStream getData(String url) throws IOException { | ||
InputStream is = cache.getData(url); | ||
if (is == null) { | ||
throw new RuntimeException("Query '" + url + "' not cached"); | ||
} | ||
return is; | ||
} | ||
|
||
@Override | ||
public InputStream deleteHttpRequest(HistoDbUrl url) throws IOException { | ||
return getData(url.format()); | ||
} | ||
|
||
@Override | ||
public InputStream getHttpRequest(HistoDbUrl url) throws IOException { | ||
return getData(url.format()); | ||
} | ||
|
||
@Override | ||
public InputStream postHttpRequest(HistoDbUrl url, byte[] content) throws IOException { | ||
return getData(url.format()); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
modules/src/main/java/eu/itesla_project/modules/offline/ForwardingOfflineDb.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Copyright (c) 2016, 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 eu.itesla_project.modules.offline; | ||
|
||
import eu.itesla_project.iidm.network.Country; | ||
import eu.itesla_project.iidm.network.Network; | ||
import eu.itesla_project.simulation.securityindexes.SecurityIndex; | ||
import eu.itesla_project.simulation.securityindexes.SecurityIndexId; | ||
|
||
import java.io.Writer; | ||
import java.util.*; | ||
|
||
/** | ||
* | ||
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com> | ||
*/ | ||
public class ForwardingOfflineDb<T extends OfflineDb> implements OfflineDb { | ||
|
||
protected final T delegate; | ||
|
||
public ForwardingOfflineDb(T delegate) { | ||
this.delegate = Objects.requireNonNull(delegate); | ||
} | ||
|
||
@Override | ||
public List<String> listWorkflows() { | ||
return delegate.listWorkflows(); | ||
} | ||
|
||
@Override | ||
public String createWorkflow(String workflowId, OfflineWorkflowCreationParameters parameters) { | ||
return delegate.createWorkflow(workflowId, parameters); | ||
} | ||
|
||
@Override | ||
public OfflineWorkflowCreationParameters getParameters(String workflowId) { | ||
return delegate.getParameters(workflowId); | ||
} | ||
|
||
@Override | ||
public void deleteWorkflow(String workflowId) { | ||
delegate.deleteWorkflow(workflowId); | ||
} | ||
|
||
@Override | ||
public int createSample(String workflowId) { | ||
return delegate.createSample(workflowId); | ||
} | ||
|
||
@Override | ||
public void storeState(String workflowId, int sampleId, Network network, Set<Country> countryFilter) { | ||
delegate.storeState(workflowId, sampleId, network, countryFilter); | ||
} | ||
|
||
@Override | ||
public void storeTaskStatus(String workflowId, int sampleId, OfflineTaskType taskType, OfflineTaskStatus taskStatus, String taskFailureReason) { | ||
delegate.storeTaskStatus(workflowId, sampleId, taskType, taskStatus, taskFailureReason); | ||
} | ||
|
||
@Override | ||
public void storeSecurityIndexes(String workflowId, int sampleId, Collection<SecurityIndex> securityIndexes) { | ||
delegate.storeSecurityIndexes(workflowId, sampleId, securityIndexes); | ||
} | ||
|
||
@Override | ||
public int getSampleCount(String workflowId) { | ||
return delegate.getSampleCount(workflowId); | ||
} | ||
|
||
@Override | ||
public Collection<SecurityIndexId> getSecurityIndexIds(String workflowId) { | ||
return delegate.getSecurityIndexIds(workflowId); | ||
} | ||
|
||
@Override | ||
public Map<Integer, SecurityIndex> getSecurityIndexes(String workflowId, SecurityIndexId securityIndexId) { | ||
return delegate.getSecurityIndexes(workflowId, securityIndexId); | ||
} | ||
|
||
@Override | ||
public SecurityIndexSynthesis getSecurityIndexesSynthesis(String workflowId) { | ||
return delegate.getSecurityIndexesSynthesis(workflowId); | ||
} | ||
|
||
@Override | ||
public void exportCsv(String workflowId, Writer writer, OfflineDbCsvExportConfig config) { | ||
delegate.exportCsv(workflowId, writer, config); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
delegate.close(); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
modules/src/main/java/eu/itesla_project/modules/validation/XmlValidationDb.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright (c) 2016, 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 eu.itesla_project.modules.validation; | ||
|
||
import eu.itesla_project.iidm.datasource.DataSource; | ||
import eu.itesla_project.iidm.datasource.GzFileDataSource; | ||
import eu.itesla_project.iidm.network.Network; | ||
import eu.itesla_project.iidm.xml.NetworkXml; | ||
import eu.itesla_project.iidm.xml.XMLExportOptions; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* | ||
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com> | ||
*/ | ||
class XmlValidationDb implements ValidationDb { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(XmlValidationDb.class); | ||
|
||
private final Path dbDir; | ||
|
||
XmlValidationDb(Path dbDir) { | ||
this.dbDir = Objects.requireNonNull(dbDir); | ||
} | ||
|
||
private Path getDir(String path) { | ||
return dbDir.resolve(path); | ||
} | ||
|
||
@Override | ||
public void init(String path) { | ||
Path dir = getDir(path); | ||
try { | ||
if (Files.exists(dir)) { | ||
try (Stream<Path> stream = Files.list(dir)) { | ||
stream.filter(p -> p.getFileName().toString().endsWith(".xml.gz")).forEach(p -> { | ||
try { | ||
Files.delete(p); | ||
} catch (IOException e) { | ||
LOGGER.error(e.toString(), e); | ||
} | ||
}); | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void save(Network network, String path, String name) { | ||
LOGGER.info("Save {} in {} of validation db", name, path); | ||
Path dir = getDir(path); | ||
try { | ||
Files.createDirectories(dir); | ||
DataSource outputStreamFactory = new GzFileDataSource(dir, name); | ||
try (OutputStream os = new BufferedOutputStream(outputStreamFactory.newOutputStream(null, "xml", false))) { | ||
XMLExportOptions options = new XMLExportOptions(true, false, true, false); | ||
NetworkXml.write(network, options, os); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
modules/src/main/java/eu/itesla_project/modules/validation/XmlValidationDbFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) 2016, 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 eu.itesla_project.modules.validation; | ||
|
||
import eu.itesla_project.commons.config.PlatformConfig; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* | ||
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com> | ||
*/ | ||
public class XmlValidationDbFactory implements ValidationDbFactory { | ||
|
||
@Override | ||
public ValidationDb create() { | ||
Path dir = PlatformConfig.defaultConfig().getModuleConfig("xml-validation-db").getPathProperty("directory"); | ||
return new XmlValidationDb(dir); | ||
} | ||
|
||
} |