From da94e5c27265964c8c687dca4ef8ad422b547530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Bo=CC=88hm?= Date: Mon, 27 Nov 2023 13:59:19 +0100 Subject: [PATCH 1/2] Add push number range and fix length of tokens --- .../de/tum/cit/ase/domain/Simulation.java | 22 +++++++++++++ .../interaction/SimulatedArtemisStudent.java | 16 +++++++-- .../simulation/SimulationDataService.java | 2 ++ .../00000000000008_add_commit_range.xml | 15 +++++++++ .../00000000000009_increase_token_length.xml | 12 +++++++ .../resources/config/liquibase/master.xml | 2 ++ .../app/entities/simulation/simulation.ts | 2 ++ .../create-simulation-box.component.html | 33 +++++++++++++++++-- .../create-simulation-box.component.ts | 8 ++++- .../simulation-card.component.html | 1 + 10 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/config/liquibase/changelog/00000000000008_add_commit_range.xml create mode 100644 src/main/resources/config/liquibase/changelog/00000000000009_increase_token_length.xml diff --git a/src/main/java/de/tum/cit/ase/domain/Simulation.java b/src/main/java/de/tum/cit/ase/domain/Simulation.java index 0a8af7ed..7b65a6fc 100644 --- a/src/main/java/de/tum/cit/ase/domain/Simulation.java +++ b/src/main/java/de/tum/cit/ase/domain/Simulation.java @@ -44,6 +44,12 @@ public class Simulation { @Column(name = "user_range") private String userRange; + @Column(name = "number_of_commits_and_pushes_from") + private int numberOfCommitsAndPushesFrom; + + @Column(name = "number_of_commits_and_pushes_to") + private int numberOfCommitsAndPushesTo; + public Long getId() { return id; } @@ -132,6 +138,22 @@ public void setUserRange(String userRange) { this.userRange = userRange; } + public int getNumberOfCommitsAndPushesFrom() { + return numberOfCommitsAndPushesFrom; + } + + public void setNumberOfCommitsAndPushesFrom(int numberOfCommitsAndPushesFrom) { + this.numberOfCommitsAndPushesFrom = numberOfCommitsAndPushesFrom; + } + + public int getNumberOfCommitsAndPushesTo() { + return numberOfCommitsAndPushesTo; + } + + public void setNumberOfCommitsAndPushesTo(int numberOfCommitsAndPushesTo) { + this.numberOfCommitsAndPushesTo = numberOfCommitsAndPushesTo; + } + public enum Mode { /** * We create a temporary course and exam, prepare the exam and delete everything afterwards. diff --git a/src/main/java/de/tum/cit/ase/service/artemis/interaction/SimulatedArtemisStudent.java b/src/main/java/de/tum/cit/ase/service/artemis/interaction/SimulatedArtemisStudent.java index 3353fb9e..70da7d97 100644 --- a/src/main/java/de/tum/cit/ase/service/artemis/interaction/SimulatedArtemisStudent.java +++ b/src/main/java/de/tum/cit/ase/service/artemis/interaction/SimulatedArtemisStudent.java @@ -30,10 +30,20 @@ public class SimulatedArtemisStudent extends SimulatedArtemisUser { private String examIdString; private Long studentExamId; private StudentExam studentExam; - - public SimulatedArtemisStudent(String artemisUrl, ArtemisUser artemisUser, ArtemisUserService artemisUserService) { + private final int numberOfCommitsAndPushesFrom; + private final int numberOfCommitsAndPushesTo; + + public SimulatedArtemisStudent( + String artemisUrl, + ArtemisUser artemisUser, + ArtemisUserService artemisUserService, + int numberOfCommitsAndPushesFrom, + int numberOfCommitsAndPushesTo + ) { super(artemisUrl, artemisUser, artemisUserService); log = LoggerFactory.getLogger(SimulatedArtemisStudent.class.getName() + "." + username); + this.numberOfCommitsAndPushesFrom = numberOfCommitsAndPushesFrom; + this.numberOfCommitsAndPushesTo = numberOfCommitsAndPushesTo; } @Override @@ -293,7 +303,7 @@ private List solveAndSubmitProgrammingExercise(ProgrammingExercise long start = System.nanoTime(); requestStats.add(cloneRepo(repositoryCloneUrl)); - int n = new Random().nextInt(10, 15); // we do a random number of commits and pushes to make some noise + int n = new Random().nextInt(numberOfCommitsAndPushesFrom, numberOfCommitsAndPushesTo); // we do a random number of commits and pushes to make some noise log.info("Commit and push {}x for {}", n, username); for (int j = 0; j < n; j++) { sleep(100); diff --git a/src/main/java/de/tum/cit/ase/service/simulation/SimulationDataService.java b/src/main/java/de/tum/cit/ase/service/simulation/SimulationDataService.java index 7c738d12..7698ca4a 100644 --- a/src/main/java/de/tum/cit/ase/service/simulation/SimulationDataService.java +++ b/src/main/java/de/tum/cit/ase/service/simulation/SimulationDataService.java @@ -97,6 +97,8 @@ public boolean validateSimulation(Simulation simulation) { var basicRequirements = simulation.getMode() != null && simulation.getServer() != null && + simulation.getNumberOfCommitsAndPushesTo() > simulation.getNumberOfCommitsAndPushesFrom() && + simulation.getNumberOfCommitsAndPushesFrom() >= 0 && simulation.getName() != null && ((!simulation.isCustomizeUserRange() && simulation.getNumberOfUsers() > 0) || (simulation.isCustomizeUserRange() && diff --git a/src/main/resources/config/liquibase/changelog/00000000000008_add_commit_range.xml b/src/main/resources/config/liquibase/changelog/00000000000008_add_commit_range.xml new file mode 100644 index 00000000..ead7537a --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/00000000000008_add_commit_range.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/00000000000009_increase_token_length.xml b/src/main/resources/config/liquibase/changelog/00000000000009_increase_token_length.xml new file mode 100644 index 00000000..305707c5 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/00000000000009_increase_token_length.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index 87a8a498..c498ed75 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -16,6 +16,8 @@ + + diff --git a/src/main/webapp/app/entities/simulation/simulation.ts b/src/main/webapp/app/entities/simulation/simulation.ts index 42d6b77a..ba9e0647 100644 --- a/src/main/webapp/app/entities/simulation/simulation.ts +++ b/src/main/webapp/app/entities/simulation/simulation.ts @@ -13,6 +13,8 @@ export class Simulation { public runs: SimulationRun[], public creationDate: Date, public customizeUserRange: boolean, + public numberOfCommitsAndPushesFrom: number, + public numberOfCommitsAndPushesTo: number, public userRange?: string, ) {} } diff --git a/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.html b/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.html index 05625d90..e13bfabf 100644 --- a/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.html +++ b/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.html @@ -62,7 +62,7 @@ } -
+
@if (!customizeUserRange) { Number of users. Users with IDs 1 to n will be used. See Artemis Users for the IDs of your users. @@ -100,7 +100,36 @@ }
} - +
Number of commits and pushes:
+
+
+ + +
+
+ + +
+
+
+ For each student, the number of commits and pushes will be chosen randomly in the given range.
+ From must be positive and smaller than To. +
+
The simulation will not be executed immediately.
diff --git a/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.ts b/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.ts index 13bc365c..34f80d88 100644 --- a/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.ts +++ b/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.ts @@ -19,6 +19,8 @@ export class CreateSimulationBoxComponent implements OnInit { mode: Mode = Mode.CREATE_COURSE_AND_EXAM; customizeUserRange: boolean = false; userRange: string = ''; + numberOfCommitsAndPushesFrom: number = 8; + numberOfCommitsAndPushesTo: number = 15; availableServers = [ArtemisServer.TS1, ArtemisServer.TS3, ArtemisServer.PRODUCTION, ArtemisServer.STAGING]; availableModes = [ @@ -58,6 +60,8 @@ export class CreateSimulationBoxComponent implements OnInit { [], new Date(), this.customizeUserRange, + this.numberOfCommitsAndPushesFrom, + this.numberOfCommitsAndPushesTo, this.userRange, ); this.simulationToCreate.emit(simulation); @@ -67,7 +71,9 @@ export class CreateSimulationBoxComponent implements OnInit { inputValid(): boolean { const basicRequirements: boolean = this.name.length > 0 && - ((!this.customizeUserRange && this.numberOfUsers > 0) || (this.customizeUserRange && this.userRange.length > 0)); + ((!this.customizeUserRange && this.numberOfUsers > 0) || (this.customizeUserRange && this.userRange.length > 0)) && + this.numberOfCommitsAndPushesFrom > 0 && + this.numberOfCommitsAndPushesTo > this.numberOfCommitsAndPushesFrom; if (this.mode === Mode.CREATE_COURSE_AND_EXAM) { return basicRequirements; diff --git a/src/main/webapp/app/layouts/simulation-card/simulation-card.component.html b/src/main/webapp/app/layouts/simulation-card/simulation-card.component.html index 9a18d29a..8595369e 100644 --- a/src/main/webapp/app/layouts/simulation-card/simulation-card.component.html +++ b/src/main/webapp/app/layouts/simulation-card/simulation-card.component.html @@ -24,6 +24,7 @@ Users: {{ simulation.numberOfUsers }} }

+

Commits: {{ simulation.numberOfCommitsAndPushesFrom }} - {{ simulation.numberOfCommitsAndPushesTo }}

@if (simulation.mode != Mode.CREATE_COURSE_AND_EXAM) {

Course-ID: {{ simulation.courseId }}

} From 36ca3c7abf99853f82beefda2306dc6c7069144c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Bo=CC=88hm?= Date: Mon, 27 Nov 2023 13:59:19 +0100 Subject: [PATCH 2/2] Add push number range and fix length of tokens --- .../de/tum/cit/ase/domain/Simulation.java | 22 +++++++++++++ .../interaction/SimulatedArtemisStudent.java | 16 +++++++-- .../simulation/SimulationDataService.java | 2 ++ .../SimulationRunExecutionService.java | 11 ++++++- .../00000000000008_add_commit_range.xml | 15 +++++++++ .../00000000000009_increase_token_length.xml | 12 +++++++ .../resources/config/liquibase/master.xml | 2 ++ .../app/entities/simulation/simulation.ts | 2 ++ .../create-simulation-box.component.html | 33 +++++++++++++++++-- .../create-simulation-box.component.ts | 8 ++++- .../simulation-card.component.html | 1 + 11 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/config/liquibase/changelog/00000000000008_add_commit_range.xml create mode 100644 src/main/resources/config/liquibase/changelog/00000000000009_increase_token_length.xml diff --git a/src/main/java/de/tum/cit/ase/domain/Simulation.java b/src/main/java/de/tum/cit/ase/domain/Simulation.java index 0a8af7ed..7b65a6fc 100644 --- a/src/main/java/de/tum/cit/ase/domain/Simulation.java +++ b/src/main/java/de/tum/cit/ase/domain/Simulation.java @@ -44,6 +44,12 @@ public class Simulation { @Column(name = "user_range") private String userRange; + @Column(name = "number_of_commits_and_pushes_from") + private int numberOfCommitsAndPushesFrom; + + @Column(name = "number_of_commits_and_pushes_to") + private int numberOfCommitsAndPushesTo; + public Long getId() { return id; } @@ -132,6 +138,22 @@ public void setUserRange(String userRange) { this.userRange = userRange; } + public int getNumberOfCommitsAndPushesFrom() { + return numberOfCommitsAndPushesFrom; + } + + public void setNumberOfCommitsAndPushesFrom(int numberOfCommitsAndPushesFrom) { + this.numberOfCommitsAndPushesFrom = numberOfCommitsAndPushesFrom; + } + + public int getNumberOfCommitsAndPushesTo() { + return numberOfCommitsAndPushesTo; + } + + public void setNumberOfCommitsAndPushesTo(int numberOfCommitsAndPushesTo) { + this.numberOfCommitsAndPushesTo = numberOfCommitsAndPushesTo; + } + public enum Mode { /** * We create a temporary course and exam, prepare the exam and delete everything afterwards. diff --git a/src/main/java/de/tum/cit/ase/service/artemis/interaction/SimulatedArtemisStudent.java b/src/main/java/de/tum/cit/ase/service/artemis/interaction/SimulatedArtemisStudent.java index 3353fb9e..70da7d97 100644 --- a/src/main/java/de/tum/cit/ase/service/artemis/interaction/SimulatedArtemisStudent.java +++ b/src/main/java/de/tum/cit/ase/service/artemis/interaction/SimulatedArtemisStudent.java @@ -30,10 +30,20 @@ public class SimulatedArtemisStudent extends SimulatedArtemisUser { private String examIdString; private Long studentExamId; private StudentExam studentExam; - - public SimulatedArtemisStudent(String artemisUrl, ArtemisUser artemisUser, ArtemisUserService artemisUserService) { + private final int numberOfCommitsAndPushesFrom; + private final int numberOfCommitsAndPushesTo; + + public SimulatedArtemisStudent( + String artemisUrl, + ArtemisUser artemisUser, + ArtemisUserService artemisUserService, + int numberOfCommitsAndPushesFrom, + int numberOfCommitsAndPushesTo + ) { super(artemisUrl, artemisUser, artemisUserService); log = LoggerFactory.getLogger(SimulatedArtemisStudent.class.getName() + "." + username); + this.numberOfCommitsAndPushesFrom = numberOfCommitsAndPushesFrom; + this.numberOfCommitsAndPushesTo = numberOfCommitsAndPushesTo; } @Override @@ -293,7 +303,7 @@ private List solveAndSubmitProgrammingExercise(ProgrammingExercise long start = System.nanoTime(); requestStats.add(cloneRepo(repositoryCloneUrl)); - int n = new Random().nextInt(10, 15); // we do a random number of commits and pushes to make some noise + int n = new Random().nextInt(numberOfCommitsAndPushesFrom, numberOfCommitsAndPushesTo); // we do a random number of commits and pushes to make some noise log.info("Commit and push {}x for {}", n, username); for (int j = 0; j < n; j++) { sleep(100); diff --git a/src/main/java/de/tum/cit/ase/service/simulation/SimulationDataService.java b/src/main/java/de/tum/cit/ase/service/simulation/SimulationDataService.java index 7c738d12..7698ca4a 100644 --- a/src/main/java/de/tum/cit/ase/service/simulation/SimulationDataService.java +++ b/src/main/java/de/tum/cit/ase/service/simulation/SimulationDataService.java @@ -97,6 +97,8 @@ public boolean validateSimulation(Simulation simulation) { var basicRequirements = simulation.getMode() != null && simulation.getServer() != null && + simulation.getNumberOfCommitsAndPushesTo() > simulation.getNumberOfCommitsAndPushesFrom() && + simulation.getNumberOfCommitsAndPushesFrom() >= 0 && simulation.getName() != null && ((!simulation.isCustomizeUserRange() && simulation.getNumberOfUsers() > 0) || (simulation.isCustomizeUserRange() && diff --git a/src/main/java/de/tum/cit/ase/service/simulation/SimulationRunExecutionService.java b/src/main/java/de/tum/cit/ase/service/simulation/SimulationRunExecutionService.java index 8b7a5498..9d46a897 100644 --- a/src/main/java/de/tum/cit/ase/service/simulation/SimulationRunExecutionService.java +++ b/src/main/java/de/tum/cit/ase/service/simulation/SimulationRunExecutionService.java @@ -307,7 +307,13 @@ private SimulatedArtemisStudent[] initializeStudents(Simulation simulation) { SimulatedArtemisStudent[] users = new SimulatedArtemisStudent[artemisUsers.size()]; for (int i = 0; i < artemisUsers.size(); i++) { users[i] = - new SimulatedArtemisStudent(artemisConfiguration.getUrl(simulation.getServer()), artemisUsers.get(i), artemisUserService); + new SimulatedArtemisStudent( + artemisConfiguration.getUrl(simulation.getServer()), + artemisUsers.get(i), + artemisUserService, + simulation.getNumberOfCommitsAndPushesFrom(), + simulation.getNumberOfCommitsAndPushesTo() + ); } return users; } @@ -359,6 +365,9 @@ private void logAndSend(boolean error, SimulationRun simulationRun, String forma } else { log.info(message); } + if (message.length() > 255) { + message = message.substring(0, 255); + } LogMessage logMessage = new LogMessage(); logMessage.setSimulationRun(simulationRun); logMessage.setMessage(message); diff --git a/src/main/resources/config/liquibase/changelog/00000000000008_add_commit_range.xml b/src/main/resources/config/liquibase/changelog/00000000000008_add_commit_range.xml new file mode 100644 index 00000000..ead7537a --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/00000000000008_add_commit_range.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/00000000000009_increase_token_length.xml b/src/main/resources/config/liquibase/changelog/00000000000009_increase_token_length.xml new file mode 100644 index 00000000..305707c5 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/00000000000009_increase_token_length.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index 87a8a498..c498ed75 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -16,6 +16,8 @@ + + diff --git a/src/main/webapp/app/entities/simulation/simulation.ts b/src/main/webapp/app/entities/simulation/simulation.ts index 42d6b77a..ba9e0647 100644 --- a/src/main/webapp/app/entities/simulation/simulation.ts +++ b/src/main/webapp/app/entities/simulation/simulation.ts @@ -13,6 +13,8 @@ export class Simulation { public runs: SimulationRun[], public creationDate: Date, public customizeUserRange: boolean, + public numberOfCommitsAndPushesFrom: number, + public numberOfCommitsAndPushesTo: number, public userRange?: string, ) {} } diff --git a/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.html b/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.html index 05625d90..e13bfabf 100644 --- a/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.html +++ b/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.html @@ -62,7 +62,7 @@ }
-
+
@if (!customizeUserRange) { Number of users. Users with IDs 1 to n will be used. See Artemis Users for the IDs of your users. @@ -100,7 +100,36 @@ }
} - +
Number of commits and pushes:
+
+
+ + +
+
+ + +
+
+
+ For each student, the number of commits and pushes will be chosen randomly in the given range.
+ From must be positive and smaller than To. +
+
The simulation will not be executed immediately.
diff --git a/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.ts b/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.ts index 13bc365c..34f80d88 100644 --- a/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.ts +++ b/src/main/webapp/app/layouts/create-simulation-box/create-simulation-box.component.ts @@ -19,6 +19,8 @@ export class CreateSimulationBoxComponent implements OnInit { mode: Mode = Mode.CREATE_COURSE_AND_EXAM; customizeUserRange: boolean = false; userRange: string = ''; + numberOfCommitsAndPushesFrom: number = 8; + numberOfCommitsAndPushesTo: number = 15; availableServers = [ArtemisServer.TS1, ArtemisServer.TS3, ArtemisServer.PRODUCTION, ArtemisServer.STAGING]; availableModes = [ @@ -58,6 +60,8 @@ export class CreateSimulationBoxComponent implements OnInit { [], new Date(), this.customizeUserRange, + this.numberOfCommitsAndPushesFrom, + this.numberOfCommitsAndPushesTo, this.userRange, ); this.simulationToCreate.emit(simulation); @@ -67,7 +71,9 @@ export class CreateSimulationBoxComponent implements OnInit { inputValid(): boolean { const basicRequirements: boolean = this.name.length > 0 && - ((!this.customizeUserRange && this.numberOfUsers > 0) || (this.customizeUserRange && this.userRange.length > 0)); + ((!this.customizeUserRange && this.numberOfUsers > 0) || (this.customizeUserRange && this.userRange.length > 0)) && + this.numberOfCommitsAndPushesFrom > 0 && + this.numberOfCommitsAndPushesTo > this.numberOfCommitsAndPushesFrom; if (this.mode === Mode.CREATE_COURSE_AND_EXAM) { return basicRequirements; diff --git a/src/main/webapp/app/layouts/simulation-card/simulation-card.component.html b/src/main/webapp/app/layouts/simulation-card/simulation-card.component.html index 9a18d29a..8595369e 100644 --- a/src/main/webapp/app/layouts/simulation-card/simulation-card.component.html +++ b/src/main/webapp/app/layouts/simulation-card/simulation-card.component.html @@ -24,6 +24,7 @@ Users: {{ simulation.numberOfUsers }} }

+

Commits: {{ simulation.numberOfCommitsAndPushesFrom }} - {{ simulation.numberOfCommitsAndPushesTo }}

@if (simulation.mode != Mode.CREATE_COURSE_AND_EXAM) {

Course-ID: {{ simulation.courseId }}

}