Example #1
0
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)
Example #2
0
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)
Example #3
0
 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)
Example #4
0
 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.'))
Example #5
0
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.')))
Example #6
0
 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.'))
Example #7
0
 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.'))
Example #8
0
 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.'))
Example #9
0
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.')))
Example #10
0
File: framework.py Project: ymc/hue
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")
Example #11
0
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)
Example #12
0
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)
Example #13
0
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.')))
Example #14
0
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.')))
Example #15
0
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)
Example #16
0
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.')))
Example #17
0
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.')))
Example #18
0
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.')))
Example #19
0
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.')))
Example #20
0
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.')))
Example #21
0
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)
Example #22
0
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.')))
Example #23
0
File: job.py Project: zkenstein/hue
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.')))
Example #24
0
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)