Example #1
0
    def from_dict(dictionary):
        th = DictSerializer.load(dictionary, as_class=TaskHeader)
        th.last_checking = time.time()

        if isinstance(th.task_owner, dict):
            th.task_owner = DictSerializer.load(th.task_owner, as_class=Node)
        if hasattr(th, 'docker_images') and th.docker_images is not None:
            for i, di in enumerate(th.docker_images):
                if isinstance(di, dict):
                    th.docker_images[i] = DictSerializer.load(
                        di, as_class=DockerImage)
        return th
Example #2
0
 def from_dict(dictionary: dict) -> 'TaskHeader':
     th: TaskHeader = DictSerializer.load(dictionary, as_class=TaskHeader)
     if isinstance(th.fixed_header, dict):
         th.fixed_header = TaskFixedHeader.from_dict(th.fixed_header)
     if isinstance(th.mask, dict):
         th.mask = Mask.from_dict(th.mask)
     return th
Example #3
0
 def create_task(self, t_dict):
     try:
         task = DictSerializer.load(t_dict)
         new_task = self.enqueue_new_task(task)
         return unicode(new_task.header.task_id)
     except Exception:
         log.exception("Cannot create task {}".format(t_dict))
Example #4
0
 def _get_test_task_definition(cls) -> TaskDefinition:
     task_path = Path(__file__).parent / cls.TASK_FILE
     with open(task_path) as f:
         golem_path = get_golem_path()
         json_str = f.read().replace('$GOLEM_DIR',
                                     Path(golem_path).as_posix())
         return DictSerializer.load(json.loads(json_str))
    def test_load(self):
        client = self.client
        task_file_name = self._create_blender_task(client.get_dir_manager())

        def run_success(instance):
            instance.success_callback()

        def run_error(instance):
            instance.error_callback()

        with client_ctx(Tasks, client):

            with self._run_context(run_success):

                client.create_task.call_args = None
                client.create_task.called = False

                tasks = Tasks()
                tasks.load(task_file_name, True)

                call_args = client.create_task.call_args[0]
                assert len(call_args) == 1
                assert isinstance(DictSerializer.load(call_args[0]),
                                  BlenderRenderTask)

            with self._run_context(run_error):
                client.create_task.call_args = None
                client.create_task.called = False

                tasks = Tasks()
                tasks.load(task_file_name, True)

                call_args = client.create_task.call_args[0]

                assert len(call_args) == 1
                assert isinstance(DictSerializer.load(call_args[0]),
                                  BlenderRenderTask)

            with self._run_context(run_error):
                client.create_task.call_args = None
                client.create_task.called = False

                tasks = Tasks()

                with self.assertRaises(CommandException):
                    tasks.load(task_file_name, False)
Example #6
0
    def test_properties(self):
        obj = MockSerializationSubject()
        dict_repr = DictSerializer.dump(obj)

        self.assertTrue('property_1' in dict_repr)
        self.assertTrue('property_2' in dict_repr)
        self.assertFalse('_property_3' in dict_repr)
        self.assertFalse('method_1' in dict_repr)
        self.assertFalse('_method_2' in dict_repr)

        deserialized = DictSerializer.load(dict_repr)
        assert_properties(deserialized, obj)
Example #7
0
    def test_serialization_as_class(self):

        obj = MockSerializationSubject()
        dict_repr = DictSerializer.dump(obj)

        self.assertTrue(DictCoder.cls_key in dict_repr)
        self.assertTrue('property_1' in dict_repr)
        self.assertTrue('property_2' in dict_repr)
        self.assertTrue(
            isinstance(DictSerializer.load(dict_repr),
                       MockSerializationSubject))

        dict_repr = DictSerializer.dump(obj, typed=False)

        self.assertFalse(DictCoder.cls_key in dict_repr)
        self.assertTrue('property_1' in dict_repr)
        self.assertTrue('property_2' in dict_repr)
        self.assertTrue(isinstance(DictSerializer.load(dict_repr), dict))
        self.assertTrue(
            isinstance(
                DictSerializer.load(dict_repr,
                                    as_class=MockSerializationSubject),
                MockSerializationSubject))
Example #8
0
    def _run_test_task(self, t_dict):
        def on_success(*args, **kwargs):
            self.task_tester = None
            self._publish(Task.evt_task_test_status, TaskTestStatus.success,
                          *args, **kwargs)

        def on_error(*args, **kwargs):
            self.task_tester = None
            self._publish(Task.evt_task_test_status, TaskTestStatus.error,
                          *args, **kwargs)

        t = DictSerializer.load(t_dict)
        self.task_tester = TaskTester(t, self.datadir, on_success, on_error)
        self.task_tester.run()
        self._publish(Task.evt_task_test_status, TaskTestStatus.started, True)
Example #9
0
    def test_node(self, *_):
        c = self.client
        self.assertIsInstance(c.get_node(), dict)
        self.assertIsInstance(DictSerializer.load(c.get_node()), Node)

        self.assertIsInstance(c.get_node_key(), unicode)
        self.assertIsNotNone(c.get_node_key())

        c.node.key = None

        self.assertNotIsInstance(c.get_node_key(), unicode)
        self.assertIsNone(c.get_node_key())

        self.assertIsInstance(c.get_public_key(), bytes)
        self.assertEqual(c.get_public_key(), c.keys_auth.public_key)
Example #10
0
    def from_dict(dictionary) -> 'TaskFixedHeader':
        if 'subtasks_count' not in dictionary:
            logger.debug(
                "Subtasks count missing. Implicit 1. dictionary=%r",
                dictionary,
            )
            dictionary['subtasks_count'] = 1
        th: TaskFixedHeader = \
            DictSerializer.load(dictionary, as_class=TaskFixedHeader)
        th.last_checking = time.time()

        if isinstance(th.task_owner, dict):
            th.task_owner = Node.from_dict(th.task_owner)

        th.update_checksum()
        return th
Example #11
0
    def task_status_changed(self, task_id):
        if task_id in self.tasks:
            ts_dict = yield self.client.query_task_state(task_id)
            ts = DictSerializer.load(ts_dict)
            if not isinstance(ts, TaskState):
                raise TypeError(
                    "Incorrect task state type: {}. Should be TaskState".
                    format(ts))
            self.tasks[task_id].task_state = ts
            self.customizer.update_tasks(self.tasks)
            if ts.status in task_to_remove_status:
                self.client.delete_task(task_id)
        else:
            logger.warning("Unknown task_id {}".format(task_id))

        if self.customizer.current_task_highlighted.definition.task_id == task_id:
            self.customizer.update_task_additional_info(self.tasks[task_id])
Example #12
0
    def register_client(self, client):
        # client is golem.rpc.session.Client
        datadir = yield client.get_datadir()
        config_dict = yield client.get_settings()
        client_id = yield client.get_key_id()
        payment_address = yield client.get_payment_address()
        description = yield client.get_description()

        config = DictSerializer.load(config_dict)

        self.client = client
        self.datadir = datadir
        self.node_name = config.node_name
        self.dir_manager = DirManager(self.datadir)

        self.customizer.init_config()
        self.customizer.set_options(config, client_id, payment_address,
                                    description)

        if not self.node_name:
            self.customizer.prompt_node_name(self.node_name)
Example #13
0
 def get_config(self):
     config_dict = yield self.client.get_settings()
     returnValue(DictSerializer.load(config_dict))
Example #14
0
 def update_settings(self, settings_dict, run_benchmarks=False):
     cfg_desc = DictSerializer.load(settings_dict)
     self.change_config(cfg_desc, run_benchmarks)