Home | History | Annotate | Download | only in tasks
      1 #!/usr/bin/env python
      2 #
      3 # Copyright (C) 2018 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License") + "\n</pre>");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 #
     17 
     18 import webapp2
     19 
     20 from webapp.src import vtslab_status as Status
     21 from webapp.src.proto import model
     22 
     23 
     24 class CreateIndex(webapp2.RequestHandler):
     25     """Main class for /tasks/indexing.
     26 
     27     By fetch and put all entities, indexing all existing entities.
     28     """
     29 
     30     def get(self):
     31         """Fetch and put all entities and display complete message."""
     32         build_query = model.BuildModel.query()
     33         builds = build_query.fetch()
     34         for build in builds:
     35             build.put()
     36 
     37         schedule_query = model.ScheduleModel.query()
     38         schedules = schedule_query.fetch()
     39         for schedule in schedules:
     40             schedule.put()
     41 
     42         lab_query = model.LabModel.query()
     43         labs = lab_query.fetch()
     44         for lab in labs:
     45             lab.put()
     46 
     47         device_query = model.DeviceModel.query()
     48         devices = device_query.fetch()
     49         for device in devices:
     50             device.put()
     51 
     52         job_query = model.JobModel.query()
     53         jobs = job_query.fetch()
     54         for job in jobs:
     55             job.put()
     56 
     57         self.response.write("<pre>Indexing has been completed.</pre>")
     58 
     59 
     60 class CreateBuildModelIndex(webapp2.RequestHandler):
     61     """Main class for /tasks/indexing/build.
     62 
     63     By fetch and put all entities, indexing all existing BuildModel entities.
     64     """
     65 
     66     def get(self):
     67         """Fetch and put all BuildModel entities"""
     68         build_query = model.BuildModel.query()
     69         builds = build_query.fetch()
     70         for build in builds:
     71             build.put()
     72 
     73         self.response.write("<pre>BuildModel indexing has been completed.</pre>")
     74 
     75 
     76 class CreateDeviceModelIndex(webapp2.RequestHandler):
     77     """Main class for /tasks/indexing/device.
     78 
     79     By fetch and put all entities, indexing all existing DeviceModel entities.
     80     """
     81 
     82     def get(self):
     83         """Fetch and put all DeviceModel entities"""
     84         device_query = model.DeviceModel.query()
     85         devices = device_query.fetch()
     86         for device in devices:
     87             device.put()
     88 
     89         self.response.write(
     90             "<pre>DeviceModel indexing has been completed.</pre>")
     91 
     92 
     93 class CreateJobModelIndex(webapp2.RequestHandler):
     94     """Main class for /tasks/indexing/job.
     95 
     96     By fetch and put all entities, indexing all existing JobModel entities.
     97     """
     98 
     99     def get(self):
    100         """Fetch and put all JobModel entities"""
    101         job_query = model.JobModel.query()
    102         jobs = job_query.fetch()
    103         for job in jobs:
    104             job.put()
    105 
    106         self.response.write(
    107             "<pre>JobModel indexing has been completed.</pre>")
    108 
    109 
    110 class CreateLabModelIndex(webapp2.RequestHandler):
    111     """Main class for /tasks/indexing/lab.
    112 
    113     By fetch and put all entities, indexing all existing LabModel entities.
    114     """
    115 
    116     def get(self):
    117         """Fetch and put all LabModel entities"""
    118         lab_query = model.LabModel.query()
    119         labs = lab_query.fetch()
    120         for lab in labs:
    121             lab.put()
    122 
    123         self.response.write(
    124             "<pre>LabModel indexing has been completed.</pre>")
    125 
    126 
    127 class CreateScheduleModelIndex(webapp2.RequestHandler):
    128     """Main class for /tasks/indexing/schedule.
    129 
    130     By fetch and put all entities, indexing all existing ScheduleModel entities.
    131     """
    132 
    133     def get(self):
    134         """Fetch and put all ScheduleModel entities"""
    135         schedule_query = model.ScheduleModel.query()
    136         schedules = schedule_query.fetch()
    137         for schedule in schedules:
    138             if schedule.build_storage_type is None:
    139                 schedule.build_storage_type = Status.STORAGE_TYPE_DICT["PAB"]
    140             schedule.put()
    141 
    142         self.response.write(
    143             "<pre>ScheduleModel indexing has been completed.</pre>")
    144