예제 #1
0
    def post(self, request, *args, **kwargs):
        assert isinstance(request, HttpRequest)
        assert request.META['CONTENT_TYPE'] == 'application/json'

        json_data = request.body
        data = json.loads(json_data)

        pool_id = data['pool_id']
        secret_key = data['secret_key']

        pool = CondorPool.objects.get(uuid=pool_id)
        #Validate that we trust this pool
        assert pool.secret_key == secret_key
        #Update the Condor jobs with their new condor q id
        for condor_job_id, queue_id in data['condor_jobs']:
            condor_job = CondorJob.objects.get(id=condor_job_id)
            assert condor_job.subtask.task.condor_pool == pool
            condor_job.queue_id = queue_id
            condor_job.queue_status = 'I'
            condor_job.save()

        try:
            #Set the subtask status as active. Look at the last condor_jobn
            subtask = condor_job.subtask
            subtask.status = 'queued'
            subtask.save()
        except:
            #Test case - no condor jobs submitted, therefore we can't know which subtask was updated
            pass

        #Now a task has been submitted, add termination alarms to the instances if this has been requested.

        try:
            ec2_tools.add_instances_alarms(pool)
        except Exception as e:
            log.exception(e)

        #Construct a json response to send back
        response_data = {'status': 'created'}
        json_response = json.dumps(response_data)

        return HttpResponse(json_response,
                            content_type="application/json",
                            status=201)
예제 #2
0
    def post(self, request, *args, **kwargs):
        assert isinstance(request, HttpRequest)
        assert request.META['CONTENT_TYPE'] == 'application/json'
        
        json_data=request.body
        data = json.loads(json_data)
        
        pool_id = data['pool_id']
        secret_key = data['secret_key']
        
        pool=CondorPool.objects.get(uuid=pool_id)
        #Validate that we trust this pool
        assert pool.secret_key == secret_key
        #Update the Condor jobs with their new condor q id
        for condor_job_id, queue_id in data['condor_jobs']:
            condor_job = CondorJob.objects.get(id=condor_job_id)
            assert condor_job.subtask.task.condor_pool == pool
            condor_job.queue_id = queue_id
            condor_job.queue_status = 'I'
            condor_job.save()
        
        try:
            #Set the subtask status as active. Look at the last condor_jobn
            subtask = condor_job.subtask
            subtask.status = 'queued'
            subtask.save()
        except:
            #Test case - no condor jobs submitted, therefore we can't know which subtask was updated
            pass
        
        
        #Now a task has been submitted, add termination alarms to the instances if this has been requested.

        try:
            ec2_tools.add_instances_alarms(pool)
        except Exception, e:
            log.exception(e)
예제 #3
0
    def post(self, request, *args, **kwargs):
        assert isinstance(request, HttpRequest)
        assert request.META['CONTENT_TYPE'] == 'application/json'
        json_data = request.body
        data = json.loads(json_data)

        pool_id = data['pool_id']
        secret_key = data['secret_key']

        pool = EC2Pool.objects.get(uuid=pool_id)
        assert pool.secret_key == secret_key

        #Get the condor jobs associated with the condor pool which we think are still running
        pool_jobs = CondorJob.objects.filter(subtask__task__condor_pool=pool)
        running_jobs = pool_jobs.filter(queue_status='R')
        idle_jobs = pool_jobs.filter(queue_status='I')
        held_jobs = pool_jobs.filter(queue_status='H')

        queued_jobs = running_jobs | idle_jobs | held_jobs

        for condor_queue_id, queue_status in data['condor_jobs']:
            condor_job = queued_jobs.get(queue_id=condor_queue_id)
            condor_job.queue_status = queue_status
            condor_job.save()

            #Since this job appeared in the list, it's not finished

            queued_jobs = queued_jobs.exclude(id=condor_job.id)

        #Assume that everything left in queued_jobs has finished
        for job in queued_jobs:
            job.queue_status = 'F'
            job.save()

        #Get all subtasks that are running on the pool

        active_subtasks = Subtask.objects.filter(
            task__condor_pool=pool).filter(active=True)

        for subtask in active_subtasks:
            #Look at all the jobs. Are they all finished?
            all_jobs_finished = True
            errors = False

            for job in subtask.condorjob_set.all():
                if job.queue_status != 'F':
                    all_jobs_finished = False
                elif job.queue_status == 'H':
                    errors = True

            if errors:
                print(sys.stderr, 'Error!')
                subtask.active = False
                subtask.status = 'error'
                subtask.save()
                subtask.task.status = 'error'
                subtask.task.save()

            elif all_jobs_finished:
                print >> sys.stderr, 'All jobs finished'
                subtask.active = False
                subtask.status = 'finished'
                subtask.save()

                #Is there another subtask to run?
                TaskClass = tools.get_task_class(subtask.task.task_type)

                subtask_count = TaskClass.subtasks

                task_instance = TaskClass(subtask.task)

                if subtask.index < subtask_count:
                    #We have another subtask to run
                    print('Another subtask to run!')

                    task_instance.submit_subtask(subtask.index + 1)

                else:
                    #The task must have finished
                    #Request the transfer of files
                    task_instance.request_file_transfer(
                        subtask.index, 'finished')

        #Finally, add instance alarms to the task if needed:
        try:
            ec2_tools.add_instances_alarms(pool)
        except Exception as e:
            log.exception(e)

        #Construct a json response to send back
        response_data = {'status': 'created'}
        json_response = json.dumps(response_data)

        return HttpResponse(json_response,
                            content_type="application/json",
                            status=201)
