def launch_burst(self, burst_configuration, simulator_index, simulator_id, user_id, launch_mode=LAUNCH_NEW): """ Given a burst configuration and all the necessary data do the actual launch. :param burst_configuration: BurstConfiguration :param simulator_index: the position within the workflows step list that the simulator will take. This is needed so that the rest of the portlet workflow steps know what steps do their dynamic parameters come from. :param simulator_id: the id of the simulator adapter as stored in the DB. It's needed to load the simulator algo group and category that are then passed to the launcher's prepare_operation method. :param user_id: the id of the user that launched this burst :param launch_mode: new/branch/continue """ ## 1. Prepare BurstConfiguration entity if launch_mode == LAUNCH_NEW: ## Fully new entity for new simulation burst_config = burst_configuration.clone() if burst_config.name is None: new_id = dao.get_max_burst_id() + 1 burst_config.name = "simulation_" + str(new_id) else: ## Branch or Continue simulation burst_config = burst_configuration simulation_state = dao.get_generic_entity( SIMULATION_DATATYPE_MODULE + "." + SIMULATION_DATATYPE_CLASS, burst_config.id, "fk_parent_burst" ) if simulation_state is None or len(simulation_state) < 1: exc = BurstServiceException( "Simulation State not found for %s, " "thus we are unable to branch from it!" % burst_config.name ) self.logger.error(exc) raise exc simulation_state = simulation_state[0] burst_config.update_simulation_parameter("simulation_state", simulation_state.gid) burst_config = burst_configuration.clone() count = dao.count_bursts_with_name(burst_config.name, burst_config.fk_project) burst_config.name = burst_config.name + "_" + launch_mode + str(count) ## 2. Create Operations and do the actual launch if launch_mode in [LAUNCH_NEW, LAUNCH_BRANCH]: ## New Burst entry in the history burst_id = self._store_burst_config(burst_config) thread = threading.Thread( target=self._async_launch_and_prepare, kwargs={ "burst_config": burst_config, "simulator_index": simulator_index, "simulator_id": simulator_id, "user_id": user_id, }, ) thread.start() return burst_id, burst_config.name else: ## Continue simulation ## TODO return burst_config.id, burst_config.name
def launch_pse(self, **data): # TODO: Split into: set range values and Launch, show message with finished config and nr of simulations all_range_parameters = self.range_parameters.get_all_range_parameters() range_param1, range_param2 = SimulatorPSEParamRangeFragment.fill_from_post( all_range_parameters, **data) session_stored_simulator = common.get_from_session( common.KEY_SIMULATOR_CONFIG) project = common.get_current_project() user = common.get_logged_user() burst_config = common.get_from_session(common.KEY_BURST_CONFIG) burst_config.start_time = datetime.now() # if burst_name != 'none_undefined': # burst_config.name = burst_name # TODO: branch simulation name is different if burst_config.name is None: new_id = dao.get_max_burst_id() + 1 burst_config.name = 'simulation_' + str(new_id) operation_group = OperationGroup( project.id, ranges=[range_param1.to_json(), range_param2.to_json()]) operation_group = dao.store_entity(operation_group) metric_operation_group = OperationGroup( project.id, ranges=[range_param1.to_json(), range_param2.to_json()]) metric_operation_group = dao.store_entity(metric_operation_group) burst_config.operation_group = operation_group burst_config.operation_group_id = operation_group.id burst_config.metric_operation_group = metric_operation_group burst_config.metric_operation_group_id = metric_operation_group.id dao.store_entity(burst_config) try: thread = threading.Thread( target=self.simulator_service.async_launch_and_prepare_pse, kwargs={ 'burst_config': burst_config, 'user': user, 'project': project, 'simulator_algo': self.cached_simulator_algorithm, 'range_param1': range_param1, 'range_param2': range_param2, 'session_stored_simulator': session_stored_simulator }) thread.start() except BurstServiceException as e: self.logger.exception("Could not launch burst!") return {'error': e.message}
def launch_burst(self, burst_configuration, simulator_index, simulator_id, user_id, launch_mode=LAUNCH_NEW): """ Given a burst configuration and all the necessary data do the actual launch. :param burst_configuration: BurstConfiguration :param simulator_index: the position within the workflows step list that the simulator will take. This is needed so that the rest of the portlet workflow steps know what steps do their dynamic parameters come from. :param simulator_id: the id of the simulator adapter as stored in the DB. It's needed to load the simulator algo group and category that are then passed to the launcher's prepare_operation method. :param user_id: the id of the user that launched this burst :param launch_mode: new/branch/continue """ ## 1. Prepare BurstConfiguration entity if launch_mode == LAUNCH_NEW: ## Fully new entity for new simulation burst_config = burst_configuration.clone() if burst_config.name is None: new_id = dao.get_max_burst_id() + 1 burst_config.name = 'simulation_' + str(new_id) else: ## Branch or Continue simulation burst_config = burst_configuration simulation_state = dao.get_generic_entity(SIMULATION_DATATYPE_MODULE + "." + SIMULATION_DATATYPE_CLASS, burst_config.id, "fk_parent_burst") if simulation_state is None or len(simulation_state) < 1: exc = BurstServiceException("Simulation State not found for %s, " "thus we are unable to branch from it!" % burst_config.name) self.logger.error(exc) raise exc simulation_state = simulation_state[0] burst_config.update_simulation_parameter("simulation_state", simulation_state.gid) burst_config = burst_configuration.clone() count = dao.count_bursts_with_name(burst_config.name, burst_config.fk_project) burst_config.name = burst_config.name + "_" + launch_mode + str(count) ## 2. Create Operations and do the actual launch if launch_mode in [LAUNCH_NEW, LAUNCH_BRANCH]: ## New Burst entry in the history burst_id = self._store_burst_config(burst_config) thread = threading.Thread(target=self._async_launch_and_prepare, kwargs={'burst_config': burst_config, 'simulator_index': simulator_index, 'simulator_id': simulator_id, 'user_id': user_id}) thread.start() return burst_id, burst_config.name else: ## Continue simulation ## TODO return burst_config.id, burst_config.name
def launch_simulation(self, launch_mode, **data): current_form = SimulatorFinalFragment() try: current_form.fill_from_post(data) except Exception as exc: self.logger.exception(exc) return {'error': str(exc)} burst_name = current_form.simulation_name.value session_stored_simulator = common.get_from_session( common.KEY_SIMULATOR_CONFIG) is_simulator_copy = common.get_from_session( common.KEY_IS_SIMULATOR_COPY) project = common.get_current_project() user = common.get_logged_user() session_burst_config = common.get_from_session(common.KEY_BURST_CONFIG) if burst_name != 'none_undefined': session_burst_config.name = burst_name burst_config_to_store = session_burst_config simulation_state_index_gid = None if launch_mode == self.simulator_service.LAUNCH_NEW: if session_burst_config.name is None: new_id = dao.get_max_burst_id() + 1 session_burst_config.name = 'simulation_' + str(new_id) if is_simulator_copy: burst_config_to_store = session_burst_config.clone() else: burst_config_to_store = session_burst_config.clone() count = dao.count_bursts_with_name(session_burst_config.name, session_burst_config.project_id) session_burst_config.name = session_burst_config.name + "_" + launch_mode + str( count) simulation_state_index = dao.get_generic_entity( SimulationStateIndex.__module__ + "." + SimulationStateIndex.__name__, session_burst_config.id, "fk_parent_burst") if simulation_state_index is None or len( simulation_state_index) < 1: exc = BurstServiceException( "Simulation State not found for %s, thus we are unable to branch from " "it!" % session_burst_config.name) self.logger.error(exc) raise exc simulation_state_index_gid = simulation_state_index[0].gid burst_config_to_store.start_time = datetime.now() dao.store_entity(burst_config_to_store) try: thread = threading.Thread(target=self.simulator_service. async_launch_and_prepare_simulation, kwargs={ 'burst_config': burst_config_to_store, 'user': user, 'project': project, 'simulator_algo': self.cached_simulator_algorithm, 'session_stored_simulator': session_stored_simulator, 'simulation_state_gid': simulation_state_index_gid }) thread.start() return {'id': burst_config_to_store.id} except BurstServiceException as e: self.logger.exception('Could not launch burst!') return {'error': e.message}