def onFinishedPreprocessingTask(task):
    status = 500
    SSHCommand.onFinishParcellationAndCorrelationinSSH(task)
    task.Task_Finish = True
    task.Progress_value = 100
    task.Task_EndTime = timezone.now()
    task.save()
    ServerManagement.PopAvailableServer(task.Task_Server)
    if task.Preprocess_Type == 'Static':
        preprocessTaskList = CorrelationConnectivityTask.objects.filter(Task_Modal=task.Task_Modal,
                                                                        Preprocess_Type='Dynamic')
        taskDynamic = preprocessTaskList[0]
        taskDynamic.Task_Server = task.Task_Server
        taskDynamic.save()
        check_and_submitTask(taskPrefer=taskDynamic)

        # create Causality Task
    elif task.Preprocess_Type == 'Dynamic':
        taskTMP = CausalityConnectivityTask.objects.filter(Task_Modal=task.Task_Modal)
        if not len(taskTMP):
            causalityTask = CausalityConnectivityTask.objects.create(Task_Modal=task.Task_Modal, Task_Status=200,
                                                                 Task_Type='Causality',
                                                                 Preprocessed_Dir=task.Preprocessed_Dir)
            causalityTask.save()
        isDebug = TaskQueue.objects.get(Type='CorrelationConnectivity').isDebug
        if not isDebug:
            SSHCommand.CleanUpParcellationServer(task.Task_Server)
        SSHCommand.RestartServer(task.Task_Server)

    status = 200
    return status
Beispiel #2
0
def ResetPreprocessingTask(request, ModalID):
    if not request.session.get('is_login', None):
        return HttpResponse('Please login in first')

    TasksToReset = CorrelationConnectivityTask.objects.filter(Task_Modal_id=ModalID)
    if len(TasksToReset):
        Server = TasksToReset[0].Task_Server
        if Server:
            servers_occupied = CorrelationConnectivityTask.objects.filter(Task_Server=Server).filter(Task_Start=1,
                                                                                                     Task_Finish=0)
            if len(servers_occupied) == 1:

                if servers_occupied[0] == TasksToReset[0]:
                    # print('Only One server occupied, can be reset ' + Server.Server_IP)
                    # print('Going to reset' + Server.Server_IP)
                    isDebug = TaskQueue.objects.get(Type='CorrelationConnectivity').isDebug
                    if not isDebug:
                        SSHCommand.CleanUpParcellationServer(Server)  # 可能清除掉动态脑连接预处理文件目录,谨慎使用
                    SSHCommand.RestartServer(Server)
                    Server.Server_IsBusy = False
                    Server.save()
        for task in TasksToReset:
            task.Progress_value = 0
            task.Task_Status = 200
            task.Task_Server = None
            task.Task_Finish = 0
            task.Task_Start = 0
            task.save()

    return HttpResponse('Task Reset successfully')
def AbandonTask(modal):
    """
    当预处理出现错误时,放弃该任务,释放服务器,等待用户手动删除该visit
    :param modalID: 与visit相关的所有task,包括静态和动态脑连接计算task
    :return:
    """
    logging.info('\033[1;33m ---------------------Going to Abandon this Causality task-------------------- \033[0m')
    # print('\033[0;35;46m ---------------------Going to Abandon this Causality task-------------------- \033[0m')
    tasks = CausalityConnectivityTask.objects.filter(Task_Modal=modal)

    if len(tasks):
        server = tasks[0].Task_Server
        for eachTask in tasks:
            eachTask.Task_Start = True
            eachTask.Task_Finish = True
            eachTask.Task_Status = -1
            # eachTask.Task_Server = None
            eachTask.save()

        if server:
            isDebug = TaskQueue.objects.get(Type='CausalityConnectivity').isDebug
            if not isDebug:
                SSHCommand.CleanUpCausalityServer(server)
            # SSHCommand.RestartServer(server)
            server.Server_IsBusy = False
            server.save()
Beispiel #4
0
def toDeletePreprocessFolders(modal):
    status = 500
    # try:
    taskList = CausalityConnectivityTask.objects.filter(Task_Modal=modal)
    for task in taskList:
        SSHCommand.toDeleteCausalityProgressFolderInSSH(task)

    taskList = CorrelationConnectivityTask.objects.filter(Task_Modal=modal)
    for task in taskList:
        SSHCommand.toDeleteParcellationAndCorrelationPreprocessFolderInSSH(task)
    status = 200
    # except:
    #     status = 500
    #     print(
    #         'task folder delete with error. Task ID:' + str(task.id) + '   -- Owner: ' + task.Task_Modal.RARFile.uploader.name)
    return status
