def create_link(request): response = {'status': 0, 'errors': None, 'link': None} if 'link' not in request.POST: raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Error saving link'), data={'errors': 'Link is missing.'}, error_code=400) d = json.loads(smart_str(request.POST.get('link'))) link = client.Link.from_dict(d) try: c = client.SqoopClient( conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) response['link'] = c.create_link(link).to_dict() except RestException as e: response.update(handle_rest_exception(e, _('Could not create link.'))) except SqoopException as e: response['status'] = 100 response['errors'] = e.to_dict() return JsonResponse(response)
def create_job(request): if request.method != 'POST': raise StructuredException(code="INVALID_METHOD", message=_('POST request required.'), error_code=405) response = { 'status': 0, 'errors': None, 'job': None } if 'job' not in request.POST: raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Error saving job'), data={'errors': 'job is missing.'}, error_code=400) d = json.loads(smart_str(request.POST.get('job'))) job = client.Job.from_dict(d) try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) response['job'] = c.create_job(job).to_dict() except RestException as e: response.update(handle_rest_exception(e, _('Could not create job.'))) except SqoopException as e: response['status'] = 100 response['errors'] = e.to_dict() return JsonResponse(response)
def decorate(request, submission_id, *args, **kwargs): try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) submission = c.get_submission(int(submission_id)) except RestException as e: handle_rest_exception(e, _('Could not get submission.')) return view_func(request, submission=submission, *args, **kwargs)
def decorate(request, submission_id, *args, **kwargs): try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) submission = c.get_submission(int(submission_id)) except RestException, e: handle_rest_exception(e, _('Could not get submission.'))
def get_links(request): response = {'status': 0, 'errors': None, 'links': []} try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) response['links'] = list_to_dict(c.get_links()) except RestException, e: response.update(handle_rest_exception(e, _('Could not get links.')))
def decorate(request, connector_id, *args, **kwargs): try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) connector = c.get_connector(int(connector_id)) except RestException, e: handle_rest_exception(e, _('Could not get connector.'))
def decorate(request, job_id, *args, **kwargs): try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) job = c.get_job(int(job_id)) except RestException, e: handle_rest_exception(e, _('Could not get job.'))
def decorate(request, link_id, *args, **kwargs): try: c = client.SqoopClient( conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) link = c.get_link(int(link_id)) except RestException, e: handle_rest_exception(e, _('Could not get link.'))
def get_submissions(request): response = {'status': 0, 'errors': None, 'submissions': []} status = request.GET.get('status', 'submissions').split(',') try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) submissions = c.get_submissions() response['submissions'] = list_to_dict(submissions) except RestException, e: response.update( handle_rest_exception(e, _('Could not get submissions.')))
def framework(request): response = {'status': 0, 'errors': None, 'framework': None} if request.method == 'GET': try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) response['framework'] = c.get_framework().to_dict() except RestException, e: response.update( handle_rest_exception(e, _('Could not get framework.'))) return HttpResponse(json.dumps(response), mimetype="application/json")
def get_links(request): response = {'status': 0, 'errors': None, 'links': []} try: c = client.SqoopClient( conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) response['links'] = list_to_dict(c.get_links()) except RestException as e: response.update(handle_rest_exception(e, _('Could not get links.'))) return JsonResponse(response)
def driver(request): response = { 'status': 0, 'errors': None, 'driver': None } if request.method == 'GET': try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) response['driver'] = c.get_driver().to_dict() except RestException, e: response.update(handle_rest_exception(e, _('Could not get driver.'))) return JsonResponse(response)
def link_delete(request, link): if request.method != 'POST': raise StructuredException(code="INVALID_METHOD", message=_('POST request required.'), error_code=405) response = { 'status': 0, 'errors': None } try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) c.delete_link(link) except RestException, e: response.update(handle_rest_exception(e, _('Could not delete link.')))
def job_stop(request, job): if request.method != 'POST': raise StructuredException(code="INVALID_METHOD", message=_('POST request required.'), error_code=405) response = {'status': 0, 'errors': None, 'submission': None} try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) response['submission'] = c.stop_job(job).to_dict() except RestException, e: response.update(handle_rest_exception(e, _('Could not stop job.')))
def get_submissions(request): response = { 'status': 0, 'errors': None, 'submissions': [] } status = request.GET.get('status', 'submissions').split(',') try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) submissions = c.get_submissions() response['submissions'] = list_to_dict(submissions) except RestException as e: response.update(handle_rest_exception(e, _('Could not get submissions.'))) return JsonResponse(response)
def job_clone(request, job): if request.method != 'POST': raise StructuredException(code="INVALID_METHOD", message=_('POST request required.'), error_code=405) response = {'status': 0, 'errors': None, 'job': None} job.id = -1 job.name = '%s-copy' % job.name try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) response['job'] = c.create_job(job).to_dict() except RestException, e: response.update(handle_rest_exception(e, _('Could not clone job.')))
def update_link(request, link): response = { 'status': 0, 'errors': None, 'link': None } if 'link' not in request.POST: raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Error saving link'), data={'errors': 'Link is missing.'}, error_code=400) link.update_from_dict(json.loads(smart_str(request.POST['link']))) try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) response['link'] = c.update_link(link).to_dict() except RestException, e: response.update(handle_rest_exception(e, _('Could not update link.')))
def job_delete(request, job): if request.method != 'POST': raise StructuredException(code="INVALID_METHOD", message=_('POST request required.'), error_code=405) response = {'status': 0, 'errors': None, 'job': None} try: c = client.SqoopClient( conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) c.delete_job(job) except RestException, e: response.update(handle_rest_exception(e, _('Could not delete job.')))
def update_connection(request, connection): response = {'status': 0, 'errors': None, 'connection': None} if 'connection' not in request.POST: raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Error saving connection'), data={'errors': 'Connection is missing.'}, error_code=400) connection.update_from_dict(json.loads(request.POST['connection'])) try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) response['connection'] = c.update_connection(connection).to_dict() except RestException, e: response.update( handle_rest_exception(e, _('Could not update connection.')))
def job_status(request, job): if request.method != 'GET': raise StructuredException(code="INVALID_METHOD", message=_('GET request required.'), error_code=405) response = {'status': 0, 'errors': None, 'submission': None} try: c = client.SqoopClient( conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) response['submission'] = c.get_job_status(job).to_dict() except RestException, e: response.update( handle_rest_exception(e, _('Could not get job status.')))
def driver(request): response = {'status': 0, 'errors': None, 'driver': None} if request.method == 'GET': try: c = client.SqoopClient( conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) response['driver'] = c.get_driver().to_dict() except RestException as e: response.update( handle_rest_exception(e, _('Could not get driver.'))) return JsonResponse(response) else: raise StructuredException(code="INVALID_METHOD", message=_('GET request required.'), error_code=405)
def link_clone(request, link): if request.method != 'POST': raise StructuredException(code="INVALID_METHOD", message=_('POST request required.'), error_code=405) response = {'status': 0, 'errors': None, 'link': None} link.id = -1 link.name = '%s-copy' % link.name try: c = client.SqoopClient( conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) response['link'] = c.create_link(link).to_dict() except RestException, e: response.update(handle_rest_exception(e, _('Could not clone link.')))
def update_job(request, job): if request.method != 'POST': raise StructuredException(code="INVALID_METHOD", message=_('POST request required.'), error_code=405) response = { 'status': 0, 'errors': None, 'job': None } if 'job' not in request.POST: raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Error saving job'), data={'errors': 'job is missing.'}, error_code=400) job.update_from_dict(json.loads(smart_str(request.POST.get('job')))) try: c = client.SqoopClient(conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE) response['job'] = c.update_job(job).to_dict() except RestException, e: response.update(handle_rest_exception(e, _('Could not update job.')))
def link_delete(request, link): if request.method != 'POST': raise StructuredException(code="INVALID_METHOD", message=_('POST request required.'), error_code=405) response = {'status': 0, 'errors': None} try: c = client.SqoopClient( conf.SERVER_URL.get(), request.user.username, request.LANGUAGE_CODE, ssl_cert_ca_verify=conf.SSL_CERT_CA_VERIFY.get()) c.delete_link(link) except RestException as e: response.update(handle_rest_exception(e, _('Could not delete link.'))) except SqoopException as e: response['status'] = 100 response['errors'] = e.to_dict() return JsonResponse(response)