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 all 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 @@ -48,7 +48,7 @@ private Runner(SecurityAnalysisProvider provider) {
this.provider = Objects.requireNonNull(provider);
}

public CompletableFuture<SecurityAnalysisResult> runAsync(Network network,
public CompletableFuture<SecurityAnalysisReport> runAsync(Network network,
String workingStateId,
LimitViolationDetector detector,
LimitViolationFilter filter,
Expand All @@ -67,39 +67,20 @@ public CompletableFuture<SecurityAnalysisResult> runAsync(Network network,
return provider.run(network, workingStateId, detector, filter, computationManager, parameters, contingenciesProvider, interceptors);
}

public CompletableFuture<SecurityAnalysisResult> runAsync(Network network, LimitViolationFilter filter,
public CompletableFuture<SecurityAnalysisReport> runAsync(Network network, LimitViolationFilter filter,
ComputationManager computationManager) {
return runAsync(network, network.getVariantManager().getWorkingVariantId(), new DefaultLimitViolationDetector(), filter, computationManager, SecurityAnalysisParameters.load(), new EmptyContingencyListProvider(), Collections.emptyList());
}

public CompletableFuture<SecurityAnalysisResult> runAsync(Network network, ComputationManager computationManager) {
public CompletableFuture<SecurityAnalysisReport> runAsync(Network network, ComputationManager computationManager) {
return runAsync(network, LimitViolationFilter.load(), computationManager);
}

public CompletableFuture<SecurityAnalysisResult> runAsync(Network network) {
public CompletableFuture<SecurityAnalysisReport> 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,
public SecurityAnalysisReport run(Network network,
String workingStateId,
LimitViolationDetector detector,
LimitViolationFilter filter,
Expand All @@ -110,16 +91,16 @@ public SecurityAnalysisResult run(Network network,
return runAsync(network, workingStateId, detector, filter, computationManager, parameters, contingenciesProvider, interceptors).join();
}

public SecurityAnalysisResult run(Network network, LimitViolationFilter filter,
public SecurityAnalysisReport run(Network network, LimitViolationFilter filter,
ComputationManager computationManager) {
return run(network, network.getVariantManager().getWorkingVariantId(), new DefaultLimitViolationDetector(), filter, computationManager, SecurityAnalysisParameters.load(), new EmptyContingencyListProvider(), Collections.emptyList());
}

public SecurityAnalysisResult run(Network network, ComputationManager computationManager) {
public SecurityAnalysisReport run(Network network, ComputationManager computationManager) {
return run(network, LimitViolationFilter.load(), computationManager);
}

public SecurityAnalysisResult run(Network network) {
public SecurityAnalysisReport run(Network network) {
return run(network, LocalComputationManager.getDefault());
}

Expand Down Expand Up @@ -157,7 +138,7 @@ public static Runner find() {
return find(null);
}

public static CompletableFuture<SecurityAnalysisResult> runAsync(Network network,
public static CompletableFuture<SecurityAnalysisReport> runAsync(Network network,
String workingStateId,
LimitViolationDetector detector,
LimitViolationFilter filter,
Expand All @@ -168,20 +149,20 @@ public static CompletableFuture<SecurityAnalysisResult> runAsync(Network network
return find().runAsync(network, workingStateId, detector, filter, computationManager, parameters, contingenciesProvider, interceptors);
}

public static CompletableFuture<SecurityAnalysisResult> runAsync(Network network, LimitViolationFilter filter,
public static CompletableFuture<SecurityAnalysisReport> runAsync(Network network, LimitViolationFilter filter,
ComputationManager computationManager) {
return find().runAsync(network, filter, computationManager);
}

public static CompletableFuture<SecurityAnalysisResult> runAsync(Network network, ComputationManager computationManager) {
public static CompletableFuture<SecurityAnalysisReport> runAsync(Network network, ComputationManager computationManager) {
return find().runAsync(network, computationManager);
}

public static CompletableFuture<SecurityAnalysisResult> runAsync(Network network) {
public static CompletableFuture<SecurityAnalysisReport> runAsync(Network network) {
return find().runAsync(network);
}

public static SecurityAnalysisResult run(Network network,
public static SecurityAnalysisReport run(Network network,
String workingStateId,
LimitViolationDetector detector,
LimitViolationFilter filter,
Expand All @@ -192,16 +173,16 @@ public static SecurityAnalysisResult run(Network network,
return find().run(network, workingStateId, detector, filter, computationManager, parameters, contingenciesProvider, interceptors);
}

public static SecurityAnalysisResult run(Network network, LimitViolationFilter filter,
public static SecurityAnalysisReport run(Network network, LimitViolationFilter filter,
ComputationManager computationManager) {
return find().run(network, filter, computationManager);
}

public static SecurityAnalysisResult run(Network network, ComputationManager computationManager) {
public static SecurityAnalysisReport run(Network network, ComputationManager computationManager) {
return find().run(network, computationManager);
}

public static SecurityAnalysisResult run(Network network) {
public static SecurityAnalysisReport run(Network network) {
return find().run(network);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* 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
Expand Down 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<SecurityAnalysisReport> 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
@@ -1,30 +1,35 @@
/**
* Copyright (c) 2019, RTE (http://www.rte-france.com)
* Copyright (c) 2021, 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 com.powsybl.security;

import com.powsybl.commons.extensions.AbstractExtendable;

import java.util.Objects;
import java.util.Optional;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
* @author Thomas Adam <tadam at silicom.fr>
*/
public class SecurityAnalysisResultWithLog {
public class SecurityAnalysisReport extends AbstractExtendable<SecurityAnalysisReport> {

private final SecurityAnalysisResult result;

private byte[] logBytes;

public SecurityAnalysisResultWithLog(SecurityAnalysisResult result) {
this.result = Objects.requireNonNull(result);
public static SecurityAnalysisReport empty() {
return new SecurityAnalysisReport(SecurityAnalysisResult.empty());
}

public SecurityAnalysisResultWithLog(SecurityAnalysisResult result, byte[] logBytes) {
public SecurityAnalysisReport(SecurityAnalysisResult result) {
this.result = Objects.requireNonNull(result);
this.logBytes = logBytes;
}

public SecurityAnalysisResult getResult() {
return result;
}

/**
Expand All @@ -35,7 +40,8 @@ public Optional<byte[]> getLogBytes() {
return Optional.ofNullable(logBytes);
}

public SecurityAnalysisResult getResult() {
return result;
public SecurityAnalysisReport setLogBytes(byte[] logBytes) {
this.logBytes = logBytes;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.ExecutionEnvironment;
import com.powsybl.computation.ExecutionHandler;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.SecurityAnalysisResultWithLog;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.execution.SecurityAnalysisExecution;
import com.powsybl.security.execution.SecurityAnalysisExecutionInput;

Expand Down Expand Up @@ -39,20 +38,10 @@ public DistributedSecurityAnalysisExecution(ExternalSecurityAnalysisConfig confi
}

@Override
public CompletableFuture<SecurityAnalysisResult> execute(ComputationManager computationManager,
public CompletableFuture<SecurityAnalysisReport> 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);
ExecutionHandler<SecurityAnalysisReport> executionHandler = SecurityAnalysisExecutionHandlers.distributed(data, subtaskCount);
return computationManager.execute(itoolsEnv, executionHandler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.ExecutionEnvironment;
import com.powsybl.computation.ExecutionHandler;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.SecurityAnalysisResultWithLog;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.execution.SecurityAnalysisExecution;
import com.powsybl.security.execution.SecurityAnalysisExecutionInput;

Expand Down Expand Up @@ -44,20 +43,11 @@ public ForwardedSecurityAnalysisExecution(ExternalSecurityAnalysisConfig config,
}

@Override
public CompletableFuture<SecurityAnalysisResult> execute(ComputationManager computationManager,
public CompletableFuture<SecurityAnalysisReport> execute(ComputationManager computationManager,
SecurityAnalysisExecutionInput data) {

ExecutionEnvironment itoolsEnv = new ExecutionEnvironment(Collections.emptyMap(), "security_analysis_", config.isDebug());
ExecutionHandler<SecurityAnalysisResult> executionHandler = SecurityAnalysisExecutionHandlers.forwarded(data, forwardedTaskCount);
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);
ExecutionHandler<SecurityAnalysisReport> executionHandler = SecurityAnalysisExecutionHandlers.forwarded(data, forwardedTaskCount);
return computationManager.execute(itoolsEnv, executionHandler);
}

Expand Down
Loading