def onFinishedPreprocessingTask(task):
    """
    任务结束后,拷贝数据,并删除文件夹,释放服务器
    :param task:
    :return:
    """
    status = 500
    SSHCommand.onFinishTaskInSSH(task)
    task.Task_Finish = True
    task.Progress_value = 100
    task.Task_EndTime = timezone.now()
    task.save()

    ServerManagement.PopAvailableServer(task.Task_Server)
    SSHCommand.CleanUpCausalityServer(task.Task_Server)
    # SSHCommand.RestartServer(task.Task_Server)
    status = 200
    return status
def updateOwnedTaskStatus(task):
    """
    检查服务器状态
    :param task:
    :return:
    """
    status = SSHCommand.CheckCausalityThreadInServer(task.Task_Server.Server_IP)
    task.Task_Status = status
    task.save()
    return status
def toStartPreprocessingTask(task):
    status = 500
    try:
        SSHCommand.toStartParcellationAndCorrelationInSSH(task)
        task.Task_StartTime = timezone.now()
        task.Task_Start = True
        task.Task_Status = 200
        task.Preprocessed_Dir = '/'.join(
            task.Task_Modal.RARFile.storage_path.split('/')[0:4]) + '/Preprocessed/' + task.Task_Modal.uuidStr
        server = task.Task_Server
        server.Server_IsBusy = True
        server.save()
        task.save()
        status = 200
    except:
        status = 500
    # print(
    #     'task start with error. Task ID:' + str(task.id) + '   -- Owner: ' + task.Task_Modal.RARFile.uploader.name)
    return status
Beispiel #8
0
def MigrateModal(request, ModalID, toServerIP):
    if not request.session.get('is_login', None):
        return HttpResponse("Please Login in first")
    authorized = checkAuthorization(userid=request.session['user_id'])
    if not authorized:
        return HttpResponse("Not authorized")

    modalID = ModalID
    toServerIP = toServerIP

    status = SSHCommand.MigrateModal(ModalID, toServerIP)
    if status == 500:
        return HttpResponse('Failed')
    return HttpResponse('Migration Successed')
def toStartPreprocessingTask(task):
    """
    To Start Causality Analysis Task
    :param task: Causality Task in which server has been assigned
    :return: status
    """
    status = 500
    try:
        SSHCommand.toStartCausalityInSSH(task)
        task.Task_StartTime = timezone.now()
        task.Task_Start = True
        task.Task_Status = 200
        task.Preprocessed_Dir = '/'.join(
            task.Task_Modal.RARFile.storage_path.split('/')[0:4]) + '/Preprocessed/' + task.Task_Modal.uuidStr
        server = task.Task_Server
        server.Server_IsBusy = True
        server.save()
        task.save()
        status = 200
    except:
        status = 500
    # print(
    #     'task start with error. Task ID:' + str(task.id) + '   -- Owner: ' + task.Task_Modal.RARFile.uploader.name)
    return status
Beispiel #10
0
def CheckParcellationPreprocessingTask(request, ModalID):
    """
    检查服务器上的脑分区进程是否正常
    :param request:
    :param ModalID:
    :return:
    """
    if not request.session.get('is_login', None):
        return HttpResponse('Please login in first')
    result = 'Task not assigned'
    TasksToReset = CorrelationConnectivityTask.objects.filter(Task_Modal_id=ModalID)
    if len(TasksToReset):
        if (TasksToReset[0].Task_Server):
            Server_IP = TasksToReset[0].Task_Server.Server_IP
            result = SSHCommand.CheckParcellationThreadInServer(Server_IP)
    return HttpResponse(result)
def updateOwnedTaskProgressValue(task):
    """
    更新任务的预处理进度
    :param task: 格兰杰因果或新型因果关系脑连接计算任务
    :return:状态值,200,更新成功
    """
    progress_result = SSHCommand.lookupCausalityLogfileInSSH(task)
    progress_value = progress_result['value']
    progress_status = progress_result['status']
    # if progress_status == 500:
    #     AbandonTask(task.Task_Modal)
    task.Progress_value = round(float(progress_value), 2)
    task.save()
    if task.Progress_value == float('100'):
        status = onFinishedPreprocessingTask(task)
    else:
        status = updateOwnedTaskStatus(task)
        if status == -1:
            AbandonTask(task.Task_Modal)
    return
def updateOwnedTaskProgressValue(task):
    """
    更新任务的预处理进度
    :param task: 静态或动态脑链接计算任务
    :return:状态值,200,更新成功,300 查询异常
    """
    progress_result = SSHCommand.lookupParcellationAndCorrelationLogFilesInSSH(task)
    progress_value = progress_result['value']
    progress_status = progress_result['status']
    # if progress_status == 500:
    #     AbandonTask(task.Task_Modal)
    task.Progress_value = round(float(progress_value), 2)
    task.save()
    if progress_value == '100':
        status = onFinishedPreprocessingTask(task)
    else:
        status = updateOwnedTaskStatus(task)
        if status == -1:
            AbandonTask(task.Task_Modal)
    return