Esempio n. 1
0
    def __init__(self, application_id, plugin_info):
        self.logger = Log("single.controller.log", "controller.log")
        configure_logging()

        self.application_id = application_id
        self.instances = plugin_info["instances"]
        self.check_interval = plugin_info["check_interval"]
        self.trigger_down = plugin_info["trigger_down"]
        self.trigger_up = plugin_info["trigger_up"]
        self.min_cap = plugin_info["min_cap"]
        self.max_cap = plugin_info["max_cap"]
        self.actuation_size = plugin_info["actuation_size"]
        self.metric_rounding = plugin_info["metric_rounding"]
        self.actuator_type = plugin_info["actuator"]
        self.metric_source_type = plugin_info["metric_source"]

        self.running = True
        self.running_lock = threading.RLock()

        metric_source = MetricSourceBuilder().get_metric_source(
            self.metric_source_type, plugin_info)

        actuator = ActuatorBuilder().get_actuator(self.actuator_type,
                                                  plugin_info)

        self.alarm = BasicAlarm(actuator, metric_source, self.trigger_down,
                                self.trigger_up, self.min_cap, self.max_cap,
                                self.actuation_size, self.metric_rounding)
Esempio n. 2
0
    def __init__(self, metric_source, actuator, plugin_info):
        # Set up logging
        self.logger = Log("basic.controller.log", "controller.log")
        configure_logging()

        check_interval = plugin_info["check_interval"]
        trigger_down = plugin_info["trigger_down"]
        trigger_up = plugin_info["trigger_up"]
        min_cap = plugin_info["min_cap"]
        max_cap = plugin_info["max_cap"]
        actuation_size = plugin_info["actuation_size"]
        metric_rounding = plugin_info["metric_rounding"]

        # Start alarm
        self.alarm = BasicAlarm(actuator, metric_source, trigger_down,
                                trigger_up, min_cap, max_cap, actuation_size,
                                metric_rounding)

        # Start up controller thread
        # Create lock to access application list
        self.applications_lock = threading.RLock()
        self.applications = {}
        self.controller = _BasicControllerThread(self.applications,
                                                 self.applications_lock,
                                                 self.alarm, check_interval)

        self.controller_thread = threading.Thread(target=self.controller.start)
        self.controller_thread.start()
Esempio n. 3
0
 def __init__(self):
     self.monasca_username = api.monasca_username
     self.monasca_password = api.monasca_password
     self.monasca_auth_url = api.monasca_auth_url
     self.monasca_project_name = api.monasca_project_name
     self.monasca_api_version = api.monasca_api_version
     self._get_monasca_client()
     self.LOG = Log('monasca_client_log', 'monasca_client.log')
Esempio n. 4
0
    def __init__(self, app_id, k8s_manifest):

        try:
            config.load_kube_config(k8s_manifest)
        except Exception:
            raise Exception("Couldn't load kube config")
        self.k8s_api = client.BatchV1Api()
        self.app_id = app_id
        self.logger = Log("basic.controller.log", "controller.log")
Esempio n. 5
0
    def __init__(self, applications, applications_lock, alarm, check_interval):
        self.logger = Log("basic.controller_thread.log", "controller.log")
        configure_logging()

        self.applications = applications
        self.applications_lock = applications_lock
        self.alarm = alarm
        self.check_interval = check_interval
        self.running = True
Esempio n. 6
0
 def __init__(self, parameters):
     self.keypair_path = parameters['keypair_path']
     self.host_ip = parameters['host_ip']
     self.log_path = parameters['log_path']
     self.start_time = parameters['start_time']
     self.expected_time = parameters['reference_value']
     self.host_username = '******'
     self.last_checked = ''
     self.logger = Log("metrics.log", "metrics.log")
     configure_logging()
