aboutsummaryrefslogtreecommitdiffstats
path: root/moon_engine/moon_engine/orchestration_driver.py
blob: 85ca436dc289e75d0179dfe42c7be6555b44bc90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Software Name: MOON

# Version: 5.4

# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors
# SPDX-License-Identifier: Apache-2.0

# This software is distributed under the 'Apache License 2.0',
# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt'
# or see the "LICENSE" file for more details.


import logging
from moon_engine.api import configuration
from moon_engine.api.orchestration import pipeline

logger = logging.getLogger("moon.engine.orchestration_driver")


PipelineManager = None


class Driver:

    def __init__(self, driver_name, engine_name):
        self.name = driver_name
        self.plug = configuration.get_orchestration_driver()
        self.driver = self.plug.Connector(driver_name, engine_name)


class PipelineDriver(Driver):

    def __init__(self, driver_name, engine_name):
        super(PipelineDriver, self).__init__(driver_name, engine_name)
        self.engine = engine_name

    def update_pipeline(self, pipeline_id, data):
        """Update a pipeline

        :param pipeline_id: the ID of the pipeline
        :param data: a dictionary {
            "name": "the name of the pipeline",
            "description": "the description of the pipeline",
            "wrapper": {"url": "http://127.0.0.1:20000"},
            # "wrapper": {"url": "local"}  # if the pipeline should be configured inside the wrapper
            "plugins": ["moon_engine.plugins.authz", ]  # the first plugin is the default
        }
        :return: the pipeline updated
        """
        raise NotImplementedError()  # pragma: no cover

    def delete_pipeline(self, pipeline_id):
        """Delete the pipeline

        :param pipeline_id: the ID of the pipeline
        :return: True if the pipeline has been deleted
        """
        raise NotImplementedError()  # pragma: no cover

    def add_pipeline(self, pipeline_id=None, data=None):
        """Create a new pipeline

        :param pipeline_id: (optional) the ID of the pipeline to create
        :param data: a dictionary {
            "name": "the name of the pipeline",
            "description": "the description of the pipeline",
            "wrapper": {"url": "http://127.0.0.1:20000"},
            # "wrapper": {"url": "local"}  # if the pipeline should be configured inside the wrapper
            "plugins": ["moon_engine.plugins.authz", ]  # the first plugin is the default
        }
        :return: the pipeline created
        """
        raise NotImplementedError()  # pragma: no cover

    def get_pipelines(self, pipeline_id=None):
        """List one or more pipelines

        :param pipeline_id: (optional) the ID of the pipeline to list
        :return: a list of one or more pipelines
        """
        raise NotImplementedError()  # pragma: no cover

    def get_pipeline_api_key(self, pipeline_id):
        """Returns the api key of the pipeline with id pipeline_id

        :param pipeline_id: the ID of the pipeline to list
        :return: The api key of the pipeline
        """
        raise NotImplementedError()  # pragma: no cover


def init():
    global PipelineManager

    logger.info("Initializing driver")
    conf = configuration.get_configuration("orchestration")

    PipelineManager = pipeline.PipelineManager(
        PipelineDriver(conf['driver'], conf.get('url'))
    )