Example #1
0
def process_runtask(hosttag, sqltext, mytask):
    flag = (1 if mytask.backup_status == 1 else 3)
    # db_type_record = func.get_dbtype_bydbtag(hosttag)
    # dbtype_flag = str(db_type_record[0][0])
    results, col, tar_dbname = incept.inception_check(hosttag, sqltext, flag)
    incept.make_sure_mysql_usable()
    # if dbtype_flag == 'mysql':
    #     results, col, tar_dbname = incept.inception_check(hosttag, sqltext, flag)
    #     incept.make_sure_mysql_usable()
    # elif dbtype_flag == 'Oracle':
    #     results, col, tar_dbname = incept_oracle_run(hosttag,sqltext,useraccount,ipaddr)
    #incept.make_sure_mysql_usable()
    status = 'executed'
    c_time = mytask.create_time
    mytask.update_time = datetime.datetime.now()
    if flag == 1:
        mytask.backup_status = 2
    mytask.save()
    for row in results:
        try:
            inclog = Incep_error_log(myid=row[0],stage=row[1],errlevel=row[2],stagestatus=row[3],errormessage=row[4],\
                         sqltext=row[5],affectrow=row[6],sequence=row[7],backup_db=row[8],execute_time=row[9],sqlsha=row[10],\
                         create_time=c_time,finish_time=mytask.update_time)
            inclog.save()
            #if some error occured in inception_check stage
        except Exception, e:
            inclog = Incep_error_log(myid=999,stage='',errlevel=999,stagestatus='',errormessage=row[0],\
                         sqltext=e,affectrow=999,sequence='',backup_db='',execute_time='',sqlsha='',\
                         create_time=c_time,finish_time=mytask.update_time)
            inclog.save()
        if (int(row[2]) != 0):
            status = 'executed failed'
Example #2
0
def process_runtask(hosttag, sqltext, mytask):
    results, col, tar_dbname = incept.inception_check(hosttag, sqltext, 1)
    status = 'executed'
    c_time = mytask.create_time
    mytask.update_time = datetime.datetime.now()
    mytask.save()
    for row in results:
        try:
            inclog = Incep_error_log(myid=row[0],stage=row[1],errlevel=row[2],stagestatus=row[3],errormessage=row[4],\
                         sqltext=row[5],affectrow=row[6],sequence=row[7],backup_db=row[8],execute_time=row[9],sqlsha=row[10],\
                         create_time=c_time,finish_time=mytask.update_time)
            inclog.save()
            #if some error occured in inception_check stage
        except Exception, e:
            inclog = Incep_error_log(myid=999,stage='',errlevel=999,stagestatus='',errormessage=row[0],\
                         sqltext=e,affectrow=999,sequence='',backup_db='',execute_time='',sqlsha='',\
                         create_time=c_time,finish_time=mytask.update_time)
            inclog.save()
        if (int(row[2]) != 0):
            status = 'executed failed'
Example #3
0
def process_runtask(hosttag,sqltext,mytask):
    results,col,tar_dbname = incept.inception_check(hosttag,sqltext,1)
    status='executed'
    c_time = mytask.create_time
    mytask.update_time = datetime.datetime.now()
    mytask.save()
    for row in results:
        try:
            inclog = Incep_error_log(myid=row[0],stage=row[1],errlevel=row[2],stagestatus=row[3],errormessage=row[4],\
                         sqltext=row[5],affectrow=row[6],sequence=row[7],backup_db=row[8],execute_time=row[9],sqlsha=row[10],\
                         create_time=c_time,finish_time=mytask.update_time)
            inclog.save()
            #if some error occured in inception_check stage
        except Exception,e:
            inclog = Incep_error_log(myid=999,stage='',errlevel=999,stagestatus='',errormessage=row[0],\
                         sqltext=e,affectrow=999,sequence='',backup_db='',execute_time='',sqlsha='',\
                         create_time=c_time,finish_time=mytask.update_time)
            inclog.save()
        if (int(row[2])!=0):
            status='executed failed'
