def store_burst(project_id, operation=None): """ Build and persist BurstConfiguration entity. """ burst = BurstConfiguration(project_id) if operation is not None: burst.name = 'dummy_burst' burst.status = BurstConfiguration.BURST_FINISHED burst.start_time = datetime.now() burst.range1 = '["conduction_speed", {"lo": 50, "step": 1.0, "hi": 100.0}]' burst.range2 = '["connectivity", null]' burst.fk_simulation = operation.id burst.simulator_gid = uuid.uuid4().hex BurstService().store_burst_configuration(burst) return dao.store_entity(burst)
def get_burst_for_migration(burst_id, burst_match_dict, date_format, selected_db): """ This method is supposed to only be used when migrating from version 4 to version 5. It finds a BurstConfig in the old format (when it did not inherit from HasTraitsIndex), deletes it and returns its parameters. """ session = SA_SESSIONMAKER() burst_params = session.execute("""SELECT * FROM "BURST_CONFIGURATION" WHERE id = """ + burst_id).fetchone() session.close() if burst_params is None: return None, False burst_params_dict = {'datatypes_number': burst_params['datatypes_number'], 'dynamic_ids': burst_params['dynamic_ids'], 'range_1': burst_params['range1'], 'range_2': burst_params['range2'], 'fk_project': burst_params['fk_project'], 'name': burst_params['name'], 'status': burst_params['status'], 'error_message': burst_params['error_message'], 'start_time': burst_params['start_time'], 'finish_time': burst_params['finish_time'], 'fk_simulation': burst_params['fk_simulation'], 'fk_operation_group': burst_params['fk_operation_group'], 'fk_metric_operation_group': burst_params['fk_metric_operation_group']} if selected_db == 'sqlite': burst_params_dict['start_time'] = string2date(burst_params_dict['start_time'], date_format=date_format) burst_params_dict['finish_time'] = string2date(burst_params_dict['finish_time'], date_format=date_format) if burst_id not in burst_match_dict: burst_config = BurstConfiguration(burst_params_dict['fk_project']) burst_config.datatypes_number = burst_params_dict['datatypes_number'] burst_config.dynamic_ids = burst_params_dict['dynamic_ids'] burst_config.error_message = burst_params_dict['error_message'] burst_config.finish_time = burst_params_dict['finish_time'] burst_config.fk_metric_operation_group = burst_params_dict['fk_metric_operation_group'] burst_config.fk_operation_group = burst_params_dict['fk_operation_group'] burst_config.fk_project = burst_params_dict['fk_project'] burst_config.fk_simulation = burst_params_dict['fk_simulation'] burst_config.name = burst_params_dict['name'] burst_config.range1 = burst_params_dict['range_1'] burst_config.range2 = burst_params_dict['range_2'] burst_config.start_time = burst_params_dict['start_time'] burst_config.status = burst_params_dict['status'] new_burst = True else: burst_config = dao.get_burst_by_id(burst_match_dict[burst_id]) new_burst = False return burst_config, new_burst
def test_get_history_status(self): burst_config = BurstConfiguration(self.test_project.id) burst_config.start_time = datetime.now() dao.store_entity(burst_config) burst = dao.get_bursts_for_project(self.test_project.id) self.sess_mock['burst_ids'] = '["' + str(burst[0].id) + '"]' with patch('cherrypy.session', self.sess_mock, create=True): common.add2session(common.KEY_BURST_CONFIG, self.session_stored_simulator) common.add2session(common.KEY_BURST_CONFIG, burst_config) result = self.simulator_controller.get_history_status(**self.sess_mock._data).split(',') assert int(result[0][2:]) == burst[0].id, "Incorrect burst was used." assert result[1] == ' "running"', "Status should be set to running." assert result[2] == ' false', "Burst shouldn't be group." assert result[3] == ' ""', "Message should be empty, which means that there shouldn't be any errors." assert int(result[4][2:-4]) >= 0, "Running time should be greater than or equal to 0."
def build(test_user, test_project, simulation_length=10, is_group=False): model = SimulatorAdapterModel() model.connectivity = connectivity_index_factory().gid model.simulation_length = simulation_length burst = BurstConfiguration(test_project.id, name="Sim " + str(datetime.now())) burst.start_time = datetime.now() algorithm = dao.get_algorithm_by_module(SIMULATOR_MODULE, SIMULATOR_CLASS) service = SimulatorService() if is_group: range_param = RangeParameter("conduction_speed", float, Range(lo=50.0, hi=100.0, step=20.0)) burst.range1 = range_param.to_json() burst = BurstService().prepare_burst_for_pse(burst) op = service.async_launch_and_prepare_pse(burst, test_user, test_project, algorithm, range_param, None, model) else: dao.store_entity(burst) op = service.async_launch_and_prepare_simulation(burst, test_user, test_project, algorithm, model) return op
def fire_simulation(project_id, simulator): project = dao.get_project_by_id(project_id) assert isinstance(simulator, Simulator) # Load the SimulatorAdapter algorithm from DB cached_simulator_algorithm = FlowService( ).get_algorithm_by_module_and_class(IntrospectionRegistry.SIMULATOR_MODULE, IntrospectionRegistry.SIMULATOR_CLASS) # Instantiate a SimulatorService and launch the configured simulation simulator_service = SimulatorService() burst = BurstConfiguration(project.id) burst.name = "Sim " + str(datetime.now()) burst.start_time = datetime.now() dao.store_entity(burst) launched_operation = simulator_service.async_launch_and_prepare_simulation( burst, project.administrator, project, cached_simulator_algorithm, simulator, None) LOG.info("Operation launched ....") return launched_operation