base_api.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import logging
  18. from django.utils.translation import ugettext as _
  19. from desktop.lib.exceptions_renderable import PopupException
  20. LOG = logging.getLogger(__name__)
  21. def get_api(user, interface):
  22. from jobbrowser.apis.bundle_api import BundleApi
  23. from jobbrowser.apis.job_api import JobApi
  24. from jobbrowser.apis.schedule_api import ScheduleApi
  25. from jobbrowser.apis.workflow_api import WorkflowApi
  26. if interface == 'jobs':
  27. return JobApi(user)
  28. elif interface == 'workflows':
  29. return WorkflowApi(user)
  30. elif interface == 'schedules':
  31. return ScheduleApi(user)
  32. elif interface == 'bundles':
  33. return BundleApi(user)
  34. elif interface == 'slas':
  35. return BundleApi(user)
  36. else:
  37. raise PopupException(_('Interface %s is unknown') % interface)
  38. class Api(object):
  39. def __init__(self, user):
  40. self.user = user
  41. self.request = None
  42. def apps(self, filters): return []
  43. def app(self, appid): return {} # Also contains progress (0-100) and status [RUNNING, FINISHED, PAUSED]
  44. def action(self, appid, operation): return {}
  45. def logs(self, appid, app_type, log_name): return {'progress': 0, 'logs': ''}
  46. def profile(self, appid, app_type, app_property): return {} # Tasks, XML, counters...
  47. def _set_request(self, request):
  48. self.request = request
  49. class MockDjangoRequest():
  50. def __init__(self, user, get=None, post=None):
  51. self.user = user
  52. self.jt = None
  53. self.GET = get if get is not None else {'format': 'json'}
  54. self.POST = post if post is not None else {}
  55. self.method = "POST"