org.jboss.shrinkwrap.api.Domain Java Examples

The following examples show how to use org.jboss.shrinkwrap.api.Domain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void init(SimulationParameters parameters, Map<String, Object> context) throws Exception {
    Objects.requireNonNull(parameters, "parameters is null");
    Objects.requireNonNull(context, "context is null");

    this.parameters = parameters;
    dictionary = getDictionary(context);

    // read all contingencies
    allContingencies.addAll(contingenciesProvider.getContingencies(network));

    if (config.isUseBroadcast()) {
        Domain domain = ShrinkWrap.createDomain();
        try (OutputStream os = computationManager.newCommonFile(ALL_SCENARIOS_ZIP_FILE_NAME)) {
            writeAllScenarios(domain, os);
        }
        try (OutputStream os = computationManager.newCommonFile(WP43_ALL_CONFIGS_ZIP_FILE_NAME)) {
            writeAllWp43Configs(domain, os);
        }
        try (OutputStream os = computationManager.newCommonFile(LIMITS_ZIP_FILE_NAME)) {
            writeLimits(network, dictionary, domain, os, exportConfig);
        }
    }
}
 
Example #2
Source File: EurostagScenario.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public GenericArchive writeFaultSeqArchive(Domain domain, List<Contingency> contingencies, Network network, EurostagDictionary dictionary, Function<Integer, String> seqFileNameFct) throws IOException {
    if ((contingencies == null) || (contingencies.isEmpty())) {
        throw new RuntimeException("contingencies list is empty, cannot write .seq scenario files");
    }
    GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class);
    try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) {
        Path rootDir = fileSystem.getPath("/");
        for (int i = 0; i < contingencies.size(); i++) {
            Contingency contingency = contingencies.get(i);
            Path seqFile = rootDir.resolve(seqFileNameFct.apply(i));
            try (BufferedWriter writer = Files.newBufferedWriter(seqFile, StandardCharsets.UTF_8)) {
                writeFaultSeq(writer, contingency, network, dictionary);
            }
        }
    }
    return archive;
}
 
Example #3
Source File: Swarm.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private void createShrinkWrapDomain() {
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
        if (isFatJar()) {
            Module appModule = Module.getBootModuleLoader().loadModule(APPLICATION_MODULE_NAME);
            Thread.currentThread().setContextClassLoader(appModule.getClassLoader());
        }
        Domain domain = ShrinkWrap.getDefaultDomain();
        domain.getConfiguration().getExtensionLoader().addOverride(ZipExporter.class, ZipExporterImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(ZipImporter.class, ZipImporterImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(ExplodedExporter.class, ExplodedExporterImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(ExplodedImporter.class, ExplodedImporterImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(JavaArchive.class, JavaArchiveImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(WebArchive.class, WebArchiveImpl.class);
    } catch (Exception e) {
        SwarmMessages.MESSAGES.shrinkwrapDomainSetupFailed(e);
    } finally {
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
 
Example #4
Source File: EurostagStabilization.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
private void writeDtaAndControls(Domain domain, OutputStream ddbOs, OutputStream dictGensOs) throws IOException {
    GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class);
    try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) {
        Path rootDir = fileSystem.getPath("/");
        ddbClient.dumpDtaFile(rootDir, DTA_FILE_NAME, network, parallelIndexes.toMap(), EurostagUtil.VERSION, dictionary.toMap(), parameters);
    }
    archive.as(ZipExporter.class).exportTo(ddbOs);
    //put just the generators dict csv file (extracted from the ddb files) in the common files set, to be used by wp43 transient stability index
    if (archive.get(DDB_DICT_GENS_CSV) != null) {
        ByteStreams.copy(archive.get(DDB_DICT_GENS_CSV).getAsset().openStream(), dictGensOs);
    } else {
        LOGGER.warn(DDB_DICT_GENS_CSV + " is missing in the dynamic data files set: some security indexers (e.g. transient stability) need this file");
    }
}
 
Example #5
Source File: EurostagStabilization.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void init(SimulationParameters parameters, Map<String, Object> context) throws Exception {
    Objects.requireNonNull(parameters, "parameters is null");
    Objects.requireNonNull(context, "context is null");

    this.parameters = parameters;

    // exportConfig = new EurostagEchExportConfig(config.isLfNoGeneratorMinMaxQ());
    // isLfNoGeneratorMinMaxQ must now be configured in eurostag-ech-export section
    exportConfig = EurostagEchExportConfig.load();

    fakeNodes = EurostagFakeNodes.build(network, exportConfig);

    parallelIndexes = BranchParallelIndexes.build(network, exportConfig, fakeNodes);

    // fill iTesla id to Esg id dictionary
    dictionary = EurostagDictionary.create(network, parallelIndexes, exportConfig, fakeNodes);

    if (config.isUseBroadcast()) {
        Domain domain = ShrinkWrap.createDomain();
        try (OutputStream ddbOs = computationManager.newCommonFile(DDB_ZIP_FILE_NAME);
             OutputStream dictGensOs = computationManager.newCommonFile(DDB_DICT_GENS_CSV)) {
            writeDtaAndControls(domain, ddbOs, dictGensOs);
        }
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(computationManager.newCommonFile(PRE_FAULT_SEQ_FILE_NAME), StandardCharsets.UTF_8))) {
            writePreFaultSeq(writer);
        }
    }

    context.put("dictionary", dictionary);
}
 
Example #6
Source File: EurostagStabilization.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
private EurostagContext before(Path workingDir) throws IOException {
    if (config.isDebug()) {
        // dump state info for debugging
        Networks.dumpStateId(workingDir, network);

        Exporter exporter = Exporters.getExporter("XIIDM");
        if (exporter != null) {
            Properties parameters = new Properties();
            parameters.setProperty("iidm.export.xml.indent", "true");
            parameters.setProperty("iidm.export.xml.with-branch-state-variables", "true");
            parameters.setProperty("iidm.export.xml.with-breakers", "true");
            try {
                exporter.export(network, parameters, new FileDataSource(workingDir, "network"));
            } catch (Exception e) {
                LOGGER.error(e.toString(), e);
            }
        }
    }

    EurostagContext context = new EurostagContext();

    if (!config.isUseBroadcast()) {
        Domain domain = ShrinkWrap.createDomain();
        try (OutputStream ddbOs = Files.newOutputStream(workingDir.resolve(DDB_ZIP_FILE_NAME));
             ByteArrayOutputStream dictGensOs = new ByteArrayOutputStream()) {
            writeDtaAndControls(domain, ddbOs, dictGensOs);
            dictGensOs.flush();
            context.dictGensCsv = dictGensOs.toByteArray();
        }
        try (BufferedWriter writer = Files.newBufferedWriter(workingDir.resolve(PRE_FAULT_SEQ_FILE_NAME), StandardCharsets.UTF_8)) {
            writePreFaultSeq(writer);
        }
    }

    writeEch(workingDir);

    return context;
}
 
Example #7
Source File: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
private void writeWp43Configs(Domain domain, List<Contingency> contingencies, OutputStream os) throws IOException, ConfigurationException {
    // copy wp43 configuration files
    GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class);
    try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) {
        Path rootDir = fileSystem.getPath("/");
        writeWp43Configs(contingencies, rootDir);
    }
    archive.as(ZipExporter.class).exportTo(os);
}
 
