def update_db_with_results(operation, sim_h5_filenames, metric_operation, metric_h5_filename): # type: (Operation, list, Operation, str) -> (str, int) """ Generate corresponding Index entities for the resulted H5 files and insert them in DB. """ burst_service = BurstService() index_list = [] is_group = operation.fk_operation_group is not None burst_config = burst_service.get_burst_for_operation_id(operation.id) if is_group: burst_config = burst_service.get_burst_for_operation_id( operation.fk_operation_group, True) all_indexes = burst_service.prepare_indexes_for_simulation_results( operation, sim_h5_filenames, burst_config) if is_group: # Update the operation group name operation_group = dao.get_operationgroup_by_id( metric_operation.fk_operation_group) operation_group.fill_operationgroup_name("DatatypeMeasureIndex") dao.store_entity(operation_group) metric_index = burst_service.prepare_index_for_metric_result( metric_operation, metric_h5_filename, burst_config) all_indexes.append(metric_index) for index in all_indexes: index = dao.store_entity(index) index_list.append(index) burst_service.update_burst_status(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 = 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))
def cancel_or_remove_operation(self, operation_id, is_group, remove_after_stop=False): """ Stop the operation given by operation_id. If is_group is true stop all the operations from that group. """ # Load before we remove, to have its data in memory here burst_config = BurstService.get_burst_for_operation_id(operation_id, is_group) if burst_config is not None: self.burst_service.mark_burst_finished(burst_config, BurstConfiguration.BURST_CANCELED, store_h5_file=False) while GROUP_BURST_PENDING.get(burst_config.id, False): pass GROUP_BURST_PENDING.pop(burst_config.id, False) result = OperationService.stop_operation(operation_id, is_group, remove_after_stop) if remove_after_stop: current_burst = self.context.burst_config if (current_burst is not None and burst_config is not None and current_burst.id == burst_config.id and ((current_burst.fk_simulation == operation_id and not is_group) or (current_burst.fk_operation_group == operation_id and is_group))): self.reset_simulator_configuration() if burst_config is not None: burst_config = BurstService.load_burst_configuration(burst_config.id) if burst_config: BurstService.remove_burst_configuration(burst_config.id) return result
def update_db_with_results(self, operation, sim_h5_filenames, metric_operation, metric_h5_filename): # type: (Operation, list, Operation, str) -> (str, int) """ Generate corresponding Index entities for the resulted H5 files and insert them in DB. """ burst_service = BurstService() index_list = [] burst_config = burst_service.get_burst_for_operation_id(operation.id) all_indexes = burst_service.prepare_indexes_for_simulation_results( operation, sim_h5_filenames, burst_config) if burst_config.fk_operation_group: metric_index = burst_service.prepare_index_for_metric_result( metric_operation, metric_h5_filename, burst_config) all_indexes.append(metric_index) for index in all_indexes: index = dao.store_entity(index) index_list.append(index) sim_adapter = SimulatorAdapter() sim_adapter.extract_operation_data(operation) sim_adapter.generic_attributes.parent_burst = burst_config.gid mesage, _ = sim_adapter._capture_operation_results(index_list) burst_service.update_burst_status(burst_config) # self.update_datatype_groups() return mesage
def cancel_or_remove_operation(self, operation_id, is_group, remove_after_stop=False): """ Stop the operation given by operation_id. If is_group is true stop all the operations from that group. """ operation_id = int(operation_id) is_group = int(is_group) != 0 # Load before we remove, to have its data in memory here burst_config = BurstService.get_burst_for_operation_id(operation_id) result = OperationService.stop_operation(operation_id, is_group, remove_after_stop) if remove_after_stop: current_burst = common.get_from_session(common.KEY_BURST_CONFIG) if current_burst is not None and burst_config is not None and current_burst.id == burst_config.id: common.remove_from_session(common.KEY_BURST_CONFIG) common.add2session(common.KEY_BURST_CONFIG, BurstConfiguration(burst_config.project.id)) return result
def cancel_or_remove_operation(self, operation_id, is_group, remove_after_stop=False): """ Stop the operation given by operation_id. If is_group is true stop all the operations from that group. """ # Load before we remove, to have its data in memory here burst_config = BurstService.get_burst_for_operation_id( operation_id, is_group) result = OperationService.stop_operation(operation_id, is_group, remove_after_stop) if remove_after_stop: current_burst = self.context.burst_config if (current_burst is not None and burst_config is not None and current_burst.id == burst_config.id and ((current_burst.fk_simulation == operation_id and not is_group) or (current_burst.fk_operation_group == operation_id and is_group))): self.reset_simulator_configuration() return result