Beispiel #1
0
    def on_task_start(self, task, config):
        if not config:
            return

        files = config
        if isinstance(config, basestring):
            files = [config]

        for name in files:
            name = os.path.expanduser(name)
            if not os.path.isabs(name):
                name = os.path.join(task.manager.config_base, name)
            include = yaml.load(io.open(name, encoding='utf-8'))
            errors = process_config(include,
                                    plugin.plugin_schemas(context='task'))
            if errors:
                log.error('Included file %s has invalid config:' % name)
                for error in errors:
                    log.error('[%s] %s', error.json_pointer, error.message)
                task.abort('Invalid config in included file %s' % name)
            log.debug('Merging %s into task %s' % (name, task.name))
            # merge
            try:
                merge_dict_from_to(include, task.config)
            except MergeException:
                raise plugin.PluginError(
                    'Failed to merge include file to task %s, incompatible datatypes'
                    % task.name)
Beispiel #2
0
def register_config_key():
    task_config_schema = {
        'type': 'object',
        'additionalProperties': plugin_schemas(context='task')
    }

    config_schema.register_config_key('tasks', task_config_schema, required=True)
    def on_task_start(self, task, config):
        if not config:
            return

        files = config
        if isinstance(config, basestring):
            files = [config]

        for name in files:
            name = os.path.expanduser(name)
            if not os.path.isabs(name):
                name = os.path.join(task.manager.config_base, name)
            include = yaml.load(io.open(name, encoding='utf-8'))
            errors = process_config(include, plugin.plugin_schemas(context='task'))
            if errors:
                log.error('Included file %s has invalid config:' % name)
                for error in errors:
                    log.error('[%s] %s', error.json_pointer, error.message)
                task.abort('Invalid config in included file %s' % name)
            log.debug('Merging %s into task %s' % (name, task.name))
            # merge
            try:
                merge_dict_from_to(include, task.config)
            except MergeException:
                raise plugin.PluginError('Failed to merge include file to task %s, incompatible datatypes' % task.name)
Beispiel #4
0
    def on_task_prepare(self, task, config):
        if not config:
            return

        files = config
        if isinstance(config, str):
            files = [config]

        for file_name in files:
            file = os.path.expanduser(file_name)
            if not os.path.isabs(file):
                file = os.path.join(task.manager.config_base, file)
            with io.open(file, encoding='utf-8') as inc_file:
                include = yaml.safe_load(inc_file)
                inc_file.flush()
            errors = process_config(include, plugin.plugin_schemas(interface='task'))
            if errors:
                logger.error('Included file {} has invalid config:', file)
                for error in errors:
                    logger.error('[{}] {}', error.json_pointer, error.message)
                task.abort('Invalid config in included file %s' % file)

            logger.debug('Merging {} into task {}', file, task.name)
            # merge
            try:
                task.merge_config(include)
            except MergeException:
                raise plugin.PluginError(
                    'Failed to merge include file to task %s, incompatible datatypes' % task.name
                )
Beispiel #5
0
    def on_task_prepare(self, task, config):
        if not config:
            return

        files = config
        if isinstance(config, str):
            files = [config]

        for file_name in files:
            file = os.path.expanduser(file_name)
            if not os.path.isabs(file):
                file = os.path.join(task.manager.config_base, file)
            with io.open(file, encoding='utf-8') as inc_file:
                include = yaml.load(inc_file)
                inc_file.flush()
            errors = process_config(include, plugin.plugin_schemas(interface='task'))
            if errors:
                log.error('Included file %s has invalid config:', file)
                for error in errors:
                    log.error('[%s] %s', error.json_pointer, error.message)
                task.abort('Invalid config in included file %s' % file)

            log.debug('Merging %s into task %s', file, task.name)
            # merge
            try:
                task.merge_config(include)
            except MergeException:
                raise plugin.PluginError('Failed to merge include file to task %s, incompatible datatypes' % task.name)
Beispiel #6
0
def register_config_key():
    task_config_schema = {
        'type': 'object',
        'additionalProperties': plugin_schemas(context='task')
    }

    config_schema.register_config_key('tasks', task_config_schema, required=True)
Beispiel #7
0
    def on_task_start(self, task, config):
        if not config:
            return

        files = config
        if isinstance(config, str):
            files = [config]

        for file_name in files:
            file_name = os.path.expanduser(file_name)
            if not os.path.isabs(file_name):
                file_name = os.path.join(task.manager.config_base, file_name)
            with io.open(file_name, encoding='utf-8') as inc_file:
                include = yaml.load(inc_file)
                inc_file.flush()
            errors = process_config(include,
                                    plugin.plugin_schemas(interface='task'))
            if errors:
                log.error('Included file %s has invalid config:', file_name)
                for error in errors:
                    log.error('[%s] %s', error.json_pointer, error.message)
                task.abort('Invalid config in included file %s' % file_name)

            new_hash = str(get_config_hash(include))
            with Session() as session:
                last_hash = session.query(LastHash).filter(
                    LastHash.task == task.name).filter(
                        LastHash.file == file_name).first()
                if not last_hash:
                    log.debug(
                        'no config hash detected for task %s with file %s, creating',
                        task.name, file_name)
                    last_hash = LastHash(task=task.name, file=file_name)
                    session.add(last_hash)
                if last_hash.hash != new_hash:
                    log.debug(
                        'new hash detected, triggering config change event')
                    task.config_changed()
                last_hash.hash = new_hash

            log.debug('Merging %s into task %s', file_name, task.name)
            # merge
            try:
                merge_dict_from_to(include, task.config)
            except MergeException:
                raise plugin.PluginError(
                    'Failed to merge include file to task %s, incompatible datatypes'
                    % task.name)
