-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7b6057b
commit 9bf9c07
Showing
15 changed files
with
213 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/client/java/teammates/client/scripts/PopulateCourseSearchDocuments.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package teammates.client.scripts; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import com.googlecode.objectify.cmd.Query; | ||
|
||
import teammates.client.util.BackDoor; | ||
import teammates.common.datatransfer.DataBundle; | ||
import teammates.common.datatransfer.attributes.InstructorAttributes; | ||
import teammates.common.datatransfer.attributes.StudentAttributes; | ||
import teammates.logic.api.Logic; | ||
import teammates.storage.entity.Course; | ||
|
||
/** | ||
* Script to populate search documents into the system back-end. | ||
*/ | ||
public class PopulateCourseSearchDocuments extends DataMigrationEntitiesBaseScript<Course> { | ||
|
||
private static final int STUDENT_SIZE_LIMIT = 300; | ||
private final Logic logic = new Logic(); | ||
|
||
public PopulateCourseSearchDocuments() { | ||
numberOfScannedKey.set(0L); | ||
numberOfAffectedEntities.set(0L); | ||
numberOfUpdatedEntities.set(0L); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
PopulateCourseSearchDocuments populator = new PopulateCourseSearchDocuments(); | ||
populator.doOperationRemotely(); | ||
} | ||
|
||
@Override | ||
protected Query<Course> getFilterQuery() { | ||
Instant createdAtBound = Instant.now(); | ||
// To change the boundary of the createdAt timestamp, uncomment the next line and insert the appropriate timestamp. | ||
// createdAtBound = Instant.ofEpochMilli(1618053102147L); | ||
return ofy().load().type(Course.class) | ||
.filter("createdAt <=", createdAtBound) | ||
.order("-createdAt"); | ||
} | ||
|
||
@Override | ||
protected boolean isPreview() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected boolean isMigrationNeeded(Course course) throws Exception { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void migrateEntity(Course course) throws Exception { | ||
List<StudentAttributes> students = logic.getStudentsForCourse(course.getUniqueId()); | ||
List<InstructorAttributes> instructors = logic.getInstructorsForCourse(course.getUniqueId()); | ||
|
||
int nLoop = students.size() / STUDENT_SIZE_LIMIT; | ||
|
||
System.out.println("---------"); | ||
System.out.println("Going to populate search documents for students and instructors from course " | ||
+ course.getUniqueId()); | ||
System.out.println("Course is created at epoch " + course.getCreatedAt().toEpochMilli()); | ||
System.out.println(); | ||
|
||
for (int i = 0; i <= nLoop + 1; i++) { | ||
DataBundle bundle = new DataBundle(); | ||
bundle.students = new HashMap<>(); | ||
bundle.instructors = new HashMap<>(); | ||
if (i == nLoop + 1) { | ||
// For final loop, migrate instructors | ||
if (instructors.isEmpty()) { | ||
System.out.println("No instructors to migrate"); | ||
System.out.println(); | ||
continue; | ||
} | ||
instructors.forEach(instructor -> bundle.instructors.put(instructor.getEmail(), instructor)); | ||
} else { | ||
List<StudentAttributes> studentsSubList = | ||
students.subList(i * STUDENT_SIZE_LIMIT, | ||
Math.min(students.size(), (i + 1) * STUDENT_SIZE_LIMIT)); | ||
if (studentsSubList.isEmpty()) { | ||
System.out.println("No students to migrate"); | ||
System.out.println(); | ||
continue; | ||
} | ||
studentsSubList.forEach(student -> bundle.students.put(student.getEmail(), student)); | ||
} | ||
|
||
long time = System.currentTimeMillis(); | ||
System.out.println("Total load: " + bundle.students.size() + " students, " | ||
+ bundle.instructors.size() + " instructors"); | ||
String result = BackDoor.getInstance().putDocuments(bundle); | ||
System.out.println("Operation result: " + result); | ||
System.out.println("Time elapsed: " + (System.currentTimeMillis() - time) + "ms"); | ||
System.out.println(); | ||
} | ||
|
||
System.out.println("Search document insertion completed"); | ||
System.out.println("---------"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package teammates.client.util; | ||
|
||
import teammates.test.AbstractBackDoor; | ||
|
||
/** | ||
* Used to create API calls to the back-end without going through the UI. | ||
*/ | ||
public final class BackDoor extends AbstractBackDoor { | ||
|
||
private static BackDoor instance = new BackDoor(); | ||
|
||
private BackDoor() { | ||
// Utility class | ||
} | ||
|
||
public static BackDoor getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
protected String getAppUrl() { | ||
return ClientProperties.API_URL; | ||
} | ||
|
||
@Override | ||
protected String getBackdoorKey() { | ||
return ClientProperties.BACKDOOR_KEY; | ||
} | ||
|
||
@Override | ||
protected String getCsrfKey() { | ||
return ClientProperties.CSRF_KEY; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.