diff options
-rw-r--r-- | gae/webapp/src/proto/model.py | 4 | ||||
-rw-r--r-- | gae/webapp/src/scheduler/periodic.py | 9 | ||||
-rw-r--r-- | gae/webapp/src/tasks/indexing.py | 89 | ||||
-rw-r--r-- | gae/webapp/src/vtslab_status.py | 7 | ||||
-rw-r--r-- | gae/webapp/src/webapp_main.py | 7 |
5 files changed, 106 insertions, 10 deletions
diff --git a/gae/webapp/src/proto/model.py b/gae/webapp/src/proto/model.py index 6ca9947..803feed 100644 --- a/gae/webapp/src/proto/model.py +++ b/gae/webapp/src/proto/model.py @@ -195,14 +195,14 @@ class JobModel(ndb.Model): period = ndb.IntegerProperty() # GSI information - gsi_storage_type = ndb.StringProperty() + gsi_storage_type = ndb.IntegerProperty() gsi_branch = ndb.StringProperty() gsi_build_target = ndb.StringProperty() gsi_build_id = ndb.StringProperty() gsi_pab_account_id = ndb.StringProperty() # test suite information - test_storage_type = ndb.StringProperty() + test_storage_type = ndb.IntegerProperty() test_branch = ndb.StringProperty() test_build_target = ndb.StringProperty() test_build_id = ndb.StringProperty() diff --git a/gae/webapp/src/scheduler/periodic.py b/gae/webapp/src/scheduler/periodic.py index 5aeecc3..1c8a3d0 100644 --- a/gae/webapp/src/scheduler/periodic.py +++ b/gae/webapp/src/scheduler/periodic.py @@ -23,10 +23,6 @@ from webapp.src import vtslab_status as Status from webapp.src.proto import model from webapp.src.utils import logger -UNKNOWN_BUILD_STORAGE_TYPE = 0 -BUILD_STORAGE_TYPE_PAB = 1 -BUILD_STORAGE_TYPE_GCS = 2 - def StrGT(left, right): """Returns true if `left` string is greater than `right` in value.""" @@ -152,7 +148,8 @@ class PeriodicScheduler(webapp2.RequestHandler): new_job.build_id = "" - if new_job.build_storage_type == BUILD_STORAGE_TYPE_PAB: + if new_job.build_storage_type == ( + Status.STORAGE_TYPE_DICT["PAB"]): new_job.build_id = self.FindBuildId(new_job) if new_job.build_id: self.ReserveDevices(target_device_serials) @@ -164,7 +161,7 @@ class PeriodicScheduler(webapp2.RequestHandler): else: self.logger.Println("NO BUILD FOUND") elif new_job.build_storage_type == ( - BUILD_STORAGE_TYPE_GCS): + Status.STORAGE_TYPE_DICT["GCS"]): new_job.status = Status.JOB_STATUS_DICT["ready"] new_job.timestamp = datetime.datetime.now() new_job.put() diff --git a/gae/webapp/src/tasks/indexing.py b/gae/webapp/src/tasks/indexing.py index 8c7b9f4..4816363 100644 --- a/gae/webapp/src/tasks/indexing.py +++ b/gae/webapp/src/tasks/indexing.py @@ -17,6 +17,7 @@ import webapp2 +from webapp.src import vtslab_status as Status from webapp.src.proto import model @@ -53,4 +54,90 @@ class CreateIndex(webapp2.RequestHandler): for job in jobs: job.put() - self.response.write("<pre>Indexing has been completed.</pre>")
\ No newline at end of file + self.response.write("<pre>Indexing has been completed.</pre>") + + +class CreateBuildModelIndex(webapp2.RequestHandler): + """Main class for /tasks/indexing/build. + + By fetch and put all entities, indexing all existing BuildModel entities. + """ + + def get(self): + """Fetch and put all BuildModel entities""" + build_query = model.BuildModel.query() + builds = build_query.fetch() + for build in builds: + build.put() + + self.response.write("<pre>BuildModel indexing has been completed.</pre>") + + +class CreateDeviceModelIndex(webapp2.RequestHandler): + """Main class for /tasks/indexing/device. + + By fetch and put all entities, indexing all existing DeviceModel entities. + """ + + def get(self): + """Fetch and put all DeviceModel entities""" + device_query = model.DeviceModel.query() + devices = device_query.fetch() + for device in devices: + device.put() + + self.response.write( + "<pre>DeviceModel indexing has been completed.</pre>") + + +class CreateJobModelIndex(webapp2.RequestHandler): + """Main class for /tasks/indexing/job. + + By fetch and put all entities, indexing all existing JobModel entities. + """ + + def get(self): + """Fetch and put all JobModel entities""" + job_query = model.JobModel.query() + jobs = job_query.fetch() + for job in jobs: + job.put() + + self.response.write( + "<pre>JobModel indexing has been completed.</pre>") + + +class CreateLabModelIndex(webapp2.RequestHandler): + """Main class for /tasks/indexing/lab. + + By fetch and put all entities, indexing all existing LabModel entities. + """ + + def get(self): + """Fetch and put all LabModel entities""" + lab_query = model.LabModel.query() + labs = lab_query.fetch() + for lab in labs: + lab.put() + + self.response.write( + "<pre>LabModel indexing has been completed.</pre>") + + +class CreateScheduleModelIndex(webapp2.RequestHandler): + """Main class for /tasks/indexing/schedule. + + By fetch and put all entities, indexing all existing ScheduleModel entities. + """ + + def get(self): + """Fetch and put all ScheduleModel entities""" + schedule_query = model.ScheduleModel.query() + schedules = schedule_query.fetch() + for schedule in schedules: + if schedule.build_storage_type is None: + schedule.build_storage_type = Status.STORAGE_TYPE_DICT["PAB"] + schedule.put() + + self.response.write( + "<pre>ScheduleModel indexing has been completed.</pre>") diff --git a/gae/webapp/src/vtslab_status.py b/gae/webapp/src/vtslab_status.py index fd4bdd1..c200ed2 100644 --- a/gae/webapp/src/vtslab_status.py +++ b/gae/webapp/src/vtslab_status.py @@ -64,6 +64,13 @@ JOB_PRIORITY_DICT = { } +STORAGE_TYPE_DICT = { + "unknown": 0, + "PAB": 1, + "GCS": 2 +} + + def PrioritySortHelper(priority): """Helper function to sort jobs based on priority. diff --git a/gae/webapp/src/webapp_main.py b/gae/webapp/src/webapp_main.py index 2aa7fc0..11c3142 100644 --- a/gae/webapp/src/webapp_main.py +++ b/gae/webapp/src/webapp_main.py @@ -57,7 +57,12 @@ app = webapp2.WSGIApplication( ("/tasks/schedule", periodic.PeriodicScheduler), ("/tasks/device_heartbeat", device_heartbeat.PeriodicDeviceHeartBeat), ("/tasks/job_heartbeat", job_heartbeat.PeriodicJobHeartBeat), - ("/tasks/indexing", indexing.CreateIndex) + ("/tasks/indexing", indexing.CreateIndex), + ("/tasks/indexing/build", indexing.CreateBuildModelIndex), + ("/tasks/indexing/device", indexing.CreateDeviceModelIndex), + ("/tasks/indexing/job", indexing.CreateJobModelIndex), + ("/tasks/indexing/lab", indexing.CreateLabModelIndex), + ("/tasks/indexing/schedule", indexing.CreateScheduleModelIndex) ], config=config, debug=False) |