Пример #1
0
 def _update_pse_burst_status(self, burst_config):
     operations_in_group = dao.get_operations_in_group(
         burst_config.fk_operation_group)
     if burst_config.fk_metric_operation_group:
         operations_in_group.extend(
             dao.get_operations_in_group(
                 burst_config.fk_metric_operation_group))
     operation_statuses = list()
     for operation in operations_in_group:
         if not has_finished(operation.status):
             self.logger.debug(
                 'Operation {} in group {} is not finished, burst status will not be updated'
                 .format(operation.id, operation.fk_operation_group))
             return
         operation_statuses.append(operation.status)
     self.logger.debug(
         'All operations in burst {} have finished. Will update burst status'
         .format(burst_config.id))
     if STATUS_ERROR in operation_statuses:
         self.mark_burst_finished(
             burst_config, BurstConfiguration.BURST_ERROR,
             'Some operations in PSE have finished with errors')
     elif STATUS_CANCELED in operation_statuses:
         self.mark_burst_finished(burst_config,
                                  BurstConfiguration.BURST_CANCELED)
     else:
         self.mark_burst_finished(burst_config)
def do_operation_launch(operation_id):
    """
    Event attached to the local queue for executing an operation, when we will have resources available.
    """
    log = get_logger('tvb.core.operation_async_launcher')
    burst_service = BurstService2()

    try:
        log.debug("Loading operation with id=%s" % operation_id)
        curent_operation = dao.get_operation_by_id(operation_id)
        stored_adapter = curent_operation.algorithm
        log.debug("Importing Algorithm: " + str(stored_adapter.classname) +
                  " for Operation:" + str(curent_operation.id))
        params = parse_json_parameters(curent_operation.parameters)
        adapter_instance = ABCAdapter.build_adapter(stored_adapter)
        # These should go once we have a common place for it
        if not isinstance(adapter_instance, SimulatorAdapter):
            adapter_form = adapter_instance.get_form()(
                project_id=curent_operation.fk_launched_in)
            adapter_form.fill_from_post(params)
            adapter_instance.submit_form(adapter_form)

        # Un-comment bellow for profiling an operation:
        # import cherrypy.lib.profiler as profiler
        # p = profiler.Profiler("/Users/lia.domide/TVB/profiler/")
        # p.run(OperationService().initiate_prelaunch, curent_operation, adapter_instance, {}, **PARAMS)

        OperationService().initiate_prelaunch(curent_operation,
                                              adapter_instance, **params)
        if curent_operation.fk_operation_group:
            parent_burst = dao.get_generic_entity(
                BurstConfiguration2, curent_operation.fk_operation_group,
                'operation_group_id')[0]
            operations_in_group = dao.get_operations_in_group(
                curent_operation.fk_operation_group)
            if parent_burst.metric_operation_group_id:
                operations_in_group.extend(
                    dao.get_operations_in_group(
                        parent_burst.metric_operation_group_id))
            for operation in operations_in_group:
                if not has_finished(operation.status):
                    break
                if parent_burst is not None:
                    burst_service.mark_burst_finished(parent_burst)
        else:
            parent_burst = burst_service.get_burst_for_operation_id(
                operation_id)
            if parent_burst is not None:
                burst_service.mark_burst_finished(parent_burst)

        log.debug("Successfully finished operation " + str(operation_id))

    except Exception as excep:
        log.error("Could not execute operation " + str(sys.argv[1]))
        log.exception(excep)
        parent_burst = burst_service.get_burst_for_operation_id(operation_id)
        if parent_burst is not None:
            burst_service.mark_burst_finished(parent_burst,
                                              error_message=str(excep))
def do_operation_launch(operation_id):
    """
    Event attached to the local queue for executing an operation, when we will have resources available.
    """
    log = get_logger('tvb.core.operation_async_launcher')
    burst_service = BurstService()

    try:
        log.debug("Loading operation with id=%s" % operation_id)
        curent_operation = dao.get_operation_by_id(operation_id)
        stored_adapter = curent_operation.algorithm
        log.debug("Importing Algorithm: " + str(stored_adapter.classname) +
                  " for Operation:" + str(curent_operation.id))
        adapter_instance = ABCAdapter.build_adapter(stored_adapter)
        # Un-comment bellow for profiling an operation:
        # import cherrypy.lib.profiler as profiler
        # p = profiler.Profiler("/Users/lia.domide/TVB/profiler/")
        # p.run(OperationService().initiate_prelaunch, curent_operation, adapter_instance, {}, **PARAMS)

        OperationService().initiate_prelaunch(curent_operation,
                                              adapter_instance)
        if curent_operation.fk_operation_group:
            parent_burst = dao.get_generic_entity(
                BurstConfiguration, curent_operation.fk_operation_group,
                'fk_operation_group')[0]
            operations_in_group = dao.get_operations_in_group(
                curent_operation.fk_operation_group)
            if parent_burst.fk_metric_operation_group:
                operations_in_group.extend(
                    dao.get_operations_in_group(
                        parent_burst.fk_metric_operation_group))
            burst_finished = True
            for operation in operations_in_group:
                if not has_finished(operation.status):
                    burst_finished = False
                    break

            if burst_finished and parent_burst is not None and parent_burst.status != BurstConfiguration.BURST_ERROR:
                burst_service.mark_burst_finished(parent_burst)
        else:
            parent_burst = burst_service.get_burst_for_operation_id(
                operation_id)
            if parent_burst is not None:
                burst_service.mark_burst_finished(parent_burst)

        log.debug("Successfully finished operation " + str(operation_id))

    except Exception as excep:
        log.error("Could not execute operation " + str(operation_id))
        log.exception(excep)
        parent_burst = burst_service.get_burst_for_operation_id(operation_id)
        if parent_burst is not None:
            burst_service.mark_burst_finished(parent_burst,
                                              error_message=str(excep))