예제 #4
0
    def post(self, request, *args, **kwargs):
        assert isinstance(request, HttpRequest)
        assert request.META['CONTENT_TYPE'] == 'application/json'
        json_data=request.body
        data = json.loads(json_data)

        pool_id = data['pool_id']
        secret_key = data['secret_key']
        
        
        pool=EC2Pool.objects.get(uuid=pool_id)
        assert pool.secret_key == secret_key
        
        
        #Get the condor jobs associated with the condor pool which we think are still running
        pool_jobs = CondorJob.objects.filter(subtask__task__condor_pool=pool)
        running_jobs = pool_jobs.filter(queue_status='R')
        idle_jobs = pool_jobs.filter(queue_status='I')
        held_jobs = pool_jobs.filter(queue_status='H')
        
        queued_jobs = running_jobs | idle_jobs | held_jobs
        
        
        for condor_queue_id, queue_status in data['condor_jobs']:
            condor_job = queued_jobs.get(queue_id=condor_queue_id)
            condor_job.queue_status=queue_status
            condor_job.save()
            
            #Since this job appeared in the list, it's not finished
            
            queued_jobs = queued_jobs.exclude(id=condor_job.id)
        
        #Assume that everything left in queued_jobs has finished
        for job in queued_jobs:
            job.queue_status = 'F'
            job.save()

        
        #Get all subtasks that are running on the pool
        
        active_subtasks = Subtask.objects.filter(task__condor_pool=pool).filter(active=True)
        
        for subtask in active_subtasks:
            #Look at all the jobs. Are they all finished?
            all_jobs_finished = True
            errors = False
            
            for job in subtask.condorjob_set.all():
                if job.queue_status != 'F':
                    all_jobs_finished = False
                elif job.queue_status == 'H':
                    errors = True
            
            if errors:
                print sys.stderr, 'Error!'
                subtask.active=False
                subtask.status='error'
                subtask.save()
                subtask.task.status='error'
                subtask.task.save()
                
            elif all_jobs_finished:
                print >>sys.stderr, 'All jobs finished'
                subtask.active = False
                subtask.status = 'finished'
                subtask.save()
                
                
                #Is there another subtask to run?
                TaskClass = tools.get_task_class(subtask.task.task_type)
                
                subtask_count = TaskClass.subtasks
                
                task_instance = TaskClass(subtask.task)
                
                if subtask.index < subtask_count:
                    #We have another subtask to run
                    print 'Another subtask to run!'
                    
                    task_instance.submit_subtask(subtask.index + 1)
                    
                else:
                    #The task must have finished
                    #Request the transfer of files
                    task_instance.request_file_transfer(subtask.index, 'finished')
                    
        
        #Finally, add instance alarms to the task if needed:
        try:
            ec2_tools.add_instances_alarms(pool)
        except Exception, e:
            log.exception(e)