Ejemplo n.º 1
0
    def register_workflow(roc_link, workflow_submitter: User, workflow_version,
                          workflow_uuid=None, workflow_identifier=None,
                          workflow_registry: Optional[models.WorkflowRegistry] = None,
                          authorization=None, name=None):

        # find or create a user workflow
        if workflow_registry:
            w = workflow_registry.get_workflow(workflow_uuid or workflow_identifier)
        else:
            w = models.Workflow.get_user_workflow(workflow_submitter, workflow_uuid)
        if not w:
            w = models.Workflow(uuid=workflow_uuid, identifier=workflow_identifier, name=name)
            w.permissions.append(Permission(user=workflow_submitter, roles=[RoleType.owner]))
            if workflow_registry:
                for auth in workflow_submitter.get_authorization(workflow_registry):
                    auth.resources.append(w)

        if str(workflow_version) in w.versions:
            raise lm_exceptions.WorkflowVersionConflictException(workflow_uuid, workflow_version)
        if not roc_link:
            if not workflow_registry:
                raise ValueError("Missing ROC link")
            else:
                roc_link = workflow_registry.build_ro_link(workflow_submitter, w.external_id)

        wv = w.add_version(workflow_version, roc_link, workflow_submitter,
                           name=name, hosting_service=workflow_registry)
        wv.permissions.append(Permission(user=workflow_submitter, roles=[RoleType.owner]))
        if authorization:
            auth = ExternalServiceAuthorizationHeader(workflow_submitter, header=authorization)
            auth.resources.append(wv)
        if name is None:
            w.name = wv.dataset_name
            wv.name = wv.dataset_name
        if wv.test_metadata:
            logger.debug("Test metadata found in the crate")
            # FIXME: the test metadata can describe more than one suite
            wv.add_test_suite(workflow_submitter, wv.test_metadata)
        w.save()
        return wv
Ejemplo n.º 2
0
    def register_workflow(
            cls,
            roc_link,
            workflow_submitter: User,
            workflow_version,
            workflow_uuid=None,
            workflow_identifier=None,
            workflow_registry: Optional[models.WorkflowRegistry] = None,
            authorization=None,
            name=None):

        # find or create a user workflow
        if workflow_registry:
            w = workflow_registry.get_workflow(workflow_uuid
                                               or workflow_identifier)
        else:
            w = models.Workflow.get_user_workflow(workflow_submitter,
                                                  workflow_uuid)
        if not w:
            w = models.Workflow(uuid=workflow_uuid,
                                identifier=workflow_identifier,
                                name=name)
            if workflow_submitter:
                w.permissions.append(
                    Permission(user=workflow_submitter,
                               roles=[RoleType.owner]))
                if workflow_registry:
                    for auth in workflow_submitter.get_authorization(
                            workflow_registry):
                        auth.resources.append(w)

        if str(workflow_version) in w.versions:
            raise lm_exceptions.WorkflowVersionConflictException(
                workflow_uuid, workflow_version)
        if not roc_link:
            if not workflow_registry:
                raise ValueError("Missing ROC link")
            else:
                roc_link = workflow_registry.build_ro_link(
                    workflow_submitter, w.external_id)

        wv = w.add_version(workflow_version,
                           roc_link,
                           workflow_submitter,
                           name=name,
                           hosting_service=workflow_registry)

        if workflow_submitter:
            wv.permissions.append(
                Permission(user=workflow_submitter, roles=[RoleType.owner]))
        if authorization:
            auth = ExternalServiceAuthorizationHeader(workflow_submitter,
                                                      header=authorization)
            auth.resources.append(wv)
        if name is None:
            w.name = wv.dataset_name
            wv.name = wv.dataset_name

        # parse roc_metadata and register suites and instances
        try:
            for _, raw_suite in wv.roc_suites.items():
                cls._init_test_suite_from_json(wv, workflow_submitter,
                                               raw_suite)
        except KeyError as e:
            raise lm_exceptions.SpecificationNotValidException(
                f"Missing property: {e}")
        w.save()
        return wv