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

Refactoring security-analysis-api : Remove WithLog suffixed methods #1667

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,6 @@ public CompletableFuture<SecurityAnalysisResult> runAsync(Network network) {
return runAsync(network, LocalComputationManager.getDefault());
}

public CompletableFuture<SecurityAnalysisResultWithLog> runAsyncWithLog(Network network,
String workingStateId,
LimitViolationDetector detector,
LimitViolationFilter filter,
ComputationManager computationManager,
SecurityAnalysisParameters parameters,
ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors) {
Objects.requireNonNull(network, "Network should not be null");
Objects.requireNonNull(workingStateId, "WorkingVariantId should not be null");
Objects.requireNonNull(detector, "LimitViolation detector should not be null");
Objects.requireNonNull(filter, "LimitViolation filter should not be null");
Objects.requireNonNull(computationManager, "ComputationManager should not be null");
Objects.requireNonNull(contingenciesProvider, "Contingencies provider should not be null");
Objects.requireNonNull(parameters, "Sensitivity analysis parameters should not be null");
Objects.requireNonNull(interceptors, "Interceptor list should not be null");
return provider.runWithLog(network, workingStateId, detector, filter, computationManager, parameters, contingenciesProvider, interceptors);
}

public SecurityAnalysisResult run(Network network,
String workingStateId,
LimitViolationDetector detector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,12 @@ public interface SecurityAnalysisProvider extends Versionable, PlatformConfigNam
/**
* Run an asynchronous single security analysis job.
*
* @param network IIDM network on which the security analysis will be performed
* @param workingVariantId network variant ID on which the analysis will be performed
* @param detector
* @param filter
* @param computationManager
* @param parameters specific security analysis parameters
* @param contingenciesProvider provides list of contingencies
* @param interceptors
* @return a {@link CompletableFuture} on {@link SecurityAnalysisResult} that gathers security factor values
*/
CompletableFuture<SecurityAnalysisResult> run(Network network,
String workingVariantId,
LimitViolationDetector detector,
LimitViolationFilter filter,
ComputationManager computationManager,
SecurityAnalysisParameters parameters,
ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors);

/**
* To be consistent with {@link #run(Network, String, LimitViolationDetector, LimitViolationFilter, ComputationManager, SecurityAnalysisParameters, ContingenciesProvider, List)}, this method would also complete exceptionally
* if there are exceptions thrown. But the original exception would be wrapped in {@link com.powsybl.computation.ComputationException}, and those .out/.err log file's contents
* are be collected in the {@link com.powsybl.computation.ComputationException} too.
*
*
* <pre> {@code
* try {
* SecurityAnalysisResultWithLog resultWithLog = securityAnalysis.runAsyncWithLog(network, variantId, detector, filter, computationManager, parameters, contingenciesProvider, interceptors).join();
* result = resultWithLog.getResult();
* SecurityAnalysisResult result = securityAnalysis.run(network, variantId, detector, filter, computationManager, parameters, contingenciesProvider, interceptors).join();
* } catch (CompletionException e) {
* if (e.getCause() instanceof ComputationException) {
* ComputationException computationException = (ComputationException) e.getCause();
Expand All @@ -82,6 +59,7 @@ CompletableFuture<SecurityAnalysisResult> run(Network network,
* throw e;
* }
* }</pre>
*
* @param network IIDM network on which the security analysis will be performed
* @param workingVariantId network variant ID on which the analysis will be performed
* @param detector
Expand All @@ -90,17 +68,14 @@ CompletableFuture<SecurityAnalysisResult> run(Network network,
* @param parameters specific security analysis parameters
* @param contingenciesProvider provides list of contingencies
* @param interceptors
* @return
* @return a {@link CompletableFuture} on {@link SecurityAnalysisResult} that gathers security factor values
*/

default CompletableFuture<SecurityAnalysisResultWithLog> runWithLog(Network network,
String workingVariantId,
LimitViolationDetector detector,
LimitViolationFilter filter,
ComputationManager computationManager,
SecurityAnalysisParameters parameters,
ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors) {
return run(network, workingVariantId, detector, filter, computationManager, parameters, contingenciesProvider, interceptors).thenApply(r -> new SecurityAnalysisResultWithLog(r, null));
}
CompletableFuture<SecurityAnalysisResult> run(Network network,
String workingVariantId,
LimitViolationDetector detector,
LimitViolationFilter filter,
ComputationManager computationManager,
SecurityAnalysisParameters parameters,
ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand All @@ -23,6 +24,8 @@ public class SecurityAnalysisResult extends AbstractExtendable<SecurityAnalysisR

private final List<PostContingencyResult> postContingencyResults;

private byte[] logBytes;
miovd marked this conversation as resolved.
Show resolved Hide resolved

public static SecurityAnalysisResult empty() {
return new SecurityAnalysisResult(LimitViolationsResult.empty(), Collections.emptyList());
}
Expand All @@ -49,4 +52,17 @@ public LimitViolationsResult getPreContingencyResult() {
public List<PostContingencyResult> getPostContingencyResults() {
return postContingencyResults;
}

/**
* Gets log file in bytes.
* @return an Optional describing the zip bytes
*/
public Optional<byte[]> getLogBytes() {
return Optional.ofNullable(logBytes);
}

public SecurityAnalysisResult setLogBytes(byte[] logBytes) {
this.logBytes = logBytes;
return this;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.powsybl.computation.ExecutionEnvironment;
import com.powsybl.computation.ExecutionHandler;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.SecurityAnalysisResultWithLog;
import com.powsybl.security.execution.SecurityAnalysisExecution;
import com.powsybl.security.execution.SecurityAnalysisExecutionInput;

Expand Down Expand Up @@ -41,21 +40,11 @@ public DistributedSecurityAnalysisExecution(ExternalSecurityAnalysisConfig confi
@Override
public CompletableFuture<SecurityAnalysisResult> execute(ComputationManager computationManager,
SecurityAnalysisExecutionInput data) {

ExecutionEnvironment itoolsEnv = new ExecutionEnvironment(Collections.emptyMap(), "security_analysis_task_", config.isDebug());
ExecutionHandler<SecurityAnalysisResult> executionHandler = SecurityAnalysisExecutionHandlers.distributed(data, subtaskCount);
return computationManager.execute(itoolsEnv, executionHandler);
}

@Override
public CompletableFuture<SecurityAnalysisResultWithLog> executeWithLog(ComputationManager computationManager,
SecurityAnalysisExecutionInput data) {

ExecutionEnvironment itoolsEnv = new ExecutionEnvironment(Collections.emptyMap(), "security_analysis_task_", config.isDebug());
ExecutionHandler<SecurityAnalysisResultWithLog> executionHandler = SecurityAnalysisExecutionHandlers.distributedWithLog(data, subtaskCount);
return computationManager.execute(itoolsEnv, executionHandler);
}

private static int checkSubtaskCount(int count) {
checkArgument(count > 0, "Sub-tasks count must be positive.");
return count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.powsybl.computation.ExecutionEnvironment;
import com.powsybl.computation.ExecutionHandler;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.SecurityAnalysisResultWithLog;
import com.powsybl.security.execution.SecurityAnalysisExecution;
import com.powsybl.security.execution.SecurityAnalysisExecutionInput;

Expand Down Expand Up @@ -52,15 +51,6 @@ public CompletableFuture<SecurityAnalysisResult> execute(ComputationManager comp
return computationManager.execute(itoolsEnv, executionHandler);
}

@Override
public CompletableFuture<SecurityAnalysisResultWithLog> executeWithLog(ComputationManager computationManager,
SecurityAnalysisExecutionInput data) {

ExecutionEnvironment itoolsEnv = new ExecutionEnvironment(Collections.emptyMap(), "security_analysis_", config.isDebug());
ExecutionHandler<SecurityAnalysisResultWithLog> executionHandler = SecurityAnalysisExecutionHandlers.forwardedWithLogs(data, forwardedTaskCount);
return computationManager.execute(itoolsEnv, executionHandler);
}

private static Integer checkForwardedTaskCount(Integer count) {
checkArgument(count == null || count > 0, "Forwarded task count must be positive.");
return count;
Expand Down
Loading