Beispiel #1
0
def newApply(request):
  if not request.user.is_authenticated() and not sso_user_is_authenticated(request) :
    return HttpResponseRedirect('/accounts/login/?next=%s' % request.path)
  applicant = sso_user_get_username(request)
  uid = sso_user_get_empid(request)
  applicant_mail = sso_user_get_email(request)
  if request.method == 'POST':
    form = ApplyForm(request.POST)
    if form.is_valid():
      data = form.cleaned_data
      applicant = data["username"]
      applicant_mail = data["email"]
      if sso_user_is_authenticated(request) :
        #apply = AppApply(name=data['name'],describe= (data['describe']),qps=data['qps'],capacity=data['capacity'],notes=u"#department:%s company:%s\n%s"%(sso_user_get_dep(request),sso_user_get_corp(request) ,data["notes"]),
        apply = AppApply(name=data['name'],describe= (data['describe']),qps=data['qps'],capacity=data['capacity'],notes=data["notes"],
          cache_or_durable=data['cache_or_durable'],restful_api=data['restful_api'],trade_critical=data['trade_critical'],
          data_source=data['data_source'],complicate_datastruct=data['complicate_datastruct'],entry_num=data["entry_num"],
          get_none_key=data['get_none_key'], two_cluster=data['two_cluster'], used_tair_before=data['used_tair_before'],
          create_by_username=applicant, modify_by_username=applicant, email=applicant_mail)
      elif request.user.is_authenticated():
        #apply = AppApply(name=data['name'],describe= (data['describe']),qps=data['qps'],capacity=data['capacity'],notes=u"#部门:%s 公司:%s\n%s"%(sso_user_get_dep(request),sso_user_get_corp(request) ,data["notes"]),
        apply = AppApply(name=data['name'],describe= (data['describe']),qps=data['qps'],capacity=data['capacity'],notes=data["notes"],
          cache_or_durable=data['cache_or_durable'],restful_api=data['restful_api'],trade_critical=data['trade_critical'],
          data_source=data['data_source'],complicate_datastruct=data['complicate_datastruct'],entry_num=data["entry_num"],
          get_none_key=data['get_none_key'], two_cluster=data['two_cluster'], used_tair_before=data['used_tair_before'],
          create_by=request.user, modify_by=request.user, email=applicant_mail)
      else:
        #apply = AppApply(name=data['name'],describe= (data['describe']),qps=data['qps'],capacity=data['capacity'],notes=u"#部门:%s 公司:%s\n%s"%(sso_user_get_dep(request),sso_user_get_corp(request) ,data["notes"]),
        apply = AppApply(name=data['name'],describe= (data['describe']),qps=data['qps'],capacity=data['capacity'],notes=data["notes"],
          cache_or_durable=data['cache_or_durable'],restful_api=data['restful_api'],trade_critical=data['trade_critical'],
          data_source=data['data_source'],complicate_datastruct=data['complicate_datastruct'],entry_num=data["entry_num"],
          get_none_key=data['get_none_key'], two_cluster=data['two_cluster'], used_tair_before=data['used_tair_before'],
          email=applicant_mail)
      apply.save()
      app = App(name=data['name'], status='1', apply=apply)
      app.save() 
      if data['email']:
        return render_to_response('thanks.html', {'email': data['email']},context_instance=RequestContext(request))
      else:
        return HttpResponseRedirect('/app/thanks')
  else:
      #desc_tip=u"#业务场景 KeyValue分别是什么,keyValue的大小\n\n#访问特点 读写比例 访问时间(高峰时间)\n\n#数据量大小,每天数据增量\n\n#对访问响应时间有什么要求\n "
      try:
        desc_tip = Constant.objects.get(key="t_describe_apply").value
      except Constant.DoesNotExist:
        desc_tip = None
      form = ApplyForm(initial={'describe':desc_tip})
  tip={}
  tip["username"]=applicant
  tip["email"]=applicant_mail
  return render_to_response('newapply.html', {'form': form, 'tips':tip},context_instance=RequestContext(request))