Example #8
Source File: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
protected static void writeLimits(Network network, EurostagDictionary dictionary, Domain domain, OutputStream os, EurostagEchExportConfig exportConfig) throws IOException {
    GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class);
    try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) {
        Path rootDir = fileSystem.getPath("/");
        // dump first current limits for each of the branches
        try (BufferedWriter writer = Files.newBufferedWriter(rootDir.resolve(CURRENT_LIMITS_CSV), StandardCharsets.UTF_8)) {
            for (Line l : network.getLines()) {
                if (exportConfig.isExportMainCCOnly() && !EchUtil.isInMainCc(l, exportConfig.isNoSwitch())) {
                    continue;
                }
                dumpLimits(dictionary, writer, l);
            }
            for (TwoWindingsTransformer twt : network.getTwoWindingsTransformers()) {
                if (exportConfig.isExportMainCCOnly() && !EchUtil.isInMainCc(twt, exportConfig.isNoSwitch())) {
                    continue;
                }
                dumpLimits(dictionary, writer, twt);
            }
            for (DanglingLine dl : network.getDanglingLines()) {
                if (exportConfig.isExportMainCCOnly() && !EchUtil.isInMainCc(dl, exportConfig.isNoSwitch())) {
                    continue;
                }
                dumpLimits(dictionary, writer, dl.getId(),
                        dl.getCurrentLimits(),
                        null,
                        dl.getTerminal().getVoltageLevel().getNominalV(),
                        dl.getTerminal().getVoltageLevel().getNominalV());
            }
        }
        try (BufferedWriter writer = Files.newBufferedWriter(rootDir.resolve(VOLTAGE_LIMITS_CSV), StandardCharsets.UTF_8)) {
            for (Bus b : EchUtil.getBuses(network, dictionary.getConfig())) {
                if (exportConfig.isExportMainCCOnly() && !(EchUtil.isInMainCc(b))) {
                    continue;
                }
                VoltageLevel vl = b.getVoltageLevel();
                if (!Double.isNaN(vl.getLowVoltageLimit()) && !Double.isNaN(vl.getHighVoltageLimit())) {
                    writer.write(dictionary.getEsgId(b.getId()));
                    writer.write(";");
                    writer.write(Double.toString(vl.getLowVoltageLimit()));
                    writer.write(";");
                    writer.write(Double.toString(vl.getHighVoltageLimit()));
                    writer.write(";");
                    writer.write(Double.toString(vl.getNominalV()));
                    writer.newLine();
                }
            }
        }

        //dump lines dictionary, for WP43 integration
        dumpLinesDictionary(network, dictionary, rootDir, exportConfig);
        //dump buses dictionary, for WP43 integration
        dumpBusesDictionary(network, dictionary, rootDir, exportConfig);
    }

    archive.as(ZipExporter.class).exportTo(os);
}
 
Example #9
Source File: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
private void writeScenarios(Domain domain, List<Contingency> contingencies, OutputStream os) throws IOException {
    GenericArchive archive = new EurostagScenario(parameters, config).writeFaultSeqArchive(domain, contingencies, network, dictionary,
        faultNum -> FAULT_SEQ_FILE_NAME.replace(CommandConstants.EXECUTION_NUMBER_PATTERN, Integer.toString(faultNum)));
    archive.as(ZipExporter.class).exportTo(os);
}
 
Example #10
Source File: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
private void writeAllScenarios(Domain domain, OutputStream os) throws IOException {
    writeScenarios(domain, allContingencies, os);
}
 
Example #11
Source File: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
private void writeAllWp43Configs(Domain domain, OutputStream os) throws IOException, ConfigurationException {
    writeWp43Configs(domain, allContingencies, os);
}
 
Example #12
Source File: Server.java    From thorntail with Apache License 2.0 4 votes vote down vote up
/**
 * @return the shrinkwrapDomain
 */
protected final Domain getShrinkwrapDomain() {
    return shrinkwrapDomain;
}
 
Example #13
Source File: Server.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
/**
 * @return the shrinkwrapDomain
 */
protected final Domain getShrinkwrapDomain() {
    return shrinkwrapDomain;
}