def get(self, process_key=None): logging.debug('Begin ProcessHandler.get() method') process = self.is_client_allowed(process_key) logging.debug('Returning Process "%s" as JSON to client.', process.id) build_json(self, process.to_dict()) logging.debug('Finished ProcessHandler.get() method')
def get(self, team_key=None): logging.debug('Begin TeamHandler.get() method') client = self.is_valid() team = models.Team.get(team_key, client) logging.info('Returning Team "%s" as JSON to client.', team.id) build_json(self, team.to_dict()) logging.debug('Finished TeamHandler.get() method')
def get(self, execution_key): logging.debug('Begin ExecutionHandler.get() method') execution = self.is_client_allowed(execution_key) logging.info('Returning Execution "%s" as JSON to client.', execution.id) build_json(self, execution.to_dict()) logging.debug('Finished ExecutionHandler.get() method')
def get(self, request_key=None): logging.debug("Begin RequestHandler.get() method") client = self.is_valid() if not request_key: raise exceptions.MissingException('Missing "request_key" parameter.') request = models.Request.get(request_key, client) build_json(self, request.to_dict()) logging.debug("Finished RequestHandler.get() method")
def post(self, request_key=None): logging.debug("Begin RequestHandler.post() method") data = self.request.params process_key = data.get("process", None) if not process_key: raise exceptions.MissingException('Missing "process" parameter.') process = models.Process.get(process_key) if not process.is_valid(): raise exceptions.ValidationException('Process "%s" is not valid.' % process_key) requestor = data.get("requestor", None) if not requestor: raise exceptions.MissingException('Missing "requestor" parameter.') if request_key: request = models.Request.get(request_key) if request: raise exceptions.InternalException('Request "%s" already exists.' % request_key) else: request_key = utils.generate_key() request = models.Request(key_name=request_key, process=process, client=process.client, requestor=requestor) callback_url = data.get("callback_url", None) response_url = data.get("response_url", None) reserved_keys = ["callback_url", "response_url"] for key, value in data.items(): if not hasattr(request, key) and key not in reserved_keys: setattr(request, key, value) request.put() if callback_url: # Queue task to submit the callback response queue = taskqueue.Queue("request-callback") task = taskqueue.Task(params={"request_key": request.id, "callback_url": callback_url}) queue.add(task) if response_url: logging.info('Permanently redirecting client to "%s".', response_url) self.redirect(response_url, permanent=True) else: logging.info('Returning Request "%s" as JSON to client.', request.id) build_json(self, {"key": request.id}, 201) logging.debug("Finished RequestHandler.post() method")
def put(self, team_key=None): logging.debug('Begin TeamHandler.put() method') client = self.is_valid() from django.utils import simplejson data = simplejson.loads(self.request.body) team = models.Team.from_dict(client, data, team_key) team.put() logging.info('Returning Team "%s" as JSON to client.', team.id) build_json(self, team.to_dict(), 201) logging.debug('Finished TeamHandler.put() method')
def get(self, process_key): logging.debug('Begin MonthHandler.get() method') process = self.is_client_allowed(process_key) year = self.get_param('year') month = self.get_param('month') return_stats = self.get_param('filter') stats = {} keys = list_to_dict(return_stats) cal = calendar.Calendar() for day in cal.itermonthdays(year, month): if day < 1: continue if len(keys) == 1: stats[day] = 0 else: stats[day] = copy.copy(keys) query = models.Statistic.all() query.filter('process =', process) query.filter('year =', year) query.filter('month =', month) query.filter('type =', 'daily') query.order('day') results = query.fetch(32) for result in results: day = int(result.day) if len(keys) == 1: stats[day] = getattr(result, return_stats[0]) else: for key in return_stats: stats[day][key] = getattr(result, key, 0) logging.info('Returning JSON response to client.') build_json(self, stats) logging.debug('Finished MonthHandler.get() method')
def get(self, process_key): logging.debug('Begin DayHandler.get() method') process = self.is_client_allowed(process_key) year = self.get_param('year') month = self.get_param('month') day = self.get_param('day') return_stats = self.get_param('filter') stats = {} keys = list_to_dict(return_stats) for hour in range(0, 24): if len(keys) == 1: stats[hour] = 0 else: stats[hour] = copy.copy(keys) query = models.Statistic.all() query.filter('process =', process) query.filter('year =', year) query.filter('month =', month) query.filter('day =', day) query.filter('type =', 'hourly') query.order('hour') results = query.fetch(25) for result in results: hour = int(result.hour) if len(keys) == 1: stats[hour] = getattr(result, return_stats[0]) else: for key in return_stats: stats[hour][key] = getattr(result, key, 0) logging.info('Returning JSON response to client.') build_json(self, stats) logging.debug('Finished DayHandler.get() method')
def get(self, process_key): logging.debug('Begin WeekHandler.get() method') process = self.is_client_allowed(process_key) year = self.get_param('year') week_num = self.get_param('week_num') return_stats = self.get_param('filter') stats = {} keys = list_to_dict(return_stats) for day in range(1, 8): if len(keys) == 1: stats[day] = 0 else: stats[day] = copy.copy(keys) query = models.Statistic.all() query.filter('process =', process) query.filter('year =', year) query.filter('week_num =', week_num) query.filter('type =', 'daily') query.order('week_day') results = query.fetch(7) for result in results: week_day = int(result.week_day) if len(keys) == 1: stats[week_day] = getattr(result, return_stats[0]) else: for key in return_stats: stats[week_day][key] = getattr(result, key, 0) logging.info('Returning JSON response to client.') build_json(self, stats) logging.debug('Finished WeekHandler.get() method')
def get(self, process_key): logging.debug('Begin YearHandler.get() method') process = self.is_client_allowed(process_key) year = self.get_param('year') return_stats = self.get_param('filter') stats = {} keys = list_to_dict(return_stats) for month in range(1, 13): if len(keys) == 1: stats[month] = 0 else: stats[month] = copy.copy(keys) query = models.Statistic.all() query.filter('process =', process) query.filter('year =', year) query.filter('type =', 'monthly') query.order('month') results = query.fetch(12) for result in results: month = int(result.month) if len(keys) == 1: stats[month] = getattr(result, return_stats[0]) else: for key in return_stats: stats[month][key] = getattr(result, key, 0) logging.info('Returning JSON response to client.') build_json(self, stats) logging.debug('Finished YearHandler.get() method')
except Exception, exc: process.delete_steps_actions() raise exc # Load any actions on this process logging.info('Loading actions for Process "%s".', process.id) actions = data.get('actions', None) if actions: try: db.run_in_transaction(process.add_actions, actions) except Exception, exc: process.delete_steps_actions() raise exc logging.info('Returning Process "%s" as JSON to client.', process.id) build_json(self, {'key': process.id}, 201) logging.debug('Finished ProcessHandler.put() method') def delete(self, process_key=None): logging.debug('Begin ProcessHandler.delete() method') process = self.is_client_allowed(process_key) process.delete() self.error(204) logging.debug('Finished ProcessHandler.delete() method') def main():