def launch_taskflow(user, body):
    # Perform some validation
    taskFlowBody = body.get('taskFlowBody')
    if taskFlowBody is None:
        raise RestException('taskFlowBody is a required key')

    if 'taskFlowClass' not in taskFlowBody:
        raise RestException('taskFlowClass is required in taskFlowBody')

    taskflow_class = taskFlowBody['taskFlowClass']

    # Check that we can load the taskflow class
    try:
        load_class(taskflow_class)
    except Exception as ex:
        msg = 'Unable to load taskflow class: %s (%s)' % \
              (taskflow_class, ex)
        raise RestException(msg, 400)

    # Set up the taskflow input
    taskFlowInput = body.get('taskFlowInput', {})
    if 'cluster' not in taskFlowInput:
        # Make a cluster
        taskFlowInput['cluster'] = create_cluster_object(user)

    if 'container' not in taskFlowInput:
        taskFlowInput['container'] = 'docker'

    # Load the queue
    queue = fetch_or_create_queue(user)

    # Create the taskflow
    taskflow = TaskflowModel().create(user, taskFlowBody)

    # Add it to the queue and start it
    QueueModel().add(queue, taskflow, taskFlowInput, user)
    QueueModel().pop(queue, limit=sys.maxsize, user=user)

    return taskflow['_id']
Esempio n. 2
0
    def create(self, params):
        user = self.getCurrentUser()
        taskflow = getBodyJson()

        self.requireParams(['taskFlowClass'], taskflow)

        # Check that we can load the class
        try:
            load_class(taskflow['taskFlowClass'])
        except Exception as ex:
            msg = 'Unable to load taskflow class: %s (%s)' % \
                  (taskflow['taskFlowClass'], ex)
            logger.exception(msg)
            traceback.print_exc()
            raise RestException(msg, 400)
        taskflow = self._model.create(user, taskflow)

        cherrypy.response.status = 201
        cherrypy.response.headers['Location'] = '/taskflows/%s' % \
                                                taskflow['_id']

        return taskflow
Esempio n. 3
0
    def start(self, taskflow, params):
        user = self.getCurrentUser()

        try:
            params = getBodyJson()
        except RestException:
            params = {}

        constructor = load_class(taskflow['taskFlowClass'])
        token = self.model('token').createToken(user=user, days=7)

        workflow = constructor(id=str(taskflow['_id']),
                               girder_token=token['_id'],
                               girder_api_url=cumulus.config.girder.baseUrl)

        workflow.start(**params)
Esempio n. 4
0
    def _start_taskflow(self, taskflow_id, params, user):
        taskflow = TaskflowModel().load(taskflow_id, user=user)

        constructor = load_class(taskflow['taskFlowClass'])
        token = ModelImporter.model('token').createToken(user=user, days=7)

        workflow = constructor(id=str(taskflow['_id']),
                               girder_token=token['_id'],
                               girder_api_url=cumulus.config.girder.baseUrl)

        if params is None:
            params = {}

        workflow.start(**params)

        return workflow
Esempio n. 5
0
    def terminate(self, taskflow, params):
        user = getCurrentUser()
        taskflow['status'] = TaskFlowState.TERMINATING

        self._model.save(taskflow)
        constructor = load_class(taskflow['taskFlowClass'])
        token = self.model('token').createToken(user=user, days=7)
        taskflow_instance = constructor(
            id=str(taskflow['_id']),
            girder_token=token['_id'],
            girder_api_url=cumulus.config.girder.baseUrl)

        # Set the meta data
        taskflow_instance['meta'] = taskflow.get('meta', {})
        # Mark the taskflow as being used to termination
        taskflow_instance['terminate'] = True

        taskflow_instance.terminate()
Esempio n. 6
0
    def _start_taskflow(self, taskflow_id, params, user):
        taskflow = TaskflowModel().load(taskflow_id, user=user)

        constructor = load_class(taskflow['taskFlowClass'])
        token = self.model('token').createToken(user=user, days=7)

        workflow = constructor(
            id=str(taskflow['_id']),
            girder_token=token['_id'],
            girder_api_url=cumulus.config.girder.baseUrl
        )

        if params is None:
            params = {}

        workflow.start(**params)

        return workflow
Esempio n. 7
0
    def delete(self, taskflow, params):
        user = self.getCurrentUser()

        status = self._model.status(user, taskflow)
        if status == TaskFlowState.RUNNING:
            raise RestException('Taskflow is running', 400)

        constructor = load_class(taskflow['taskFlowClass'])
        token = self.model('token').createToken(user=user, days=7)

        if taskflow['status'] != TaskFlowState.DELETING:

            taskflow['status'] = TaskFlowState.DELETING
            self._model.save(taskflow)

            workflow = constructor(
                id=str(taskflow['_id']),
                girder_token=token['_id'],
                girder_api_url=cumulus.config.girder.baseUrl)

            workflow.delete()

            # Check if we have any active tasks, it not then we are done and
            # can delete the tasks and taskflows
            taskflow = self._model.load(taskflow['_id'],
                                        user=user,
                                        level=AccessType.ADMIN)
            if taskflow['activeTaskCount'] == 0:
                self._model.delete(taskflow)
                cherrypy.response.status = 200
                taskflow['status'] = TaskFlowState.DELETED

                return taskflow

        cherrypy.response.status = 202
        return taskflow