Example #4
0
def template_dmldata(request):
    #objlist = func.get_mysql_hostlist(request.user.username, 'meta')
    # result = func.get_diff('mysql-lepus-test','mysql_replication','mysql-lepus','mysql_replication')
    # print result
    form = AddForm(request.POST)
    objlist = func.get_mysql_hostlist(request.user.username, 'incept')
    templist = func.get_template_demo("")
    if request.method == 'POST':
        choosed_host = request.POST['dbhost']
        sqlmemo = request.POST['sqlmemo'][0:100]
        choosed_temp = request.POST['cx_temp']
        searchtempname = request.POST['searchtempname']
        if len(choosed_temp) == 0:
            return render(
                request, 'template_dmldata.html', {
                    "form": form,
                    "objlist": objlist,
                    'choosed_host': choosed_host,
                    "sqlmemo_val": sqlmemo,
                    "templist": templist,
                    "cx_temp": choosed_temp,
                    "tmp_search": searchtempname
                })
        # if len(sqlmemo) == 0:
        #     form = AddForm(request.POST)
        #     status="Please input the memo"
        #     return render(request, 'template_dmldata.html',
        #                   {"form": form, "objlist": objlist,  'choosed_host': choosed_host,"sqlmemo_val":sqlmemo,"status":status,"templist":templist})
        if request.POST.has_key('check'):
            if form.is_valid():
                a = form.cleaned_data['a']
                try:
                    tmpsqltext = ''
                    for i in sqlfilter.get_sqldml_detail(
                            sqlfilter.sql_init_filter(a), 2):
                        tmpsqltext = tmpsqltext + i
                    a = tmpsqltext
                    form = AddForm(initial={'a': a})
                except Exception, e:
                    pass

                data_mysql, collist, dbname = incept.inception_check(
                    choosed_host, a, 2)
                # check the nee to split sqltext first

                if len(data_mysql) > 1:
                    split = 1
                    # return render(request, 'template_dmldata.html',
                    #               { "form": form,"objlist":objlist,"data_list":data_mysql,"collist":collist,"split":split, 'choosed_host': choosed_host,"sqlmemo_val":sqlmemo,"templist":templist})
                    return render(
                        request, 'template_dmldata.html', {
                            "form": form,
                            "objlist": objlist,
                            'choosed_host': choosed_host,
                            "sqlmemo_val": sqlmemo,
                            "templist": templist,
                            "cx_temp": choosed_temp,
                            "tmp_search": searchtempname,
                            "data_list": data_mysql,
                            "collist": collist,
                            "split": split
                        })
                else:
                    data_mysql, collist, dbname = incept.inception_check(
                        choosed_host, a)
                    # return render(request, 'template_dmldata.html',
                    #               { "form": form,"objlist":objlist,"data_list":data_mysql,"collist":collist, 'choosed_host': choosed_host,"sqlmemo_val":sqlmemo,"templist":templist})
                return render(
                    request, 'template_dmldata.html', {
                        "form": form,
                        "objlist": objlist,
                        'choosed_host': choosed_host,
                        "sqlmemo_val": sqlmemo,
                        "templist": templist,
                        "cx_temp": choosed_temp,
                        "tmp_search": searchtempname,
                        "data_list": data_mysql,
                        "collist": collist
                    })
            else:
                return render(request, 'template_dmldata.html', locals())
        elif request.POST.has_key('addsql'):
            needbackup = 1
            if form.is_valid():
                sqltext = form.cleaned_data['a']
                # get valid statement
                try:
                    tmpsqltext = ''
                    for i in sqlfilter.get_sqldml_detail(
                            sqlfilter.sql_init_filter(sqltext), 2):
                        tmpsqltext = tmpsqltext + i
                    sqltext = tmpsqltext
                    form = AddForm(initial={'a': sqltext})
                except Exception, e:
                    pass
                data_mysql, tmp_col, dbname = incept.inception_check(
                    choosed_host, sqltext, 2)
                # check if the sqltext need to be splited before uploaded
                if len(data_mysql) > 1:
                    split = 1
                    status = 'UPLOAD  FAIL'
                    # return render(request, 'inception.html', {'form': form,
                    #                                           'objlist': objlist,
                    #                                           'status': status,
                    #                                           'split': split,
                    #                                           'choosed_host': choosed_host,"sqlmemo_val":sqlmemo})
                    return render(
                        request, 'template_dmldata.html', {
                            "form": form,
                            "objlist": objlist,
                            'choosed_host': choosed_host,
                            'status': status,
                            'split': split,
                            "sqlmemo_val": sqlmemo,
                            "templist": templist,
                            "cx_temp": choosed_temp,
                            "tmp_search": searchtempname,
                            "data_list": data_mysql
                        })
                # check sqltext before uploaded
                else:
                    tmp_data, tmp_col, dbname = incept.inception_check(
                        choosed_host, sqltext)
                    for i in tmp_data:
                        if int(i[2]) != 0:
                            status = 'UPLOAD TASK FAIL,CHECK NOT PASSED'
                            return render(request, 'template_dmldata.html',
                                          locals())
                specification = "template_dml:" + sqlmemo
                rstatus = 'check passed'
                myNewTask = incept.record_taskdml(request, sqltext,
                                                  choosed_host, specification,
                                                  needbackup, rstatus)
                nllflag = task_run(myNewTask.id, request)
                status = 'EXEC OK'
                datalist = Task.objects.filter(
                    id=myNewTask.id).order_by("-create_time")[0:50]
                # sendmail_task.delay(choosed_host+'\n'+sqltext)
                #sendmail_task.delay(myNewTask)

                # return render(request, 'template_dmldata.html', {'form': form,
                #                                           'objlist': objlist,
                #                                           'status': status,
                #                                           'choosed_host': choosed_host,"datalist":datalist,"sqlmemo_val":sqlmemo})
                return render(
                    request, 'template_dmldata.html', {
                        "form": form,
                        "objlist": objlist,
                        'choosed_host': choosed_host,
                        'status': status,
                        "sqlmemo_val": sqlmemo,
                        "templist": templist,
                        "cx_temp": choosed_temp,
                        "tmp_search": searchtempname,
                        "data_list": data_mysql
                    })
            else:
                status = 'EXEC  FAIL'
                return render(
                    request, 'template_dmldata.html', {
                        'form': form,
                        'objlist': objlist,
                        'status': status,
                        'choosed_host': choosed_host,
                        "sqlmemo_val": sqlmemo
                    })
            form = AddForm()
            return render(
                request, 'template_dmldata.html', {
                    'form': form,
                    'upform': upform,
                    'objlist': objlist,
                    'choosed_host': choosed_host,
                    "sqlmemo_val": sqlmemo
                })
            return render(request, 'template_dmldata.html', locals())