Skip to content

Commit

Permalink
Replace CommandExecutor by ComputationManager in DataComparator
Browse files Browse the repository at this point in the history
  • Loading branch information
yichen88 committed Sep 6, 2017
1 parent b813620 commit 0a8e915
Showing 1 changed file with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

Expand Down Expand Up @@ -129,19 +126,37 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception {
throw new RuntimeException("either specify both set1 and set2 parameters, or none of them");
}

try (CommandExecutor executor = context.getComputationManager().newCommandExecutor(createEnv(config), WORKING_DIR_PREFIX, config.isDebug())) {
Path workingDir = executor.getWorkingDir();
eu.itesla_project.computation.Command cmd = createConcatMatFilesCmd(config.getValidationDir(), MOD3FILES_PATTERN, config.getValidationDir().resolve(CONCATSAMPLESFILENAME), config);
int priority = 1;
ExecutionReport report = executor.start(new CommandExecution(cmd, 1, priority));
report.log();
if (report.getErrors().isEmpty()) {
report = executor.start(new CommandExecution(createDataComparatorCmd(config.getValidationDir().resolve(M1INPUTFILENAME).toFile().getAbsolutePath(), config.getValidationDir().resolve(CONCATSAMPLESFILENAME).toFile().getAbsolutePath(), set1, set2, config), 1, priority));
ExecutionEnvironment executionEnvironment = new ExecutionEnvironment(createEnv(config), WORKING_DIR_PREFIX, config.isDebug());
context.getComputationManager().execute(executionEnvironment, new AbstractExecutionHandler<Void>() {
@Override
public List<CommandExecution> before(Path workingDir) throws IOException {
eu.itesla_project.computation.Command cmd = createConcatMatFilesCmd(config.getValidationDir(), MOD3FILES_PATTERN, config.getValidationDir().resolve(CONCATSAMPLESFILENAME), config);
return Arrays.asList(new CommandExecution(cmd, 1, 1));
}

@Override
public Void after(Path workingDir, ExecutionReport report) throws IOException {
report.log();
Files.copy(workingDir.resolve(DATA_COMPARATOR_OUT_FIG), Paths.get(oFilePrefix + ".fig"), REPLACE_EXISTING);
Files.copy(workingDir.resolve(DATA_COMPARATOR_OUT_PNG), Paths.get(oFilePrefix + ".png"), REPLACE_EXISTING);
if (report.getErrors().isEmpty()) {
context.getComputationManager().execute(executionEnvironment, new AbstractExecutionHandler<Void>() {
@Override
public List<CommandExecution> before(Path workingDir) throws IOException {
eu.itesla_project.computation.Command dataCompartorCmd = createDataComparatorCmd(config.getValidationDir().resolve(M1INPUTFILENAME).toFile().getAbsolutePath(), config.getValidationDir().resolve(CONCATSAMPLESFILENAME).toFile().getAbsolutePath(), set1, set2, config);
return Arrays.asList(new CommandExecution(dataCompartorCmd, 1, 1));
}

@Override
public Void after(Path workingDir, ExecutionReport report) throws IOException {
report.log();
Files.copy(workingDir.resolve(DATA_COMPARATOR_OUT_FIG), Paths.get(oFilePrefix + ".fig"), REPLACE_EXISTING);
Files.copy(workingDir.resolve(DATA_COMPARATOR_OUT_PNG), Paths.get(oFilePrefix + ".png"), REPLACE_EXISTING);
return null;
}
});
}
return null;
}
}
});
}


Expand Down

0 comments on commit 0a8e915

Please sign in to comment.