-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config and runner fixes needed to be tested.
- Loading branch information
1 parent
720987e
commit 71bef57
Showing
13 changed files
with
414 additions
and
298 deletions.
There are no files selected for viewing
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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/org/gridsuite/cases/importer/job/CaseAcquisitionConfig.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,48 @@ | ||
package org.gridsuite.cases.importer.job; | ||
|
||
import com.powsybl.commons.PowsyblException; | ||
import com.powsybl.commons.config.ModuleConfig; | ||
import com.powsybl.commons.config.PlatformConfig; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Data | ||
@Configuration | ||
@ConfigurationProperties(prefix = "org.gridsuite.job") | ||
public class CaseAcquisitionConfig { | ||
public CaseAcquisitionConfig() { | ||
final PlatformConfig platformConfig = PlatformConfig.defaultConfig(); | ||
final ModuleConfig moduleConfigAcquisitionServer = platformConfig.getOptionalModuleConfig("acquisition-server").orElseThrow(() -> new PowsyblException("Module acquisition-server not found !!")); | ||
this.acquisitionServer = new AcquisitionServerConfig( | ||
moduleConfigAcquisitionServer.getStringProperty("username"), | ||
moduleConfigAcquisitionServer.getStringProperty("password"), | ||
moduleConfigAcquisitionServer.getStringProperty("url"), | ||
moduleConfigAcquisitionServer.getStringProperty("cases-directory"), | ||
moduleConfigAcquisitionServer.getStringProperty("label") | ||
); | ||
final ModuleConfig moduleConfigCaseServer = platformConfig.getOptionalModuleConfig("case-server").orElseThrow(() -> new PowsyblException("Module case-server not found !!")); | ||
this.caseServer = new CaseServerConfig(moduleConfigCaseServer.getStringProperty("url")); | ||
} | ||
|
||
private AcquisitionServerConfig acquisitionServer; | ||
private CaseServerConfig caseServer; | ||
|
||
@Data | ||
@AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
public static class AcquisitionServerConfig { | ||
private String username; | ||
private String password; | ||
private String url; | ||
private String casesDirectory; | ||
private String label; | ||
} | ||
|
||
@Data | ||
@AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
public static class CaseServerConfig { | ||
private String url; | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
src/main/java/org/gridsuite/cases/importer/job/CaseAcquisitionRunner.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,71 @@ | ||
/** | ||
* 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 org.gridsuite.cases.importer.job; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class CaseAcquisitionRunner implements CommandLineRunner { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CaseAcquisitionRunner.class); | ||
|
||
private final DataSource dataSource; | ||
private final CaseAcquisitionConfig config; | ||
|
||
@Override | ||
public void run(final String... args) throws Exception { | ||
final CaseImportServiceRequester caseImportServiceRequester = new CaseImportServiceRequester(config.getCaseServer().getUrl()); | ||
|
||
try (AcquisitionServer acquisitionServer = new AcquisitionServer(config.getAcquisitionServer().getUrl(), | ||
config.getAcquisitionServer().getUsername(), | ||
config.getAcquisitionServer().getPassword()); | ||
CaseImportLogger caseImportLogger = new CaseImportLogger(dataSource)) { | ||
acquisitionServer.open(); | ||
|
||
final String serverLabel = config.getAcquisitionServer().getLabel(); | ||
Map<String, String> filesToAcquire = acquisitionServer.listFiles(config.getAcquisitionServer().getCasesDirectory()); | ||
LOGGER.info("{} files found on server", filesToAcquire.size()); | ||
|
||
List<String> filesImported = new ArrayList<>(); | ||
List<String> filesAlreadyImported = new ArrayList<>(); | ||
List<String> filesImportFailed = new ArrayList<>(); | ||
for (final Entry<String, String> fileInfo : filesToAcquire.entrySet()) { | ||
if (!caseImportLogger.isImportedFile(fileInfo.getKey(), serverLabel)) { | ||
TransferableFile acquiredFile = acquisitionServer.getFile(fileInfo.getKey(), fileInfo.getValue()); | ||
LOGGER.info("Importing file '{}'...", fileInfo.getKey()); | ||
boolean importOk = caseImportServiceRequester.importCase(acquiredFile); | ||
if (importOk) { | ||
caseImportLogger.logFileAcquired(acquiredFile.getName(), serverLabel, new Date()); | ||
filesImported.add(fileInfo.getKey()); | ||
} else { | ||
filesImportFailed.add(fileInfo.getKey()); | ||
} | ||
} else { | ||
filesAlreadyImported.add(fileInfo.getKey()); | ||
} | ||
} | ||
LOGGER.info("===== JOB EXECUTION SUMMARY ====="); | ||
LOGGER.info("{} files already imported", filesAlreadyImported.size()); | ||
LOGGER.info("{} files successfully imported", filesImported.size()); | ||
filesImported.forEach(f -> LOGGER.info("File '{}' successfully imported", f)); | ||
LOGGER.info("{} files import failed", filesImportFailed.size()); | ||
filesImportFailed.forEach(f -> LOGGER.info("File '{}' import failed !!", f)); | ||
LOGGER.info("================================="); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.