Esempio n. 7
0
    def __init__(self, actuator, metric_source, trigger_down, trigger_up,
                 min_cap, max_cap, actuation_size, metric_rounding):

        self.metric_source = metric_source
        self.actuator = actuator
        self.trigger_down = trigger_down
        self.trigger_up = trigger_up
        self.min_cap = min_cap
        self.max_cap = max_cap
        self.metric_rounding = metric_rounding
        self.actuation_size = actuation_size

        self.logger = Log("proportional.alarm.log", "controller.log")
        self.cap_logger = Log("cap.log", "cap.log")

        configure_logging()

        self.last_progress_error_timestamp = datetime.datetime.strptime(
            "0001-01-01T00:00:00.0Z", '%Y-%m-%dT%H:%M:%S.%fZ')
        self.last_progress_error = None
        self.cap = -1
        self.last_action = ""
    def __init__(self, actuator, metric_source, trigger_down, trigger_up,
                 min_cap, max_cap, actuation_size, metric_rounding):

        # TODO: Check parameters
        self.metric_source = metric_source
        self.actuator = actuator
        self.trigger_down = trigger_down
        self.trigger_up = trigger_up
        self.min_cap = min_cap
        self.max_cap = max_cap
        self.actuation_size = actuation_size
        self.metric_rounding = metric_rounding

        self.logger = Log("basic.alarm.log", "controller.log")
        configure_logging()

        self.last_time_progress_timestamp = datetime.datetime.strptime(
            "0001-01-01T00:00:00.0Z", '%Y-%m-%dT%H:%M:%S.%fZ')

        self.last_job_progress_timestamp = datetime.datetime.strptime(
            "0001-01-01T00:00:00.0Z", '%Y-%m-%dT%H:%M:%S.%fZ')
    def __init__(self, application_id, plugin_info):
        self.logger = Log(
            "tendency.proportional.controller.log", "controller.log")
        configure_logging()

        plugin_info = plugin_info["plugin_info"]

        self.application_id = application_id
        self.instances = plugin_info["instances"]
        self.check_interval = plugin_info["check_interval"]
        self.trigger_down = plugin_info["trigger_down"]
        self.trigger_up = plugin_info["trigger_up"]
        self.min_cap = plugin_info["min_cap"]
        self.max_cap = plugin_info["max_cap"]
        self.metric_rounding = plugin_info["metric_rounding"]
        self.actuation_size = plugin_info["actuation_size"]
        self.actuator_type = plugin_info["actuator"]
        self.metric_source_type = plugin_info["metric_source"]

        self.running = True
        self.running_lock = threading.RLock()

        # Gets a new metric source plugin using the given name
        metric_source = MetricSourceBuilder().get_metric_source(
                            self.metric_source_type, plugin_info
                        )

        # Gets a new actuator plugin using the given name
        actuator = ActuatorBuilder().get_actuator(self.actuator_type,
                                                  plugin_info)

        """ The alarm here is responsible for deciding whether to scale up or
            down, or even do nothing """
        self.alarm = TendencyAwareProportionalAlarm(actuator, metric_source,
                                                    self.trigger_down,
                                                    self.trigger_up,
                                                    self.min_cap,
                                                    self.max_cap,
                                                    self.actuation_size,
                                                    self.metric_rounding)
Esempio n. 10
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from controller.plugins.actuator.builder import ActuatorBuilder
from controller.plugins.controller.builder import ControllerBuilder
from controller.service import plugin_service
from controller.utils.logger import Log
from controller.exceptions import api as ex
from threading import Thread

API_LOG = Log("APIv10", "APIv10.log")

scaled_apps = {}

controller_builder = ControllerBuilder()
actuator_builder = ActuatorBuilder()


def install_plugin(source, plugin):
    status = plugin_service.install_plugin(source, plugin)
    if status:
        return {"message": "Plugin installed successfully"}, 200
    return {"message": "Error installing plugin"}, 400


def setup_environment(data):
Esempio n. 11
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import traceback

import flask
from werkzeug import datastructures

from controller.exceptions import api as ex
from controller.utils import serializer as u_serializer
from controller.utils.logger import Log

LOG = Log("UtilsAPI", "utilsapi.log")


class Rest(flask.Blueprint):
    def get(self, rule, status_code=200):
        return self._mroute('GET', rule, status_code)

    def post(self, rule, status_code=202):
        return self._mroute('POST', rule, status_code)

    def post_file(self, rule, status_code=202):
        return self._mroute('POST', rule, status_code, file_upload=True)

    def put(self, rule, status_code=204):
        return self._mroute('PUT', rule, status_code)
Esempio n. 12
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import configparser
from controller.utils.logger import Log

LOG = Log('api_log', 'api.log')

try:
    # Conf reading
    config = configparser.RawConfigParser()
    config.read('./controller.cfg')
    """ General configuration """
    host = config.get("general", "host")
    port = config.getint("general", "port")
    actuator_plugins = config.get('general', 'actuator_plugins').split(',')
    metric_source_plugins = config.get('general',
                                       'metric_source_plugins').split(',')
    """ Validate if really exists a section to listed plugins """
    for plugin in actuator_plugins:
        if plugin != '' and plugin not in config.sections():
            raise Exception("plugin '%s' section missing" % plugin)
Esempio n. 13
0
 def __init__(self, parameters):
     self.rds = redis.StrictRedis(host=parameters['redis_ip'],
                                  port=parameters['redis_port'])
     self.LOG = Log('redis_log', 'redis.log')
     self.last_metric = 0.0
     self.last_timestamp = datetime.datetime.now()