コード例 #1
0
    def load_burst_entity(self, json_burst, project_id):
        """
        Load BurstConfiguration from JSON (possibly exported from a different machine).
        Nothing gets persisted in DB or on disk.

        :param json_burst: Burst JSON export
        :param project_id: Current project ID (it will be used if the user later starts this simulation)
        :return: BurstConfiguration  filled from JSON
        """

        burst_information = BurstInformation.load_from_dict(json_burst)
        burst_entity = model.BurstConfiguration(project_id)
        burst_entity.from_dict(burst_information.data)
        burst_entity.prepare_after_load()
        burst_entity.reset_tabs()

        workflow_info = burst_information.get_workflows()[0]
        workflow_entity = model.Workflow(project_id, None)
        workflow_entity.from_dict(workflow_info.data)

        view_steps = workflow_info.get_view_steps()
        analyze_steps = workflow_info.get_workflow_steps()

        for view_step in view_steps:
            try:
                algorithm = view_step.get_algorithm()
                portlet = view_step.get_portlet()
                view_step_entity = model.WorkflowStepView(
                    algorithm.id, portlet_id=portlet.id)
                view_step_entity.from_dict(view_step.data)
                view_step_entity.workflow = workflow_entity

                ## For each visualize step, also load all of the analyze steps.
                analyzers = []
                for an_step in analyze_steps:
                    if (an_step.data["tab_index"] != view_step_entity.tab_index
                            or an_step.data["index_in_tab"] !=
                            view_step_entity.index_in_tab):
                        continue
                    algorithm = an_step.get_algorithm()
                    wf_step_entity = model.WorkflowStep(algorithm.id)
                    wf_step_entity.from_dict(an_step.data)
                    wf_step_entity.workflow = workflow_entity
                    analyzers.append(wf_step_entity)

                portlet = PortletConfiguration(portlet.id)
                portlet.set_visualizer(view_step_entity)
                portlet.set_analyzers(analyzers)
                burst_entity.set_portlet(view_step_entity.tab_index,
                                         view_step_entity.index_in_tab,
                                         portlet)

            except Exception:
                # only log exception and ignore this step from loading
                self.logger.exception("Could not restore Workflow Step " +
                                      view_step.get_algorithm().name)

        return burst_entity
コード例 #2
0
 def create_and_store_workflow(project_id, burst_id, simulator_index,
                               simulator_id, operations):
     """
     Create and store the workflow given the project, user and burst in which the workflow is created.
     :param simulator_index: the index of the simulator in the workflow
     :param simulator_id: the id of the simulator adapter
     :param operations: a list with the operations created for the simulator steps
     """
     workflows = []
     for operation in operations:
         new_workflow = model.Workflow(project_id, burst_id)
         new_workflow = dao.store_entity(new_workflow)
         workflows.append(new_workflow)
         simulation_step = model.WorkflowStep(
             algorithm_id=simulator_id,
             workflow_id=new_workflow.id,
             step_index=simulator_index,
             static_param=operation.parameters)
         simulation_step.fk_operation = operation.id
         dao.store_entity(simulation_step)
     return workflows
コード例 #3
0
 def import_workflows(self, project, bursts_dict, burst_ids_mapping):
     """
     Import the workflow entities for all bursts imported in the project.
     :param project: the current
     :param bursts_dict: a dictionary that holds all the required information in order to
                         import the bursts from the new project
     :param burst_ids_mapping: a dictionary of the form {old_burst_id : new_burst_id} so we
                         know what burst to link each workflow to
     """
     for burst_id in bursts_dict:
         workflows_info = bursts_dict[burst_id].get_workflows()
         for one_wf_info in workflows_info:
             # Use the new burst id when creating the workflow
             workflow_entity = model.Workflow(
                 project.id, burst_ids_mapping[int(burst_id)])
             workflow_entity.from_dict(one_wf_info.data)
             workflow_entity = dao.store_entity(workflow_entity)
             wf_steps_info = one_wf_info.get_workflow_steps()
             view_steps_info = one_wf_info.get_view_steps()
             self.import_workflow_steps(workflow_entity, wf_steps_info,
                                        view_steps_info)