Beispiel #8
0
 def validate_config(config):
     schema = plugin_schemas(context='task')
     # Don't validate commented out plugins
     schema['patternProperties'] = {'^_': {}}
     return config_schema.process_config(config, schema)
Beispiel #9
0
 def validate_config(config):
     schema = plugin_schemas(context='task')
     # Don't validate commented out plugins
     schema['patternProperties'] = {'^_': {}}
     return config_schema.process_config(config, schema)
Beispiel #10
0
def register_config():
    root_config_schema = {
        'type': 'object',
        'additionalProperties': plugin.plugin_schemas(context='task')
    }
    register_config_key('templates', root_config_schema)
Beispiel #11
0
 def validate_config(config):
     schema = plugin_schemas(context="task")
     # Don't validate commented out plugins
     schema["patternProperties"] = {"^_": {}}
     return config_schema.process_config(config, schema)
Beispiel #12
0
            kwargs['options'] = exec_parser.parse_args(options_string, raise_errors=True).execute
        except ValueError as e:
            return jsonify(error='invalid options_string specified: %s' % e.message), 400

    # We'll stream the log results as they arrive in the bufferqueue
    kwargs['output'] = BufferQueue()
    manager.scheduler.execute(**kwargs)

    return Response(kwargs['output'], mimetype='text/plain'), 200


task_schema = {
    'type': 'object',
    'properties': {
        'name': {'type': 'string', 'description': 'The name of this task.'},
        'config': plugin_schemas(context='task')
    },
    'required': ['name'],
    'additionalProperties': False,
    'links': [
        {'rel': 'self', 'href': '/api/tasks/{name}/'},
        {'rel': 'edit', 'method': 'PUT', 'href': '', 'schema': {'$ref': '#'}},
        {'rel': 'delete', 'method': 'DELETE', 'href': ''}
    ]
}

tasks_schema = {
    'type': 'array',
    'items': {'$ref': '/schema/api/tasks/task'},
    'links': [
        {'rel': 'add', 'method': 'POST', 'href': '/api/tasks/', 'schema': {'$ref': '/schema/api/tasks/task'}}
Beispiel #13
0
def cs_plugin_container(section, name):

    return plugin_schemas(context='task')
Beispiel #14
0
    # We'll stream the log results as they arrive in the bufferqueue
    kwargs['output'] = BufferQueue()
    manager.scheduler.execute(**kwargs)

    return Response(kwargs['output'], mimetype='text/plain'), 200


task_schema = {
    'type':
    'object',
    'properties': {
        'name': {
            'type': 'string',
            'description': 'The name of this task.'
        },
        'config': plugin_schemas(context='task')
    },
    'required': ['name'],
    'additionalProperties':
    False,
    'links': [{
        'rel': 'self',
        'href': '/api/tasks/{name}/'
    }, {
        'rel': 'edit',
        'method': 'PUT',
        'href': '',
        'schema': {
            '$ref': '#'
        }
    }, {
Beispiel #15
0
def register_config_key():
    task_config_schema = {"type": "object", "additionalProperties": plugin_schemas(context="task")}

    config_schema.register_config_key("tasks", task_config_schema, required=True)
Beispiel #16
0
def cs_plugin_container(section, name):


    return plugin_schemas(context='task')
Beispiel #17
0
def register_config():
    root_config_schema = {
        'type': 'object',
        'additionalProperties': plugin.plugin_schemas(interface='task')
    }
    register_config_key('templates', root_config_schema)
Beispiel #18
0
            kwargs["options"] = exec_parser.parse_args(options_string, raise_errors=True).execute
        except ValueError as e:
            return jsonify(error="invalid options_string specified: %s" % e.message), 400

    # We'll stream the log results as they arrive in the bufferqueue
    kwargs["output"] = BufferQueue()
    manager.execute(**kwargs)

    return Response(kwargs["output"], mimetype="text/plain"), 200


task_schema = {
    "type": "object",
    "properties": {
        "name": {"type": "string", "description": "The name of this task."},
        "config": plugin_schemas(context="task"),
    },
    "required": ["name"],
    "additionalProperties": False,
    "links": [
        {"rel": "self", "href": "/api/tasks/{name}/"},
        {"rel": "edit", "method": "PUT", "href": "", "schema": {"$ref": "#"}},
        {"rel": "delete", "method": "DELETE", "href": ""},
    ],
}

tasks_schema = {
    "type": "object",
    "properties": {
        "tasks": {
            "type": "array",