コード例 #1
0
    def load_burst_from_json(self, **data):
        """Upload Burst from previously exported JSON file"""
        self.logger.debug("Uploading ..." + str(data))

        try:
            upload_param = "uploadedfile"
            if upload_param in data and data[upload_param]:

                upload_param = data[upload_param]
                if isinstance(upload_param, FieldStorage) or isinstance(
                        upload_param, Part):
                    if not upload_param.file:
                        raise BurstServiceException(
                            "Please select a valid JSON file.")
                    upload_param = upload_param.file.read()

                upload_param = json.loads(upload_param)
                prj_id = common.get_current_project().id
                importer = ImportService()
                burst_entity = importer.load_burst_entity(upload_param, prj_id)
                common.add2session(common.KEY_BURST_CONFIG, burst_entity)

        except Exception as excep:
            self.logger.warning(excep.message)
            common.set_error_message(excep.message)

        raise cherrypy.HTTPRedirect('/burst/')
コード例 #2
0
    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
コード例 #3
0
    def get_simulation_state_index(self, burst_config,
                                   simulation_history_class):
        parent_burst = burst_config.parent_burst_object
        simulation_state_index = dao.get_generic_entity(
            simulation_history_class, parent_burst.gid, "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!" % burst_config.name)
            self.logger.error(exc)
            raise exc

        return simulation_state_index
コード例 #4
0
    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}