Пример #1
0
def get_test_node():
    node = Node()
    node.title = 'Command 1x1'
    node.description = 'Any command with 1 arg'
    node.base_node_name = "command"

    node.inputs = []
    node.inputs.append(Input())
    node.inputs[-1].name = 'in'
    node.inputs[-1].file_types = [FileTypes.FILE]
    node.inputs[-1].values = []

    node.outputs = []
    node.outputs.append(Output())
    node.outputs[-1].name = 'out'
    node.outputs[-1].file_type = FileTypes.FILE
    node.outputs[-1].resource_id = None

    node.parameters = []
    node.parameters.append(Parameter())
    node.parameters[-1].name = 'number'
    node.parameters[-1].parameter_type = ParameterTypes.INT
    node.parameters[-1].value = -1
    node.parameters[-1].widget = ParameterWidget.from_dict({'alias': 'Number'})

    node.parameters.append(Parameter())
    node.parameters[-1].name = 'cmd'
    node.parameters[-1].parameter_type = ParameterTypes.STR
    node.parameters[-1].value = 'cat ${input[in]} | grep ${param[text]} > ${output[out]}'
    node.parameters[-1].widget = ParameterWidget.from_dict({'alias': 'Command line'})

    return node
Пример #2
0
    def test_serialization(self):
        node1 = get_test_node()
        node1_dict = node1.to_dict()
        node2 = Node.from_dict(node1_dict)
        node2_dict = node2.to_dict()

        print(node1_dict)
        print("-")
        print(node2_dict)

        self.assertTrue(compare_dictionaries(node1_dict, node2_dict), "Serialized nodes are not equal")
Пример #3
0
 def get_default(cls):
     node = Node()
     node.title = ''
     node.description = ''
     node.base_node_name = cls.get_base_name()
     node.node_status = NodeStatus.CREATED
     node.public = False
     node.parameters = [
         Parameter.from_dict({
             'name': 'cmd',
             'parameter_type': ParameterTypes.TEXT,
             'value': 'bash -c " "',
             'mutable_type': False,
             'publicable': False,
             'removable': False,
         }),
         Parameter.from_dict({
             'name': 'cacheable',
             'parameter_type': ParameterTypes.BOOL,
             'value': True,
             'mutable_type': False,
             'publicable': False,
             'removable': False,
         })
     ]
     node.logs = [
         Output.from_dict({
             'name': 'stderr',
             'file_type': FileTypes.FILE,
             'resource_id': None,
         }),
         Output({
             'name': 'stdout',
             'file_type': FileTypes.FILE,
             'resource_id': None,
         }),
         Output({
             'name': 'worker',
             'file_type': FileTypes.FILE,
             'resource_id': None,
         }),
     ]
     return node
Пример #4
0
 def get_default(cls):
     node = Node()
     node.title = ''
     node.description = ''
     node.base_node_name = cls.get_base_name()
     node.node_status = NodeStatus.CREATED
     node.public = False
     node.parameters = [
         Parameter(name='resource_id',
                   parameter_type=ParameterTypes.STR,
                   value='hello',
                   mutable_type=False,
                   publicable=True,
                   removable=False)
     ]
     node.outputs = [
         Output(name='out', file_type=FileTypes.FILE, resource_id=None)
     ]
     return node
Пример #5
0
    def upgrade_nodes(graph):
        """Upgrade deprecated Nodes.

        The function does not change the Graph in the database.

        Return:
            (int)   Number of upgraded Nodes
        """
        node_ids = set(
            [to_object_id(node.parent_node) for node in graph.nodes])
        db_nodes = GraphCollectionManager.node_collection_manager.get_db_nodes_by_ids(
            node_ids)
        new_node_db_mapping = {}

        for db_node in db_nodes:
            original_parent_node_id = db_node['_id']
            new_db_node = db_node
            if original_parent_node_id not in new_node_db_mapping:
                while new_db_node[
                        'node_status'] != NodeStatus.READY and 'successor_node' in new_db_node and new_db_node[
                            'successor_node']:
                    n = GraphCollectionManager.node_collection_manager.get_db_node(
                        new_db_node['successor_node'])
                    if n:
                        new_db_node = n
                    else:
                        break
                new_node_db_mapping[original_parent_node_id] = new_db_node

        new_nodes = [
            GraphCollectionManager._transplant_node(
                node,
                Node.from_dict(new_node_db_mapping[to_object_id(
                    node.parent_node)])) for node in graph.nodes
        ]

        upgraded_nodes_count = sum(
            1 for node, new_node in zip(graph.nodes, new_nodes)
            if node.parent_node != new_node.parent_node)

        graph.nodes = new_nodes
        return upgraded_nodes_count
Пример #6
0
def post_node():
    app.logger.debug(request.data)
    try:
        body = json.loads(request.data)['body']

        node = Node.from_dict(body['node'])
        node.author = g.user._id

        action = body['action']
        if action == NodePostAction.SAVE:
            if node.node_status != NodeStatus.CREATED and node.base_node_name != 'file':
                return _make_fail_response('Cannot save node with status `{}`'.format(node.node_status))

            node.save(force=True)

        elif action == NodePostAction.APPROVE:
            if node.node_status != NodeStatus.CREATED:
                return _make_fail_response('Node status `{}` expected. Found `{}`'.format(NodeStatus.CREATED, node.node_status))
            validation_error = node.get_validation_error()
            if validation_error:
                return JSONEncoder().encode({
                    'status': NodePostStatus.VALIDATION_FAILED,
                    'message': 'Node validation failed',
                    'validation_error': validation_error.to_dict()
                })

            node.node_status = NodeStatus.READY
            node.save(force=True)

        elif action == NodePostAction.VALIDATE:
            validation_error = node.get_validation_error()

            if validation_error:
                return JSONEncoder().encode({
                    'status': NodePostStatus.VALIDATION_FAILED,
                    'message': 'Node validation failed',
                    'validation_error': validation_error.to_dict()
                })
        elif action == NodePostAction.DEPRECATE:
            if node.node_status == NodeStatus.CREATED:
                return _make_fail_response('Node status `{}` not expected.'.format(node.node_status))

            node.node_status = NodeStatus.DEPRECATED
            node.save(force=True)
        elif action == NodePostAction.MANDATORY_DEPRECATE:
            if node.node_status == NodeStatus.CREATED:
                return _make_fail_response('Node status `{}` not expected.'.format(node.node_status))

            node.node_status = NodeStatus.MANDATORY_DEPRECATED
            node.save(force=True)
        elif action == NodePostAction.PREVIEW_CMD:
            job = node_collection.make_job(node)

            return JSONEncoder().encode(
                {
                    'status': NodePostStatus.SUCCESS,
                    'message': 'Successfully created preview',
                    'preview_text': job.run(preview=True)
                })

        else:
            return _make_fail_response('Unknown action `{}`'.format(action))

        return JSONEncoder().encode(
            {
                'status': NodePostStatus.SUCCESS,
                'message': 'Node(_id=`{}`) successfully updated'.format(str(node._id))
            })
    except Exception as e:
        app.logger.error(e)
        return _make_fail_response('Internal error: "{}"'.format(str(e)))