Skip to content
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>fr.insalyon.creatis</groupId>
<artifactId>gasw-batch-plugin</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>jar</packaging>

<name>GASW-Batch-Plugin</name>
Expand All @@ -14,7 +14,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<gasw-version>4.2</gasw-version>
<gasw-version>4.3</gasw-version>
</properties>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
final public class BatchMonitor extends GaswMonitor {

@Getter
@Setter
private BatchManager manager;
@Setter
private boolean stop = false;

public BatchMonitor() {
super();
}

private boolean notRunningJob(GaswStatus s) {

Check warning on line 32 in src/main/java/fr/insalyon/creatis/gasw/executor/batch/BatchMonitor.java

View workflow job for this annotation

GitHub Actions / all

Parameter 's' is not assigned and could be declared final

Reports method and constructor parameters that can be made final because they are never reassigned within the body of the method. This rule ignores unused parameters so as not to overlap with the rule {% rule java/bestpractices/UnusedFormalParameter %}. It will also ignore the parameters of abstract methods. MethodArgumentCouldBeFinal (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/snapshot/pmd_rules_java_codestyle.html#methodargumentcouldbefinal
return s != GaswStatus.RUNNING
&& s != GaswStatus.QUEUED
&& s != GaswStatus.UNDEFINED
Expand All @@ -37,7 +37,7 @@
}

@Override
public void run() {

Check warning on line 40 in src/main/java/fr/insalyon/creatis/gasw/executor/batch/BatchMonitor.java

View workflow job for this annotation

GitHub Actions / all

The method 'run()' has a cyclomatic complexity of 10.

The complexity of methods directly affects maintenance costs and readability. Concentrating too much decisional logic in a single method makes its behaviour hard to read and change. Cyclomatic complexity assesses the complexity of a method by counting the number of decision points in a method, plus one for the method entry. Decision points are places where the control flow jumps to another place in the program. As such, they include all control flow statements, such as `if`, `while`, `for`, and `case`. For more details on the calculation, see the documentation {% jdoc java::lang.java.metrics.JavaMetrics#CYCLO %}. Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote high complexity, and 11+ is very high complexity. By default, this rule reports methods with a complexity >= 10. Additionally, classes with many methods of moderate complexity get reported as well once the total of their methods' complexities reaches 80, even if none of the methods was directly reported. Reported methods should be broken down into several smaller methods. Reported classes should probably be broken down into subcomponents. CyclomaticComplexity (Priority: 3, Ruleset: Design) https://docs.pmd-code.org/snapshot/pmd_rules_java_design.html#cyclomaticcomplexity

Check warning on line 40 in src/main/java/fr/insalyon/creatis/gasw/executor/batch/BatchMonitor.java

View workflow job for this annotation

GitHub Actions / all

The method 'run()' has a cognitive complexity of 22, current threshold is 15

Methods that are highly complex are difficult to read and more costly to maintain. If you include too much decisional logic within a single method, you make its behavior hard to understand and more difficult to modify. Cognitive complexity is a measure of how difficult it is for humans to read and understand a method. Code that contains a break in the control flow is more complex, whereas the use of language shorthands doesn't increase the level of complexity. Nested control flows can make a method more difficult to understand, with each additional nesting of the control flow leading to an increase in cognitive complexity. Information about Cognitive complexity can be found in the original paper here: <https://www.sonarsource.com/docs/CognitiveComplexity.pdf> By default, this rule reports methods with a complexity of 15 or more. Reported methods should be broken down into less complex components. CognitiveComplexity (Priority: 3, Ruleset: Design) https://docs.pmd-code.org/snapshot/pmd_rules_java_design.html#cognitivecomplexity
while ( ! stop) {
verifySignaledJobs();
try {
Expand All @@ -55,7 +55,7 @@
}

jobDAO.update(daoJob);
new BatchOutputParser(job).start();

Check warning on line 58 in src/main/java/fr/insalyon/creatis/gasw/executor/batch/BatchMonitor.java

View workflow job for this annotation

GitHub Actions / all

Avoid instantiating new objects inside loops

New objects created within loops should be checked to see if they can created outside them and reused. AvoidInstantiatingObjectsInLoops (Priority: 3, Ruleset: Performance) https://docs.pmd-code.org/snapshot/pmd_rules_java_performance.html#avoidinstantiatingobjectsinloops

} else if (status == GaswStatus.RUNNING) {
updateJob(daoJob, status);
Expand All @@ -74,7 +74,7 @@
}

@Override
public synchronized void add(final String jobID, final String symbolicName, final String fileName, final String parameters) throws GaswException {

Check warning on line 77 in src/main/java/fr/insalyon/creatis/gasw/executor/batch/BatchMonitor.java

View workflow job for this annotation

GitHub Actions / all

Rather than using a lot of String arguments, consider using a container object for those values.

When you write a public method, you should be thinking in terms of an API. If your method is public, it means other class will use it, therefore, you want (or need) to offer a comprehensive and evolutive API. If you pass a lot of information as a simple series of Strings, you may think of using an Object to represent all those information. You'll get a simpler API (such as doWork(Workload workload), rather than a tedious series of Strings) and more importantly, if you need at some point to pass extra data, you'll be able to do so by simply modifying or extending Workload without any modification to your API. UseObjectForClearerAPI (Priority: 3, Ruleset: Design) https://docs.pmd-code.org/snapshot/pmd_rules_java_design.html#useobjectforclearerapi
final Job job = new Job(jobID, GaswConfiguration.getInstance().getSimulationID(),
GaswStatus.QUEUED, symbolicName, fileName, parameters,
Constants.EXECUTOR_NAME);
Expand All @@ -84,7 +84,7 @@
log.info("Adding job: {}", jobID);
}

public synchronized void stopMonitor(boolean force) throws InterruptedException {

Check warning on line 87 in src/main/java/fr/insalyon/creatis/gasw/executor/batch/BatchMonitor.java

View workflow job for this annotation

GitHub Actions / all

Parameter 'force' is not assigned and could be declared final

Reports method and constructor parameters that can be made final because they are never reassigned within the body of the method. This rule ignores unused parameters so as not to overlap with the rule {% rule java/bestpractices/UnusedFormalParameter %}. It will also ignore the parameters of abstract methods. MethodArgumentCouldBeFinal (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/snapshot/pmd_rules_java_codestyle.html#methodargumentcouldbefinal
if (force) {
interrupt();
} else {
Expand All @@ -98,7 +98,7 @@

// kill jobs that are still running (context of soft-kill)
try {
for (Job job : jobDAO.getActiveJobs()) {

Check warning on line 101 in src/main/java/fr/insalyon/creatis/gasw/executor/batch/BatchMonitor.java

View workflow job for this annotation

GitHub Actions / all

Local variable 'job' could be declared final

A local variable assigned only once can be declared final. LocalVariableCouldBeFinal (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/snapshot/pmd_rules_java_codestyle.html#localvariablecouldbefinal
kill(job);
}
} catch (DAOException e) {
Expand All @@ -122,7 +122,7 @@
}

@Override
protected void kill(Job job) {

Check warning on line 125 in src/main/java/fr/insalyon/creatis/gasw/executor/batch/BatchMonitor.java

View workflow job for this annotation

GitHub Actions / all

Parameter 'job' is not assigned and could be declared final

Reports method and constructor parameters that can be made final because they are never reassigned within the body of the method. This rule ignores unused parameters so as not to overlap with the rule {% rule java/bestpractices/UnusedFormalParameter %}. It will also ignore the parameters of abstract methods. MethodArgumentCouldBeFinal (Priority: 3, Ruleset: Code Style) https://docs.pmd-code.org/snapshot/pmd_rules_java_codestyle.html#methodargumentcouldbefinal
final BatchJob batchJob = manager.getJob(job.getId());

if (batchJob != null) {
Expand All @@ -133,6 +133,7 @@
log.info("Job {} successfully killed!", job.getId());

updateJob(job, GaswStatus.DELETED);
new BatchOutputParser(batchJob).start();

} catch (GaswException e) {
log.warn("Failed to kill job {}", job.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,10 @@ public GaswOutput getGaswOutput() throws GaswException {
if (job.getStatus() != GaswStatus.DELETED) {
exitCode = parseStdOut(stdOut);
exitCode = parseStdErr(stdErr, exitCode);

switch (exitCode) {
case 0:
gaswExitCode = GaswExitCode.SUCCESS;
break;
case 1:
gaswExitCode = GaswExitCode.ERROR_READ_GRID;
break;
case 2:
gaswExitCode = GaswExitCode.ERROR_WRITE_GRID;
break;
case 6:
gaswExitCode = GaswExitCode.EXECUTION_FAILED;
break;
case 7:
gaswExitCode = GaswExitCode.ERROR_WRITE_LOCAL;
break;
default:
gaswExitCode = GaswExitCode.UNDEFINED;
}
gaswExitCode = GaswExitCode.fromExitCode(exitCode);
} else {
gaswExitCode = GaswExitCode.EXECUTION_CANCELED;
parseNonStdOut(GaswExitCode.EXECUTION_CANCELED.getExitCode());
}

return new GaswOutput(job.getId(), gaswExitCode, "", uploadedResults,
Expand Down
Loading