Skip to content

Commit

Permalink
Merge pull request #58 from ls1intum/develop
Browse files Browse the repository at this point in the history
Add push number range and fix length of tokens
  • Loading branch information
valentin-boehm authored Nov 27, 2023
2 parents 0f12980 + a71e4aa commit 87ee58b
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 7 deletions.
22 changes: 22 additions & 0 deletions src/main/java/de/tum/cit/ase/domain/Simulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -293,7 +303,7 @@ private List<RequestStat> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<changeSet id="00000000000008" author="valentin-boehm">
<addColumn tableName="simulation">
<column name="number_of_commits_and_pushes_from" type="int" defaultValue="8" />
<column name="number_of_commits_and_pushes_to" type="int" defaultValue="15" />
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<changeSet id="00000000000009" author="valentin-boehm">
<modifyDataType tableName="artemis_user" columnName="jwt_token" newDataType="varchar(800)"/>
</changeSet>
</databaseChangeLog>
2 changes: 2 additions & 0 deletions src/main/resources/config/liquibase/master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<include file="config/liquibase/changelog/00000000000005_add_simulation_creation_date.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/00000000000006_add_artemis_users.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/00000000000007_add_user_range.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/00000000000008_add_commit_range.xml" relativeToChangelogFile="false"/>
<include file="config/liquibase/changelog/00000000000009_increase_token_length.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here -->
<!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
<!-- jhipster-needle-liquibase-add-incremental-changelog - JHipster will add incremental liquibase changelogs here -->
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/app/entities/simulation/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
</div>
</div>
<div class="form-text">
<div class="form-text mb-3">
@if (!customizeUserRange) {
Number of users. Users with IDs 1 to n will be used. See
<a class="text-info" routerLink="/artemis-users/{{ server }}">Artemis Users</a> for the IDs of your users.
Expand Down Expand Up @@ -100,7 +100,36 @@
}
</div>
}
<button type="submit" class="btn btn-primary" [disabled]="!inputValid()" (click)="createSimulation()">Create Simulation</button>
<div class="mt-3 mb-2">Number of commits and pushes:</div>
<div class="flex-wrapper">
<div class="me-3">
<label for="from-input" class="form-label">From</label>
<input
type="number"
class="form-control"
id="from-input"
min="0"
[(ngModel)]="numberOfCommitsAndPushesFrom"
[ngModelOptions]="{ standalone: true }"
/>
</div>
<div class="me-3">
<label for="to-input" class="form-label">To (excluded)</label>
<input
type="number"
class="form-control"
id="to-input"
min="1"
[(ngModel)]="numberOfCommitsAndPushesTo"
[ngModelOptions]="{ standalone: true }"
/>
</div>
</div>
<div class="form-text mb-3">
For each student, the number of commits and pushes will be chosen randomly in the given range.<br />
From must be positive and smaller than To.
</div>
<button type="submit" class="btn btn-primary mt-3" [disabled]="!inputValid()" (click)="createSimulation()">Create Simulation</button>
<div class="form-text">The simulation will not be executed immediately.</div>
</form>
<div class="mt-5 w-40 ms-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -58,6 +60,8 @@ export class CreateSimulationBoxComponent implements OnInit {
[],
new Date(),
this.customizeUserRange,
this.numberOfCommitsAndPushesFrom,
this.numberOfCommitsAndPushesTo,
this.userRange,
);
this.simulationToCreate.emit(simulation);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Users: {{ simulation.numberOfUsers }}
}
</p>
<p>Commits: {{ simulation.numberOfCommitsAndPushesFrom }} - {{ simulation.numberOfCommitsAndPushesTo }}</p>
@if (simulation.mode != Mode.CREATE_COURSE_AND_EXAM) {
<p>Course-ID: {{ simulation.courseId }}</p>
}
Expand Down

0 comments on commit 87ee58b

Please sign in to comment.