Exemplo n.º 1
0
    def update_task(self, task: Task) -> Task:
        with self._session():
            t: STask = self._get_sql_object_by_id(self.tasks, task.id)
            if t is None:
                raise NonExistingTaskError(task)
            kwargs = STask.get_kwargs(task)
            kwargs.pop('models', None)
            kwargs.pop('images', None)
            kwargs.pop('pipelines', None)
            update_attrs(t, **kwargs)

            for m in t.models:
                if m.id in task.models:
                    self.update_model(task.models.get(m.id))
                else:
                    task._models.add(m.to_obj())
            for p in t.pipelines:
                if p.id in task.pipelines:
                    self.update_pipeline(task.pipelines.get(p.id))
                else:
                    task._images.add(p.to_obj())

            for i in t.images:
                if i.id in task.images:
                    self.update_image(task.images.get(i.id))
                else:
                    task._images.add(i.to_obj())
            return task
Exemplo n.º 2
0
 def delete_task(self, task: Task):
     if task.id is None:
         raise NonExistingTaskError(task)
     if self.get_models(task) or self.get_pipelines(
             task) or self.get_images(task):
         raise TaskWithFKError(task)
     self.data.remove_task(task.id)
     self.save()
     task.unbind_meta_repo()
Exemplo n.º 3
0
    def create_model(self, model: Model) -> Model:
        self._validate_model(model)

        existing_task = self.get_task_by_id(model.task_id)
        if existing_task is None:
            raise NonExistingTaskError(model.task_id)

        if self.get_model_by_name(model.name, existing_task) is not None:
            raise ExistingModelError(model)

        model._id = self.data.get_and_increment('next_model_id')
        self.data.add_model(copy.deepcopy(model))
        self.save()
        return model
Exemplo n.º 4
0
    def create_image(self, image: Image) -> Image:
        self._validate_image(image)

        task = self.get_task_by_id(image.task_id)
        if task is None:
            raise NonExistingTaskError(image.task_id)

        if self.get_image_by_name(image.name, task) is not None:
            raise ExistingImageError(image)

        image._id = self.data.get_and_increment('next_image_id')
        self.data.add_image(copy.deepcopy(image))
        self.save()
        return image
Exemplo n.º 5
0
    def create_pipeline(self, pipeline: Pipeline) -> Pipeline:
        self._validate_pipeline(pipeline)

        existing_task = self.get_task_by_id(pipeline.task_id)
        if existing_task is None:
            raise NonExistingTaskError(pipeline.task_id)

        if self.get_pipeline_by_name(pipeline.name, existing_task) is not None:
            raise ExistingPipelineError(pipeline)

        pipeline._id = self.data.get_and_increment('next_pipeline_id')
        self.data.add_pipeline(copy.deepcopy(pipeline))
        self.save()
        return pipeline
Exemplo n.º 6
0
    def create_model(self, model: Model) -> Model:
        self._validate_model(model)

        existing_task = self.get_task_by_id(model.task_id)
        if existing_task is None:
            raise NonExistingTaskError(model.task_id)

        if self.get_model_by_name(model.name, existing_task) is not None:
            raise ExistingModelError(model)

        model._id = str(uuid.uuid4())
        existing_task._models.add(model)
        self.data.add_model(copy.deepcopy(model))
        self.save()
        return model
Exemplo n.º 7
0
    def update_image(self, image: Image) -> Image:
        self._validate_image(image)

        existing_task = self.get_task_by_id(image.task_id)
        if existing_task is None:
            raise NonExistingTaskError(image.task_id)

        existing_image = self.get_image_by_id(image.id)
        if existing_image is None:
            raise NonExistingImageError(image)

        self.data.remove_image(image.id)
        self.data.add_image(copy.deepcopy(image))
        self.save()
        return image
Exemplo n.º 8
0
 def update_task(self, task: Task) -> Task:
     with self._session(False) as s:
         t: STask = self._get_sql_object_by_id(self.tasks, task.id)
         if t is None:
             raise NonExistingTaskError(task)
         kwargs = STask.get_kwargs(task)
         kwargs.pop('models', None)
         update_attrs(t, **kwargs)
         s.commit()
         for m in t.models:
             mid = str(m.id)
             if mid in task.models:
                 self.update_model(task.models.get(mid))
             else:
                 task._models.add(m.to_obj())
         return task
Exemplo n.º 9
0
    def update_model(self, model: Model) -> Model:
        self._validate_model(model)

        task = self.get_task_by_id(model.task_id)
        if task is None:
            raise NonExistingTaskError(model.task_id)

        existing_model = self.get_model_by_id(model.id)
        if existing_model is None:
            raise NonExistingModelError(model)

        self.data.remove_model(model.id)
        model_copy = copy.deepcopy(model)
        self.data.add_model(model_copy)
        self.save()
        return model
Exemplo n.º 10
0
    def update_task(self, task: Task) -> Task:
        if task.id is None or self.get_task_by_id(task.id) is None:
            raise NonExistingTaskError(task)
        self._validate_task(task)

        existing_project = self.get_project_by_id(task.project_id)
        if existing_project is None:
            raise NonExistingProjectError(task.project_id)

        self.data.remove_task(task.id, False)
        task_copy = copy.deepcopy(task)
        self.data.add_task(task_copy)
        for model in task_copy.models.values():
            self.save_model(model)
        self.save()
        return task
Exemplo n.º 11
0
    def update_pipeline(self, pipeline: Pipeline) -> Pipeline:
        self._validate_pipeline(pipeline)

        task = self.get_task_by_id(pipeline.task_id)
        if task is None:
            raise NonExistingTaskError(pipeline.task_id)

        existing_pipeline = self.get_pipeline_by_id(pipeline.id)
        if existing_pipeline is None:
            raise NonExistingPipelineError(pipeline)

        self.data.remove_pipeline(pipeline.id)
        pipeline_copy = copy.deepcopy(pipeline)
        self.data.add_pipeline(pipeline_copy)
        self.save()
        return pipeline
Exemplo n.º 12
0
 def delete_task(self, task: Task):
     if task.id is None:
         raise NonExistingTaskError(task)
     self.data.remove_task(task.id, True)
     self.save()
     task.unbind_meta_repo()
Exemplo n.º 13
0
 def create_image(self, image: Image) -> Image:
     self._validate_image(image)
     if self._get_sql_object_by_id(self.tasks, image.task_id) is None:
         raise NonExistingTaskError(image.task_id)
     return self._create_object(self.images, image, ExistingImageError)
Exemplo n.º 14
0
 def create_pipeline(self, pipeline: Pipeline) -> Pipeline:
     self._validate_pipeline(pipeline)
     if self._get_sql_object_by_id(self.tasks, pipeline.task_id) is None:
         raise NonExistingTaskError(pipeline.task_id)
     return self._create_object(self.pipelines, pipeline,
                                ExistingPipelineError)
Exemplo n.º 15
0
 def create_model(self, model: Model) -> Model:
     self._validate_model(model)
     if self._get_sql_object_by_id(self.tasks, model.task_id) is None:
         raise NonExistingTaskError(model.task_id)
     return self._create_object(self.models, model, ExistingModelError)