Beispiel #2
0
def area(request, area_key):
  print "xxx"
  if request.method == 'POST':
    ctype = request.POST.get("type", "")
    quota = request.POST.get("quota", -1)
    print "post ", area_key, ctype, quota
    try:
      q = int(quota)
    except :
      return HttpResponseBadRequest("quota invalid")
    #if q <= 0:
    #  return HttpResponseBadRequest("quota invalid")
    if ctype == "alloc0" or ctype == "alloc1": 
      app = App.objects.filter(name=area_key)
      if app.count() != 0:
        return HttpResponseConflict("app key existed!")
      apply = AppApply(name=area_key,describe="system auto",qps=0,capacity=q,notes="",
        cache_or_durable=True,restful_api=False,trade_critical=False,
        data_source=False,complicate_datastruct=False,entry_num=0,
        get_none_key=False, two_cluster=True, used_tair_before=False,
        create_by_username="******",email="*****@*****.**")
      apply.save()
      app = App(name=area_key, status='1', important='3', apply=apply)
      app.save() 
      g = findGroupAuto("mdb")
      if g == None:
        return HttpResponseNotFound("suitable group not found!")
      (ret, res) = allocNamespace(area_key ,q, g, app, ctype)
      if ret == TAIR_SUCCESS:
        return HttpResponse(json.dumps(res))
      else:
      	print "alloc ns error"
        return HttpResponse({'error':res})
  
    elif ctype == "modify":
      app = App.objects.filter(name=area_key)
      if (app.count() == 0):
        return HttpResponseNotFound("area key not existed!")
      if not app[0].review:
        return HttpResponseNotFound("area key not reviewed!")
      group = app[0].review.group
      ret = setQuota(area_key, quota, group, app[0])
      if ret == TAIR_SUCCESS: 
        app.review.quota = quota
        app.review.save()
        return HttpResponse(json.dumps({'error':'OK'}))
      else :
        return HttpResponse(json.dumps({'error':'error'}))

    else :
      return HttpResponseBadRequest("ctype invalid")


  if request.method == 'GET':
    ctype = request.GET.get("type", None)
    #quota = request.POST.get("quota", -1)
    #cs_1 = request.POST.get("cs1", None)
    #cs_2 = request.POST.get("cs2", None)
    #group = request.POST.get("group", None)
    #cluster_id = request.POST.get("cluster", -1)
    if ctype == 'cluster':
      g = findGroupAuto("mdb")
      if g == None:
        return HttpResponseNotFound("suitable group not found!")
      app = App.objects.filter(name=area_key)
      if (app.count() == 0):
        return HttpResponseNotFound("area key not existed!")
      area_num = app[0].review.namespace
      quota = app[0].review.quota
      (ret, res)= getClusterInfo(g, area_num, quota)
      if ret == TAIR_SUCCESS: 
        return HttpResponse(json.dumps(res))
      else :
        return HttpResponseNotFound("area cluster info not found!")
    if ctype == 'stat':
      app = App.objects.filter(name=area_key)
      if (app.count() == 0):
        return HttpResponseNotFound("area key not existed!")
      if not app[0].review:
        return HttpResponseNotFound("area key not reviewed!")
      group = app[0].review.group
      (ret, res) = getAreaStat(area_key, group, app)
      if ret == TAIR_SUCCESS: 
        return HttpResponse(json.dumps(res))
      else :
        return HttpResponseNotFound("area key get stat failed!")
    return HttpResponse("please indicate type")
    

  if request.method == 'DELETE':
    app = App.objects.filter(name=area_key)
    if (app.count() == 0):
      return HttpResponseNotFound("area key not existed!")
    if not app[0].review:
      return HttpResponseNotFound("area key not reviewed!")
    group = app[0].review.group
    print 'xxx', area_key
    ret = setQuota(area_key, 0, group, app[0])
    if ret == TAIR_SUCCESS: 
      review = app[0].review
      apply = app[0].apply
      try:
        if review:
          print 's2reveiw'
          review.delete()
        if apply:
          print 's2apply'
          apply.delete()
      except e:
        print e
      return HttpResponse(json.dumps(ret))
    else :
      return HttpResponseNotFound("area key delete failed!")