# Path: project/autoscaling/autoscaling/scaler.py
# class Scaler(object):
#     """docstring for ClassName"""
#     def __init__(self, marathon_client, app):
#         self.logger = logging.getLogger("Scaler")
#         self.marathon_client = marathon_client
#         self.app = app
# 
#     def scale(self, delta):
#         """sacle app_name (add or remove) delta intances
# 
#         @param int delta number intances add if (delta > 0) or remove if (delta < 0)
#         """
#         current_instances = self.marathon_client.get_app("app-"+self.app.uuid).instances
#         new_instance = current_instances + delta
#         if(new_instance > self.app.max_instances):
#             new_instance = self.app.max_instances
#         if(new_instance < self.app.min_instances):
#             new_instance = self.app.min_instances
#         if(new_instance != current_instances):
#             self.logger.info("scale to: %d", new_instance)
#             self.marathon_client.scale_app("app-"+self.app.uuid, new_instance)
#         else:
#             self.logger.info("number instances to threshold, no scale!")
# 
# Path: project/autoscaling/autoscaling/monitor.py
# class Monitor(object):
#     """docstring for Moniter"""
# 
#     def __init__(self, influxdb_client, app):
#         """init
# 
#         @param model.WebApp app
#         """
#         self.influxdb_client = influxdb_client
#         self.app = app
# 
#     def get_metrics(self):
#         query = "SELECT COUNT(DISTINCT(mesos_task_id)), MEAN(cpu_usage), MEAN(mem_usage)  FROM monitoring where app_uuid = 'app-{}' and time > now()-1m group by time(10s)".format(self.app.uuid)
#         metrics = self.influxdb_client.query(query)
#         if metrics:
#             points = metrics[0]["points"]
#             if points:
#                 return points[0]
#         return None


from .autoscaling import *
from .model import *
from .scaler import Scaler
from .monitor import Monitor
import logging
import time

class BaseRuleDecider(Decider):
    """docstring for BaseRuleDecider"""

    def __init__(self,app, influxdb_client, marathon_client):
        """init

        @param model.WebApp app
        """
        self.logger = logging.getLogger("BaseRuleDecider")
        self.app = app

# Path: project/autoscaling/autoscaling/scaler.py
# class Scaler(object):
#     """docstring for ClassName"""
#     def __init__(self, marathon_client, app):
#         self.logger = logging.getLogger("Scaler")
#         self.marathon_client = marathon_client
#         self.app = app
# 
#     def scale(self, delta):
#         """sacle app_name (add or remove) delta intances
# 
#         @param int delta number intances add if (delta > 0) or remove if (delta < 0)
#         """
#         current_instances = self.marathon_client.get_app("app-"+self.app.uuid).instances
#         new_instance = current_instances + delta
#         if(new_instance > self.app.max_instances):
#             new_instance = self.app.max_instances
#         if(new_instance < self.app.min_instances):
#             new_instance = self.app.min_instances
#         if(new_instance != current_instances):
#             self.logger.info("scale to: %d", new_instance)
#             self.marathon_client.scale_app("app-"+self.app.uuid, new_instance)
#         else:
#             self.logger.info("number instances to threshold, no scale!")
# 
# Path: project/autoscaling/autoscaling/monitor.py
# class Monitor(object):
#     """docstring for Moniter"""
# 
#     def __init__(self, influxdb_client, app):
#         """init
# 
#         @param model.WebApp app
#         """
#         self.influxdb_client = influxdb_client
#         self.app = app
# 
#     def get_metrics(self):
#         query = "SELECT COUNT(DISTINCT(mesos_task_id)), MEAN(cpu_usage), MEAN(mem_usage)  FROM monitoring where app_uuid = 'app-{}' and time > now()-1m group by time(10s)".format(self.app.uuid)
#         metrics = self.influxdb_client.query(query)
#         if metrics:
#             points = metrics[0]["points"]
#             if points:
#                 return points[0]
#         return None


# Path: project/autoscaling/autoscaling/decider.py
from .autoscaling import *
from .model import *
from .scaler import Scaler
from .monitor import Monitor
import logging
import time


class BaseRuleDecider(Decider):
    """docstring for BaseRuleDecider"""

    def __init__(self,app, influxdb_client, marathon_client):
        """init

        @param model.WebApp app
        """
        self.logger = logging.getLogger("BaseRuleDecider")
        self.app = app

        self.scaler = Scaler(marathon_client, app)